Dieser Inhalt ist in der von Ihnen ausgewählten Sprache nicht verfügbar.
Chapter 16. Understanding and managing pod security admission
Pod security admission is an implementation of the Kubernetes pod security standards. Use pod security admission to restrict the behavior of pods.
16.1. About pod security admission Link kopierenLink in die Zwischenablage kopiert!
OpenShift Container Platform includes Kubernetes pod security admission. Pods that do not comply with the pod security admission defined globally or at the namespace level are not admitted to the cluster and cannot run.
Globally, the
privileged
restricted
You can also configure the pod security admission settings at the namespace level.
Do not run workloads in or share access to default projects. Default projects are reserved for running core cluster components.
The following default projects are considered highly privileged:
default
kube-public
kube-system
openshift
openshift-infra
openshift-node
openshift.io/run-level
0
1
16.1.1. Pod security admission modes Link kopierenLink in die Zwischenablage kopiert!
You can configure the following pod security admission modes for a namespace:
| Mode | Label | Description |
|---|---|---|
|
|
| Rejects a pod from admission if it does not comply with the set profile |
|
|
| Logs audit events if a pod does not comply with the set profile |
|
|
| Displays warnings if a pod does not comply with the set profile |
16.1.2. Pod security admission profiles Link kopierenLink in die Zwischenablage kopiert!
You can set each of the pod security admission modes to one of the following profiles:
| Profile | Description |
|---|---|
|
| Least restrictive policy; allows for known privilege escalation |
|
| Minimally restrictive policy; prevents known privilege escalations |
|
| Most restrictive policy; follows current pod hardening best practices |
16.1.3. Privileged namespaces Link kopierenLink in die Zwischenablage kopiert!
The following system namespaces are always set to the
privileged
-
default -
kube-public -
kube-system
You cannot change the pod security profile for these privileged namespaces.
Example privileged namespace configuration
apiVersion: v1
kind: Namespace
metadata:
labels:
openshift.io/cluster-monitoring: "true"
pod-security.kubernetes.io/enforce: privileged
pod-security.kubernetes.io/audit: privileged
pod-security.kubernetes.io/warn: privileged
name: "<mig_namespace>"
# ...
16.1.4. Pod security admission and security context constraints Link kopierenLink in die Zwischenablage kopiert!
Pod security admission standards and security context constraints are reconciled and enforced by two independent controllers. The two controllers work independently using the following processes to enforce security policies:
-
The security context constraint controller may mutate some security context fields per the pod’s assigned SCC. For example, if the seccomp profile is empty or not set and if the pod’s assigned SCC enforces field to be
seccompProfiles, the controller sets the default type toruntime/default.RuntimeDefault - The security context constraint controller validates the pod’s security context against the matching SCC.
- The pod security admission controller validates the pod’s security context against the pod security standard assigned to the namespace.
16.2. About pod security admission synchronization Link kopierenLink in die Zwischenablage kopiert!
In addition to the global pod security admission control configuration, a controller applies pod security admission control
warn
audit
The controller examines
ServiceAccount
warn
audit
Namespace labeling is based on consideration of namespace-local service account privileges.
Applying pods directly might use the SCC privileges of the user who runs the pod. However, user privileges are not considered during automatic labeling.
16.2.1. Pod security admission synchronization namespace exclusions Link kopierenLink in die Zwischenablage kopiert!
Pod security admission synchronization is permanently disabled on most system-created namespaces. Synchronization is also initially disabled on user-created
openshift-*
If a pod security admission label (
pod-security.kubernetes.io/<mode>
If necessary, you can enable synchronization again by using one of the following methods:
- By removing the modified pod security admission label from the namespace
By setting the
label tosecurity.openshift.io/scc.podSecurityLabelSynctrueIf you force synchronization by adding this label, then any modified pod security admission labels will be overwritten.
16.2.1.1. Permanently disabled namespaces Link kopierenLink in die Zwischenablage kopiert!
Namespaces that are defined as part of the cluster payload have pod security admission synchronization disabled permanently. The following namespaces are permanently disabled:
-
default -
kube-node-lease -
kube-system -
kube-public -
openshift -
All system-created namespaces that are prefixed with , except for
openshift-openshift-operators
16.2.1.2. Initially disabled namespaces Link kopierenLink in die Zwischenablage kopiert!
By default, all namespaces that have an
openshift-
openshift-*
openshift-operators
You cannot enable synchronization for any system-created
openshift-*
openshift-operators
If an Operator is installed in a user-created
openshift-*
16.3. Controlling pod security admission synchronization Link kopierenLink in die Zwischenablage kopiert!
You can enable or disable automatic pod security admission synchronization for most namespaces.
You cannot enable pod security admission synchronization on some system-created namespaces. For more information, see Pod security admission synchronization namespace exclusions.
Procedure
For each namespace that you want to configure, set a value for the
label:security.openshift.io/scc.podSecurityLabelSyncTo disable pod security admission label synchronization in a namespace, set the value of the
label tosecurity.openshift.io/scc.podSecurityLabelSync.falseRun the following command:
$ oc label namespace <namespace> security.openshift.io/scc.podSecurityLabelSync=falseTo enable pod security admission label synchronization in a namespace, set the value of the
label tosecurity.openshift.io/scc.podSecurityLabelSync.trueRun the following command:
$ oc label namespace <namespace> security.openshift.io/scc.podSecurityLabelSync=true
NoteUse the
flag to overwrite the value if this label is already set on the namespace.--overwrite
Additional resources
16.4. Configuring pod security admission for a namespace Link kopierenLink in die Zwischenablage kopiert!
You can configure the pod security admission settings at the namespace level. For each of the pod security admission modes on the namespace, you can set which pod security admission profile to use.
Procedure
For each pod security admission mode that you want to set on a namespace, run the following command:
$ oc label namespace <namespace> \1 pod-security.kubernetes.io/<mode>=<profile> \2 --overwrite
16.5. About pod security admission alerts Link kopierenLink in die Zwischenablage kopiert!
A
PodSecurityViolation
View the Kubernetes API server audit logs to investigate alerts that were triggered. As an example, a workload is likely to fail admission if global enforcement is set to the
restricted
For assistance in identifying pod security admission violation audit events, see Audit annotations in the Kubernetes documentation.
16.5.1. Identifying pod security violations Link kopierenLink in die Zwischenablage kopiert!
The
PodSecurityViolation
must-gather
pod-security.kubernetes.io/audit-violations
Prerequisites
-
You have installed .
jq -
You have access to the cluster as a user with the role.
cluster-admin
Procedure
To gather the audit logs, enter the following command:
$ oc adm must-gather -- /usr/bin/gather_audit_logsTo output the affected workload details, enter the following command:
$ zgrep -h pod-security.kubernetes.io/audit-violations must-gather.local.<archive_id>/<image_digest_id>/audit_logs/kube-apiserver/*log.gz \ | jq -r 'select((.annotations["pod-security.kubernetes.io/audit-violations"] != null) and (.objectRef.resource=="pods")) | .objectRef.namespace + " " + .objectRef.name' \ | sort | uniq -cReplace
and<archive_id>with the actual path names.<image_digest_id>Example output
1 test-namespace my-pod