liveBook · Manning

Privileged container

As explained in Google Anthos in Action

A privileged container is a container granted broad host-level capabilities, kernel access, and device access through privileged mode.

A privileged container is allowed access to host resources normally blocked from containers, including host devices. In Kubernetes, the `privileged` setting in a container’s security context controls this access. Some orchestration components may need host access, but ordinary workloads should not receive it by default. section 13.3.2 section 13.4

Privilege and user identity are separate controls. Running as root inside a nonprivileged container does not by itself grant root access to the worker node. Running as root with `privileged: true`, however, can let a process change host settings or extract host data. A privileged container running as a nonroot user remains limited by that user’s host permissions. section 13.6 section 13.4

Table 13.3 Root and privileged container permissions (view table figure)

Running container user

Privileged value

Host permissions

Running as root

False

None

Running as root

True

Root access

Running as nonroot

False

None

Running as nonroot

True

Limited; only permissions that have been granted to the same user on the host system

Compare host permissions across the four combinations of root or nonroot execution and privileged mode. section 13.6

Testing a host-level change

A root container without privileged mode cannot change a host kernel setting. Enabling privileged mode for that root container permits the change. Switching the privileged container to user 1000 causes the attempted kernel change to be denied again. The result depends on both controls, not either one alone. section 13.6.2

Limit which Pods may run privileged, and define the permitted container user as a separate policy decision. Anthos Config Management includes a Gatekeeper constraint template for denying privileged containers; a `K8sPSPPrivilegedContainer` constraint matched against Pods also checks Pods created through Deployments. Test the constraint before broad enforcement: system namespaces can contain privileged Pods, and an enforced rule may affect their operation. Admission checks apply to newly admitted objects, not existing Pods, although existing violations can be reported. section 13.6.2 section 13.4.1

apiVersion: constraints.gatekeeper.sh/v1beta1
kind: K8sPSPPrivilegedContainer
metadata:
  name: psp-privileged-container
spec:
  enforcementAction: dryrun
  match:
    kinds:
      - apiGroups: [""]
        kinds: ["Pod"]

The sample constraint matches Pods and uses `enforcementAction: dryrun` to identify privileged-container violations before enforcing a denial. section 13.4.1

How Google Anthos in Action covers it

How deep it goes
Works through user-and-privilege permission combinations and kernel-change tests, then outlines admission-policy enforcement.
Examples
Uses a kernel-setting test, a permission matrix, and a dry-run constraint matching Pods.
What it assumes
Assumes familiarity with Kubernetes Pods, container images, and manifests while distinguishing container-root identity from host permissions.
What you can do after
Operate/configure it by assessing host-access risk and testing a Gatekeeper constraint before denying privileged Pods.
How it connects
Connects privileged mode to container user identity, host access, Kubernetes security contexts, and Gatekeeper admission constraints.

Also explained in

Compare how 2 books explain privileged container →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Google Anthos in Action. The section links point to the parts of the book it draws on.