liveBook · Manning

Privileged container

As explained in Kubernetes in Action, Second Edition

A privileged container is a container whose processes receive unrestricted or nearly unrestricted access to the host kernel's operations.

A privileged container gives its processes full or nearly unrestricted access to the operating system kernel. Because those processes can execute system calls that affect the node, most containers should run without elevated privileges; use privileged mode only when necessary and trusted. section 2.3.4 section 17.2.1

Choose the narrowest permission model that satisfies the workload:

  • Run without elevated privileges for ordinary application workloads. section 2.3.4
  • Use a privileged container when the process needs full kernel access, such as modifying node network packet-filtering rules. section 17.2.1
  • Grant selected Linux capabilities when the workload needs only particular privileged operations; examples include NET_ADMIN, NET_RAW, NET_BIND_SERVICE, and SYS_TIME. section 2.3.4 section 17.2.1

Kubernetes node agents

The kube-proxy DaemonSet sets securityContext.privileged to true because it needs root access to the host kernel for Kubernetes Service networking. The kindnet DaemonSet instead adds NET_RAW and NET_ADMIN while setting privileged to false. section 17.2.1

$ kubectl -n kube-system get ds kube-proxy -o yaml
apiVersion: apps/v1
kind: DaemonSet
spec:
  template:
    spec:
      containers:
      - name: kube-proxy
        securityContext:        #1
          privileged: true      #1
    ...

Inspect the kube-proxy DaemonSet manifest to see privileged: true in the container securityContext. section 17.2.1

$ kubectl -n kube-system get ds kindnet -o yaml
apiVersion: apps/v1
kind: DaemonSet
spec:
  template:
    spec:
      containers:
      - name: kindnet-cni
        securityContext:         #1
          capabilities:          #1
            add:                 #1
            - NET_RAW            #1
            - NET_ADMIN          #1
          privileged: false       #2

Inspect the kindnet DaemonSet manifest to compare selected capabilities with privileged: false. section 17.2.1

How Kubernetes in Action, Second Edition covers it

How deep it goes
Explains system calls, full kernel access, and capability-based alternatives, but does not detail individual seccomp profiles.
Examples
Demonstrates Docker --privileged, Kubernetes kube-proxy, and kindnet configurations.
What it assumes
Assumes basic containers and explains system calls, kernel access, and capabilities directly.
What you can do after
Apply Kubernetes securityContext settings or Docker's --privileged flag while preferring only the capabilities a workload requires.
How it connects
Connects privileged containers with system calls, Linux capabilities, Kubernetes DaemonSets, and container security contexts.

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 Kubernetes in Action, Second Edition. The section links point to the parts of the book it draws on.