Skip to content

Commit ddf46cf

Browse files
authored
Merge pull request #29124 from tallclair/podsecurity
[PodSecurity] Correct and clarify a few things
2 parents 43c48ea + 6ac692b commit ddf46cf

File tree

2 files changed

+52
-30
lines changed

2 files changed

+52
-30
lines changed

content/en/docs/concepts/security/pod-security-admission.md

Lines changed: 42 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ The Kubernetes [Pod Security Standards](/docs/concepts/security/pod-security-sta
1919
different isolation levels for Pods. These standards let you define how you want to restrict the
2020
behavior of pods in a clear, consistent fashion.
2121

22-
As an Alpha feature, Kubernetes offers a built-in _Pod Security_ admission plugin, the successor
22+
As an Alpha feature, Kubernetes offers a built-in _Pod Security_ {{< glossary_tooltip
23+
text="admission controller" term_id="admission-controller" >}}, the successor
2324
to [PodSecurityPolicies](/docs/concepts/policy/pod-security-policy/). Pod security restrictions
2425
are applied at the {{< glossary_tooltip text="namespace" term_id="namespace" >}} level when pods
2526
are created.
@@ -40,12 +41,14 @@ Setting pod security controls by namespace is an alpha feature. You must enable
4041
--feature-gates="...,PodSecurity=true"
4142
```
4243

43-
## Pod Security Admission configuration for pods
44+
## Pod Security levels
4445

45-
Different policy levels (e.g. `baseline`, `restricted`) have different requirements for
46-
[Security Context](/docs/tasks/configure-pod-container/security-context/) objects and other related
47-
fields. Check out the [Pod Security Standards](/docs/concepts/security/pod-security-standards) page
48-
for an in-depth look at those requirements.
46+
Pod Security admission places requirements on a Pod's [Security
47+
Context](/docs/tasks/configure-pod-container/security-context/) and other related fields according
48+
to the three levels defined by the [Pod Security
49+
Standards](/docs/concepts/security/pod-security-standards): `privileged`, `baseline`, and
50+
`restricted`. Refer to the [Pod Security Standards](/docs/concepts/security/pod-security-standards)
51+
page for an in-depth look at those requirements.
4952

5053
## Pod Security Admission labels for namespaces
5154

@@ -64,7 +67,9 @@ Mode | Description
6467
**`warn`** | Policy violations will trigger a user-facing warning, but are otherwise allowed.
6568
{{< /table >}}
6669

67-
For each mode, there are two labels that you can use:
70+
A namespace can configure any or all modes, or even set a different level for different modes.
71+
72+
For each mode, there are two labels that determine the policy used:
6873

6974
```yaml
7075
# The per-mode level label indicates which policy level to apply for the mode.
@@ -74,56 +79,67 @@ For each mode, there are two labels that you can use:
7479
pod-security.kubernetes.io/<MODE>: <LEVEL>
7580

7681
# Optional: per-mode version label that can be used to pin the policy to the
77-
# version that shipped with a given Kubernetes minor version (e.g. v{{< skew latestVersion >}}).
82+
# version that shipped with a given Kubernetes minor version (for example v{{< skew latestVersion >}}).
7883
#
7984
# MODE must be one of `enforce`, `audit`, or `warn`.
80-
# VERSION must be a valid Kubernetes version label.
85+
# VERSION must be a valid Kubernetes minor version, or `latest`.
8186
pod-security.kubernetes.io/<MODE>-version: <VERSION>
8287
```
8388
8489
Check out [Enforce Pod Security Standards with Namespace Labels](/docs/tasks/configure-pod-container/enforce-standards-namespace-labels) to see example usage.
8590
91+
## Workload resources and Pod templates
92+
93+
Pods are often created indirectly, by creating a [workload
94+
object](https://kubernetes.io/docs/concepts/workloads/controllers/) such as a {{< glossary_tooltip
95+
term_id="deployment" >}} or {{< glossary_tooltip term_id="job">}}. The workload object defines a
96+
_Pod template_ and a {{< glossary_tooltip term_id="controller" text="controller" >}} for the
97+
workload resource creates Pods based on that template. To help catch violations early, both the
98+
audit and warning modes are applied to the workload resources. However, enforce mode is **not**
99+
applied to workload resources, only to the resulting pod objects.
100+
86101
## Exemptions
87102
88103
You can define _exemptions_ from pod security enforcement in order allow the creation of pods that
89104
would have otherwise been prohibited due to the policy associated with a given namespace.
90105
Exemptions can be statically configured in the
91106
[Admission Controller configuration](#configuring-the-admission-controller).
92107
93-
Exemptions must be explicitly enumerated, and do not support indirection such as label or group
94-
selectors. Requests meeting exemption criteria are _ignored_ by the Admission Controller (all
95-
`enforce`, `audit` and `warn` behaviors), except to record an audit annotation. Exemption
96-
dimensions include:
108+
Exemptions must be explicitly enumerated. Requests meeting exemption criteria are _ignored_ by the
109+
Admission Controller (all `enforce`, `audit` and `warn` behaviors are skipped). Exemption dimensions include:
97110

98111
- **Usernames:** requests from users with an exempt authenticated (or impersonated) username are
99112
ignored.
100-
- **RuntimeClassNames:** pods and templated pods specifying an exempt runtime class name are
113+
- **RuntimeClassNames:** pods and [workload resources](#workload-resources-and-pod-templates) specifying an exempt runtime class name are
101114
ignored.
102-
- **Namespaces:** pods and templated pods in an exempt namespace are ignored.
115+
- **Namespaces:** pods and [workload resources](#workload-resources-and-pod-templates) in an exempt namespace are ignored.
116+
117+
{{< caution >}}
103118

104-
The username exemption is special in that the creating user is not persisted on the Pod object,
105-
and the Pod may be modified by different non-exempt users in the future. Use cases for username
106-
exemptions include:
119+
Most pods are created by a controller in response to a [workload
120+
resource](#workload-resources-and-pod-templates), meaning that exempting an end user will only
121+
exempt them from enforcement when creating pods directly, but not when creating a workload resource.
122+
Controller service accounts (such as `system:serviceaccount:kube-system:replicaset-controller`)
123+
should generally not be exempted, as doing so would implicitly exempt any user that can create the
124+
corresponding workload resource.
107125

108-
- Trusted {{< glossary_tooltip term_id="controller" text="controllers" >}} that create pods.
109-
- Usernames that represent break-glass operations roles, for example for debugging workloads
110-
in a namespace that has restrictions configured. This mechanism only works with a username
111-
match; you cannot grant exemptions based on group membership.
126+
{{< /caution >}}
112127

113-
Updates to the following pod fields are exempt from policy checks, meaning that if a pod update request only changes these fields, it will not be denied even if the pod is in violation of the current policy level:
128+
Updates to the following pod fields are exempt from policy checks, meaning that if a pod update
129+
request only changes these fields, it will not be denied even if the pod is in violation of the
130+
current policy level:
114131

115-
- Any metadata updates EXCEPT changes to the seccomp or apparmor annotations:
132+
- Any metadata updates **except** changes to the seccomp or AppArmor annotations:
116133
- `seccomp.security.alpha.kubernetes.io/pod` (deprecated)
117134
- `container.seccomp.security.alpha.kubernetes.io/*` (deprecated)
118135
- `container.apparmor.security.beta.kubernetes.io/*`
119136
- Valid updates to `.spec.activeDeadlineSeconds`
120137
- Valid updates to `.spec.tolerations`
121-
- Valid updates to Pod resources
122138

123139
## {{% heading "whatsnext" %}}
124140

125141
- [Pod Security Standards](/docs/concepts/security/pod-security-standards)
126142
- [Enforcing Pod Security Standards](/docs/setup/best-practices/enforcing-pod-security-standards)
127143
- [Enforce Pod Security Standards by Configuring the Built-in Admission Controller](/docs/tasks/configure-pod-container/enforce-standards-admission-controller)
128144
- [Enforce Pod Security Standards with Namespace Labels](/docs/tasks/configure-pod-container/enforce-standards-namespace-labels)
129-
- [Migrating from PodSecurityPolicy to PodSecurity](/docs/tasks/secure-pods/migrate-from-psp)
145+
- [Migrating from PodSecurityPolicy to PodSecurity](/docs/tasks/secure-pods/migrate-from-psp)

content/en/docs/tasks/configure-pod-container/enforce-standards-namespace-labels.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,22 @@ kubectl label --dry-run=server --overwrite ns --all \
5959
### Applying to all namespaces
6060

6161
If you're just getting started with the Pod Security Standards, a suitable first step would be to
62-
configure all namespaces as `privileged` but set up audit annotations for a stricter level such as
63-
`baseline`:
62+
configure all namespaces with audit annotations for a stricter level such as `baseline`:
6463

6564
```shell
6665
kubectl label --overwrite ns --all \
67-
pod-security.kubernetes.io/enforce=privileged \
6866
pod-security.kubernetes.io/audit=baseline \
6967
pod-security.kubernetes.io/warn=baseline
7068
```
7169

70+
Note that this is not setting an enforce level, so that namespaces that haven't been explicitly
71+
evaluated can be distinguished. You can list namespaces without an explicitly set enforce level
72+
using this command:
73+
74+
```shell
75+
kubectl get namespaces --selector='!pod-security.kubernetes.io/enforce'
76+
```
77+
7278
### Applying to a single namespace
7379

7480
You can update a specific namespace as well. This command adds the `enforce=restricted`
@@ -78,4 +84,4 @@ policy to `my-existing-namespace`, pinning the restricted policy version to v{{<
7884
kubectl label --overwrite ns my-existing-namespace \
7985
pod-security.kubernetes.io/enforce=restricted \
8086
pod-security.kubernetes.io/enforce-version=v{{< skew latestVersion >}}
81-
```
87+
```

0 commit comments

Comments
 (0)