Repository navigation
Conversation
…BPF filter The systemd feature implies cgroupsv2_devices since youki-dev#3721, so every systemd build compiles libbpf from C source (libbpf-sys, needing libelf and zlib on every build host and target). systemd_base is the systemd manager without it; systemd is now systemd_base plus cgroupsv2_devices, so its meaning and the default features are unchanged. The device rule emulator and the default device lists are pure Rust and are now available to systemd_base; only bpf, program and the eBPF controller still require cgroupsv2_devices. Without the filter, device rules are expressed only through DevicePolicy/DeviceAllow, and a rule set with a deny rule, which DeviceAllow cannot express, is refused with DenyRuleWithoutFilter instead of leaving the container without devices. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Marco Napetti <marco.napetti@proton.me>
There was a problem hiding this comment.
🟡 Changes recommended
With systemd_base alone, unsupported allow rules can be silently dropped, so apply() reports success while requested device access remains denied.
1 open issue
What changed in this PR
Adds systemd_base so libcgroups users can use the systemd manager without compiling libbpf or its native dependencies. Existing systemd and default features retain their behavior.
Changes:
- Splits systemd support from the optional eBPF device filter.
- Makes pure-Rust device-rule helpers available to
systemd_baseand rejects deny rules when the filter is disabled. - Adds filter-free feature builds and adjusts device-rule tests.
| File | Description |
|---|---|
scripts/features_test.sh |
Adds systemd_base feature combinations. |
crates/libcgroups/src/v2/mod.rs |
Exposes device helpers to systemd_base. |
crates/libcgroups/src/v2/devices/mod.rs |
Gates eBPF components separately from the emulator. |
crates/libcgroups/src/systemd/devices.rs |
Adds filter-free deny-rule rejection and tests. |
crates/libcgroups/src/systemd/dbus_native/dbus.rs |
Enables D-Bus tests under systemd_base. |
crates/libcgroups/src/lib.rs |
Selects the systemd implementation through systemd_base. |
crates/libcgroups/src/common.rs |
Updates manager and device-helper feature gates. |
crates/libcgroups/Cargo.toml |
Defines systemd_base and preserves existing defaults. |
Review effort: Balanced
| #[cfg(not(feature = "cgroupsv2_devices"))] | ||
| if has_deny_rule { | ||
| return Err(SystemdDevicesError::DenyRuleWithoutFilter); | ||
| } |
There was a problem hiding this comment.
Fixed in 0b19399. Without cgroupsv2_devices, allow rules that DeviceAllow cannot express are now refused with UnrepresentableRuleWithoutFilter: *:minor, and on systemd < 240 a major with no /proc/devices group or a node that does not exist. With the filter nothing changes (warn and skip). A rule granting no access is left out in both builds, since it grants nothing. Filter-free regression tests are added, and the three tests that expect skipping now run only with cgroupsv2_devices.
With systemd_base alone nothing carries a device rule that DeviceAllow cannot express, so apply() used to succeed while the requested access stayed denied. Refuse '*:minor' rules and the systemd-version-dependent cases (unknown device group, missing node before systemd 240) with UnrepresentableRuleWithoutFilter. Behaviour with cgroupsv2_devices is unchanged (warn and skip). Rules granting no access are left out silently in both builds. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Marco Napetti <marco.napetti@proton.me>
|
@nappa85 We'd like to avoid relying on systemd's DevicePolicy/DeviceAllow alone, without youki's own eBPF filter. DeviceAllow can only express allow rules, so deny rules can't be enforced, and which rules are representable depends on the systemd version (e.g. *:minor rules, or majors without a /proc/devices entry on systemd < 240). So we don't think it's a reliable way to enforce device rules. That said, we agree that systemd shouldn't always force the eBPF filter. How about the following approach instead of adding
This is similar to runc, where device support is opt-in and What do you think? |
My use case, hakoniwa, won't rely on eBPF anyway, because rootless, so #3940 is probably enough to not break musl builds, you can probably close this PR if it's not the desired approach |

Description
Since #3721 the
systemdfeature impliescgroupsv2_devices, so every build with the systemd manager compiles libbpf from C source throughlibbpf-sys. That brings in a C toolchain,make, and the libelf and zlib headers on every build host, plus libelf for every cross target.That is a problem for pure-Rust users of libcgroups. hakoniwa is a Rust sandbox whose
cgroupsfeature has so far built as pure Rust through libcgroups. Updating it to 0.8.0 (souk4711/hakoniwa#209) means taking on the C build, a new licence (BSD-2-Clause) and libelf in its aarch64 and musl release builds. Yet hakoniwa usually runs rootless, where libcgroups 0.8 skips the eBPF filter anyway.This PR adds
systemd_base, the systemd manager without the eBPF device filter:systemdand the default features keep exactly their current meaning, so nothing changes for existing users. Crates that can't take the C dependency opt intosystemd_base.cfg(feature = "systemd")gates in libcgroups now usesystemd_base, whichsystemdimplies.Emulatoranddefault_devices()/default_allow_devices()are pure Rust and are now available tosystemd_base. Onlybpf,programand the eBPFcontrollerstill requirecgroupsv2_devices.DevicePolicy/DeviceAllow. A rule set with a deny rule, whichDeviceAllowcannot express, is refused with the newSystemdDevicesError::DenyRuleWithoutFilter. Without that, the deny-all fallback would silently leave the container with no devices; with the filter, behaviour is unchanged.Type of Change
Testing
Added new unit tests
Added new integration tests
Ran existing test suite
Tested manually (please provide steps)
A new test checks that a deny rule is refused without the filter. The two deny-all fallback tests now run only with
cgroupsv2_devices.scripts/features_test.shbuilds libcgroups withsystemd_baseand withv1 systemd_base.Builds: libcgroups builds with
v1,v2,systemd,systemd_base,v1 systemd_base,v2 cgroupsv2_devicesandsystemd_base cgroupsv2_devices. Withv1 v2 systemd_base,cargo treeshows nolibbpf-sysorrbpf.Lint:
cargo +nightly fmt --all -- --checkandcargo clippy --all --all-targets --all-features -- -D warningspass. Clippy also passes on libcgroups withsystemd_baseand withv1,systemd_base.Tests:
cargo test -p libcgroups --libpasses 260 tests with the default features and 194 withsystemd_baseonly. In both, the same 9 systemd and D-Bus tests fail on my machine, which has no systemd; they fail the same way on unmodified 0.8.0.Related Issues
Follows up #3721 and #3904. Related: souk4711/hakoniwa#209.
Additional Context
libcontainer still enables
libcgroups/systemd, so youki itself is unchanged. If useful, libcontainer could expose a matching feature later; I kept this PR to libcgroups.🤖 Generated with Claude Code