Repository navigation
install: label only the directories it creates - #15333
abendrothj wants to merge 2 commits into
Conversation
| match directory_creation_context(&target, b) { | ||
| Ok(guard) => guard, | ||
| Err(e) => { | ||
| show!(e); |
There was a problem hiding this comment.
Is this stdout? or show_error!?
There was a problem hiding this comment.
It's stderr: show! prints like show_error! and also sets the exit code to 1, which GNU returns here.
|
GNU testsuite comparison: |
3ddad2f to
69c9757
Compare
Merging this PR will regress 1 benchmark
|
| Mode | Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|---|
| ❌ |
Simulation | sort_reverse_utf8_locale |
79.2 ms | 82 ms | -3.39% |
| ⚡ | Simulation | factor_three_39_bit_primes |
567 ms | 481.6 ms | +17.72% |
| ⚡ | Simulation | factor_thirteen_39_bit_primes |
9.5 s | 9.1 s | +3.78% |
Tip
Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.
Comparing abendrothj:install-context-created-dirs (c28736c) with main (c76f272)
Footnotes
-
70 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩
| #[cfg(all(feature = "selinux", any(target_os = "linux", target_os = "android")))] | ||
| fn test_selinux_invalid_context_existing_directory() { | ||
| if !uucore::selinux::is_selinux_enabled() { | ||
| println!("Skipping SELinux test: SELinux is not enabled"); |
There was a problem hiding this comment.
I don't think there's any sense of using println! in tests, what do you think @xtqqczze?
There was a problem hiding this comment.
I don't know, but we do the same in test_selinux.
| let _selinux_guard = { | ||
| let target = dir_strip_dot_for_creation(path); | ||
| match directory_creation_context(&target, b) { | ||
| Ok(guard) => guard, |
There was a problem hiding this comment.
dir_strip_dot_for_creation(path) is computed again a few lines below, could be shared?
| // Like GNU, -Z resets an existing target to its default context; --context doesn't. | ||
| #[cfg(all(feature = "selinux", any(target_os = "linux", target_os = "android")))] | ||
| if b.privileged && b.default_context && is_selinux_enabled() { | ||
| show_if_err!(set_selinux_security_context(path, None)); |
There was a problem hiding this comment.
why not set_selinux_default_context(path) as before?
and please add a test for this -Z reset of an existing dir
There was a problem hiding this comment.
set_selinux_default_context doesn't ask the policy: it keeps the dir's own context, so nothing gets reset. set_selinux_security_context(path, None) looks the default up. Added test_selinux_default_context_resets_existing_directory, which fails with the old call.
| let mode = uucore::libc::S_IFDIR | DEFAULT_MODE as uucore::libc::mode_t; | ||
| uucore::selinux::FsCreateContext::new(path, Some(mode), get_context_for_selinux(b)) | ||
| .map(Some) | ||
| .map_err(|e| uucore::error::USimpleError::new(1, e.to_string())) |
There was a problem hiding this comment.
please use InstallError::SelinuxContextFailed like the other selinux errors here
| // parent keeps its context. | ||
| #[test] | ||
| #[cfg(all(feature = "selinux", any(target_os = "linux", target_os = "android")))] | ||
| fn test_selinux_context_only_on_created_directories() { |
There was a problem hiding this comment.
could you please split it into two tests, one for -d and one for -D?
| // -Z looks the name up in the policy, which lists absolute names only: a relative | ||
| // name must get the same label as the absolute one. | ||
| #[test] | ||
| #[cfg(all(feature = "selinux", any(target_os = "linux", target_os = "android")))] |
69c9757 to
c28736c
Compare
Closes #15332
Based on #15336, which
-Zwith relative names needs (tests/install/install-Z-selinux).With
-Zor--context, install labelled directories after creating them, by walking up from the target and setting the context on every existing parent too, up to/for an absolute path. GNU labels only what it creates.Directories are now created under the creation context, through uucore's
FsCreateContextas mkdir does, so only new ones are labelled and nothing is relabelled afterwards. It also resolves a relative name whose parents are created by the same command. This also gives new directories under-Zthe policy's default type, the directory half of #15091 (except GNU'stmp_tfor an absolute name directly in/tmp). As in GNU 9.12,-d -Zstill resets an existing target to its default context, and-d --contextleaves an existing target alone. An unusable--contextnow fails before anything is done, as in GNU, also when the target directory exists. With SELinux off, no context is set, as in mkdir.Checked as root on Fedora 44 (enforcing) against GNU 9.12 for
-dand-Dwith-Zand--contexton new and existing directories: labels and exit status match, except that a new directory named by a relative path gets the kernel's default under-Z. That comes from the policy lookup inFsCreateContext, which mkdir shares, and is fixed separately in #15336. Added tests for-dand-Dwith--context, for the-Zreset of an existing directory, and for relative names with missing parents; each fails without the change.