Merge pull request #29124 from tallclair/podsecurity

[PodSecurity] Correct and clarify a few things
This commit is contained in:
Kubernetes Prow Robot
2021-07-28 11:26:47 -07:00
committed by GitHub
2 changed files with 52 additions and 30 deletions
@@ -19,7 +19,8 @@ The Kubernetes [Pod Security Standards](/docs/concepts/security/pod-security-sta
different isolation levels for Pods. These standards let you define how you want to restrict the different isolation levels for Pods. These standards let you define how you want to restrict the
behavior of pods in a clear, consistent fashion. behavior of pods in a clear, consistent fashion.
As an Alpha feature, Kubernetes offers a built-in _Pod Security_ admission plugin, the successor As an Alpha feature, Kubernetes offers a built-in _Pod Security_ {{< glossary_tooltip
text="admission controller" term_id="admission-controller" >}}, the successor
to [PodSecurityPolicies](/docs/concepts/policy/pod-security-policy/). Pod security restrictions to [PodSecurityPolicies](/docs/concepts/policy/pod-security-policy/). Pod security restrictions
are applied at the {{< glossary_tooltip text="namespace" term_id="namespace" >}} level when pods are applied at the {{< glossary_tooltip text="namespace" term_id="namespace" >}} level when pods
are created. are created.
@@ -40,12 +41,14 @@ Setting pod security controls by namespace is an alpha feature. You must enable
--feature-gates="...,PodSecurity=true" --feature-gates="...,PodSecurity=true"
``` ```
## Pod Security Admission configuration for pods ## Pod Security levels
Different policy levels (e.g. `baseline`, `restricted`) have different requirements for Pod Security admission places requirements on a Pod's [Security
[Security Context](/docs/tasks/configure-pod-container/security-context/) objects and other related Context](/docs/tasks/configure-pod-container/security-context/) and other related fields according
fields. Check out the [Pod Security Standards](/docs/concepts/security/pod-security-standards) page to the three levels defined by the [Pod Security
for an in-depth look at those requirements. Standards](/docs/concepts/security/pod-security-standards): `privileged`, `baseline`, and
`restricted`. Refer to the [Pod Security Standards](/docs/concepts/security/pod-security-standards)
page for an in-depth look at those requirements.
## Pod Security Admission labels for namespaces ## Pod Security Admission labels for namespaces
@@ -64,7 +67,9 @@ Mode | Description
**`warn`** | Policy violations will trigger a user-facing warning, but are otherwise allowed. **`warn`** | Policy violations will trigger a user-facing warning, but are otherwise allowed.
{{< /table >}} {{< /table >}}
For each mode, there are two labels that you can use: A namespace can configure any or all modes, or even set a different level for different modes.
For each mode, there are two labels that determine the policy used:
```yaml ```yaml
# The per-mode level label indicates which policy level to apply for the mode. # The per-mode level label indicates which policy level to apply for the mode.
@@ -74,15 +79,25 @@ For each mode, there are two labels that you can use:
pod-security.kubernetes.io/<MODE>: <LEVEL> pod-security.kubernetes.io/<MODE>: <LEVEL>
# Optional: per-mode version label that can be used to pin the policy to the # Optional: per-mode version label that can be used to pin the policy to the
# version that shipped with a given Kubernetes minor version (e.g. v{{< skew latestVersion >}}). # version that shipped with a given Kubernetes minor version (for example v{{< skew latestVersion >}}).
# #
# MODE must be one of `enforce`, `audit`, or `warn`. # MODE must be one of `enforce`, `audit`, or `warn`.
# VERSION must be a valid Kubernetes version label. # VERSION must be a valid Kubernetes minor version, or `latest`.
pod-security.kubernetes.io/<MODE>-version: <VERSION> pod-security.kubernetes.io/<MODE>-version: <VERSION>
``` ```
Check out [Enforce Pod Security Standards with Namespace Labels](/docs/tasks/configure-pod-container/enforce-standards-namespace-labels) to see example usage. Check out [Enforce Pod Security Standards with Namespace Labels](/docs/tasks/configure-pod-container/enforce-standards-namespace-labels) to see example usage.
## Workload resources and Pod templates
Pods are often created indirectly, by creating a [workload
object](https://kubernetes.io/docs/concepts/workloads/controllers/) such as a {{< glossary_tooltip
term_id="deployment" >}} or {{< glossary_tooltip term_id="job">}}. The workload object defines a
_Pod template_ and a {{< glossary_tooltip term_id="controller" text="controller" >}} for the
workload resource creates Pods based on that template. To help catch violations early, both the
audit and warning modes are applied to the workload resources. However, enforce mode is **not**
applied to workload resources, only to the resulting pod objects.
## Exemptions ## Exemptions
You can define _exemptions_ from pod security enforcement in order allow the creation of pods that You can define _exemptions_ from pod security enforcement in order allow the creation of pods that
@@ -90,35 +105,36 @@ would have otherwise been prohibited due to the policy associated with a given n
Exemptions can be statically configured in the Exemptions can be statically configured in the
[Admission Controller configuration](#configuring-the-admission-controller). [Admission Controller configuration](#configuring-the-admission-controller).
Exemptions must be explicitly enumerated, and do not support indirection such as label or group Exemptions must be explicitly enumerated. Requests meeting exemption criteria are _ignored_ by the
selectors. Requests meeting exemption criteria are _ignored_ by the Admission Controller (all Admission Controller (all `enforce`, `audit` and `warn` behaviors are skipped). Exemption dimensions include:
`enforce`, `audit` and `warn` behaviors), except to record an audit annotation. Exemption
dimensions include:
- **Usernames:** requests from users with an exempt authenticated (or impersonated) username are - **Usernames:** requests from users with an exempt authenticated (or impersonated) username are
ignored. ignored.
- **RuntimeClassNames:** pods and templated pods specifying an exempt runtime class name are - **RuntimeClassNames:** pods and [workload resources](#workload-resources-and-pod-templates) specifying an exempt runtime class name are
ignored. ignored.
- **Namespaces:** pods and templated pods in an exempt namespace are ignored. - **Namespaces:** pods and [workload resources](#workload-resources-and-pod-templates) in an exempt namespace are ignored.
The username exemption is special in that the creating user is not persisted on the Pod object, {{< caution >}}
and the Pod may be modified by different non-exempt users in the future. Use cases for username
exemptions include:
- Trusted {{< glossary_tooltip term_id="controller" text="controllers" >}} that create pods. Most pods are created by a controller in response to a [workload
- Usernames that represent break-glass operations roles, for example for debugging workloads resource](#workload-resources-and-pod-templates), meaning that exempting an end user will only
in a namespace that has restrictions configured. This mechanism only works with a username exempt them from enforcement when creating pods directly, but not when creating a workload resource.
match; you cannot grant exemptions based on group membership. Controller service accounts (such as `system:serviceaccount:kube-system:replicaset-controller`)
should generally not be exempted, as doing so would implicitly exempt any user that can create the
corresponding workload resource.
Updates to the following pod fields are exempt from policy checks, meaning that if a pod update request only changes these fields, it will not be denied even if the pod is in violation of the current policy level: {{< /caution >}}
- Any metadata updates EXCEPT changes to the seccomp or apparmor annotations: Updates to the following pod fields are exempt from policy checks, meaning that if a pod update
request only changes these fields, it will not be denied even if the pod is in violation of the
current policy level:
- Any metadata updates **except** changes to the seccomp or AppArmor annotations:
- `seccomp.security.alpha.kubernetes.io/pod` (deprecated) - `seccomp.security.alpha.kubernetes.io/pod` (deprecated)
- `container.seccomp.security.alpha.kubernetes.io/*` (deprecated) - `container.seccomp.security.alpha.kubernetes.io/*` (deprecated)
- `container.apparmor.security.beta.kubernetes.io/*` - `container.apparmor.security.beta.kubernetes.io/*`
- Valid updates to `.spec.activeDeadlineSeconds` - Valid updates to `.spec.activeDeadlineSeconds`
- Valid updates to `.spec.tolerations` - Valid updates to `.spec.tolerations`
- Valid updates to Pod resources
## {{% heading "whatsnext" %}} ## {{% heading "whatsnext" %}}
@@ -59,16 +59,22 @@ kubectl label --dry-run=server --overwrite ns --all \
### Applying to all namespaces ### Applying to all namespaces
If you're just getting started with the Pod Security Standards, a suitable first step would be to If you're just getting started with the Pod Security Standards, a suitable first step would be to
configure all namespaces as `privileged` but set up audit annotations for a stricter level such as configure all namespaces with audit annotations for a stricter level such as `baseline`:
`baseline`:
```shell ```shell
kubectl label --overwrite ns --all \ kubectl label --overwrite ns --all \
pod-security.kubernetes.io/enforce=privileged \
pod-security.kubernetes.io/audit=baseline \ pod-security.kubernetes.io/audit=baseline \
pod-security.kubernetes.io/warn=baseline pod-security.kubernetes.io/warn=baseline
``` ```
Note that this is not setting an enforce level, so that namespaces that haven't been explicitly
evaluated can be distinguished. You can list namespaces without an explicitly set enforce level
using this command:
```shell
kubectl get namespaces --selector='!pod-security.kubernetes.io/enforce'
```
### Applying to a single namespace ### Applying to a single namespace
You can update a specific namespace as well. This command adds the `enforce=restricted` You can update a specific namespace as well. This command adds the `enforce=restricted`