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