@@ -23,7 +23,8 @@ updates.
23
23
## What is a Pod Security Policy?
24
24
25
25
A _ Pod Security Policy_ is a cluster-level resource that controls security
26
- sensitive aspects of the pod specification. The [ PodSecurityPolicy] (/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#podsecuritypolicy-v1beta1-policy) objects
26
+ sensitive aspects of the pod specification. The
27
+ [ PodSecurityPolicy] (/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#podsecuritypolicy-v1beta1-policy) objects
27
28
define a set of conditions that a pod must run with in order to be accepted into
28
29
the system, as well as defaults for the related fields. They allow an
29
30
administrator to control the following:
@@ -50,10 +51,10 @@ administrator to control the following:
50
51
51
52
## Enabling Pod Security Policies
52
53
53
- Pod security policy control is implemented as an optional [ admission
54
- controller] ( /docs/reference/access-authn-authz/admission-controllers/#podsecuritypolicy ) .
55
- PodSecurityPolicies are enforced by [ enabling the admission
56
- controller] ( /docs/reference/access-authn-authz/admission-controllers/#how-do-i-turn-on-an-admission-control-plug-in ) ,
54
+ Pod security policy control is implemented as an optional
55
+ [ admission controller] ( /docs/reference/access-authn-authz/admission-controllers/#podsecuritypolicy ) .
56
+ PodSecurityPolicies are enforced by
57
+ [ enabling the admission controller] ( /docs/reference/access-authn-authz/admission-controllers/#how-do-i-turn-on-an-admission-control-plug-in ) ,
57
58
but doing so without authorizing any policies ** will prevent any pods from being created** in the
58
59
cluster.
59
60
@@ -65,9 +66,9 @@ controller.
65
66
## Authorizing Policies
66
67
67
68
When a PodSecurityPolicy resource is created, it does nothing. In order to use
68
- it, the requesting user or target pod's [ service
69
- account] ( /docs/tasks/configure-pod-container/configure-service-account/ ) must be
70
- authorized to use the policy, by allowing the ` use ` verb on the policy.
69
+ it, the requesting user or target pod's
70
+ [ service account] ( /docs/tasks/configure-pod-container/configure-service-account/ )
71
+ must be authorized to use the policy, by allowing the ` use ` verb on the policy.
71
72
72
73
Most Kubernetes pods are not created directly by users. Instead, they are
73
74
typically created indirectly as part of a
@@ -128,6 +129,7 @@ subjects:
128
129
If a `RoleBinding` (not a `ClusterRoleBinding`) is used, it will only grant
129
130
usage for pods being run in the same namespace as the binding. This can be
130
131
paired with system groups to grant access to all pods run in the namespace :
132
+
131
133
` ` ` yaml
132
134
# Authorize all service accounts in a namespace:
133
135
- kind: Group
@@ -139,45 +141,47 @@ paired with system groups to grant access to all pods run in the namespace:
139
141
name: system:authenticated
140
142
` ` `
141
143
142
- For more examples of RBAC bindings, see [Role Binding
143
- Examples](/docs/reference/access-authn-authz/rbac#role-binding-examples).
144
- For a complete example of authorizing a PodSecurityPolicy, see
145
- [below](#example).
144
+ For more examples of RBAC bindings, see
145
+ [RoleBinding examples](/docs/reference/access-authn-authz/rbac#role-binding-examples).
146
+ For a complete example of authorizing a PodSecurityPolicy, see [below](#example).
146
147
147
148
# ## Recommended Practice
148
149
149
- PodSecurityPolicy is being replaced by a new, simplified `PodSecurity` {{< glossary_tooltip
150
- text="admission controller" term_id="admission-controller" >}}. For more details on this change, see
151
- [PodSecurityPolicy Deprecation : Past, Present, and
152
- Future](/blog/2021/04/06/podsecuritypolicy-deprecation-past-present-and-future/). Follow these
153
- guidelines to simplify migration from PodSecurityPolicy to the new admission controller :
150
+ PodSecurityPolicy is being replaced by a new, simplified `PodSecurity`
151
+ {{< glossary_tooltip text="admission controller" term_id="admission-controller" >}}.
152
+ For more details on this change, see
153
+ [PodSecurityPolicy Deprecation : Past, Present, and Future](/blog/2021/04/06/podsecuritypolicy-deprecation-past-present-and-future/).
154
+ Follow these guidelines to simplify migration from PodSecurityPolicy to the
155
+ new admission controller :
156
+
157
+ 1. Limit your PodSecurityPolicies to the policies defined by the
158
+ [Pod Security Standards](/docs/concepts/security/pod-security-standards) :
154
159
155
- 1. Limit your PodSecurityPolicies to the policies defined by the [Pod Security Standards](/docs/concepts/security/pod-security-standards) :
156
- - {{< example file="policy/privileged-psp.yaml" >}}Privileged{{< /example >}}
157
- - {{< example file="policy/baseline-psp.yaml" >}}Baseline{{< /example >}}
158
- - {{< example file="policy/restricted-psp.yaml" >}}Restricted{{< /example >}}
160
+ - {{< example file="policy/privileged-psp.yaml" >}}Privileged{{< /example >}}
161
+ - {{< example file="policy/baseline-psp.yaml" >}}Baseline{{< /example >}}
162
+ - {{< example file="policy/restricted-psp.yaml" >}}Restricted{{< /example >}}
159
163
160
- 2 . Only bind PSPs to entire namespaces, by using the `system:serviceaccounts:<namespace>` group
164
+ 1 . Only bind PSPs to entire namespaces, by using the `system:serviceaccounts:<namespace>` group
161
165
(where `<namespace>` is the target namespace). For example :
162
166
163
- ` ` ` yaml
164
- apiVersion: rbac.authorization.k8s.io/v1
165
- # This cluster role binding allows all pods in the "development" namespace to use the baseline PSP.
166
- kind: ClusterRoleBinding
167
- metadata:
168
- name: psp-baseline-namespaces
169
- roleRef:
170
- kind: ClusterRole
171
- name: psp-baseline
172
- apiGroup: rbac.authorization.k8s.io
173
- subjects:
174
- - kind: Group
175
- name: system:serviceaccounts:development
176
- apiGroup: rbac.authorization.k8s.io
177
- - kind: Group
178
- name: system:serviceaccounts:canary
179
- apiGroup: rbac.authorization.k8s.io
180
- ` ` `
167
+ ` ` ` yaml
168
+ apiVersion: rbac.authorization.k8s.io/v1
169
+ # This cluster role binding allows all pods in the "development" namespace to use the baseline PSP.
170
+ kind: ClusterRoleBinding
171
+ metadata:
172
+ name: psp-baseline-namespaces
173
+ roleRef:
174
+ kind: ClusterRole
175
+ name: psp-baseline
176
+ apiGroup: rbac.authorization.k8s.io
177
+ subjects:
178
+ - kind: Group
179
+ name: system:serviceaccounts:development
180
+ apiGroup: rbac.authorization.k8s.io
181
+ - kind: Group
182
+ name: system:serviceaccounts:canary
183
+ apiGroup: rbac.authorization.k8s.io
184
+ ` ` `
181
185
182
186
# ## Troubleshooting
183
187
@@ -213,8 +217,8 @@ only non-mutating PodSecurityPolicies are used to validate the pod.
213
217
214
218
# # Example
215
219
216
- _This example assumes you have a running cluster with the PodSecurityPolicy
217
- admission controller enabled and you have cluster admin privileges._
220
+ This example assumes you have a running cluster with the PodSecurityPolicy
221
+ admission controller enabled and you have cluster admin privileges.
218
222
219
223
# ## Set up
220
224
@@ -360,12 +364,24 @@ Let's try that again, slightly differently:
360
364
361
365
``` shell
362
366
kubectl-user create deployment pause --image=k8s.gcr.io/pause
363
- deployment " pause " created
367
+ ```
364
368
369
+ ``` none
370
+ deployment "pause" created
371
+ ```
372
+ ``` shell
365
373
kubectl-user get pods
374
+ ```
375
+
376
+ ```
366
377
No resources found.
378
+ ```
367
379
380
+ ``` shell
368
381
kubectl-user get events | head -n 2
382
+ ```
383
+
384
+ ```
369
385
LASTSEEN FIRSTSEEN COUNT NAME KIND SUBOBJECT TYPE REASON SOURCE MESSAGE
370
386
1m 2m 15 pause-7774d79b5 ReplicaSet Warning FailedCreate replicaset-controller Error creating: pods "pause-7774d79b5-" is forbidden: no providers available to validate pod request
371
387
```
@@ -386,6 +402,9 @@ is `default`:
386
402
kubectl-admin create rolebinding default:psp:unprivileged \
387
403
--role=psp:unprivileged \
388
404
--serviceaccount=psp-example:default
405
+ ```
406
+
407
+ ``` none
389
408
rolebinding "default:psp:unprivileged" created
390
409
```
391
410
@@ -394,6 +413,9 @@ eventually succeed in creating the pod:
394
413
395
414
``` shell
396
415
kubectl-user get pods --watch
416
+ ```
417
+
418
+ ``` none
397
419
NAME READY STATUS RESTARTS AGE
398
420
pause-7774d79b5-qrgcb 0/1 Pending 0 1s
399
421
pause-7774d79b5-qrgcb 0/1 Pending 0 1s
@@ -407,6 +429,9 @@ Delete the namespace to clean up most of the example resources:
407
429
408
430
``` shell
409
431
kubectl-admin delete ns psp-example
432
+ ```
433
+
434
+ ```
410
435
namespace "psp-example" deleted
411
436
```
412
437
@@ -415,6 +440,9 @@ up separately:
415
440
416
441
``` shell
417
442
kubectl-admin delete psp example
443
+ ```
444
+
445
+ ```
418
446
podsecuritypolicy "example" deleted
419
447
```
420
448
@@ -431,7 +459,8 @@ several security mechanisms.
431
459
432
460
{{< codenew file="policy/restricted-psp.yaml" >}}
433
461
434
- See [ Pod Security Standards] ( /docs/concepts/security/pod-security-standards/#policy-instantiation ) for more examples.
462
+ See [ Pod Security Standards] ( /docs/concepts/security/pod-security-standards/#policy-instantiation )
463
+ for more examples.
435
464
436
465
## Policy Reference
437
466
@@ -467,17 +496,17 @@ and `max`(inclusive). Defaults to no allowed host ports.
467
496
** Volumes** - Provides a list of allowed volume types. The allowable values
468
497
correspond to the volume sources that are defined when creating a volume. For
469
498
the complete list of volume types, see [ Types of
470
- Volumes] ( /docs/concepts/storage/volumes/#types-of-volumes ) . Additionally, ` * `
471
- may be used to allow all volume types.
499
+ Volumes] ( /docs/concepts/storage/volumes/#types-of-volumes ) . Additionally,
500
+ ` * ` may be used to allow all volume types.
472
501
473
502
The ** recommended minimum set** of allowed volumes for new PSPs are:
474
503
475
- - configMap
476
- - downwardAPI
477
- - emptyDir
478
- - persistentVolumeClaim
479
- - secret
480
- - projected
504
+ - ` configMap `
505
+ - ` downwardAPI `
506
+ - ` emptyDir `
507
+ - ` persistentVolumeClaim `
508
+ - ` secret `
509
+ - ` projected `
481
510
482
511
{{< warning >}}
483
512
PodSecurityPolicy does not limit the types of ` PersistentVolume ` objects that
@@ -489,10 +518,10 @@ should be granted permission to create `PersistentVolume` objects.
489
518
** FSGroup** - Controls the supplemental group applied to some volumes.
490
519
491
520
- * MustRunAs* - Requires at least one ` range ` to be specified. Uses the
492
- minimum value of the first range as the default. Validates against all ranges.
521
+ minimum value of the first range as the default. Validates against all ranges.
493
522
- * MayRunAs* - Requires at least one ` range ` to be specified. Allows
494
- ` FSGroups ` to be left unset without providing a default. Validates against
495
- all ranges if ` FSGroups ` is set.
523
+ ` FSGroups ` to be left unset without providing a default. Validates against
524
+ all ranges if ` FSGroups ` is set.
496
525
- * RunAsAny* - No default provided. Allows any ` fsGroup ` ID to be specified.
497
526
498
527
** AllowedHostPaths** - This specifies a list of host paths that are allowed
@@ -511,7 +540,8 @@ For example:
511
540
readOnly : true # only allow read-only mounts
512
541
` ` `
513
542
514
- {{< warning >}}There are many ways a container with unrestricted access to the host
543
+ {{< warning >}}
544
+ There are many ways a container with unrestricted access to the host
515
545
filesystem can escalate privileges, including reading data from other
516
546
containers, and abusing the credentials of system services, such as Kubelet.
517
547
@@ -552,33 +582,33 @@ spec:
552
582
**RunAsUser** - Controls which user ID the containers are run with.
553
583
554
584
- *MustRunAs* - Requires at least one `range` to be specified. Uses the
555
- minimum value of the first range as the default. Validates against all ranges.
585
+ minimum value of the first range as the default. Validates against all ranges.
556
586
- *MustRunAsNonRoot* - Requires that the pod be submitted with a non-zero
557
- ` runAsUser` or have the `USER` directive defined (using a numeric UID) in the
558
- image. Pods which have specified neither `runAsNonRoot` nor `runAsUser` settings
559
- will be mutated to set `runAsNonRoot=true`, thus requiring a defined non-zero
560
- numeric `USER` directive in the container. No default provided. Setting
561
- ` allowPrivilegeEscalation=false` is strongly recommended with this strategy.
587
+ ` runAsUser` or have the `USER` directive defined (using a numeric UID) in the
588
+ image. Pods which have specified neither `runAsNonRoot` nor `runAsUser` settings
589
+ will be mutated to set `runAsNonRoot=true`, thus requiring a defined non-zero
590
+ numeric `USER` directive in the container. No default provided. Setting
591
+ ` allowPrivilegeEscalation=false` is strongly recommended with this strategy.
562
592
- *RunAsAny* - No default provided. Allows any `runAsUser` to be specified.
563
593
564
594
**RunAsGroup** - Controls which primary group ID the containers are run with.
565
595
566
596
- *MustRunAs* - Requires at least one `range` to be specified. Uses the
567
- minimum value of the first range as the default. Validates against all ranges.
597
+ minimum value of the first range as the default. Validates against all ranges.
568
598
- *MayRunAs* - Does not require that RunAsGroup be specified. However, when RunAsGroup
569
- is specified, they have to fall in the defined range.
599
+ is specified, they have to fall in the defined range.
570
600
- *RunAsAny* - No default provided. Allows any `runAsGroup` to be specified.
571
601
572
602
573
603
**SupplementalGroups** - Controls which group IDs containers add.
574
604
575
605
- *MustRunAs* - Requires at least one `range` to be specified. Uses the
576
- minimum value of the first range as the default. Validates against all ranges.
606
+ minimum value of the first range as the default. Validates against all ranges.
577
607
- *MayRunAs* - Requires at least one `range` to be specified. Allows
578
- ` supplementalGroups` to be left unset without providing a default.
579
- Validates against all ranges if `supplementalGroups` is set.
608
+ ` supplementalGroups` to be left unset without providing a default.
609
+ Validates against all ranges if `supplementalGroups` is set.
580
610
- *RunAsAny* - No default provided. Allows any `supplementalGroups` to be
581
- specified.
611
+ specified.
582
612
583
613
# ## Privilege Escalation
584
614
@@ -623,8 +653,8 @@ added. Capabilities listed in `RequiredDropCapabilities` must not be included in
623
653
` AllowedCapabilities` or `DefaultAddCapabilities`.
624
654
625
655
**DefaultAddCapabilities** - The capabilities which are added to containers by
626
- default, in addition to the runtime defaults. See the [Docker
627
- documentation](https://docs.docker.com/engine/reference/run/#runtime-privilege-and-linux-capabilities)
656
+ default, in addition to the runtime defaults. See the
657
+ [Docker documentation](https://docs.docker.com/engine/reference/run/#runtime-privilege-and-linux-capabilities)
628
658
for the default list of capabilities when using the Docker runtime.
629
659
630
660
# ## SELinux
@@ -651,16 +681,17 @@ denoted as the string `Unmasked`.
651
681
652
682
# ## AppArmor
653
683
654
- Controlled via annotations on the PodSecurityPolicy. Refer to the [AppArmor
655
- documentation](/docs/tutorials/clusters /apparmor/#podsecuritypolicy-annotations).
684
+ Controlled via annotations on the PodSecurityPolicy. Refer to the
685
+ [AppArmor documentation](/docs/tutorials/security /apparmor/#podsecuritypolicy-annotations).
656
686
657
687
# ## Seccomp
658
688
659
689
As of Kubernetes v1.19, you can use the `seccompProfile` field in the
660
- ` securityContext` of Pods or containers to [control use of seccomp
661
- profiles](/docs/tutorials/clusters/seccomp). In prior versions, seccomp was
662
- controlled by adding annotations to a Pod. The same PodSecurityPolicies can be
663
- used with either version to enforce how these fields or annotations are applied.
690
+ ` securityContext` of Pods or containers to
691
+ [control use of seccomp profiles](/docs/tutorials/security/seccomp/).
692
+ In prior versions, seccomp was controlled by adding annotations to a Pod. The
693
+ same PodSecurityPolicies can be used with either version to enforce how these
694
+ fields or annotations are applied.
664
695
665
696
**seccomp.security.alpha.kubernetes.io/defaultProfileName** - Annotation that
666
697
specifies the default seccomp profile to apply to containers. Possible values
@@ -677,10 +708,10 @@ are:
677
708
flag is not defined, the default path will be used, which is
678
709
` <root-dir>/seccomp` where `<root-dir>` is specified by the `--root-dir` flag.
679
710
680
- {{< note >}}
711
+ {{< note >}}
681
712
The `--seccomp-profile-root` flag is deprecated since Kubernetes
682
713
v1.19. Users are encouraged to use the default path.
683
- {{< /note >}}
714
+ {{< /note >}}
684
715
685
716
**seccomp.security.alpha.kubernetes.io/allowedProfileNames** - Annotation that
686
717
specifies which values are allowed for the pod seccomp annotations. Specified as
@@ -692,18 +723,22 @@ default cannot be changed.
692
723
693
724
By default, all safe sysctls are allowed.
694
725
695
- - ` forbiddenSysctls` - excludes specific sysctls. You can forbid a combination of safe and unsafe sysctls in the list. To forbid setting any sysctls, use `*` on its own.
696
- - ` allowedUnsafeSysctls` - allows specific sysctls that had been disallowed by the default list, so long as these are not listed in `forbiddenSysctls`.
726
+ - ` forbiddenSysctls` - excludes specific sysctls. You can forbid a combination
727
+ of safe and unsafe sysctls in the list. To forbid setting any sysctls, use
728
+ ` *` on its own.
729
+ - ` allowedUnsafeSysctls` - allows specific sysctls that had been disallowed by
730
+ the default list, so long as these are not listed in `forbiddenSysctls`.
697
731
698
- Refer to the [Sysctl documentation](
699
- /docs/tasks/administer-cluster/sysctl-cluster/#podsecuritypolicy).
732
+ Refer to the [Sysctl documentation](/docs/tasks/administer-cluster/sysctl-cluster/#podsecuritypolicy).
700
733
701
734
# # {{% heading "whatsnext" %}}
702
735
703
- - See [PodSecurityPolicy Deprecation : Past, Present, and
704
- Future](/blog/2021/04/06/podsecuritypolicy-deprecation-past-present-and-future/) to learn about
705
- the future of pod security policy.
736
+ - See [PodSecurityPolicy Deprecation : Past, Present, and Future](/blog/2021/04/06/podsecuritypolicy-deprecation-past-present-and-future/)
737
+ to learn about the future of pod security policy.
738
+
739
+ - See [Pod Security Standards](/docs/concepts/security/pod-security-standards/)
740
+ for policy recommendations.
706
741
707
- - See [Pod Security Standards](/docs/concepts/security/pod-security-standards/) for policy recommendations.
742
+ - Refer to [PodSecurityPolicy reference](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#podsecuritypolicy-v1beta1-policy)
743
+ for the API details.
708
744
709
- - Refer to [Pod Security Policy Reference](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#podsecuritypolicy-v1beta1-policy) for the api details.
0 commit comments