Kubernetes
Cluster Policy
Security Context
Privileged Access
Cloud Security

securityContext.privileged Forbidden disallowed by cluster policy

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

Kubernetes is a powerful container orchestration platform that allows managing and deploying containerized applications. A core aspect of this system is its strong security model, which enables fine-grained control over container execution and behavior. One important security-related field within Kubernetes is `securityContext.privileged`. Improper use of this can lead to errors such as "Forbidden: disallowed by cluster policy." In this article, we will explore what this means, its implications, and provide guidance on how to manage this error effectively.

Understanding `securityContext.privileged`

The `securityContext` option in Kubernetes specifies the security settings for a Pod containing the container. Within this, the `privileged` flag is of particular significance:

  • Privileged Container: A container with `privileged: true` runs with elevated permissions. Essentially, this makes the container almost equivalent to the root user on the host system, allowing it to perform a wide range of tasks or access specific system resources that a standard, unprivileged container cannot.
  • Security Implications: While enabling `privileged` mode can be crucial for specific use cases, such as running containers that require access to host resources (e.g., network adapters or disks), it significantly increases the risk surface. Therefore, it is generally disallowed by security policies unless explicitly permitted.

The Error: Forbidden: Disallowed by Cluster Policy

When Kubernetes encounters the setting `securityContext.privileged: true`, it evaluates the cluster policy to ensure this action is allowed. By default, most Kubernetes environments are configured with security policies that disable privileged containers to minimize risk. As a result, attempting to deploy a privileged container without the necessary permissions will result in the error message: "Forbidden: disallowed by cluster policy."

Example Scenario

Suppose a developer attempts to deploy a Pod with the following configuration:

  • name: my-container
  • Capabilities: Instead of granting full privilege, selectively assign Linux capabilities. This approach provides granular permission without broad access.
  • SecurityContext Attributes: Use other securityContext attributes such as `allowPrivilegeEscalation: false`, `runAsUser`, and restrict `HostPID`, `HostIPC`, and `HostNetwork` settings.
  • Network Policies: Implement network policies to restrict communications between containers, minimizing the attack vector available to privileged containers.

Related reading
Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

All Rights Reserved.