Repository navigation
composefs: Rebuild SELinux policy when finalizing a staged deployment - #31
cgwalters-bot wants to merge 1 commit into
Conversation
Installing a local policy module rewrites the compiled policy in /etc, so from then on the /etc merge keeps the booted system's policy and every policy change a new image ships is silently dropped, while its module store does get updated. ostree fixed the same problem in ostree#2569 by running `semodule -N --refresh` in the new deployment after the merge; do the same here. With composefs the new deployment's root is its EROFS image, so rather than bwrap we mount it and chroot into it with ChrootCmd, binding the merged /etc over its /etc. That builds the policy with the new image's libsemanage and libsepol, and `--refresh` is a no-op unless the module store changed. The policy is loaded from the state /etc after switch-root, so nothing in the UKI or the sealed EROFS changes. A failure is fatal, as in ostree: the bootloader entries aren't swapped and the current deployment keeps booting. Related: bootc-dev#2511 Generated-by: AI
cgwalters-bot
left a comment
There was a problem hiding this comment.
Review guide for head 09d79d8d33: where to look closely and what is safe to skim. It is advice from the bot's reviewer and doesn't replace reading the diff; the review app walks it.
Spike PoC for bootc#2511. After the /etc merge in composefs-finalize-staged, it mounts the staged EROFS, chroots into it with ChrootCmd with the merged state /etc bound over /etc, and runs semodule -N --refresh, as ostree#2569 does with bwrap. The mechanism is sound. The mounts are RAII or live in the child's private namespace. It runs before the bootloader swap, so a failure leaves the old deployment booting. And -N never touches the running kernel. The main risk is policy, not code. A refresh failure is fatal at shutdown, so a composefs system with a broken module store (the ostree#3563 class), which upgrades today with a stale policy, would silently stop applying updates after this change. Second, inside the chroot /var and /tmp are the read-only image dirs. That is fine for store-root=/etc/selinux images (Fedora/CentOS bootc), but it would fail, fatally, for an image that keeps its store in /var/lib/selinux. The tmt test is a real reproducer (the control on main fails) and the .LOCK skip is narrow. Sealed UKI and the failure path are untested.
Hotspots
- risky · error-handling —
crates/lib/src/bootc_composefs/finalize.rs:139-146(09d79d8): Any refresh failure now aborts finalization at shutdown, silently pinning the system to the old deployment on every later upgrade (ostree#3563). Composefs systems with a bad store upgrade today with a stale policy; after this they wedge. Decide fatal vs non-fatal, or add the stage-time preflight, before merging. - look-closely · logic —
crates/lib/src/bootc_composefs/selinux.rs:201-205(09d79d8): Only /etc is writable in the chroot; /var and /tmp are the read-only EROFS dirs (ostree gives a writable deployment var and a tmpfs /tmp). An image whose semanage.conf leaves store-root at /var/lib/selinux would fail here, fatally. Consider skipping when the store is not under /etc, or linting for it. - note · logic —
crates/lib/src/bootc_composefs/selinux.rs:191-199(09d79d8): Skips when the image has no semodule, where ostree would fail on semodule --help. A sensible divergence, but it is one. - note · test-gap —
tmt/tests/booted/test-selinux-policy-finalize.nu:86-91(09d79d8): The .LOCK skip is justified (with store-root=/etc/selinux the locks sit where file_contexts says selinux_config_t, while semodule creates them via a named type transition) and narrow. The comment could name store-root as the cause.
Safe to skim
tmt/plans/integration.fmf: generated plan entrytmt/tests/tests.fmf: generated test entrycrates/lib/src/bootc_composefs/finalize.rs:1-121: imports and the Path to Utf8Path change
09d79d8 to
6568b44
Compare
6568b44 to
771473a
Compare
|
Fix round 1 of 2 for Generated-by: https://github.com/cgwalters/#llms |
771473a to
aa536e4
Compare
|
The poll stopped following this pull request: a draft with no checkpoint; mark it ready if the work is complete. It is labelled Generated-by: https://github.com/cgwalters/#llms |
|
Triage verdict: release (operator's standing rule, tracker#1445) Finish finalization PoC review and final-head VM tests including failure/sealed behavior. Generated-by: https://github.com/cgwalters/#llms |
Proof of concept for bootc-dev#2511, the composefs counterpart of ostree#2569. After the /etc merge in
composefs-finalize-staged, runsemodule -N --refreshfrom the staged deployment's own EROFS root (viaChrootCmd, with the merged state /etc bound over it). Without this, a local policy module makes the merge keep the booted system's compiled policy, and every policy change in the new image is silently dropped.Design notes, options and open questions (stage-time preflight, failure policy, sealed images): https://gist.github.com/cgwalters-bot/7fa03dcf6c3866961aed7d5199366aaa
Tested on a 16-core devspace with the new tmt test
plan-58-selinux-policy-finalize, which installs a local CIL module at runtime, switches to a derived image that adds another module, and checks that both are in the loaded policy after reboot:/usr/bin/bootc): failed with "new image's policy was not loaded". Both modules were in the store but only the local one was loaded.store-rootisn't under /etc (only /etc is writable in the chroot) and a test comment. For that head, fmt, clippy and unit tests were rerun, but the VMs weren't.cargo clippywith the Makefile's CLIPPY_CONFIG,cargo fmt --check, and theselinux/chrootunit tests passed.Related: bootc-dev#2511
Generated-by: https://github.com/cgwalters/#llms
Review draft in cgwalters-forge, not upstream yet. This section is removed when the PR is opened upstream.
bootc-dev/bootc, basemainPVTI_lADOE9oHIs4BlJLczg9kE9MTo review:
/promoteon a line of its own, to open it upstream, ready for review. Either covers only the commits pushed so far.Signed-off-by: Colin Walters <[email protected]>to the commits lacking it (the bot's and yours; anyone else's only if you ask), with you as committer./draftline (in the same comment or before) to open it upstream as a draft (/readyundoes that).Bot run: session 929c7a64, agent a04ce4e1 · claude-opus-5-5 13.3M in (92% cached) / 53k out · ~$8.81 inference + ~$3.13 compute (est., list prices) · 1h 18m wall · 19.9 core-h, Actions run 36429727126
Bot run: session 929c7a64, agent a04ce4e1 · claude-opus-5-5 16.3M in (92% cached) / 62k out · ~$10.51 inference + ~$3.42 compute (est., list prices) · 1h 32m wall · 21.7 core-h, Actions runs 36439856834, 36429727126