Skip to content

composefs: Rebuild SELinux policy when finalizing a staged deployment - #31

Draft
cgwalters-bot wants to merge 1 commit into
mainfrom
bot/composefs-selinux-finalize
Draft

cgwalters-bot wants to merge 1 commit into
mainfrom
bot/composefs-selinux-finalize

Conversation

@cgwalters-bot

@cgwalters-bot cgwalters-bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Collaborator

Proof of concept for bootc-dev#2511, the composefs counterpart of ostree#2569. After the /etc merge in composefs-finalize-staged, run semodule -N --refresh from the staged deployment's own EROFS root (via ChrootCmd, 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:

  • composefs, grub, BLS, ext4, unsealed: passed.
  • The same test on main (control build, verified to have a different /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.
  • ostree variant, same test: passed (ostree already does this refresh).
  • The tmt runs above were on 09d79d8. The current head only adds a warning-and-skip when semanage.conf's store-root isn'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 clippy with the Makefile's CLIPPY_CONFIG, cargo fmt --check, and the selinux/chroot unit 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.

  • Upstream: bootc-dev/bootc, base main
  • Board item: PVTI_lADOE9oHIs4BlJLczg9kE9M
  • Fork CI: off; the devspace testing described above is this PR's CI, and upstream CI runs once it is opened there

To review:

  • Approve, or comment /promote on a line of its own, to open it upstream, ready for review. Either covers only the commits pushed so far.
  • If upstream requires DCO, approving also signs off: promote adds 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.
  • Add a /draft line (in the same comment or before) to open it upstream as a draft (/ready undoes that).
  • Close to drop it.
  • Edit the title and description freely: they become the upstream PR's. Review comments are squashed into the commits they concern, with a reply here.

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

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 cgwalters-bot left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

  1. 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.
  2. 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.
  3. 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.
  4. 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 entry
  • tmt/tests/tests.fmf: generated test entry
  • crates/lib/src/bootc_composefs/finalize.rs:1-121: imports and the Path to Utf8Path change

@cgwalters-bot

cgwalters-bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Collaborator Author

✅ dispatch ended well. Result: #31

@cgwalters-bot
cgwalters-bot force-pushed the bot/composefs-selinux-finalize branch from 6568b44 to 771473a Compare October 17, 2026 17:02
@cgwalters-bot

cgwalters-bot commented Oct 31, 2026 •

Copy link
Copy Markdown
Collaborator Author

@cgwalters-bot
cgwalters-bot force-pushed the bot/composefs-selinux-finalize branch from 771473a to aa536e4 Compare October 31, 2026 18:57
@cgwalters-bot cgwalters-bot added the needs-human The poll stopped here; a person decides what is next label Oct 31, 2026
@cgwalters-bot

Copy link
Copy Markdown
Collaborator Author

The poll stopped following this pull request: a draft with no checkpoint; mark it ready if the work is complete. It is labelled needs-human; remove the label to have the poll start again on it, with fresh fix rounds.

Generated-by: https://github.com/cgwalters/#llms

@cgwalters-bot

Copy link
Copy Markdown
Collaborator Author

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

@cgwalters-bot cgwalters-bot removed the needs-human The poll stopped here; a person decides what is next label Nov 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

review:deep Bot draft that needs a real review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant