What Are Linux Capabilities? Narrowing Kubernetes Container Permissions
A Linux capability is a kernel feature that splits privileges traditionally bundled with root into smaller units. Kubernetes can add or remove capabilities through a container’s `securityContext.capabilities`, allowing an app to receive only the permissions it needs instead of all administrative privileges. For example, an app that must bind to a low-numbered port may need only `NET_BIND_SERVICE` in some environments. Verify the requirement with the actual image, kernel, runtime, and network configuration.
What Are Linux Capabilities? Narrowing Kubernetes Container Permissions
A Linux capability is a kernel feature that splits privileges traditionally bundled with root into smaller units. Kubernetes can add or remove capabilities through a container’s securityContext.capabilities, allowing an app to receive only the permissions it needs instead of all administrative privileges. For example, an app that must bind to a low-numbered port may need only NET_BIND_SERVICE in some environments. Verify the requirement with the actual image, kernel, runtime, and network configuration.
This article covers Linux containers. A capability is a permission control distinct from the container’s UID: runAsNonRoot selects the process user ID, while capabilities affect whether the kernel permits certain operations. Adding a capability does not automatically make the process root, but unnecessary capabilities expand what a compromised app might do.
What problem do capabilities solve?
Traditional Unix systems let root perform many administrative operations as a bundle. Linux divides those privileges into capabilities. When a protected operation is attempted, the kernel checks the process’s effective capability set. For example, CAP_NET_ADMIN relates to some network-interface, route, and firewall administration operations; CAP_NET_BIND_SERVICE permits binding to Internet ports below 1024. These are representative examples, not full definitions. Consult documentation for the relevant kernel version to confirm each capability’s full scope.
Container runtimes typically grant a limited default set, but the set varies by runtime and configuration. Do not infer which permissions are active merely because the manifest omits capabilities. Conversely, adding a capability does not automatically remove restrictions from seccomp, AppArmor, SELinux, file permissions, or network policy. These controls work at different layers.
Set capabilities in Kubernetes
Kubernetes configures capabilities in the container-level securityContext. drop lists capabilities to remove; add lists those to add. The kernel name has the CAP_ prefix, such as CAP_NET_BIND_SERVICE, but manifests omit the prefix and use NET_BIND_SERVICE.
The YAML below is a starting point for a Linux app that truly needs to bind to a low port. The image and UID are placeholders; this is not a ready-to-deploy configuration.
apiVersion: v1
kind: Pod
metadata:
name: web-app
spec:
containers:
- name: app
image: example.invalid/web-app:1.0 # placeholder; replace with a verified image
ports:
- name: http
containerPort: 80
securityContext:
runAsNonRoot: true
runAsUser: 10001
allowPrivilegeEscalation: false
capabilities:
drop: ["ALL"]
add: ["NET_BIND_SERVICE"]
seccompProfile:
type: RuntimeDefaultUse this example only if NET_BIND_SERVICE is actually required. The app might listen on a high port while a Service or proxy receives traffic on the external low port; then the capability may be unnecessary. Kernel settings for unprivileged ports and the runtime can also change behavior, so verify on the target cluster. Starting with drop: ["ALL"] and adding one capability makes the permission scope explicit, but an app that relies on other capabilities may stop working.
Choose the capability the app needs
Do not assume every permission error means a missing capability. “Permission denied” can also result from UID/GID, file ownership, a read-only root filesystem, SELinux/AppArmor policy, seccomp, mounts, or network configuration. Identify the denied system call or resource and compare it with the app and Linux documentation. When possible, fix file permissions or app configuration to remove the need for extra privilege.
Then verify the change in stages:
In a test environment, start with `drop: ["ALL"]` and exercise the app’s real functions.
Add one capability directly tied to the required operation, then test again.
Check that the requested function works and no unneeded permissions remain; Pod startup alone is not enough.
Record the capability and reason in the manifest or review notes, and reassess after app or runtime changes.
In a running container, CapEff in /proc/1/status shows a bitmask of effective capabilities. It is a hexadecimal value, not a list of names, so a decoder may be needed. Also confirm that PID 1 is the app process. This is a diagnostic clue, not proof of the app’s overall security or every process’s permissions. Where possible, compare the same image and runtime before and after the change and run functional tests.
Policies and important limits
The Restricted level of Pod Security Standards requires applicable Linux containers to drop all capabilities and permits adding back only NET_BIND_SERVICE (check Pod OS conditions and policy version). A need for another capability may conflict with this profile. Do not loosen a namespace casually just to pass policy; verify the need and design a separate trust boundary with an approved exception.
Kubernetes documentation says allowPrivilegeEscalation: false cannot be set together with a privileged container or CAP_SYS_ADMIN. SYS_ADMIN is broad and should not be treated as a small, single-purpose permission. privileged: true affects a much broader permission bundle and multiple kernel protections; it is not equivalent to adding one capability.
If a Pod is rejected or a function stops working after a permission change, use the error to identify the affected container and operation. Separate possible causes, restore the last working configuration if needed, and change one item at a time in a reproducible test. Do not add several unverified capabilities at once or enable privileged mode in production to hide the problem.
Sources
[Kubernetes: Configure a Security Context for a Pod or Container](https://kubernetes.io/docs/tasks/configure-pod-container/security-context/)
[Kubernetes: Pod Security Standards](https://kubernetes.io/docs/concepts/security/pod-security-standards/)
[Kubernetes: Application Security Checklist](https://kubernetes.io/docs/concepts/security/application-security-checklist/)
[Linux man-pages: capabilities(7)](https://man7.org/linux/man-pages/man7/capabilities.7.html)