Repository navigation
fix(ddi): restore the setuid/setgid bits Flatcar ships on sudo, su, passwd, mount, … - #255
Merged
Merged
Conversation
jeefy
force-pushed
the
fix/sudo-setuid
branch
from
September 26, 2026 18:18
600ab5f to
df261fe
Compare
…asswd On the installed image /usr/bin/sudo is -rwxr-xr-x and sudo refuses to run: sudo: /usr/bin/sudo must be owned by uid 0 and have the setuid bit set flatcar-container.tar.gz carries sudo as -rwsr-xr-x and tar (running as root in the sandbox) extracts it that way, but BuildStream artifacts record a single executable bit per file (REAPI FileNode.is_executable; buildbox-fuse keeps full modes in memory and stores only that bit), so when flatcar-usr.bst's install root is captured every special bit is dropped and /layer in the DDI build has 0755. mkfs.xfs -p copies the mode it finds, so the image ships 19 binaries without their bits: sudo, su, passwd, gpasswd, newgrp, chsh, chfn, mount, umount, mount.nfs, ksu, pkexec, newuidmap, newgidmap, polkit-agent-helper-1 (setuid) and unix_chkpwd, expiry, chage (setgid) plus dbus-daemon-launch-helper (---s--x---, staged as 0644). freedesktop-sdk hits the same limitation and re-applies `chmod 4755 sudo` from an initial-script at image assembly. Fix it at the only point where the bits can stick: flatcar-usr.bst records `find -perm /6000` (octal mode, install-root-relative path) into usr/lib/bluefin-server/setuid-modes while the archive modes are still intact -- after its own rm block, so the list never names a file the element removes -- and refuses to build if the list does not contain usr/bin/sudo (an extraction that lost the bits). bluefin-server-ddi.bst re-applies the list to /layer after depmod and before mkfs.xfs, failing with a stale-manifest message if a listed path is not in /layer, if the list is missing/empty, or if sudo does not end up 4755. A mode without an owner-read bit gets u+r added (dbus-daemon-launch-helper ships as 4110, ---s--x---, and lands as 4510): mkfs.xfs -p has to open every file it copies and buildbox-fuse enforces the mode bits itself, so the first CI build of this change failed with "mkfs.xfs: cannot open /layer/usr/libexec/dbus-daemon-launch-helper: Permission denied"; root reads such a file regardless on a real system. It logs the restored list and `ls -l sudo`, and after mkfs.xfs asserts with `xfs_db -r -c 'path /usr/bin/sudo' -c 'print core.mode'` that the written image carries 0104755, so a green build is evidence about the DDI itself (BuildStream only surfaces element output on failure). No per-binary hardcoding; a Flatcar bump that adds or drops a setuid helper is picked up automatically. Ownership is still flattened to root:root by the same artifact capture, so the three setgid-shadow helpers come back setgid root. That matches the image's 0600 root-only /etc/shadow and is unchanged by this fix. test_flatcar_usr.py extends the executed contract with setuid/setgid mocks (including umount, so sudo is not the manifest's last line and the loop's last iteration is exercised under set -e) and asserts the recorded list names none of the removed files, plus a run that must fail when sudo comes out 0755 and a check that the recording follows the last rm. test_setuid_modes.py pins the two halves to the same path and the xfs_db check to after mkfs.xfs, runs the DDI restore block against a mock /layer (every mode restored, 4110 -> 4510 with a NOTE, others untouched, restored list logged) and checks the missing/empty-list, stale-entry and sudo-not-4755 failures. Assisted-by: Claude Fable 5.1 via GitHub Copilot Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…itten Add a Common rationalizations row: BuildStream artifacts keep one executable bit per file, so chmod in an element's install-commands cannot make a file setuid in the image; point at setuid-modes, the DDI script and its post-mkfs xfs_db assertion, and say why a boot-time tmpfiles `z` line is the wrong place even though the rootfs is mounted rw. Assisted-by: Claude Fable 5.1 via GitHub Copilot Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
jeefy
force-pushed
the
fix/sudo-setuid
branch
from
September 26, 2026 18:21
df261fe to
5642df3
Compare
Contributor
There was a problem hiding this comment.
Read elements/oci/bluefin-server-ddi.bst and elements/flatcar/flatcar-usr.bst at 5642df3 in full. Looks correct to me, and the design is self-proving.
bluefin-server-ddi.bstruns underset -euo pipefail(bst:25), so the(( 8#${mode} & 8#400 ))arithmetic is valid, and a failingxfs_dbaborts the build before thecaserather than matching the*arm.findutils.bstis already a build-dep of the DDI element (bst:12) and is newly added toflatcar-usr.bst, sofind -printf '%m usr/%P'resolves in both sandboxes;%Pis relative to thefindstart point, which is exactly what theusr/prefix assumes.- The restore loop
[ -f /layer/${path} ]guard plus recording after thermblock inflatcar-usr.bstcloses the stale-manifest window in both directions. - The post-
mkfs.xfsxfs_db -r -c 'path /usr/bin/sudo' -c 'print core.mode'assertion means a greenbuildjob is evidence the mode reached the image, not just/layer— andbuild(46m) andinstaller-test / Install and boot in QEMUboth pass on this head.
Ownership flattening (setgid-shadow helpers coming back root:root, dbus-daemon-launch-helper at 4510) is called out honestly in the body and is not a regression from the current 0644/0755 state.
Confidence: 5/5 (safe)
— hive: agent=reviewer backend=copilot model=claude-fable-5.1 copilot=1.0.88
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Branch:
fix/sudo-setuid(OS payload build; independent of the installer fixes).Problem
On the installed image:
Observed in QEMU on the installed
installer-v26.08.0image while integrating with the jeefy/booty PXE server (operator account provisioned viatmpfiles.extra, thensudorefused).su,passwd,mount,umount,pkexec,newuidmap/newgidmap(rootless podman) and the rest of the list below are affected the same way.Root cause
Flatcar ships the bits (
-rwsr-xr-x root/root ./usr/bin/sudoinflatcar-container.tar.gzfor 4593.2.5) andtar— running as root inside the BuildStream sandbox — extracts them intact. They are lost one step later: BuildStream artifacts record a single executable bit per file (REAPIFileNode.is_executable; buildbox-fuse keeps the full mode in memory and stores only that bit). Whenflatcar-usr.bst's install root is captured, every special bit is dropped, so/layerin thebluefin-server-ddi.bstbuild hassudoat 0755, andmkfs.xfs -p /layerfaithfully copies the mode it finds. This is the same limitation freedesktop-sdk works around withchmod 4755 …/sudoin aninitial-scriptrun at image assembly (components/sudo.bst), which is why the FSDK-based payload never hit it and the Flatcar cutover (#132) did.The full list dropped from the 4593.2.5 archive (19 files): setuid —
sudo su passwd gpasswd newgrp chsh chfn mount umount mount.nfs ksu pkexec newuidmap newgidmap polkit-agent-helper-1; setgidshadow—unix_chkpwd expiry chage; anddbus-daemon-launch-helper(---s--x---, which is not even executable for its owner and so was staged as 0644).Fix
Apply the modes at the only point where they can stick — the
scriptelement that writes the image — without hardcoding a binary list:flatcar-usr.bst: while the archive modes are intact — after the element's ownrmblock, so the list never names a file this element removes — recordfind … -type f -perm /6000 -printf '%m usr/%P\n'intousr/lib/bluefin-server/setuid-modes(octal mode, install-root-relative path, sorted). The build fails if the list does not containusr/bin/sudo— i.e. if an extraction ever comes out without its special bits (non-root sandbox, tar flags), we refuse to ship an unusablesudorather than record an empty list.components/findutils.bstadded tobuild-depends(already used byflatcar-kernel.bst).bluefin-server-ddi.bst: afterdepmodand beforemkfs.xfs,chmodeach recorded mode onto/layer/<path>(failing with a stale-manifest message if a listed path is not in/layer), then fail if the list is missing/empty or/usr/bin/sudois not4755; log the restored list andls -l sudo. A mode without an owner-read bit getsu+radded (dbus-daemon-launch-helperships as4110,---s--x---, and lands as4510):mkfs.xfs -phas to open every file it copies and buildbox-fuse enforces the mode bits itself — the round-1 CI build failed withmkfs.xfs: cannot open /layer/usr/libexec/dbus-daemon-launch-helper: Permission denied(reproduced locally with a 4110 file). Root reads such a file regardless on a real system.bluefin-server-ddi.bst: aftermkfs.xfs, assertxfs_db -r -c 'path /usr/bin/sudo' -c 'print core.mode'reports0104755in the written image. BuildStream only surfaces element output on failure, so this check — not als -l— is what makes a green build proof that the mode reached the DDI.A Flatcar bump that adds or drops a setuid helper is picked up automatically;
just validategraph is unchanged apart from the findutils build-dep.Known remaining flattening (unchanged by this PR): ownership is also lost in the artifact capture, so the three setgid-
shadowhelpers come back setgidroot. With the image's0600 root:root /etc/shadowthat makes no practical difference, but it is why the manifest records modes, not owners. Likewise/usr/libexec/dbus-daemon-launch-helpercomes back4510 root:rootinstead of---s--x--- root:messagebus(owner read added somkfs.xfscan copy it, see fix step 2), so themessagebususer still cannot execute it and non-systemd (classic) D-Bus activation remains unavailable — unchanged from before, when it was staged0644.Verification
tests/unit/test_flatcar_usr.py— the executed contract now stagessudo/su/umount4755 andunix_chkpwd2755 mocks (umountsorts aftersudo, so the manifest's last line is notsudoand the loop's last iteration runs underset -eas in production) and asserts the recorded list byte-for-byte and that it names none of the removed files; a test runs the element's install-commands with a 0755sudoand asserts the build refuses (usr/bin/sudo is not setuid); a test asserts the recording follows the lastrm.tests/unit/test_setuid_modes.py(new) — pins both halves to the same path and ordering (depmod→ restore →mkfs.xfs→xfs_dbcheck →zstd), runs the DDI restore block against a mock/layer(4755/2755 restored, 4110 → 4510 with aNOTE, unrelated files untouched, restored list logged), and checks the missing-list, empty-list, stale-entry and sudo-not-4755 failures.python3 -m pytest tests/unit -q— 353 passed, 1 xfailed (pre-existing).bash -n+shellcheck -S warningon both extracted scripts (with%{…}substituted) — clean.python3 .github/scripts/docs-checks.py,check-flatcar-version.py(no new literals) and the othercheck-*scripts — pass.xfs_dbinvocation verified locally against amkfs.xfs -pimage of a mock tree:core.mode = 0104755for a 4755 file,0100755for 0755, and a 4110 file makesmkfs.xfsfail with the samePermission deniedCI hit.just validate/just build-ddi(no local BuildStream), so the built artefact has not been inspected locally; the round-1 CI build reachedmkfs.xfs(i.e. the restore loop and thestatgate passed on the real/layer) and failed only on the unreadable 4110 file. Root cause and fix are established from the pipeline: the tar listing (bits present), BuildStream's_casbaseddirectory.py/cascache.py(onlyis_executablecaptured; checkout chmods 0755), buildbox-fusebuildbox.cc(full mode kept in memory, only the executable bit persisted), and xfsprogsmkfs/proto.c(directory population copiesst_modeverbatim, so achmodin the DDI script reaches the image). Als -l /usr/bin/sudoon the next CI DDI is the remaining proof.Docs:
ddi-installer-build.mdgains a Common rationalizations row ("chmod 4755in install-commands makes the file setuid in the image" → no, and where it must be done instead).Review round 2
Applied from the line-by-line review and the round-1 CI failure:
mkfs.xfs: cannot open /layer/usr/libexec/dbus-daemon-launch-helper: Permission denied(run 36259023853) — the restored4110mode has no read bit and buildbox-fuse enforces modes itself. The restore loop now addsu+rto any mode lacking owner read (4110→4510) and logs aNOTE; reproduced and verified locally withmkfs.xfs -p.rmblock inflatcar-usr.bst, so a future Flatcar release shipping a setuid file this element removes cannot produce a stale entry.mkfs.xfsxfs_db … print core.modeassertion inbluefin-server-ddi.bstso CI proves the image, not just/layer; the restored list andls -l sudoare echoed for failing-run context.test_flatcar_usrmock gainsumount4755 sosudois not the manifest's last line.[ … ] && Xas last loop command →if … fi;[ -f ]check with a stale-manifest message beforechmod; whitespace/newline constraint on paths documented;ddi-installer-build.mdrow explains why a boot-time tmpfileszline is the wrong place even though the rootfs isrw.ls -l sudoline, which are the block's natural boundaries).