Merge pull request #28587 from tallclair/psp-migration
PodSecurity Standards & PSP Best Practices
This commit is contained in:
@@ -11,7 +11,8 @@ weight: 30
|
|||||||
|
|
||||||
{{< feature-state for_k8s_version="v1.21" state="deprecated" >}}
|
{{< feature-state for_k8s_version="v1.21" state="deprecated" >}}
|
||||||
|
|
||||||
PodSecurityPolicy is deprecated as of Kubernetes v1.21, and will be removed in v1.25.
|
PodSecurityPolicy is deprecated as of Kubernetes v1.21, and will be removed in v1.25. For more information on the deprecation,
|
||||||
|
see [PodSecurityPolicy Deprecation: Past, Present, and Future](/blog/2021/04/06/podsecuritypolicy-deprecation-past-present-and-future/).
|
||||||
|
|
||||||
Pod Security Policies enable fine-grained authorization of pod creation and
|
Pod Security Policies enable fine-grained authorization of pod creation and
|
||||||
updates.
|
updates.
|
||||||
@@ -48,13 +49,12 @@ administrator to control the following:
|
|||||||
|
|
||||||
## Enabling Pod Security Policies
|
## Enabling Pod Security Policies
|
||||||
|
|
||||||
Pod security policy control is implemented as an optional (but recommended)
|
Pod security policy control is implemented as an optional [admission
|
||||||
[admission
|
controller](/docs/reference/access-authn-authz/admission-controllers/#podsecuritypolicy).
|
||||||
controller](/docs/reference/access-authn-authz/admission-controllers/#podsecuritypolicy). PodSecurityPolicies
|
PodSecurityPolicies are enforced by [enabling the admission
|
||||||
are enforced by [enabling the admission
|
|
||||||
controller](/docs/reference/access-authn-authz/admission-controllers/#how-do-i-turn-on-an-admission-control-plug-in),
|
controller](/docs/reference/access-authn-authz/admission-controllers/#how-do-i-turn-on-an-admission-control-plug-in),
|
||||||
but doing so without authorizing any policies **will prevent any pods from being
|
but doing so without authorizing any policies **will prevent any pods from being created** in the
|
||||||
created** in the cluster.
|
cluster.
|
||||||
|
|
||||||
Since the pod security policy API (`policy/v1beta1/podsecuritypolicy`) is
|
Since the pod security policy API (`policy/v1beta1/podsecuritypolicy`) is
|
||||||
enabled independently of the admission controller, for existing clusters it is
|
enabled independently of the admission controller, for existing clusters it is
|
||||||
@@ -110,7 +110,11 @@ roleRef:
|
|||||||
name: <role name>
|
name: <role name>
|
||||||
apiGroup: rbac.authorization.k8s.io
|
apiGroup: rbac.authorization.k8s.io
|
||||||
subjects:
|
subjects:
|
||||||
# Authorize specific service accounts:
|
# Authorize all service accounts in a namespace (recommended):
|
||||||
|
- kind: Group
|
||||||
|
apiGroup: rbac.authorization.k8s.io
|
||||||
|
name: system:serviceaccounts:<authorized namespace>
|
||||||
|
# Authorize specific service accounts (not recommended):
|
||||||
- kind: ServiceAccount
|
- kind: ServiceAccount
|
||||||
name: <authorized service account name>
|
name: <authorized service account name>
|
||||||
namespace: <authorized pod namespace>
|
namespace: <authorized pod namespace>
|
||||||
@@ -139,6 +143,40 @@ Examples](/docs/reference/access-authn-authz/rbac#role-binding-examples).
|
|||||||
For a complete example of authorizing a PodSecurityPolicy, see
|
For a complete example of authorizing a PodSecurityPolicy, see
|
||||||
[below](#example).
|
[below](#example).
|
||||||
|
|
||||||
|
### Recommended Practice
|
||||||
|
|
||||||
|
PodSecurityPolicy is being replaced by a new, simplified `PodSecurity` {{< glossary_tooltip
|
||||||
|
text="admission controller" term_id="admission-controller" >}}. For more details on this change, see
|
||||||
|
[PodSecurityPolicy Deprecation: Past, Present, and
|
||||||
|
Future](/blog/2021/04/06/podsecuritypolicy-deprecation-past-present-and-future/). Follow these
|
||||||
|
guidelines to simplify migration from PodSecurityPolicy to the new admission controller:
|
||||||
|
|
||||||
|
1. Limit your PodSecurityPolicies to the policies defined by the [Pod Security Standards](/docs/concepts/security/pod-security-standards):
|
||||||
|
- {{< example file="policy/privileged-psp.yaml" >}}Privileged{{< /example >}}
|
||||||
|
- {{< example file="policy/baseline-psp.yaml" >}}Baseline{{< /example >}}
|
||||||
|
- {{< example file="policy/restricted-psp.yaml" >}}Restricted{{< /example >}}
|
||||||
|
|
||||||
|
2. Only bind PSPs to entire namespaces, by using the `system:serviceaccounts:<namespace>` group
|
||||||
|
(where `<namespace>` is the target namespace). For example:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
apiVersion: rbac.authorization.k8s.io/v1
|
||||||
|
# This cluster role binding allows all pods in the "development" namespace to use the baseline PSP.
|
||||||
|
kind: ClusterRoleBinding
|
||||||
|
metadata:
|
||||||
|
name: psp-baseline-namespaces
|
||||||
|
roleRef:
|
||||||
|
kind: ClusterRole
|
||||||
|
name: psp-baseline
|
||||||
|
apiGroup: rbac.authorization.k8s.io
|
||||||
|
subjects:
|
||||||
|
- kind: Group
|
||||||
|
name: system:serviceaccounts:development
|
||||||
|
apiGroup: rbac.authorization.k8s.io
|
||||||
|
- kind: Group
|
||||||
|
name: system:serviceaccounts:canary
|
||||||
|
apiGroup: rbac.authorization.k8s.io
|
||||||
|
```
|
||||||
|
|
||||||
### Troubleshooting
|
### Troubleshooting
|
||||||
|
|
||||||
@@ -661,8 +699,10 @@ Refer to the [Sysctl documentation](
|
|||||||
|
|
||||||
## {{% heading "whatsnext" %}}
|
## {{% heading "whatsnext" %}}
|
||||||
|
|
||||||
|
- See [PodSecurityPolicy Deprecation: Past, Present, and
|
||||||
|
Future](/blog/2021/04/06/podsecuritypolicy-deprecation-past-present-and-future/) to learn about
|
||||||
|
the future of pod security policy.
|
||||||
|
|
||||||
- See [Pod Security Standards](/docs/concepts/security/pod-security-standards/) for policy recommendations.
|
- See [Pod Security Standards](/docs/concepts/security/pod-security-standards/) for policy recommendations.
|
||||||
|
|
||||||
- Refer to [Pod Security Policy Reference](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#podsecuritypolicy-v1beta1-policy) for the api details.
|
- Refer to [Pod Security Policy Reference](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#podsecuritypolicy-v1beta1-policy) for the api details.
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ enforced/disallowed:
|
|||||||
<tr>
|
<tr>
|
||||||
<td>Capabilities</td>
|
<td>Capabilities</td>
|
||||||
<td>
|
<td>
|
||||||
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>
|
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>
|
||||||
<br><b>Restricted Fields:</b><br>
|
<br><b>Restricted Fields:</b><br>
|
||||||
spec.containers[*].securityContext.capabilities.add<br>
|
spec.containers[*].securityContext.capabilities.add<br>
|
||||||
spec.initContainers[*].securityContext.capabilities.add<br>
|
spec.initContainers[*].securityContext.capabilities.add<br>
|
||||||
@@ -194,7 +194,7 @@ well as lower-trust users.The following listed controls should be enforced/disal
|
|||||||
<tr>
|
<tr>
|
||||||
<td>Volume Types</td>
|
<td>Volume Types</td>
|
||||||
<td>
|
<td>
|
||||||
In addition to restricting HostPath volumes, the restricted profile limits usage of non-core volume types to those defined through PersistentVolumes.<br>
|
In addition to restricting HostPath volumes, the restricted profile limits usage of non-ephemeral volume types to those defined through PersistentVolumes.<br>
|
||||||
<br><b>Restricted Fields:</b><br>
|
<br><b>Restricted Fields:</b><br>
|
||||||
spec.volumes[*].hostPath<br>
|
spec.volumes[*].hostPath<br>
|
||||||
spec.volumes[*].gcePersistentDisk<br>
|
spec.volumes[*].gcePersistentDisk<br>
|
||||||
@@ -216,7 +216,6 @@ well as lower-trust users.The following listed controls should be enforced/disal
|
|||||||
spec.volumes[*].portworxVolume<br>
|
spec.volumes[*].portworxVolume<br>
|
||||||
spec.volumes[*].scaleIO<br>
|
spec.volumes[*].scaleIO<br>
|
||||||
spec.volumes[*].storageos<br>
|
spec.volumes[*].storageos<br>
|
||||||
spec.volumes[*].csi<br>
|
|
||||||
<br><b>Allowed Values:</b> undefined/nil<br>
|
<br><b>Allowed Values:</b> undefined/nil<br>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|||||||
@@ -6,20 +6,16 @@ metadata:
|
|||||||
# Optional: Allow the default AppArmor profile, requires setting the default.
|
# Optional: Allow the default AppArmor profile, requires setting the default.
|
||||||
apparmor.security.beta.kubernetes.io/allowedProfileNames: 'runtime/default'
|
apparmor.security.beta.kubernetes.io/allowedProfileNames: 'runtime/default'
|
||||||
apparmor.security.beta.kubernetes.io/defaultProfileName: 'runtime/default'
|
apparmor.security.beta.kubernetes.io/defaultProfileName: 'runtime/default'
|
||||||
# Optional: Allow the default seccomp profile, requires setting the default.
|
seccomp.security.alpha.kubernetes.io/allowedProfileNames: '*'
|
||||||
seccomp.security.alpha.kubernetes.io/allowedProfileNames: 'docker/default,runtime/default,unconfined'
|
|
||||||
seccomp.security.alpha.kubernetes.io/defaultProfileName: 'unconfined'
|
|
||||||
spec:
|
spec:
|
||||||
privileged: false
|
privileged: false
|
||||||
# The moby default capability set, defined here:
|
# The moby default capability set, minus NET_RAW
|
||||||
# https://github.com/moby/moby/blob/0a5cec2833f82a6ad797d70acbf9cbbaf8956017/oci/caps/defaults.go#L6-L19
|
|
||||||
allowedCapabilities:
|
allowedCapabilities:
|
||||||
- 'CHOWN'
|
- 'CHOWN'
|
||||||
- 'DAC_OVERRIDE'
|
- 'DAC_OVERRIDE'
|
||||||
- 'FSETID'
|
- 'FSETID'
|
||||||
- 'FOWNER'
|
- 'FOWNER'
|
||||||
- 'MKNOD'
|
- 'MKNOD'
|
||||||
- 'NET_RAW'
|
|
||||||
- 'SETGID'
|
- 'SETGID'
|
||||||
- 'SETUID'
|
- 'SETUID'
|
||||||
- 'SETFCAP'
|
- 'SETFCAP'
|
||||||
@@ -36,15 +32,16 @@ spec:
|
|||||||
- 'projected'
|
- 'projected'
|
||||||
- 'secret'
|
- 'secret'
|
||||||
- 'downwardAPI'
|
- 'downwardAPI'
|
||||||
# Assume that persistentVolumes set up by the cluster admin are safe to use.
|
# Assume that ephemeral CSI drivers & persistentVolumes set up by the cluster admin are safe to use.
|
||||||
|
- 'csi'
|
||||||
- 'persistentVolumeClaim'
|
- 'persistentVolumeClaim'
|
||||||
|
- 'ephemeral'
|
||||||
# Allow all other non-hostpath volume types.
|
# Allow all other non-hostpath volume types.
|
||||||
- 'awsElasticBlockStore'
|
- 'awsElasticBlockStore'
|
||||||
- 'azureDisk'
|
- 'azureDisk'
|
||||||
- 'azureFile'
|
- 'azureFile'
|
||||||
- 'cephFS'
|
- 'cephFS'
|
||||||
- 'cinder'
|
- 'cinder'
|
||||||
- 'csi'
|
|
||||||
- 'fc'
|
- 'fc'
|
||||||
- 'flexVolume'
|
- 'flexVolume'
|
||||||
- 'flocker'
|
- 'flocker'
|
||||||
@@ -67,6 +64,9 @@ spec:
|
|||||||
runAsUser:
|
runAsUser:
|
||||||
rule: 'RunAsAny'
|
rule: 'RunAsAny'
|
||||||
seLinux:
|
seLinux:
|
||||||
|
# This policy assumes the nodes are using AppArmor rather than SELinux.
|
||||||
|
# The PSP SELinux API cannot express the SELinux Pod Security Standards,
|
||||||
|
# so if using SELinux, you must choose a more restrictive default.
|
||||||
rule: 'RunAsAny'
|
rule: 'RunAsAny'
|
||||||
supplementalGroups:
|
supplementalGroups:
|
||||||
rule: 'RunAsAny'
|
rule: 'RunAsAny'
|
||||||
|
|||||||
@@ -5,14 +5,11 @@ metadata:
|
|||||||
annotations:
|
annotations:
|
||||||
seccomp.security.alpha.kubernetes.io/allowedProfileNames: 'docker/default,runtime/default'
|
seccomp.security.alpha.kubernetes.io/allowedProfileNames: 'docker/default,runtime/default'
|
||||||
apparmor.security.beta.kubernetes.io/allowedProfileNames: 'runtime/default'
|
apparmor.security.beta.kubernetes.io/allowedProfileNames: 'runtime/default'
|
||||||
seccomp.security.alpha.kubernetes.io/defaultProfileName: 'runtime/default'
|
|
||||||
apparmor.security.beta.kubernetes.io/defaultProfileName: 'runtime/default'
|
apparmor.security.beta.kubernetes.io/defaultProfileName: 'runtime/default'
|
||||||
spec:
|
spec:
|
||||||
privileged: false
|
privileged: false
|
||||||
# Required to prevent escalations to root.
|
# Required to prevent escalations to root.
|
||||||
allowPrivilegeEscalation: false
|
allowPrivilegeEscalation: false
|
||||||
# This is redundant with non-root + disallow privilege escalation,
|
|
||||||
# but we can provide it for defense in depth.
|
|
||||||
requiredDropCapabilities:
|
requiredDropCapabilities:
|
||||||
- ALL
|
- ALL
|
||||||
# Allow core volume types.
|
# Allow core volume types.
|
||||||
@@ -22,8 +19,10 @@ spec:
|
|||||||
- 'projected'
|
- 'projected'
|
||||||
- 'secret'
|
- 'secret'
|
||||||
- 'downwardAPI'
|
- 'downwardAPI'
|
||||||
# Assume that persistentVolumes set up by the cluster admin are safe to use.
|
# Assume that ephemeral CSI drivers & persistentVolumes set up by the cluster admin are safe to use.
|
||||||
|
- 'csi'
|
||||||
- 'persistentVolumeClaim'
|
- 'persistentVolumeClaim'
|
||||||
|
- 'ephemeral'
|
||||||
hostNetwork: false
|
hostNetwork: false
|
||||||
hostIPC: false
|
hostIPC: false
|
||||||
hostPID: false
|
hostPID: false
|
||||||
|
|||||||
Reference in New Issue
Block a user