Skip to content

Make SELinux support an optional (default) cargo feature - #12

Closed
cgwalters-bot wants to merge 3 commits into
mainfrom
bot/selinux-feature
Closed

cgwalters-bot wants to merge 3 commits into
mainfrom
bot/selinux-feature

Conversation

@cgwalters-bot

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

Copy link
Copy Markdown
Collaborator

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 selinux cargo 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 way ostree_ext::selinux::is_selinux_enabled does). 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 recognizing unlabeled_t files when relabeling, and bootc internals selinux is-unlabeled. In particular, bootc install of 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 feature is prep work. Without it, cargo test -p bootc-lib --no-default-features doesn't compile.
  • lib: Make SELinux support an optional default feature adds the feature. crates/cli now forwards bootc-lib's default features, because otherwise --no-default-features on the binary would not turn libselinux off. make validate now also checks crates/cli and builds the bootc-lib tests without default features.
  • build: Add CARGO_NO_DEFAULT_FEATURES to the Makefile makes 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's pre-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 validate passed. It now includes cargo check --no-default-features for crates/cli, and building the bootc-lib tests without default features.
  • just unit-tests passed (443 tests, with the default features).
  • Early install failure: I built bootc with --no-default-features --features install-to-disk on the host and bind-mounted it into quay.io/centos-bootc/centos-bootc:stream10. There, bootc install to-disk --via-loopback failed with Target 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.
  • The reporter's case: in an archlinux:latest container 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, and bootc --version works. cargo test -p bootc-lib --no-default-features --features install-to-disk --lib lsm passed there (2 tests, including test_selinux_not_built).
  • Earlier round, not rerun here because that code is unchanged: cargo tree shows selinux-sys only with the default features, and the no-default-features lsm tests passed on the SELinux-enforcing host, where selinux_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.

  • Upstream: bootc-dev/bootc, base main
  • Board item: PVTI_lAHOAQ_SPs4Bj2Gizg8P4GY

To review:

  • Approve to open it upstream, ready for review.
  • Comment /draft, then approve, 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 addressed with fixup commits and a reply here.

`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
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

Copy link
Copy Markdown
Collaborator Author

Opened upstream as bootc-dev#2494. Closing this review draft.

@cgwalters-bot

Copy link
Copy Markdown
Collaborator Author

Signed off 2 commit(s) with Signed-off-by: Colin Walters <walters@verbum.org> for bootc-dev/bootc's DCO check, on cgwalters's approval bootc-dev#2494 (review) of 14af1d60f7e3. Same trees; the head is now b0c20225a54b.

@cgwalters-bot

Copy link
Copy Markdown
Collaborator Author

Signed off 1 commit(s) with Signed-off-by: Colin Walters <walters@verbum.org> for bootc-dev/bootc's DCO check, on cgwalters's approval bootc-dev#2494 (review) of 9dad68b96191. Same trees; the head is now e014310f7b64.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

v1.16.11: selinux is an unconditional dependency, breaking source builds on distros that don't package libselinux

2 participants