-
Notifications
You must be signed in to change notification settings - Fork 828
CMP-3628: fixed rule to allow kubelet to be unconfined #14700
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
Open
vickeybrown
wants to merge
1
commit into
ComplianceAsCode:master
Choose a base branch
from
vickeybrown:CMP-3628-rule-fix
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
35 changes: 35 additions & 0 deletions
35
linux_os/guide/system/selinux/selinux_confinement_of_daemons/oval/rhcos4.xml
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| <def-group> | ||
| <definition class="compliance" id="selinux_confinement_of_daemons" version="2"> | ||
| {{{ oval_metadata("All pids in /proc should be assigned an SELinux security context other than 'unconfined_service_t' (kubelet excluded).", rule_title=rule_title) }}} | ||
| <criteria operator="OR"> | ||
| <criterion comment="no unconfined_service_t processes exist" test_ref="test_no_unconfined_service_t_processes" /> | ||
| <criterion comment="at most one unconfined_service_t process" test_ref="test_at_most_one_unconfined_process" /> | ||
| </criteria> | ||
| </definition> | ||
|
|
||
| <!-- Test 1: Check if NO processes have unconfined_service_t --> | ||
| <linux:selinuxsecuritycontext_test check="none satisfy" check_existence="any_exist" | ||
| comment="no processes with unconfined_service_t" id="test_no_unconfined_service_t_processes" version="1"> | ||
| <linux:object object_ref="object_selinux_confinement_of_daemons" /> | ||
| <linux:state state_ref="state_unconfined_service_t" /> | ||
| </linux:selinuxsecuritycontext_test> | ||
|
|
||
| <!-- Test 2: Check that at most one process has unconfined_service_t (assumed to be kubelet) --> | ||
| <linux:selinuxsecuritycontext_test check="all" check_existence="only_one_exists" | ||
| comment="at most one process with unconfined_service_t" id="test_at_most_one_unconfined_process" version="1"> | ||
| <linux:object object_ref="object_selinux_confinement_of_daemons" /> | ||
| <linux:state state_ref="state_unconfined_service_t" /> | ||
| </linux:selinuxsecuritycontext_test> | ||
|
|
||
| <!-- Object: Find all processes in /proc --> | ||
| <linux:selinuxsecuritycontext_object comment="find all processes in /proc" id="object_selinux_confinement_of_daemons" version="2"> | ||
| <linux:behaviors max_depth="1" recurse_direction="down" /> | ||
| <linux:path>/proc</linux:path> | ||
| <linux:filename operation="pattern match">^[0-9]+$</linux:filename> | ||
| </linux:selinuxsecuritycontext_object> | ||
|
|
||
| <!-- State: Match unconfined_service_t type --> | ||
| <linux:selinuxsecuritycontext_state comment="state unconfined_service_t" id="state_unconfined_service_t" version="1"> | ||
| <linux:type datatype="string" operation="equals">unconfined_service_t</linux:type> | ||
| </linux:selinuxsecuritycontext_state> | ||
| </def-group> |
38 changes: 38 additions & 0 deletions
38
...ide/system/selinux/selinux_confinement_of_daemons/tests/kubelet_unconfined.rhcos4.pass.sh
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| #!/bin/bash | ||
| # | ||
| # This test verifies that kubelet is allowed to run with unconfined_service_t on RHCOS4. | ||
| # On RHCOS4, kubelet is explicitly allowed to be unconfined. | ||
|
|
||
| # Create a mock kubelet binary with unconfined_service_t | ||
| # The binary name must be "kubelet" to match the OVAL pattern | ||
| cat > /usr/local/bin/kubelet << 'EOF' | ||
| #!/bin/bash | ||
|
|
||
| while true; do | ||
| sleep 60 | ||
| done | ||
| EOF | ||
| chmod +x /usr/local/bin/kubelet | ||
|
|
||
| cat > /etc/systemd/system/mock-kubelet.service << 'EOF' | ||
| [Unit] | ||
| Description=Mock kubelet for testing | ||
|
|
||
| [Service] | ||
| Type=simple | ||
| ExecStart=/usr/local/bin/kubelet | ||
| SELinuxContext=system_u:system_r:unconfined_service_t:s0 | ||
| Restart=no | ||
|
|
||
| [Install] | ||
| WantedBy=multi-user.target | ||
| EOF | ||
|
|
||
| systemctl daemon-reload | ||
| systemctl start mock-kubelet.service | ||
|
|
||
| # Wait for service to start | ||
| sleep 2 | ||
|
|
||
| # Exit cleanly - the OVAL check should allow kubelet to be unconfined and pass | ||
| exit 0 | ||
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still seem run on RHEL 9. Use
platformand rename the file so that its in the format ofname.pass.sh.