@@ -214,6 +214,9 @@ controller selects policies according to the following criteria:
214
214
2. If the pod must be defaulted or mutated, the first PodSecurityPolicy
215
215
(ordered by name) to allow the pod is selected.
216
216
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
+
217
220
{{< note >}}
218
221
During update operations (during which mutations to pod specs are disallowed)
219
222
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
245
248
246
249
# ## Create a policy and a pod
247
250
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.
250
252
The name of a PodSecurityPolicy object must be a valid
251
253
[DNS subdomain name](/docs/concepts/overview/working-with-objects/names#dns-subdomain-names).
252
254
@@ -255,7 +257,7 @@ The name of a PodSecurityPolicy object must be a valid
255
257
And create it with kubectl :
256
258
257
259
` ` ` shell
258
- kubectl-admin create -f example-psp.yaml
260
+ kubectl-admin create -f https://k8s.io/examples/policy/ example-psp.yaml
259
261
` ` `
260
262
261
263
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:
284
286
285
287
` ` ` shell
286
288
kubectl-user auth can-i use podsecuritypolicy/example
289
+ ` ` `
290
+
291
+ The output is similar to this :
292
+
293
+ ` ` `
287
294
no
288
295
` ` `
289
296
@@ -300,14 +307,27 @@ kubectl-admin create role psp:unprivileged \
300
307
--verb=use \
301
308
--resource=podsecuritypolicy \
302
309
--resource-name=example
310
+ ` ` `
311
+
312
+ ```
303
313
role "psp: unprivileged " created
314
+ ```
304
315
316
+ ```shell
305
317
kubectl-admin create rolebinding fake-user:psp:unprivileged \
306
318
--role=psp:unprivileged \
307
319
--serviceaccount=psp-example:fake-user
320
+ ```
321
+
322
+ ```
308
323
rolebinding "fake-user:psp:unprivileged" created
324
+ ```
309
325
326
+ ``` shell
310
327
kubectl-user auth can-i use podsecuritypolicy/example
328
+ ```
329
+
330
+ ```
311
331
yes
312
332
```
313
333
@@ -332,7 +352,20 @@ The output is similar to this
332
352
pod "pause" created
333
353
```
334
354
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
336
369
be denied:
337
370
338
371
``` shell
0 commit comments