-
Notifications
You must be signed in to change notification settings - Fork 23
must-gather: collect selinux info #2509
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
Tal-or
wants to merge
4
commits into
openshift-kni:main
Choose a base branch
from
Tal-or:mg_fetch_selinux_label
base: main
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 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
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,64 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| . namespace | ||
| NRO_NAMESPACE=$(nro_namespace) | ||
|
|
||
| SELINUX_INFO_DIR="/must-gather/selinux_info" | ||
| mkdir -p "$SELINUX_INFO_DIR" | ||
|
|
||
| # common variables | ||
| OC_GET_PODS="oc get pods -n $NRO_NAMESPACE" | ||
|
|
||
| function replace_dot_with_underscore() { | ||
| echo $1 | sed 's/\./_/g' | ||
| } | ||
|
|
||
| function gather_selinux_data() { | ||
| local rte_pods=$($OC_GET_PODS -l name='resource-topology' -o jsonpath='{.items[*].metadata.name}') | ||
|
|
||
| for pod in $rte_pods; do | ||
| local original_node_name=$($OC_GET_PODS $pod -o jsonpath='{.spec.nodeName}') | ||
| local node_name=$(replace_dot_with_underscore $original_node_name) | ||
|
|
||
| echo "Gathering SELinux data from node: $node_name" | ||
|
|
||
| local node_dir="$SELINUX_INFO_DIR/$node_name" | ||
| mkdir -p "$node_dir" | ||
|
|
||
| oc debug node/$original_node_name -- bash -c " | ||
| chroot /host bash -c ' | ||
| mkdir -p /tmp/selinux_data | ||
|
|
||
| echo \"=== SELinux context for /var/lib/kubelet ===\" > /tmp/selinux_data/contexts | ||
| ls -Z /var/lib/kubelet >> /tmp/selinux_data/contexts 2>&1 | ||
| echo \"\" >> /tmp/selinux_data/contexts | ||
| echo \"=== SELinux context for kubelet.sock ===\" >> /tmp/selinux_data/contexts | ||
| ls -Z /var/lib/kubelet/pod-resources/kubelet.sock >> /tmp/selinux_data/contexts 2>&1 | ||
|
|
||
| systemctl show kubelet.service > /tmp/selinux_data/kubelet_systemctl_show 2>&1 | ||
|
|
||
| systemctl cat kubelet.service > /tmp/selinux_data/kubelet_systemctl_cat 2>&1 | ||
|
|
||
| echo \"=== SELinux audit logs ===\" > /tmp/selinux_data/audit_selinux.log | ||
| grep -i selinux /var/log/audit/audit.log >> /tmp/selinux_data/audit_selinux.log 2>&1 | ||
|
|
||
| echo \"=== Pod-resources related audit logs ===\" > /tmp/selinux_data/audit_podresources.log | ||
| grep \"kubelet.*pod-resources\" /var/log/audit/audit.log >> /tmp/selinux_data/audit_podresources.log 2>&1 | ||
|
|
||
| tar czf - -C /tmp selinux_data | ||
shajmakh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ' | ||
| " 2>/dev/null | tar xzf - -C "$node_dir" --strip-components=1 | ||
|
|
||
| if [ $? -eq 0 ]; then | ||
| echo "Successfully collected SELinux data from node: $node_name" | ||
| else | ||
| echo "Failed to collect SELinux data from node: $node_name" | ||
| fi | ||
| done | ||
| } | ||
|
|
||
| if [ -z "${NRO_NAMESPACE}" ]; then | ||
| echo "NUMAResources Operator namespace not detected. Skipping SELinux data gathering" | ||
| else | ||
| gather_selinux_data | ||
| fi | ||
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.
Uh oh!
There was an error while loading. Please reload this page.