Skip to content

Commit 7016df1

Browse files
authored
firecracker: fix docker -p (#11427)
Docker v28 configures direct-access filtering via iptables `-t raw` for published ports. As a result, commands like `docker run -p <port>` fail with > iptables ... can't initialize iptables table `raw': Table does not exist because our current guest kernel configs all have `CONFIG_IP_NF_RAW` disabled. Repro: run the same `bb execute` command with firecracker isolation, with and without `--action_env=DOCKER_INSECURE_NO_IPTABLES_RAW=1`; manually start `dockerd &`, sleep for a bit then run `docker run -p ...` Fix: - Set `DOCKER_INSECURE_NO_IPTABLES_RAW=1` unconditionally when starting dockerd in goinit. Includes an inline note explaining why this is safe for our VM sandboxing model. - Add TODOs at the top of all guest kernel config files to enable `CONFIG_NF_TABLES` and remove the env-var fallback. (I don't want to do this right now since I think it's slightly risky, so I'd rather save this for when we incrementally start migrating to our new 6.1 config) - Update docker-in-firecracker coverage to include `docker run -p ...` on a newer docker version. Context: https://buildbuddy-corp.slack.com/archives/C0AFN0SMNG5/p1772129387671119?thread_ts=1772012498.295389&cid=C0AFN0SMNG5
1 parent 334b660 commit 7016df1

File tree

6 files changed

+24
-11
lines changed

6 files changed

+24
-11
lines changed

enterprise/server/cmd/goinit/main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,9 @@ func startDockerd(ctx context.Context) error {
192192
if *enableDockerdTCP {
193193
args = append(args, "--host=unix:///var/run/docker.sock", "--host=tcp://0.0.0.0:2375", "--tls=false")
194194
}
195-
196195
cmd := exec.CommandContext(ctx, "dockerd", args...)
196+
// Note: despite the big scary INSECURE env var name, dockerd is completely sandboxed inside a VM, so it's secure for our usage. Once we upgrade our guest kernels to support nf tables, we can remove this.
197+
cmd.Env = append(os.Environ(), "DOCKER_INSECURE_NO_IPTABLES_RAW=1")
197198
// TODO(https://github.com/buildbuddy-io/buildbuddy-internal/issues/3306):
198199
// enable logging by default
199200
if *enableLogging {

enterprise/server/remote_execution/containers/firecracker/firecracker.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ const (
120120
//
121121
// NOTE: this is part of the snapshot cache key, so bumping this version
122122
// will make existing cached snapshots unusable.
123-
GuestAPIVersion = "17"
123+
GuestAPIVersion = "18"
124124

125125
// How long to wait when dialing the vmexec server inside the VM.
126126
vSocketDialTimeout = 60 * time.Second

enterprise/server/remote_execution/containers/firecracker/firecracker_test.go

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,9 @@ const (
7575
// Alternate image to use if getting rate-limited by docker hub
7676
// busyboxImage = "gcr.io/google-containers/busybox:latest"
7777

78-
ubuntuImage = "mirror.gcr.io/library/ubuntu:20.04"
79-
imageWithDockerInstalled = "gcr.io/flame-public/executor-docker-default:enterprise-v1.6.0"
78+
ubuntuImage = "mirror.gcr.io/library/ubuntu:20.04"
79+
imageWithDockerInstalled = "gcr.io/flame-public/executor-docker-default:enterprise-v1.6.0"
80+
imageWithDockerV28Installed = platform.Ubuntu24_04Image
8081

8182
// Minimum memory needed for a firecracker VM. This may need to be increased
8283
// if the size of initrd.cpio increases.
@@ -150,8 +151,8 @@ func TestGuestAPIVersion(t *testing.T) {
150151
// Note that if you go with option 1, ALL VM snapshots will be invalidated
151152
// which will negatively affect customer experience. Be careful!
152153
const (
153-
expectedHash = "25c5043d9c3d465c5fe2e974da0e532fe113365182aa8fe59c0c1e028064562b"
154-
expectedVersion = "17"
154+
expectedHash = "d6e20637585cf821192d1b13d34b87316307ae286b4c31d27307052a3d7df45c"
155+
expectedVersion = "18"
155156
)
156157
assert.Equal(t, expectedHash, firecracker.GuestAPIHash)
157158
assert.Equal(t, expectedVersion, firecracker.GuestAPIVersion)
@@ -2455,7 +2456,7 @@ func TestFirecrackerRunNOPWithZeroDisk(t *testing.T) {
24552456
assert.Equal(t, "/workspace\n", string(res.Stdout))
24562457
}
24572458

2458-
func TestFirecrackerRunWithDockerOverUDS(t *testing.T) {
2459+
func testFirecrackerRunWithDockerOverUDS(t *testing.T, containerImage string) {
24592460
if *skipDockerTests {
24602461
t.Skip()
24612462
}
@@ -2472,7 +2473,7 @@ func TestFirecrackerRunWithDockerOverUDS(t *testing.T) {
24722473
docker pull ` + busyboxImage + ` &>/dev/null
24732474
24742475
# Try running a few commands
2475-
docker run --rm ` + busyboxImage + ` echo Hello
2476+
docker run --rm -p 127.0.0.1:18080:80 ` + busyboxImage + ` echo Hello
24762477
docker run --rm ` + busyboxImage + ` echo world
24772478
24782479
# Check what storage driver docker is using
@@ -2481,7 +2482,7 @@ func TestFirecrackerRunWithDockerOverUDS(t *testing.T) {
24812482
}
24822483

24832484
opts := firecracker.ContainerOpts{
2484-
ContainerImage: imageWithDockerInstalled,
2485+
ContainerImage: containerImage,
24852486
ActionWorkingDirectory: workDir,
24862487
VMConfiguration: &fcpb.VMConfiguration{
24872488
NumCpus: 1,
@@ -2512,6 +2513,14 @@ func TestFirecrackerRunWithDockerOverUDS(t *testing.T) {
25122513
assert.Equal(t, "", string(res.Stderr), "stderr should be empty")
25132514
}
25142515

2516+
func TestFirecrackerRunWithDockerOverUDS(t *testing.T) {
2517+
testFirecrackerRunWithDockerOverUDS(t, imageWithDockerInstalled)
2518+
}
2519+
2520+
func TestFirecrackerRunWithDockerV28OverUDS(t *testing.T) {
2521+
testFirecrackerRunWithDockerOverUDS(t, imageWithDockerV28Installed)
2522+
}
2523+
25152524
func TestFirecrackerRunWithDockerOverTCP(t *testing.T) {
25162525
if *skipDockerTests {
25172526
t.Skip()

enterprise/vmsupport/kernel/microvm-kernel-aarch64-v5.10.config

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# TODO: For our current iptables-legacy path, enable CONFIG_IP_NF_RAW (and CONFIG_IP6_NF_RAW if needed), or fully migrate to nftables (CONFIG_NF_TABLES + non-legacy iptables), then remove the DOCKER_INSECURE_NO_IPTABLES_RAW fallback in enterprise/server/cmd/goinit/main.go.
12
CONFIG_CC_VERSION_TEXT="gcc10-gcc (GCC) 10.5.0 20230707 (Red Hat 10.5.0-1)"
23
CONFIG_CC_IS_GCC=y
34
CONFIG_GCC_VERSION=100500
@@ -3113,4 +3114,4 @@ CONFIG_CC_HAS_SANCOV_TRACE_PC=y
31133114
# CONFIG_RUNTIME_TESTING_MENU is not set
31143115
# CONFIG_MEMTEST is not set
31153116
# end of Kernel Testing and Coverage
3116-
# end of Kernel hacking
3117+
# end of Kernel hacking

enterprise/vmsupport/kernel/microvm-kernel-x86_64-v5.15.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# TODO: For our current iptables-legacy path, enable CONFIG_IP_NF_RAW (and CONFIG_IP6_NF_RAW if needed), or fully migrate to nftables (CONFIG_NF_TABLES + non-legacy iptables), then remove the DOCKER_INSECURE_NO_IPTABLES_RAW fallback in enterprise/server/cmd/goinit/main.go.
12
#
23
# Config copied from https://github.com/firecracker-microvm/firecracker/blob/main/resources/guest_configs/microvm-kernel-ci-x86_64-5.10.config
34
# Linux/x86 5.10.0 Kernel Configuration

enterprise/vmsupport/kernel/microvm-kernel-x86_64-v6.1.config

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# TODO: For our current iptables-legacy path, enable CONFIG_IP_NF_RAW (and CONFIG_IP6_NF_RAW if needed), or fully migrate to nftables (CONFIG_NF_TABLES + non-legacy iptables), then remove the DOCKER_INSECURE_NO_IPTABLES_RAW fallback in enterprise/server/cmd/goinit/main.go.
12
# Config copied from https://github.com/firecracker-microvm/firecracker/blob/main/resources/guest_configs/microvm-kernel-ci-x86_64-6.1.config
23
# BuildBuddy-specific modifications:
34
# - Set CONFIG_PCI=y (see https://github.com/firecracker-microvm/firecracker/issues/4881)
@@ -3238,4 +3239,4 @@ CONFIG_ARCH_USE_MEMTEST=y
32383239
# Rust hacking
32393240
#
32403241
# end of Rust hacking
3241-
# end of Kernel hacking
3242+
# end of Kernel hacking

0 commit comments

Comments
 (0)