Skip to content

Commit 54d2e71

Browse files
authored
Merge pull request #34675 from mtardy/psp-annotation
Document the deprecated kubernetes.io/psp annotation
2 parents 9f1bf2c + 1d55061 commit 54d2e71

File tree

2 files changed

+47
-4
lines changed

2 files changed

+47
-4
lines changed

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

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,9 @@ controller selects policies according to the following criteria:
214214
2. If the pod must be defaulted or mutated, the first PodSecurityPolicy
215215
(ordered by name) to allow the pod is selected.
216216

217+
When a Pod is validated against a PodSecurityPolicy, [a `kubernetes.io/psp` annotation](/docs/reference/labels-annotations-taints/#kubernetes-io-psp)
218+
is added to the Pod, with the name of the PodSecurityPolicy as the annotation value.
219+
217220
{{< note >}}
218221
During update operations (during which mutations to pod specs are disallowed)
219222
only non-mutating PodSecurityPolicies are used to validate the pod.
@@ -245,8 +248,7 @@ alias kubectl-user='kubectl --as=system:serviceaccount:psp-example:fake-user -n
245248

246249
### Create a policy and a pod
247250

248-
Define the example PodSecurityPolicy object in a file. This is a policy that
249-
prevents the creation of privileged pods.
251+
This is a policy that prevents the creation of privileged pods.
250252
The name of a PodSecurityPolicy object must be a valid
251253
[DNS subdomain name](/docs/concepts/overview/working-with-objects/names#dns-subdomain-names).
252254

@@ -255,7 +257,7 @@ The name of a PodSecurityPolicy object must be a valid
255257
And create it with kubectl:
256258

257259
```shell
258-
kubectl-admin create -f example-psp.yaml
260+
kubectl-admin create -f https://k8s.io/examples/policy/example-psp.yaml
259261
```
260262

261263
Now, as the unprivileged user, try to create a simple pod:
@@ -284,6 +286,11 @@ pod's service account nor `fake-user` have permission to use the new policy:
284286

285287
```shell
286288
kubectl-user auth can-i use podsecuritypolicy/example
289+
```
290+
291+
The output is similar to this:
292+
293+
```
287294
no
288295
```
289296

@@ -300,14 +307,27 @@ kubectl-admin create role psp:unprivileged \
300307
--verb=use \
301308
--resource=podsecuritypolicy \
302309
--resource-name=example
310+
```
311+
312+
```
303313
role "psp:unprivileged" created
314+
```
304315
316+
```shell
305317
kubectl-admin create rolebinding fake-user:psp:unprivileged \
306318
--role=psp:unprivileged \
307319
--serviceaccount=psp-example:fake-user
320+
```
321+
322+
```
308323
rolebinding "fake-user:psp:unprivileged" created
324+
```
309325

326+
```shell
310327
kubectl-user auth can-i use podsecuritypolicy/example
328+
```
329+
330+
```
311331
yes
312332
```
313333

@@ -332,7 +352,20 @@ The output is similar to this
332352
pod "pause" created
333353
```
334354

335-
It works as expected! But any attempts to create a privileged pod should still
355+
It works as expected! You can verify that the pod was validated against the
356+
newly created PodSecurityPolicy:
357+
358+
```shell
359+
kubectl-user get pod pause -o yaml | grep kubernetes.io/psp
360+
```
361+
362+
The output is similar to this
363+
364+
```
365+
kubernetes.io/psp: example
366+
```
367+
368+
But any attempts to create a privileged pod should still
336369
be denied:
337370

338371
```shell

content/en/docs/reference/labels-annotations-taints/_index.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,16 @@ or updating objects that contain Pod templates, such as Deployments, Jobs, State
618618
See [Enforcing Pod Security at the Namespace Level](/docs/concepts/security/pod-security-admission)
619619
for more information.
620620

621+
### kubernetes.io/psp (deprecated) {#kubernetes-io-psp}
622+
623+
Example: `kubernetes.io/psp: restricted`
624+
625+
This annotation is only relevant if you are using [PodSecurityPolicies](/docs/concepts/security/pod-security-policy/).
626+
627+
When the PodSecurityPolicy admission controller admits a Pod, the admission controller
628+
modifies the Pod to have this annotation.
629+
The value of the annotation is the name of the PodSecurityPolicy that was used for validation.
630+
621631
### seccomp.security.alpha.kubernetes.io/pod (deprecated) {#seccomp-security-alpha-kubernetes-io-pod}
622632

623633
This annotation has been deprecated since Kubernetes v1.19 and will become non-functional in v1.25.

0 commit comments

Comments
 (0)