Repository navigation
Make SELinux support an optional (default) cargo feature - #12
Closed
cgwalters-bot wants to merge 3 commits into
Closed
cgwalters-bot wants to merge 3 commits into
cgwalters-bot wants to merge 3 commits into
Conversation
`cargo test -p bootc-lib --no-default-features` failed to compile because these tests use types that only exist with `install-to-disk`. Prep for testing bootc-lib with other default features turned off. Generated-by: AI
cgwalters-bot
force-pushed
the
bot/selinux-feature
branch
from
September 24, 2026 05:05
62a88c6 to
1329c00
Compare
Linking libselinux unconditionally (since 1.16.11) broke source builds on distributions that do not package it at all, such as Arch. Put the libselinux usage behind a `selinux` feature that stays on by default, so builds for SELinux-using systems are unchanged and others can opt out with `--no-default-features`. Without the feature, bootc still detects an enabled SELinux by checking for selinuxfs (as ostree-ext already does), so the install_t re-exec and the policy compatibility checks keep working. What really needs libselinux, recognizing `unlabeled_t` files when relabeling and `bootc internals selinux is-unlabeled`, fails with an explicit error rather than silently skipping work on an SELinux system. In particular `bootc install` of an SELinux image on an SELinux host fails right away, before touching the disk, and points to --disable-selinux. The bootc binary crate now forwards the lib's default features; otherwise its implicit dependency on bootc-lib's defaults would keep libselinux enabled regardless of `--no-default-features`. Closes: bootc-dev#2431 Generated-by: AI
Turning off the `selinux` feature needs `--no-default-features`, which the Makefile had no way to pass, so distributions without libselinux couldn't use the usual `make bin install-all` flow. The man page step builds bootc too (to dump the CLI), so it needs the flag as well or it would still fail to link. That build keeps install-to-disk enabled regardless, since the man pages document the whole CLI. Note the knob is workspace-wide, so packagers have to list other defaults they want (e.g. initramfs's `pre-6.15`) in CARGO_FEATURES again; the packaging docs say so. Generated-by: AI
cgwalters-bot
force-pushed
the
bot/selinux-feature
branch
from
September 24, 2026 08:52
1329c00 to
1dfa06a
Compare
cgwalters
approved these changes
Sep 24, 2026
Collaborator
Author
|
Opened upstream as bootc-dev#2494. Closing this review draft. |
Collaborator
Author
|
Signed off 2 commit(s) with |
Collaborator
Author
|
Signed off 1 commit(s) with |
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.
Since 1.16.11, bootc-lib links libselinux unconditionally. That broke source builds on distributions that don't package libselinux at all, such as Arch. This series puts the libselinux usage behind a
selinuxcargo feature. As discussed in the issue, the feature is on by default, so builds for SELinux systems don't change and turning it off takes--no-default-features.A build without the feature still detects whether SELinux is enabled, by checking for
/sys/fs/selinux/enforce(the wayostree_ext::selinux::is_selinux_enableddoes). So on a host that does have SELinux, it still re-execs into install_t and still checks policy compatibility before a soft reboot. The operations that really need libselinux fail with an explicit "built without SELinux support" error instead of silently doing the wrong thing. Those are recognizingunlabeled_tfiles when relabeling, andbootc internals selinux is-unlabeled. In particular,bootc installof an SELinux image on an SELinux host fails before touching the disk, and points to--disable-selinux. The target root is still labeled from its policy, because that goes through libostree.The commits:
install: Gate install-to-disk unit tests on their featureis prep work. Without it,cargo test -p bootc-lib --no-default-featuresdoesn't compile.lib: Make SELinux support an optional default featureadds the feature.crates/clinow forwards bootc-lib's default features, because otherwise--no-default-featureson the binary would not turn libselinux off.make validatenow also checkscrates/cliand builds the bootc-lib tests without default features.build: Add CARGO_NO_DEFAULT_FEATURES to the Makefilemakes the usual packaging flow work:make bin install-all CARGO_NO_DEFAULT_FEATURES=1 CARGO_FEATURES="install-to-disk pre-6.15". The man page step builds bootc too, so it passes the flag through xtask. The knob applies to the whole workspace, so any other defaults you want, such as the initramfs crate'spre-6.15, have to be listed again. This commit also adds the packaging docs.Caveats: libostree can still link libselinux on its own, depending on how it was built. The unit test targets (
make install-unit-tests) always use the default features, so they still need libselinux.Closes bootc-dev#2431
Testing
I tested on a 16-core RHEL 10 devspace (SELinux enforcing), rebased on current main (41049cc). The branch was built in its own checkout, with its own cargo target and buildah cache directories, and the built image reports
g1dfa06a8.just validatepassed. It now includescargo check --no-default-featuresfor crates/cli, and building the bootc-lib tests without default features.just unit-testspassed (443 tests, with the default features).bootcwith--no-default-features --features install-to-diskon the host and bind-mounted it intoquay.io/centos-bootc/centos-bootc:stream10. There,bootc install to-disk --via-loopbackfailed withTarget image and host have SELinux enabled; use --disable-selinux to install without it: bootc was built without SELinux support (the selinux feature), and left the disk image with no partitions.archlinux:latestcontainer with no libselinux installed,make bin CARGO_NO_DEFAULT_FEATURES=1 CARGO_FEATURES="install-to-disk"built the man pages and the binaries with no selinux build script, andbootc --versionworks.cargo test -p bootc-lib --no-default-features --features install-to-disk --lib lsmpassed there (2 tests, includingtest_selinux_not_built).cargo treeshowsselinux-sysonly with the default features, and the no-default-featureslsmtests passed on the SELinux-enforcing host, whereselinux_enabled()is true via/sys/fs/selinux/enforce.The commits have no
Signed-off-by; add one before merging if you want it.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_lAHOAQ_SPs4Bj2Gizg8P4GYTo review:
/draft, then approve, to open it upstream as a draft (/readyundoes that).