Skip to content

Commit c5a5e54

Browse files
committed
bob*: modularize init-container extra commands
1 parent fa769ec commit c5a5e54

File tree

3 files changed

+37
-17
lines changed

3 files changed

+37
-17
lines changed

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

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ su -s /bin/sh searcher -c "cd ~ && podman run -d \
4141
while true; do /usr/sbin/sshd -D -e; sleep 5; done'"
4242

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

6565
echo "Applying iptables rules in $NAME (PID: $pid) network namespace..."
66+
ns_iptables() { nsenter --target "$pid" --net iptables "$@" }
6667

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
68+
ns_iptables -A OUTPUT -d 169.254.169.254 -j DROP
7069

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
70+
ns_iptables -A OUTPUT -p tcp --dport 9000 -j DROP
71+
ns_iptables -A OUTPUT -p udp --dport 9000 -j DROP
7372

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
73+
ns_iptables -A OUTPUT -p udp --dport 123 -j DROP
7774

78-
echo "Injecting static hosts into $NAME..."
75+
ns_iptables -A OUTPUT -p udp --sport $SEARCHER_INPUT_CHANNEL -j DROP
76+
ns_iptables -A OUTPUT -p tcp --sport $SEARCHER_INPUT_CHANNEL -j DROP
7977

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-
'"
78+
# Helper, only used in sourced script below
79+
exec_in_container() {
80+
su -s /bin/sh searcher -c "podman exec $NAME /bin/sh -c '$1'"
81+
}
82+
83+
# Run extra commands which are customized per image,
84+
# see bob*/mkosi.extra/etc/searcher-container-init-extra
85+
#
86+
# `source` is not supported in dash
87+
. /etc/searcher-container-init-extra
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# This script is sourced from init-container.sh and contains image-specific stuff
2+
# See also: bob-common/mkosi.extra/usr/bin/init-container.sh
3+
4+
echo "Injecting static hosts into searcher container..."
5+
exec_in_container '
6+
cat <<EOF >> /etc/hosts
7+
3.149.14.12 tx.tee-searcher.flashbots.net
8+
3.136.107.142 tx.tee-searcher.flashbots.net
9+
18.221.59.61 backruns.tee-searcher.flashbots.net
10+
3.15.88.156 backruns.tee-searcher.flashbots.net
11+
52.207.17.217 fbtee.titanbuilder.xyz
12+
EOF'
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# This script is sourced from init-container.sh and contains image-specific stuff
2+
# See also: bob-common/mkosi.extra/usr/bin/init-container.sh
3+
4+
echo "Injecting static hosts into searcher container..."
5+
exec_in_container '
6+
cat <<EOF >> /etc/hosts
7+
EOF'

0 commit comments

Comments
 (0)