Skip to content

Commit b7c7076

Browse files
authored
Merge pull request #41 from flashbots/ilya/more-bob-l1-refactors
More BoB-L1 refactors, prep for BoB-L2
2 parents 7fc2ea1 + 860db35 commit b7c7076

File tree

29 files changed

+1740
-71
lines changed

29 files changed

+1740
-71
lines changed

Makefile

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,23 +39,30 @@ setup: ## Install dependencies (Linux only)
3939

4040
# Build module
4141
build: check-perms setup ## Build the specified module
42-
@$(WRAPPER) mkosi --force -I $(IMAGE).conf
42+
$(WRAPPER) mkosi --force -I $(IMAGE).conf
4343

4444
# Build module with devtools profile
4545
build-dev: check-perms setup ## Build module with development tools
46-
@$(WRAPPER) mkosi --force --profile=devtools -I $(IMAGE).conf
46+
$(WRAPPER) mkosi --force --profile=devtools -I $(IMAGE).conf
4747

4848
##@ Utilities
4949

50-
# Run measured-boot on the EFI file
51-
measure: ## Export TDX measurements for the built image
50+
measure: ## Export TDX measurements for the built EFI file
5251
@if [ ! -f build/tdx-debian.efi ]; then \
5352
echo "Error: build/tdx-debian.efi not found. Run 'make build' first."; \
5453
exit 1; \
5554
fi
5655
@$(WRAPPER) measured-boot build/tdx-debian.efi build/measurements.json --direct-uki
5756
echo "Measurements exported to build/measurements.json"
5857

58+
measure-gcp: ## Export TDX measurements for GCP
59+
@if [ ! -f build/tdx-debian.efi ]; then \
60+
echo "Error: build/tdx-debian.efi not found. Run 'make build' first."; \
61+
exit 1; \
62+
fi
63+
@$(WRAPPER) dstack-mr -uki build/tdx-debian.efi -json > build/gcp_measurements.json
64+
echo "GCP Measurements exported to build/gcp_measurements.json"
65+
5966
# Clean build artifacts
6067
clean: ## Remove cache and build artifacts
6168
rm -rf build/ mkosi.builddir/ mkosi.cache/ lima-nix/

base/debloat.sh

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ debloat_paths=(
2323
"/usr/share/bug"
2424
"/usr/share/menu"
2525
"/usr/share/systemd"
26-
"/usr/share/bash-completion"
2726
"/usr/share/zsh"
2827
"/usr/share/mime"
2928
"/usr/lib/modules"
@@ -40,4 +39,13 @@ debloat_paths=(
4039
"/nix"
4140
)
4241

43-
for p in "${debloat_paths[@]}"; do rm -rf $BUILDROOT$p; done
42+
if [[ ! "$PROFILES" == *"devtools"* ]]; then
43+
debloat_paths+=(
44+
"/usr/share/bash-completion"
45+
)
46+
fi
47+
48+
for p in "${debloat_paths[@]}"; do
49+
echo "Debloating $p"
50+
rm -rf $BUILDROOT$p
51+
done

base/mkosi.conf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ BuildPackages=build-essential
4242
cmake
4343
pkg-config
4444
clang
45-
cargo
4645
flex
4746
bison
4847
elfutils

bob-common/mkosi.conf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ Packages=podman
1515
iproute2
1616
conntrack
1717
netfilter-persistent
18-
openntpd
1918
curl
2019
jq
2120
logrotate

bob-common/mkosi.extra/etc/systemd/system/searcher-firewall.service

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[Unit]
22
Description=Searcher Network and Firewall Rules
3-
After=azure-complete-provisioning.service
4-
Requires=azure-complete-provisioning.service
3+
After=network.target network-setup.service
4+
Requires=network-setup.service
55

66
[Service]
77
Type=oneshot

bob-common/mkosi.extra/usr/bin/init-container.sh

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,30 @@ NAME=searcher-container
55

66
# PORT FORWARDS
77
SEARCHER_SSH_PORT=10022
8-
ENGINE_API_PORT=8551
98
EL_P2P_PORT=30303
109
SEARCHER_INPUT_CHANNEL=27017
1110

11+
# Run extra commands which are customized per image,
12+
# see bob*/mkosi.extra/etc/bob/searcher-container-before-init
13+
#
14+
# `source` is not supported in dash
15+
. /etc/bob/searcher-container-before-init
16+
17+
# BOB_SEARCHER_EXTRA_PODMAN_FLAGS is unescaped, it's sourced from trusted hardcoded file
18+
1219
echo "Starting $NAME..."
1320
su -s /bin/sh searcher -c "cd ~ && podman run -d \
1421
--name $NAME --replace \
1522
--init \
1623
-p ${SEARCHER_SSH_PORT}:22 \
17-
-p ${ENGINE_API_PORT}:${ENGINE_API_PORT} \
1824
-p ${EL_P2P_PORT}:${EL_P2P_PORT} \
1925
-p ${EL_P2P_PORT}:${EL_P2P_PORT}/udp \
2026
-p ${SEARCHER_INPUT_CHANNEL}:${SEARCHER_INPUT_CHANNEL}/udp \
2127
-v /persistent/searcher:/persistent:rw \
2228
-v /etc/searcher/ssh_hostkey:/etc/searcher/ssh_hostkey:rw \
2329
-v /persistent/searcher_logs:/var/log/searcher:rw \
24-
-v /persistent/cl_logs:/var/log/cl:ro \
25-
-v /tmp/jwt.hex:/secrets/jwt.hex:ro \
2630
-v /etc/searcher-logrotate.conf:/tmp/searcher.conf:ro \
31+
$BOB_SEARCHER_EXTRA_PODMAN_FLAGS \
2732
docker.io/library/ubuntu:24.04 \
2833
/bin/sh -c ' \
2934
DEBIAN_FRONTEND=noninteractive apt-get update && \
@@ -41,7 +46,7 @@ su -s /bin/sh searcher -c "cd ~ && podman run -d \
4146
while true; do /usr/sbin/sshd -D -e; sleep 5; done'"
4247

4348
# Attempt a quick check that the container is running
44-
for i in 1 2 3 4 5; do
49+
for i in $(seq 1 5); do
4550
status=$(su -s /bin/sh - searcher -c "podman inspect --format '{{.State.Status}}' $NAME 2>/dev/null || true")
4651
if [ "$status" = "running" ]; then
4752
break
@@ -63,24 +68,25 @@ if [ -z "$pid" ] || [ "$pid" = "0" ]; then
6368
fi
6469

6570
echo "Applying iptables rules in $NAME (PID: $pid) network namespace..."
71+
ns_iptables() {
72+
nsenter --target "$pid" --net iptables "$@"
73+
}
74+
75+
ns_iptables -A OUTPUT -d 169.254.169.254 -j DROP
6676

67-
# Enter network namespace and apply DROP rules on port 9000 TCP/UDP
68-
nsenter --target "$pid" --net iptables -A OUTPUT -p tcp --dport 9000 -j DROP
69-
nsenter --target "$pid" --net iptables -A OUTPUT -p udp --dport 9000 -j DROP
77+
ns_iptables -A OUTPUT -p tcp --dport 9000 -j DROP
78+
ns_iptables -A OUTPUT -p udp --dport 9000 -j DROP
7079

71-
# Enter network namespace and apply DROP rule on port 123 UDP
72-
nsenter --target "$pid" --net iptables -A OUTPUT -p udp --dport 123 -j DROP
80+
ns_iptables -A OUTPUT -p udp --dport 123 -j DROP
7381

74-
# Drop outbound traffic from SEARCHER_INPUT_CHANNEL
75-
nsenter --target "$pid" --net iptables -A OUTPUT -p udp --sport $SEARCHER_INPUT_CHANNEL -j DROP
76-
nsenter --target "$pid" --net iptables -A OUTPUT -p tcp --sport $SEARCHER_INPUT_CHANNEL -j DROP
82+
ns_iptables -A OUTPUT -p udp --sport $SEARCHER_INPUT_CHANNEL -j DROP
83+
ns_iptables -A OUTPUT -p tcp --sport $SEARCHER_INPUT_CHANNEL -j DROP
7784

78-
echo "Injecting static hosts into $NAME..."
85+
# Helper, only used in sourced script below
86+
exec_in_container() {
87+
su -s /bin/sh searcher -c "podman exec $NAME /bin/sh -c '$1'"
88+
}
7989

80-
su -s /bin/sh searcher -c "podman exec $NAME /bin/sh -c '
81-
echo \"3.149.14.12 tx.tee-searcher.flashbots.net\" >> /etc/hosts &&
82-
echo \"3.136.107.142 tx.tee-searcher.flashbots.net\" >> /etc/hosts &&
83-
echo \"18.221.59.61 backruns.tee-searcher.flashbots.net\" >> /etc/hosts &&
84-
echo \"3.15.88.156 backruns.tee-searcher.flashbots.net\" >> /etc/hosts &&
85-
echo \"52.207.17.217 fbtee.titanbuilder.xyz\" >> /etc/hosts
86-
'"
90+
# Run extra commands which are customized per image,
91+
# see bob*/mkosi.extra/etc/bob/searcher-container-after-init
92+
. /etc/bob/searcher-container-after-init

bob-common/mkosi.extra/usr/bin/init-firewall.sh

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ set -eu -o pipefail
2020
# ├(loopback?)─> ACCEPT
2121
# └─> default DROP
2222
#
23-
# - There are no ports opened in this file, refer to bob*/mkosi.extra/etc/firewall-config
23+
# - There are no ports opened in this file, refer to bob*/mkosi.extra/etc/bob/firewall-config
2424
# for actual chain rules.
2525
# - Mode-specific ESTABLISHED/RELATED connections are killed by
2626
# `conntrack -D ...` upon mode toggle.
@@ -98,7 +98,7 @@ iptables -A OUTPUT ! -o lo -d 127.0.0.0/8 -j DROP
9898

9999
###########################################################################
100100
#
101-
# Some helper functions to reduce boilerplate in /etc/firewall-config
101+
# Some helper functions to reduce boilerplate in /etc/bob/firewall-config
102102
#
103103
###########################################################################
104104
accept_dst_port() {
@@ -124,14 +124,22 @@ accept_dst_ip_port() {
124124
-m comment --comment "$comment"
125125
}
126126

127+
drop_dst_ip() {
128+
chain="$1"
129+
ip="$2"
130+
comment="$3"
131+
132+
iptables -A "$chain" -d "$ip" -j DROP \
133+
-m comment --comment "$comment"
134+
}
127135

128136
###########################################################################
129137
# (5) Load firewall rules in {MAINTENANCE,PRODUCTION}_{IN,OUT} chains.
130-
# Those are customized per image, see bob*/mkosi.extra/etc/firewall-config
138+
# Those are customized per image, see bob*/mkosi.extra/etc/bob/firewall-config
131139
#
132140
# `source` is not supported in dash
133141
###########################################################################
134-
. /etc/firewall-config
142+
. /etc/bob/firewall-config
135143

136144
###########################################################################
137145
# (6) Start in Maintenance Mode

bob-common/mkosi.postinst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ mkdir "$BUILDROOT/etc/dropbear"
2222
mkdir -p "$BUILDROOT/etc/systemd/system/minimal.target.wants"
2323
for service in \
2424
network-setup.service \
25-
openntpd.service \
2625
logrotate.service \
2726
fluent-bit.service \
2827
wait-for-key.service \

bob-l1/mkosi.conf

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
[Build]
2-
Environment=LIGHTHOUSE_BINARY KERNEL_CONFIG_SNIPPETS=bob-l1/kernel.config
2+
Environment=LIGHTHOUSE_BINARY KERNEL_CONFIG_SNIPPETS=bob-l1/kernel.config KERNEL_VERSION=6.13.12
33
WithNetwork=true
44

55
[Content]
66
ExtraTrees=bob-l1/mkosi.extra
77
PostInstallationScripts=bob-l1/mkosi.postinst
88
BuildScripts=bob-l1/mkosi.build
99

10+
Packages=openntpd
11+
1012
BuildPackages=build-essential
1113
git
1214
gcc
15+
cargo
1316
zlib1g-dev
1417
libzstd-dev
1518
libleveldb-dev

bob-l1/mkosi.extra/etc/firewall-config renamed to bob-l1/mkosi.extra/etc/bob/firewall-config

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,7 @@ accept_dst_port $CHAIN_MAINTENANCE_IN udp $EL_P2P_PORT "EL P2P (UDP)"
8484
###########################################################################
8585

8686
# Block Flashbots protect tx endpoints during maintenance
87-
iptables -A $CHAIN_MAINTENANCE_OUT \
88-
-d $FLASHBOTS_TX_STREAM_1,$FLASHBOTS_TX_STREAM_2 -j DROP \
89-
-m comment --comment "Flashbots Protect (DROP before accept-all 443)"
87+
drop_dst_ip $CHAIN_MAINTENANCE_OUT $FLASHBOTS_TX_STREAM_1,$FLASHBOTS_TX_STREAM_2 "Flashbots Protect (DROP before accept-all rules)"
9088

9189
accept_dst_port $CHAIN_MAINTENANCE_OUT udp $DNS_PORT "DNS (UDP)"
9290
accept_dst_port $CHAIN_MAINTENANCE_OUT tcp $DNS_PORT "DNS (TCP)"

0 commit comments

Comments
 (0)