Repository navigation
install: label only the directories it creates - #15333
abendrothj wants to merge 1 commit 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 not alter performance1 warning, 1 note
Comparing Footnotes
|
| #[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
| /// Traverses from the given starting path up to existing parent directories. | ||
| /// Returns a vector of paths in reverse order (from parent to child). | ||
| /// With -Z or --context, label the directories created while the returned guard lives. | ||
| /// One policy lookup for `path` serves all of them; GNU looks up each component. |
There was a problem hiding this comment.
so with -Z the created parents get the leaf's type, e.g. install -d -Z /var/www/cgi-bin/x labels /var/www as cgi content?
GNU looks up each one, could we do the same?
There was a problem hiding this comment.
Yes, good catch. Each new directory is now looked up by its own name, as GNU does (create_dir_all_safe takes a hook for it). Checked against GNU 9.12 with /var/www/…/cgi-bin/… as root.
c28736c to
f145794
Compare
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.
|
Binary size comparison: |
f145794 to
bb549c8
Compare
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.
|
rebased on main; after #12715 |
Closes #15332
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. With-Z, each new directory gets the policy's default for its own name, as in GNU; for that,create_dir_all_safetakes a hook that runs before each missing directory is created. 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, under
/var/wwwand/home, for-dand-Dwith-Zand--contexton new and existing directories, relative and absolute: labels and exit status match in all 22 cases. Added tests for-dand-Dwith--context, for the-Zreset of an existing directory, for relative names with missing parents, and for new parents of a.snapshotsdirectory, which the policy types differently; each fails without the change.