Repository navigation
Use restorecon for usbguard config-file SELinux context - #651
Closed
lorengordon wants to merge 2 commits into
Closed
lorengordon wants to merge 2 commits into
lorengordon wants to merge 2 commits into
Conversation
Forcing a type via file.managed `selinux:` makes Salt add a persistent per-file fcontext with `semanage`. Salt decides between `--add` and `--modify` by grepping `semanage fcontext -l` with a `re.escape`d path, and merges stderr into the result. On Amazon Linux 2023 (grep 3.8) the escaped `-` in `usbguard-daemon.conf` makes grep print a "stray \" warning, so Salt picks `--modify` and fails with "File context ... is not defined". This surfaced when usbguard became installed before the STIG states ran, so the file already carried `usbguard_conf_t` and the forced `etc_t` required a context change. Let the loaded policy supply the label with restorecon instead, in both usbguard states. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Member
|
Bleah... Doesn't seem to be a review-option for "entire file". At any rate… Looks like
|
Replace the hand-rolled restorecon cmd.run (and its selinuxenabled onlyif / restorecon unless checks) with the native selinux.fcontext_policy_applied state, which checks with `restorecon -n` and applies with `restorecon -F`, supports test mode and reports the context change. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description:
Replaces the
selinux:block on the usbguard config-file states (RHEL-09-291025andcontent_rule_configure_usbguard_auditbackend) with theselinux.fcontext_policy_appliedstate, which applies the label from the loaded SELinux policy usingrestorecon.Rationale:
file.managedwithselinux:callsset_selinux_context(persist=True), which adds a per-file fcontext viasemanage. Salt chooses--addvs--modifyby runningsemanage fcontext -l | grep -E '<re.escape(path)> 'and merges stderr into the result. On Amazon Linux 2023 (grep 3.8), the escaped-inusbguard-daemon.confmakes grep printgrep: warning: stray \ before -. Salt treats that as an existing entry, runssemanage fcontext --modify, and fails withFile context for /etc/usbguard/usbguard-daemon.conf is not defined.This only surfaces when the file's context needs to change. With ComplianceAsCode/content 0.1.82 the
system_with_kernelapplicability check matches AL2023, so the usbguard rules apply and the oscap remediation installsusbguardandusbguard-selinuxfirst. The file then already hasusbguard_conf_t, and the forcedetc_ttriggers thesemanagepath. Letting the loaded policy supply the label avoids that and gives the correct type whether or not usbguard is installed.Not run through Salt yet; the files render as valid Jinja/YAML. Intended to be verified with the plus3it/scap-formula#129 AL2023 integration job.
Reference Issue:
plus3it/scap-formula#129
🤖 Generated with Claude Code