Skip to content

Commit 2e97713

Browse files
committed
OCP BUGS-1585: Adding how to find workloads causing pod security violations
1 parent 2218985 commit 2e97713

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed

authentication/understanding-and-managing-pod-security-admission.adoc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,18 @@ toc::[]
88

99
Pod security admission is an implementation of the link:https://kubernetes.io/docs/concepts/security/pod-security-standards/[Kubernetes pod security standards]. Use pod security admission to restrict the behavior of pods.
1010

11+
// Security context constraint synchronization with pod security standards
1112
include::modules/security-context-constraints-psa-synchronization.adoc[leveloffset=+1]
1213

14+
// Controlling pod security admission synchronization
1315
include::modules/security-context-constraints-psa-opting.adoc[leveloffset=+1]
1416

17+
// About pod security admission alerts
1518
include::modules/security-context-constraints-psa-rectifying.adoc[leveloffset=+1]
1619

20+
// Identifying pod security violations
21+
include::modules/security-context-constraints-psa-alert-eval.adoc[leveloffset=+2]
22+
1723
[role="_additional-resources"]
1824
[id="additional-resources_managing-pod-security-admission"]
1925
== Additional resources
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Module included in the following assemblies:
2+
//
3+
// * authentication/understanding-and-managing-pod-security-admission.adoc
4+
5+
:_content-type: PROCEDURE
6+
[id="security-context-constraints-psa-alert-eval_{context}"]
7+
= Identifying pod security violations
8+
9+
The `PodSecurityViolation` alert does not provide details on which workloads are causing pod security violations. You can identify the affected workloads by reviewing the Kubernetes API server audit logs. This procedure uses the `must-gather` tool to gather the audit logs and then searches for the `pod-security.kubernetes.io/audit-violations` annotation.
10+
11+
.Prerequisites
12+
13+
* You have installed `jq`.
14+
* You have access to the cluster as a user with the `cluster-admin` role.
15+
16+
.Procedure
17+
18+
. To gather the audit logs, enter the following command:
19+
+
20+
[source,terminal]
21+
----
22+
$ oc adm must-gather -- /usr/bin/gather_audit_logs
23+
----
24+
25+
. To output the affected workload details, enter the following command:
26+
+
27+
[source,terminal]
28+
----
29+
$ zgrep -h pod-security.kubernetes.io/audit-violations must-gather.local.<archive_id>/quay*/audit_logs/kube-apiserver/*log.gz \
30+
| jq -r 'select((.annotations["pod-security.kubernetes.io/audit-violations"] != null) and (.objectRef.resource=="pods")) | .objectRef.namespace + " " + .objectRef.name + " " + .objectRef.resource' \
31+
| sort | uniq -c
32+
----
33+
+
34+
Replace `must-gather.local.<archive_id>` with the actual directory name.
35+
+
36+
.Example output
37+
[source,text]
38+
----
39+
15 ci namespace-ttl-controller deployments
40+
1 ci-op-k5whzrsh rpm-repo-546f98d8b replicasets
41+
1 ci-op-k5whzrsh rpm-repo deployments
42+
----

modules/security-context-constraints-psa-rectifying.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// * authentication/understanding-and-managing-pod-security-admission.adoc
44

5-
:_content-type: PROCEDURE
5+
:_content-type: CONCEPT
66
[id="security-context-constraints-psa-rectifying_{context}"]
77
= About pod security admission alerts
88

0 commit comments

Comments
 (0)