liveBook · Manning

Security context

As explained in Google Anthos in Action

A Kubernetes security context is a pod or container specification field that controls identity, privilege, and filesystem security settings at runtime.

A Kubernetes security context controls the identity, group membership, filesystem group, and host privileges available to a container at runtime. Apply least privilege because a container breakout can expose host resources when the process runs as root. section 13.6.1 section 13.6.2

Configure the context to control two distinct security dimensions:

  • Set runAsUser, runAsGroup, and fsGroup to run the container with a specified user, group, and filesystem group. section 13.6.1
  • Set privileged to allow or deny elevated host privileges; privilege alone does not give a nonroot user permission to change kernel settings. section 13.6.2
  • Treat root execution and privileged containers as separate controls, then define cluster policies to prevent unsafe combinations. section 13.6.2
spec:
 securityContext:
   runAsUser: 1500
   runAsGroup: 1000
   fsGroup: 1200

Use the manifest listing to see a Pod securityContext assigning UID 1500, group 1000, and filesystem group 1200. section 13.6.1

Privilege and user identity are independent

A busybox Pod running as root without privileged access cannot change host kernel settings. Allowing privileged access enables those changes for root, while a privileged container running as user 1000 remains denied. section 13.6.2

How Google Anthos in Action covers it

How deep it goes
Defines user, group, filesystem-group, and privileged settings with runtime demonstrations, but defers cluster-wide enforcement to policy tools.
Examples
Uses busybox Pods, UID and group assignments, whoami and groups checks, and attempted host kernel changes.
What you can do after
Operate/configure Pods with nonroot identities and controlled privileges, then verify identity and host-operation behavior.
How it connects
Connects containers with root users, nonroot execution, privileged containers, host kernels, and cluster security policies.

Also explained in

Compare how 4 books explain security context →

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.