Repository navigation
Make SELinux support an optional (default) cargo feature - #2494
Conversation
| # (install-unit-tests) still build with the default features and need | ||
| # libselinux. | ||
| CARGO_NO_DEFAULT_FEATURES ?= | ||
| CARGO_NO_DEFAULT_FEATURES_ARG = $(if $(filter 1,$(CARGO_NO_DEFAULT_FEATURES)),--no-default-features) |
There was a problem hiding this comment.
I think it'd be cleaner to just compute a CARGO_OPTIONS variable
There was a problem hiding this comment.
Done in a fixup: the Makefile now computes CARGO_OPTIONS ?= --features "$(CARGO_FEATURES)", used by both bin and manpages, and CARGO_NO_DEFAULT_FEATURES is gone. A libselinux-free build is make bin CARGO_OPTIONS='--no-default-features --features "install-to-disk pre-6.15"', which I tested in an archlinux:latest container without libselinux.
Generated-by: https://github.com/cgwalters/#llms
|
|
||
| #[cfg(not(feature = "selinux"))] | ||
| fn unlabeled_type() -> Result<CString> { | ||
| anyhow::bail!(SELINUX_NOT_BUILT) |
There was a problem hiding this comment.
I don't get why we need a runtime failure for this
There was a problem hiding this comment.
Agreed, and it turns out we don't need one. Without the feature, bootc now reads the unlabeled initial context from /sys/fs/selinux/initial_contexts/unlabeled (which is what libselinux does anyway) and parses the context type itself. So the "built without SELinux support" errors and the early bail in install are gone. On an SELinux-enforcing RHEL 10 host, a --no-default-features build passed the lsm tests, internals selinux is-unlabeled correctly told labeled and unlabeled_t files apart, and bootc install to-disk of centos-bootc:stream10 completed with the target labeled (etc_t, passwd_file_t, boot_t).
Generated-by: https://github.com/cgwalters/#llms
| /// features, e.g. so that it doesn't need libselinux. | ||
| #[context("Extracting CLI")] | ||
| pub fn extract_cli_json(sh: &Shell) -> Result<CliCommand> { | ||
| pub fn extract_cli_json(sh: &Shell, no_default_features: bool) -> Result<CliCommand> { |
There was a problem hiding this comment.
Hmm this is super messy indeed i think we just need to pass down the cargo features directly to here? Lets avoid specifying it twice
There was a problem hiding this comment.
Done in a fixup: xtask manpages now takes the cargo options after -- and passes them straight to cargo run, and the Makefile hands it the same CARGO_OPTIONS as bin. The docgen feature now implies install-to-disk, so xtask no longer names any feature but docgen, and the man pages still cover the whole CLI.
Generated-by: https://github.com/cgwalters/#llms
The bot never signs off, so its upstream PRs to DCO projects (e.g. bootc-dev/bootc#2494 and #2496) sit with a failing DCO check until a human does. Doing that by hand means a rebase per PR on content the bot wrote, which is tedious and easy to get subtly wrong: rebasing onto the new base tip changes what was reviewed, a global autosquash setting squashes the bot's fixup! commits, and a plain force-push can clobber a push that landed meanwhile. So this finds the PRs that need it (bot-authored or from a forge branch, into a branch whose rules require a DCO check), rebases with --signoff onto the existing merge-base with hooks off, checks trees, authors and messages are unchanged apart from the trailer, and pushes with a lease on the fetched head. It refuses to run as the bot, since only a human can make the DCO statement, and won't sign off someone else's commits unless asked. A hidden --list-only mode lets the bot see what's waiting. The test drives it against local bare repos and a fake gh. Generated-by: AI
1dfa06a to
9696e4e
Compare
| /// The SELinux xattr | ||
| const SELINUX_XATTR: &[u8] = b"security.selinux\0"; | ||
| /// The kernel initial SID used for objects without a label. | ||
| #[cfg(feature = "selinux")] |
There was a problem hiding this comment.
Either we should remove this cfg, or add it to all selinux related consts. I prefer the former
There was a problem hiding this comment.
Removed. The const is now used in both configurations, because without libselinux we read the same initial context from selinuxfs.
Generated-by: https://github.com/cgwalters/#llms
| Ok(()) | ||
| } | ||
| }, | ||
| InternalsOpts::Selinux(SelinuxOpts::IsUnlabeled { path }) => { |
There was a problem hiding this comment.
Maybe this option itself should be behind cfg(selinux)?
There was a problem hiding this comment.
With the latest fixups this command works without libselinux too: the unlabeled type now comes from selinuxfs directly, following cgwalters' point that a no-selinux build shouldn't fail at runtime. So I kept it available in both builds rather than gating it.
Generated-by: https://github.com/cgwalters/#llms
426cec0 to
82b8c66
Compare
|
Squashed the two fixup commits; the final tree is unchanged, and the last two commits (e8b5618, 82b8c66) now carry them, reworded as the fixups said (the Makefile one is now "build: Add CARGO_OPTIONS to the Makefile"). @cgwalters needs to re-run dco-signoff. Generated-by: https://github.com/cgwalters/#llms |
cgwalters
left a comment
There was a problem hiding this comment.
Btw let's add as a followup something like what ostree/systemd do with bootc --version printing our compiled in features
| /// Without libselinux, split `user:role:type[:level]` the way its | ||
| /// `context_new()` does. |
There was a problem hiding this comment.
Why are we parsing contexts if we don't have selinux? Doesn't make sense
There was a problem hiding this comment.
Agreed, it no longer does. Without the feature there is no context parsing at all: the unlabeled type can't even be constructed (it's an empty enum there), so relabeling falls back to "has any label", and internals selinux is-unlabeled isn't built. Squashed into "lib: Make SELinux support an optional default feature".
Generated-by: https://github.com/cgwalters/#llms
| boot composefs systems on kernels older than 6.15). Such a build reads the | ||
| SELinux state it needs from selinuxfs directly instead: |
There was a problem hiding this comment.
No, if we are not built with selinux support then we should not be reading anything from selinuxfs.
OK I guess we could make it some kind of serious runtime warning if we detect selinuxfs but we weren't built with support but...eh.
There was a problem hiding this comment.
Right, fixed: without the feature selinux_enabled() and host_selinux_enabled() are just false, so bootc never touches selinuxfs (no install_t re-exec, no policy compat check), and the docs now say such a build is not for SELinux hosts. I left out the runtime warning: on an SELinux host the mismatch shows up loudly anyway (label writes fail), and bootc --version listing features (your follow-up) makes it visible without reading selinuxfs. Squashed into "build: Add CARGO_OPTIONS to the Makefile" (docs) and the lib commit.
Generated-by: https://github.com/cgwalters/#llms
82b8c66 to
14af1d6
Compare
|
Reworked per the review (head 14af1d6): a build without Tested on a 16-core RHEL 10 devspace (SELinux enforcing): Commits 2 and 3 changed, so they need your sign-off again; "install: Gate install-to-disk unit tests on their feature" is unchanged and keeps it. Generated-by: https://github.com/cgwalters/#llms |
|
You can add my signoff also, a notable follow up here is we should probably have a CI job that builds on Arch or another system with selinux fully disabled |
14af1d6 to
b0c2022
Compare
b0c2022 to
f5f2f27
Compare
|
Rebased onto main (9a925fb) to resolve a conflict in |
f5f2f27 to
9dad68b
Compare
|
Rebased onto main 1968e52 to resolve conflicts with the docs/xtask man page rework; the only conflict (xtask Generated-by: https://github.com/cgwalters/#llms |
cgwalters
left a comment
There was a problem hiding this comment.
I think we can merge but some extra validation post-merge would be good.
Followup: bootc --version should output our list of compiled features, and we should cross check those in a tmt readonly test.
| #[derive(Debug)] | ||
| enum UnlabeledType {} | ||
|
|
||
| impl UnlabeledType { |
There was a problem hiding this comment.
For followup I think it'd be cleaner to use cfg_if inside the single impl
9dad68b to
e014310
Compare
`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 Signed-off-by: Colin Walters <[email protected]>
Linking libselinux unconditionally (since 1.16.11) broke source builds on distributions that do not package it at all, such as Arch. Put the SELinux support 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 treats SELinux as disabled on the host: it doesn't read selinuxfs or parse contexts at all, so it skips the install_t re-exec and the policy compatibility checks, relabels only files without any label (the behavior before unlabeled_t detection), and `internals selinux is-unlabeled` isn't built. Such a build is meant for systems that don't run SELinux; labels from an image's own policy are still written on install, via libostree. 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 Signed-off-by: Colin Walters <[email protected]>
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. CARGO_OPTIONS (by default just the CARGO_FEATURES) can be overridden wholesale, and the man page step, which builds bootc too to dump the CLI, passes the same options through to its `cargo run`, or it would still fail to link. Beyond --no-default-features, this works for any other cargo option a packager needs. The man pages document the whole CLI however bootc is configured, so the docgen feature now implies install-to-disk. Note --no-default-features is workspace-wide, so packagers have to list other defaults they want (e.g. initramfs's `pre-6.15`) again; the packaging docs say so. The man page build now also sees CARGO_FEATURES (e.g. rhsm), which only adds hidden internals commands. Generated-by: AI Signed-off-by: Colin Walters <[email protected]>
|
Rebased onto main; 3 commits, no content change. Generated-by: https://github.com/cgwalters/#llms |
e014310 to
cf74a8f
Compare
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 SELinux support behind a
selinuxcargo feature, on by default, so builds for SELinux systems don't change.Without the feature, bootc treats SELinux as disabled on the host: it never reads selinuxfs or parses SELinux contexts, so there is no install_t re-exec and no policy compatibility check, relabeling only looks at whether a label is present, and
bootc internals selinux is-unlabeledisn't built. Such a build is not meant for SELinux hosts. Installing an SELinux image still labels the target from its own policy, via libostree.install: Gate install-to-disk unit tests on their featureis prep, so thatcargo test -p bootc-lib --no-default-featurescompiles.lib: Make SELinux support an optional default featureadds the feature.crates/cliforwards bootc-lib's defaults, since otherwise--no-default-featureson the binary would not turn libselinux off.build: Add CARGO_OPTIONS to the Makefilemakes the packaging flow work:make bin CARGO_OPTIONS='--no-default-features --features "install-to-disk pre-6.15"', with the man page step passing the same options through xtask. Also adds the packaging docs.Caveats: libostree may still link libselinux itself, depending on how it was built. The unit test targets (
make install-unit-tests) always use the default features.Closes #2431
Testing
On a 16-core RHEL 10 devspace (SELinux enforcing), at head 14af1d6:
just validateandjust unit-testspassed.cargo test -p bootc-libpassed with the default features (272 tests), with--no-default-features --features install-to-disk(268) and with--no-default-features(266); clippy with the project's lints plus-Dwarningsis clean both with and without the feature.cargo treeshows no selinux crates without it.archlinux:latestcontainer with no libselinux installed,make bin CARGO_OPTIONS='--no-default-features --features "install-to-disk pre-6.15"'built the man pages and binaries,lddshows no libselinux, andbootc --versionworks.Follow-up:
bootc --versionlisting the compiled-in features, like ostree and systemd do.Generated-by: https://github.com/cgwalters/#llms