Skip to content

Commit 55d2aa3

Browse files
authored
Merge pull request #28587 from tallclair/psp-migration
PodSecurity Standards & PSP Best Practices
2 parents 0a0b885 + 8b5fb99 commit 55d2aa3

File tree

4 files changed

+63
-25
lines changed

4 files changed

+63
-25
lines changed

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

Lines changed: 50 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ weight: 30
1111

1212
{{< feature-state for_k8s_version="v1.21" state="deprecated" >}}
1313

14-
PodSecurityPolicy is deprecated as of Kubernetes v1.21, and will be removed in v1.25.
14+
PodSecurityPolicy is deprecated as of Kubernetes v1.21, and will be removed in v1.25. For more information on the deprecation,
15+
see [PodSecurityPolicy Deprecation: Past, Present, and Future](/blog/2021/04/06/podsecuritypolicy-deprecation-past-present-and-future/).
1516

1617
Pod Security Policies enable fine-grained authorization of pod creation and
1718
updates.
@@ -48,13 +49,12 @@ administrator to control the following:
4849

4950
## Enabling Pod Security Policies
5051

51-
Pod security policy control is implemented as an optional (but recommended)
52-
[admission
53-
controller](/docs/reference/access-authn-authz/admission-controllers/#podsecuritypolicy). PodSecurityPolicies
54-
are enforced by [enabling the admission
52+
Pod security policy control is implemented as an optional [admission
53+
controller](/docs/reference/access-authn-authz/admission-controllers/#podsecuritypolicy).
54+
PodSecurityPolicies are enforced by [enabling the admission
5555
controller](/docs/reference/access-authn-authz/admission-controllers/#how-do-i-turn-on-an-admission-control-plug-in),
56-
but doing so without authorizing any policies **will prevent any pods from being
57-
created** in the cluster.
56+
but doing so without authorizing any policies **will prevent any pods from being created** in the
57+
cluster.
5858

5959
Since the pod security policy API (`policy/v1beta1/podsecuritypolicy`) is
6060
enabled independently of the admission controller, for existing clusters it is
@@ -110,7 +110,11 @@ roleRef:
110110
name: <role name>
111111
apiGroup: rbac.authorization.k8s.io
112112
subjects:
113-
# Authorize specific service accounts:
113+
# Authorize all service accounts in a namespace (recommended):
114+
- kind: Group
115+
apiGroup: rbac.authorization.k8s.io
116+
name: system:serviceaccounts:<authorized namespace>
117+
# Authorize specific service accounts (not recommended):
114118
- kind: ServiceAccount
115119
name: <authorized service account name>
116120
namespace: <authorized pod namespace>
@@ -139,6 +143,40 @@ Examples](/docs/reference/access-authn-authz/rbac#role-binding-examples).
139143
For a complete example of authorizing a PodSecurityPolicy, see
140144
[below](#example).
141145

146+
### Recommended Practice
147+
148+
PodSecurityPolicy is being replaced by a new, simplified `PodSecurity` {{< glossary_tooltip
149+
text="admission controller" term_id="admission-controller" >}}. For more details on this change, see
150+
[PodSecurityPolicy Deprecation: Past, Present, and
151+
Future](/blog/2021/04/06/podsecuritypolicy-deprecation-past-present-and-future/). Follow these
152+
guidelines to simplify migration from PodSecurityPolicy to the new admission controller:
153+
154+
1. Limit your PodSecurityPolicies to the policies defined by the [Pod Security Standards](/docs/concepts/security/pod-security-standards):
155+
- {{< example file="policy/privileged-psp.yaml" >}}Privileged{{< /example >}}
156+
- {{< example file="policy/baseline-psp.yaml" >}}Baseline{{< /example >}}
157+
- {{< example file="policy/restricted-psp.yaml" >}}Restricted{{< /example >}}
158+
159+
2. Only bind PSPs to entire namespaces, by using the `system:serviceaccounts:<namespace>` group
160+
(where `<namespace>` is the target namespace). For example:
161+
162+
```yaml
163+
apiVersion: rbac.authorization.k8s.io/v1
164+
# This cluster role binding allows all pods in the "development" namespace to use the baseline PSP.
165+
kind: ClusterRoleBinding
166+
metadata:
167+
name: psp-baseline-namespaces
168+
roleRef:
169+
kind: ClusterRole
170+
name: psp-baseline
171+
apiGroup: rbac.authorization.k8s.io
172+
subjects:
173+
- kind: Group
174+
name: system:serviceaccounts:development
175+
apiGroup: rbac.authorization.k8s.io
176+
- kind: Group
177+
name: system:serviceaccounts:canary
178+
apiGroup: rbac.authorization.k8s.io
179+
```
142180

143181
### Troubleshooting
144182

@@ -661,8 +699,10 @@ Refer to the [Sysctl documentation](
661699

662700
## {{% heading "whatsnext" %}}
663701

702+
- See [PodSecurityPolicy Deprecation: Past, Present, and
703+
Future](/blog/2021/04/06/podsecuritypolicy-deprecation-past-present-and-future/) to learn about
704+
the future of pod security policy.
705+
664706
- See [Pod Security Standards](/docs/concepts/security/pod-security-standards/) for policy recommendations.
665707

666708
- Refer to [Pod Security Policy Reference](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#podsecuritypolicy-v1beta1-policy) for the api details.
667-
668-

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ enforced/disallowed:
8686
<tr>
8787
<td>Capabilities</td>
8888
<td>
89-
Adding additional capabilities beyond the <a href="https://docs.docker.com/engine/reference/run/#runtime-privilege-and-linux-capabilities">default set</a> must be disallowed.<br>
89+
Adding <tt>NET_RAW</tt> or capabilities beyond the <a href="https://docs.docker.com/engine/reference/run/#runtime-privilege-and-linux-capabilities">default set</a> must be disallowed.<br>
9090
<br><b>Restricted Fields:</b><br>
9191
spec.containers[*].securityContext.capabilities.add<br>
9292
spec.initContainers[*].securityContext.capabilities.add<br>
@@ -194,7 +194,7 @@ well as lower-trust users.The following listed controls should be enforced/disal
194194
<tr>
195195
<td>Volume Types</td>
196196
<td>
197-
In addition to restricting HostPath volumes, the restricted profile limits usage of non-core volume types to those defined through PersistentVolumes.<br>
197+
In addition to restricting HostPath volumes, the restricted profile limits usage of non-ephemeral volume types to those defined through PersistentVolumes.<br>
198198
<br><b>Restricted Fields:</b><br>
199199
spec.volumes[*].hostPath<br>
200200
spec.volumes[*].gcePersistentDisk<br>
@@ -216,7 +216,6 @@ well as lower-trust users.The following listed controls should be enforced/disal
216216
spec.volumes[*].portworxVolume<br>
217217
spec.volumes[*].scaleIO<br>
218218
spec.volumes[*].storageos<br>
219-
spec.volumes[*].csi<br>
220219
<br><b>Allowed Values:</b> undefined/nil<br>
221220
</td>
222221
</tr>

content/en/examples/policy/baseline-psp.yaml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,16 @@ metadata:
66
# Optional: Allow the default AppArmor profile, requires setting the default.
77
apparmor.security.beta.kubernetes.io/allowedProfileNames: 'runtime/default'
88
apparmor.security.beta.kubernetes.io/defaultProfileName: 'runtime/default'
9-
# Optional: Allow the default seccomp profile, requires setting the default.
10-
seccomp.security.alpha.kubernetes.io/allowedProfileNames: 'docker/default,runtime/default,unconfined'
11-
seccomp.security.alpha.kubernetes.io/defaultProfileName: 'unconfined'
9+
seccomp.security.alpha.kubernetes.io/allowedProfileNames: '*'
1210
spec:
1311
privileged: false
14-
# The moby default capability set, defined here:
15-
# https://github.com/moby/moby/blob/0a5cec2833f82a6ad797d70acbf9cbbaf8956017/oci/caps/defaults.go#L6-L19
12+
# The moby default capability set, minus NET_RAW
1613
allowedCapabilities:
1714
- 'CHOWN'
1815
- 'DAC_OVERRIDE'
1916
- 'FSETID'
2017
- 'FOWNER'
2118
- 'MKNOD'
22-
- 'NET_RAW'
2319
- 'SETGID'
2420
- 'SETUID'
2521
- 'SETFCAP'
@@ -36,15 +32,16 @@ spec:
3632
- 'projected'
3733
- 'secret'
3834
- 'downwardAPI'
39-
# Assume that persistentVolumes set up by the cluster admin are safe to use.
35+
# Assume that ephemeral CSI drivers & persistentVolumes set up by the cluster admin are safe to use.
36+
- 'csi'
4037
- 'persistentVolumeClaim'
38+
- 'ephemeral'
4139
# Allow all other non-hostpath volume types.
4240
- 'awsElasticBlockStore'
4341
- 'azureDisk'
4442
- 'azureFile'
4543
- 'cephFS'
4644
- 'cinder'
47-
- 'csi'
4845
- 'fc'
4946
- 'flexVolume'
5047
- 'flocker'
@@ -67,6 +64,9 @@ spec:
6764
runAsUser:
6865
rule: 'RunAsAny'
6966
seLinux:
67+
# This policy assumes the nodes are using AppArmor rather than SELinux.
68+
# The PSP SELinux API cannot express the SELinux Pod Security Standards,
69+
# so if using SELinux, you must choose a more restrictive default.
7070
rule: 'RunAsAny'
7171
supplementalGroups:
7272
rule: 'RunAsAny'

content/en/examples/policy/restricted-psp.yaml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,11 @@ metadata:
55
annotations:
66
seccomp.security.alpha.kubernetes.io/allowedProfileNames: 'docker/default,runtime/default'
77
apparmor.security.beta.kubernetes.io/allowedProfileNames: 'runtime/default'
8-
seccomp.security.alpha.kubernetes.io/defaultProfileName: 'runtime/default'
98
apparmor.security.beta.kubernetes.io/defaultProfileName: 'runtime/default'
109
spec:
1110
privileged: false
1211
# Required to prevent escalations to root.
1312
allowPrivilegeEscalation: false
14-
# This is redundant with non-root + disallow privilege escalation,
15-
# but we can provide it for defense in depth.
1613
requiredDropCapabilities:
1714
- ALL
1815
# Allow core volume types.
@@ -22,8 +19,10 @@ spec:
2219
- 'projected'
2320
- 'secret'
2421
- 'downwardAPI'
25-
# Assume that persistentVolumes set up by the cluster admin are safe to use.
22+
# Assume that ephemeral CSI drivers & persistentVolumes set up by the cluster admin are safe to use.
23+
- 'csi'
2624
- 'persistentVolumeClaim'
25+
- 'ephemeral'
2726
hostNetwork: false
2827
hostIPC: false
2928
hostPID: false

0 commit comments

Comments
 (0)