The platform enforces no Pod Security level, but it audits and warns at `baseline` by default. A namespace without a label admits every pod, and a pod that fails `baseline` gets a warning and an audit annotation instead of a rejection. Use those findings to roll out `baseline` or `restricted` audit-first, without breaking running workloads. ## Prerequisites - `kubectl` access to your workload cluster - A namespace with workloads deployed that you want to harden ## Levels and modes Pod Security Standards (PSS) is a built-in Kubernetes feature that restricts what pods can do inside a namespace. **Levels** go from least to most strict: - `privileged`: no restrictions. This is the default `enforce` level. - `baseline`: blocks well-known dangerous settings such as privileged containers and host namespace access. - `restricted`: hardened. Pods must run as non-root, containers must drop all Linux capabilities (fine-grained kernel privileges) with only `NET_BIND_SERVICE` allowed back, and must use a seccomp (secure computing mode) profile set to `RuntimeDefault`. Both `baseline` and `restricted` forbid `appArmorProfile: Unconfined`, so once a namespace is at `baseline` or above, a pod cannot opt out of the default [AppArmor profile](/docs/hetzner/apalla/security/use-apparmor). **Modes** control what happens when a pod violates the level: - `enforce`: reject the pod. - `audit`: allow the pod and record the violation in the API audit log. - `warn`: allow the pod and return a warning to whoever submitted it. You can set enforce, audit, and warn at once on the same namespace. Aim for `restricted` on your application namespaces. Use `baseline` when a workload genuinely needs a setting that `restricted` forbids. ## The cluster-wide default A namespace with no `pod-security.kubernetes.io` labels gets these levels from the API server: | Mode | Level | Effect on a pod that fails `baseline` | | --------- | ------------ | ------------------------------------------------------ | | `enforce` | `privileged` | None. The pod is admitted. | | `audit` | `baseline` | The API audit log entry carries a violation annotation | | `warn` | `baseline` | Whoever submitted the pod sees a warning | A privileged pod in an unlabeled namespace is created, and `kubectl` prints the finding: ```console $ kubectl apply -f privileged-pod.yaml Warning: would violate PodSecurity "baseline:latest": privileged (container "c" must not set securityContext.privileged=true) pod/priv created ``` The audit log entry for that request carries the same text in its `pod-security.kubernetes.io/audit-violations` annotation. `kube-system` is exempt, and the platform runs its components there, so they do not show up as findings. A label on a namespace replaces the default for that mode only: label `enforce` and the namespace keeps auditing and warning at `baseline` until you label those modes too. Nothing is blocked by default because host-level agents, such as log shippers, node exporters, and storage drivers, need `hostPath`, `hostNetwork`, or `privileged`, and `baseline` forbids all three. Enforcing it cluster-wide would stop those DaemonSets from rolling out. The warnings show you what a stricter level would block before you label a namespace. ## Why baseline is the minimum The node hardening does not reach privileged pods. The runtime's default [AppArmor profile](/docs/hetzner/apalla/security/use-apparmor) confines non-privileged containers only; a privileged container has full host access on its node, so there is nothing left for a profile to protect. And no namespace enforces a level by default, so in an unlabeled namespace anyone who can create a pod can set `privileged: true` and bypass that hardening. Labeling the namespace at `baseline` or above rejects privileged containers and host namespace access at admission. That label is what makes the node hardening bind to every workload in the namespace. A privileged pod is still limited. It gets host-level access on the node it runs on, not root on every node in the cluster. On that node, the [sealed OS](/docs/hetzner/apalla/security/node-and-os-security) blocks changes to the base system and tamper detection flags changes to the writable area, which limits what an attacker can quietly persist. ## Roll out a stricter level Audit first, enforce later Unlabeled namespaces already warn and audit at `baseline`. To see what your target level would reject, label the namespace to warn and audit at that level, but do not enforce yet. Nothing currently running is blocked: ```console $ kubectl label namespace team-a \ pod-security.kubernetes.io/warn=restricted \ pod-security.kubernetes.io/audit=restricted ``` Redeploy your workloads, or trigger pod restarts, and read the warnings. Fix the workloads that violate the level. The most common fix is adding a `securityContext` block to each container. It goes on the container, not on the pod: `allowPrivilegeEscalation` and `capabilities` exist only at container level, and the API server rejects them in the pod's `securityContext`. ```yaml containers: - name: app image: registry.example.com/app:1.0 securityContext: runAsNonRoot: true allowPrivilegeEscalation: false capabilities: {drop: ["ALL"]} seccompProfile: {type: RuntimeDefault} ``` See [Set security contexts](/docs/hetzner/apalla/security/set-security-contexts) for what each field does and how to apply it. Enforce Once warnings are clean, add `enforce`: ```console $ kubectl label namespace team-a \ pod-security.kubernetes.io/enforce=restricted \ --overwrite ``` From this point, a pod that violates `restricted` is rejected at admission before it starts. Pods already running are not evicted: `kubectl label` lists the ones that violate the new level, and they keep running until they are recreated. Verify ```console # Show the labels on the namespace: $ kubectl get namespace team-a -o jsonpath='{.metadata.labels}' | jq . # A privileged pod should now be rejected: $ kubectl -n team-a run bad --image=busybox --privileged --restart=Never -- sleep 1 Error from server (Forbidden): pods "bad" is forbidden: violates PodSecurity "restricted:latest": privileged (container "bad" must not set securityContext.privileged=true), allowPrivilegeEscalation != false (container "bad" must set securityContext.allowPrivilegeEscalation=false), unrestricted capabilities (container "bad" must set securityContext.capabilities.drop=["ALL"]), runAsNonRoot != true (pod or container "bad" must set securityContext.runAsNonRoot=true), seccompProfile (pod or container "bad" must set securityContext.seccompProfile.type to "RuntimeDefault" or "Localhost") ``` ## What to know **Platform namespaces must stay at `privileged`.** Platform components need host access to work, so those namespaces are the residual you accept. Do not label them with an `enforce` level. What bounds it is [RBAC](/docs/hetzner/apalla/security/manage-access-and-tenancy): who can create pods in a platform namespace. Apply PSS only to your own namespaces. **PSS is coarse and namespace-scoped.** For rules that must apply across namespaces (for example, "images must come from this registry" or "every pod needs a cost label"), write a native ValidatingAdmissionPolicy: a Kubernetes policy that runs inside the API server and can reject a resource outright. See [Control admission](/docs/hetzner/apalla/security/control-admission) for how it differs from a webhook. **Combine with other controls.** Pair a PSS level with a default-deny NetworkPolicy (see [Segment with network policies](/docs/hetzner/apalla/security/segment-with-network-policies)) and a ResourceQuota or LimitRange. Together they address the main risks in a shared namespace. ## Related - [Set security contexts](/docs/hetzner/apalla/security/set-security-contexts) - [Control admission](/docs/hetzner/apalla/security/control-admission) - [Segment with network policies](/docs/hetzner/apalla/security/segment-with-network-policies) - [Container runtimes](/docs/hetzner/apalla/workloads/runtime-classes/container-runtimes) - [Security architecture](/docs/hetzner/apalla/security/security-architecture)