Skip to content

cp: improve the selinux support #7878

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 6, 2025
Merged

Conversation

sylvestre
Copy link
Contributor

No description provided.

Copy link

github-actions bot commented May 3, 2025

GNU testsuite comparison:

Skip an intermittent issue tests/misc/stdbuf (fails in this run but passes in the 'main' branch)

@cakebaker
Copy link
Contributor

The code currently fails due to the changes in #7845:

error[E0277]: `?` couldn't convert the error to `Error`
    --> src/uu/cp/src/cp.rs:2461:86
     |
2251 | ) -> CopyResult<()> {
     |      -------------- expected `Error` because of this
...
2461 |         uucore::selinux::set_selinux_security_context(dest, options.context.as_ref())?;
     |         -----------------------------------------------------------------------------^ the trait `From<SeLinuxError>` is not implemented for `Error`
     |         |
     |         this can't be annotated with `?` because it has type `Result<_, SeLinuxError>`

Copy link

github-actions bot commented May 4, 2025

GNU testsuite comparison:

Skip an intermittent issue tests/misc/tee (fails in this run but passes in the 'main' branch)
Skipping an intermittent issue tests/timeout/timeout (passes in this run but fails in the 'main' branch)

@sylvestre sylvestre requested review from cakebaker and Copilot May 4, 2025 15:55
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR improves SELinux support across the codebase by updating error messages, refactoring the SELinux error enum, and adding new command-line options for SELinux context handling. Key changes include:

  • Updating expected error message substrings in SELinux-related tests.
  • Refactoring the SELinux error enum (now SeLinuxError) with improved error variants and messages.
  • Adding new SELinux-related command-line options in the cp utility and updating Cargo.toml dependency configurations.

Reviewed Changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tests/by-util/test_mknod.rs Adjust expected error string casing for SELinux errors
tests/by-util/test_mkfifo.rs Adjust expected error string casing for SELinux errors
tests/by-util/test_mkdir.rs Update expected SELinux error message to reflect new error variant
src/uucore/src/lib/features/selinux.rs Refactor SELinux error enum and error mapping using thiserror
src/uu/mkdir/src/mkdir.rs Update error reporting when setting SELinux context in directory creation
src/uu/cp/src/cp.rs Add SELinux context flags and update feature flag usage for SELinux
src/uu/cp/Cargo.toml Update SELinux dependency configuration to include thiserror
Comments suppressed due to low confidence (4)

tests/by-util/test_mknod.rs:189

  • Ensure that the expected error message substring matches the actual output case consistently across tests. If the change to lowercase is intentional, verify that all related tests follow this convention.
.stderr_contains("Failed to");

tests/by-util/test_mkfifo.rs:162

  • Ensure the expected error message substring now reflects the updated casing ('failed to') consistently with the changes in other SELinux tests.
.stderr_contains("Failed to");

tests/by-util/test_mkdir.rs:413

  • The expected error message has been updated to 'Failed to set default file creation context to 'testtest':'; ensure that the test expectation is aligned with the new error message generated by the updated SELinux handling.
.stderr_contains("failed to set SELinux security context:");

src/uucore/src/lib/features/selinux.rs:26

  • [nitpick] The error variant names 'ContextSetFailure' and 'ContextConversionFailure' are very similar and could be confusing; consider renaming one for clearer differentiation between failures during context conversion versus setting.
ContextConversionFailure(String, String),

@cakebaker
Copy link
Contributor

Can you please rebase? The PR currently contains commits from a different PR.

Copy link

github-actions bot commented May 5, 2025

GNU testsuite comparison:

Skipping an intermittent issue tests/misc/stdbuf (passes in this run but fails in the 'main' branch)
Skipping an intermittent issue tests/timeout/timeout (passes in this run but fails in the 'main' branch)

Comment on lines 6295 to 6297
"Expected '{}' not found in getfattr output:\n{}",
"foo",
selinux_perm
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"Expected '{}' not found in getfattr output:\n{}",
"foo",
selinux_perm
"Expected 'foo' not found in getfattr output:\n{selinux_perm}"

Comment on lines 6345 to 6347
"Expected '{}' not found in getfattr output:\n{}",
"foo",
selinux_perm_dest
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"Expected '{}' not found in getfattr output:\n{}",
"foo",
selinux_perm_dest
"Expected 'foo' not found in getfattr output:\n{selinux_perm_dest}"

Comment on lines 6375 to 6377
// Get the default SELinux context for the destination file path
// on Debian/Ubuntu, this program is provided by the selinux-utils package
// on Fedora/RHEL, this program is provided by the libselinux-devel package
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Get the default SELinux context for the destination file path
// on Debian/Ubuntu, this program is provided by the selinux-utils package
// on Fedora/RHEL, this program is provided by the libselinux-devel package
// Get the default SELinux context for the destination file path.
// On Debian/Ubuntu, this program is provided by the selinux-utils package.
// On Fedora/RHEL, this program is provided by the libselinux-devel package.

Comment on lines 6435 to 6431
// Create two different files
at.write(TEST_HELLO_WORLD_SOURCE, "source content");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either the comment is incorrect or the code. There is only one call of at.write().

}

// Copy the file with preserved context
// Only works at root
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Only works at root
// Only works as root

Copy link

github-actions bot commented May 5, 2025

GNU testsuite comparison:

Skip an intermittent issue tests/misc/stdbuf (fails in this run but passes in the 'main' branch)
Skipping an intermittent issue tests/misc/tee (passes in this run but fails in the 'main' branch)

sylvestre and others added 4 commits May 6, 2025 08:52
Copy link

github-actions bot commented May 6, 2025

GNU testsuite comparison:

Skipping an intermittent issue tests/misc/stdbuf (passes in this run but fails in the 'main' branch)
Skipping an intermittent issue tests/timeout/timeout (passes in this run but fails in the 'main' branch)

@cakebaker cakebaker merged commit c981767 into uutils:main May 6, 2025
70 checks passed
@sylvestre sylvestre deleted the selinux-cp branch May 6, 2025 08:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants