✦ For everyone, free.

Practical knowledge for real and everyday life

Home

Kubernetes Least Privilege Access

Kubernetes Least Privilege Access ensures secure container operations by restricting permissions to only what's necessary for each component.

Kubernetes Least Privilege Access is the design principle of granting every user, group, and service account in a cluster only the specific permissions required for its actual function, and no more, applied consistently across RBAC roles, workload service accounts, and pod-level security settings. It is not a single feature to enable but an ongoing discipline that shapes how roles are written, how bindings are scoped, and how workloads are configured from initial deployment through their entire operational lifetime.


Applying Least Privilege to RBAC

Starting From Actual Need, Not Convenience

Least privilege begins with enumerating the specific verbs and resources a role genuinely requires — informed by what the workload's code actually calls, or what a team's operational responsibilities actually involve — rather than starting from a broad built-in role like edit or cluster-admin because it is readily available and "probably covers it."

apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  namespace: payments
  name: config-reader
rules:
- apiGroups: [""]
  resources: ["configmaps"]
  verbs: ["get", "list", "watch"]

Avoiding Wildcards

A rule using resources: ["*"] or verbs: ["*"] defeats the purpose of a least-privilege design regardless of how narrowly other rules in the same role are scoped, since it grants an open-ended permission that will silently cover any future resource type or verb Kubernetes introduces.

Preferring Namespaced Roles Over Cluster-Wide Grants

When a permission genuinely applies to only one namespace, a Role bound with a RoleBinding keeps the effective scope contained, in contrast to a ClusterRole bound with a ClusterRoleBinding, which extends the same permission to every namespace whether or not it was ever needed elsewhere.


Applying Least Privilege to Workload Identity

One ServiceAccount per Workload

Assigning each distinct workload its own service account, scoped to precisely the permissions that workload needs, prevents a compromise of one application from automatically granting access to permissions that were only ever intended for a different, unrelated workload sharing the same namespace.

Disabling Unnecessary Token Mounts

Workloads that never call the Kubernetes API should have automountServiceAccountToken: false set, removing a credential from the container filesystem entirely rather than leaving an unused but potentially exploitable token available to any process running inside the container.

apiVersion: v1
kind: ServiceAccount
metadata:
  name: static-content-server
automountServiceAccountToken: false

Applying Least Privilege to Pod Security

Minimizing Container Capabilities

Dropping all Linux capabilities by default and adding back only the specific ones a container's process genuinely requires — rather than running with the full default capability set — extends least privilege from the API layer down to what a container process can do at the kernel level.

securityContext:
  capabilities:
    drop: ["ALL"]
    add: ["NET_BIND_SERVICE"]

Non-Root Execution and Read-Only Filesystems

Running containers as a non-root user and mounting the root filesystem read-only, adding writable volumes only where a specific directory genuinely needs write access, follows the same least-privilege logic applied to the container's runtime environment rather than only its API permissions.


Least Privilege as an Ongoing Process

Reviewing Granted Access Against Actual Usage

Audit logs reveal which verbs and resources an identity actually calls in practice; comparing this against the verbs and resources its role formally grants surfaces permissions that were provisioned but never used, which are candidates for removal during periodic review.

Adjusting as Responsibilities Change

A role scoped correctly at the time a workload was first deployed can become either too broad (if functionality was removed) or too narrow (if functionality was added) as the workload evolves; least privilege requires revisiting role definitions alongside application changes rather than treating RBAC as a one-time setup task.


Balancing Least Privilege Against Operational Friction

Avoiding Over-Restriction That Drives Workarounds

A role so narrowly scoped that legitimate operational tasks routinely fail against it tends to produce ad hoc workarounds — shared administrative credentials, temporary broad grants never revoked — that undermine the security goal least privilege was meant to achieve; scoping should be precise but informed by realistic operational patterns, not theoretically minimal in isolation.

Providing a Clear Path to Request Additional Access

Pairing a least-privilege default with a fast, well-defined process for requesting incremental access when a genuine new need arises keeps the discipline sustainable, since teams facing a slow or unclear escalation path are more likely to request broad access preemptively to avoid future friction.