Course contentsShow
← Cloud and Infrastructure
Lesson 1395 of 2,98928. Kubernetes SecurityFree lesson

Linux Capabilities

Add or drop specific Linux capabilities to fine-tune container permissions without full privileged access.

Linux Capabilities

You'll learn how to grant specific Linux kernel privileges to containers without giving them full root access.

What Are Linux Capabilities?

In traditional Unix systems, processes run either as root (with all privileges) or as a regular user (with minimal permissions). This all-or-nothing approach is risky. Linux capabilities break root's superuser powers into smaller, distinct units that can be granted or removed individually.

Think of it like a key ring: instead of giving someone the master key that opens every door in a building, you give them only the specific keys they need—perhaps the mailroom and storage closet, but not the vault.

Why Use Capabilities in Kubernetes?

By default, Docker and Kubernetes drop several capabilities to enhance security, but sometimes containers need some elevated permissions. Rather than running a privileged container (which is essentially full root), you can add specific capabilities like:

  • NET_BIND_SERVICE: Bind to privileged ports (below 1024)
  • SYS_TIME: Modify system time
  • NET_ADMIN: Perform network administration tasks
  • CHOWN: Change file ownership

You can also explicitly drop capabilities to further harden containers, even if they run as root inside the container.

How It Works

In your Pod's securityContext, use capabilities.add to grant specific permissions and capabilities.drop to remove them:

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

This configuration drops all default capabilities and adds back only the ability to bind to privileged ports.

Key Takeaway: Linux capabilities let you fine-tune container permissions by granting only the specific kernel privileges your application needs, striking a balance between security and functionality without resorting to fully privileged containers.