firecracker: rootless rootfs build loses uid/gid ownership (everything owned by node) #347
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
The Firecracker guest rootfs is built rootless —
docker export <container> | tar -xrun as the invoking (non-root) user, thenmke2fs -d(seebot_bottle/backend/firecracker/util.pybuild_base_rootfs_dir). A non-roottar -xcan't restore uid 0, so every path in the rootfs ends up owned by the build uid, which maps tonode(uid 1000) inside the guest — including/root,/etc,/usr, etc.This was invisible until the first real end-to-end launch. It broke SSH auth: dropbear (like OpenSSH) refuses root's
authorized_keyswhen/rootisn't root-owned. Worked around inbb-initwithchown -R 0:0 /root(commit "fix(firecracker): make the launch path work end-to-end").Why it's worth fixing properly
The
chown /rootpatch unblocks login, but the underlying ownership is still wrong for the whole tree:node. The agent runs asnode(uid 1000), which now owns/etc,/usr,/bin, … so a compromised agent can modify system files / binaries in its own rootfs. The VM is ephemeral and network-isolated (nft boundary), so this isn't a host-escape, but it does weaken in-guest integrity (e.g. tampering with the injected CA, sudoers-style files, setuid bits).rootvsnode) needs per-pathchownband-aids like the/rootone.Options
fakeroot-ngaround the export+extract so tar restores the original uids/gids into a fake map, thenmke2fs -dfrom that tree. Cheapest change; no new privileges.unshare -Ur(rootless userns) so uid 0 in the ns maps to the invoking uid but tar sees uid 0. Thenmke2fs -dreads correct ownership. Also rootless.docker export's tar member uids/gids and replay them via anmke2fsdevice table / a post-pass thatchowns inside the image (needs a tool that writes ext4 ownership without mounting).chowns inbb-initfor the few paths that matter (current approach), and document that the guest rootfs is node-owned by design.Option 1 or 2 is the real fix and keeps the build rootless. Worth measuring the build-time cost (the rootfs is cached by image digest, so it's a one-time-per-image hit).
Notes
bb-initchown -R 0:0 /rootworkaround can be removed.Ref: surfaced while getting the first end-to-end firecracker launch working.