Skip to main content

Insecure Access Control

Why is this important?

Access Control is one of the most fundamental security requirements. Any problem with managing access control can allow attackers to bypass business logic and access data from other users. In the context of Kubernetes this affects settings related to the securityContext and spec.

Check out this video for a high-level explanation:

Access Control Issues

Insecure SecurityContext Settings

This category refers to SecurityContext settings that are insecure at the pod or container level.

Option A: Run containers as non-root users

Force the running image to run as a non-root user to ensure least privilege.

Detailed Instructions

  1. Go through the issues that GuardRails identified

  2. Look for code like this:

    apiVersion: v1  
    kind: Pod
    metadata:
    name: security-best-practice
    spec:
    containers:
    # specification of the pod’s containers
    # ...
    securityContext:
    runAsNonRoot: false
    # it is also possible for runAsNonRoot to not be set.
  3. Replace the line containing runAsNonRoot: false with:

    spec:  
    containers:
    # specification of the pod’s containers
    # ...
    securityContext:
    runAsNonRoot: true
  4. Test it

  5. Ship it 🚢 and relax 🌴

Option B: Don't run containers in privileged mode

Privileged containers can allow almost completely unrestricted host access.

Detailed Instructions

  1. Go through the issues that GuardRails identified

  2. Look for code like this:

    apiVersion: v1  
    kind: Pod
    metadata:
    name: security-best-practice
    spec:
    containers:
    # specification of the pod’s containers
    # ...
    securityContext:
    privileged: true
  3. Replace the line containing privileged: false with:

    spec:  
    containers:
    # specification of the pod’s containers
    # ...
    securityContext:
    privileged: false
  4. Test it

  5. Ship it 🚢 and relax 🌴

Option C: Don't add SYS_ADMIN capabilities

Capabilities permit certain named root actions without giving full root access. They are a more fine-grained permissions model, and all capabilities should be dropped from a pod, with only those required added back.

There are a large number of capabilities, with CAP_SYS_ADMIN bounding most. Never enable this capability - it’s equivalent to root and should always be avoided.

Detailed Instructions

  1. Go through the issues that GuardRails identified

  2. Look for code like this:

    apiVersion: v1  
    kind: Pod
    metadata:
    name: sys-admin-capabilities
    spec:
    containers:
    # specification of the pod’s containers
    # ...
    securityContext:
    capabilities:
    drop:
    - all
    add:
    - SYS_ADMIN
  3. Remove the SYS_ADMIN capabilities

  4. Test it

  5. Ship it 🚢 and relax 🌴

Option D: Disable allowPrivilegeEscalation

Gates whether or not a user is allowed to set the security context of a container to allowPrivilegeEscalation. This defaults to allowed so as to not break setuid binaries. Setting it to false ensures that no child process of a container can gain more privileges than its parent.

Detailed Instructions

  1. Go through the issues that GuardRails identified

  2. Look for container definitions with allowPrivilegeEscalation being set to true

    apiVersion: v1
    kind: Pod
    metadata:
    name: drop-capabilities
    spec:
    containers:
    # specification of the pod’s containers
    # ...
    securityContext:
    allowPrivilegeEscalation: true
  3. Change it to allowPrivilegeEscalation: false

  4. Test it

  5. Ship it 🚢 and relax 🌴

Option E: Reduce kernel capabilities

Reducing kernel capabilities available to a container limits its attack surface. It's recommended to drop all capabilities and only add the ones specifically needed.

Detailed Instructions

  1. Go through the issues that GuardRails identified

  2. Look for container definitions without capabilities definition in the securityContext

  3. Drop all capabilities and only add the ones needed

    apiVersion: v1
    kind: Pod
    metadata:
    name: drop-capabilities
    spec:
    containers:
    # specification of the pod’s containers
    # ...
    securityContext:
    capabilities:
    drop:
    - all
    add: ["NET_ADMIN", "SYS_TIME"]

    Or better yet:

    apiVersion: v1
    kind: Pod
    metadata:
    name: drop-capabilities
    spec:
    containers:
    # specification of the pod’s containers
    # ...
    securityContext:
    capabilities:
    drop:
    - all
    add: ["NET_BIND_SERVICE"]
  4. Test it

  5. Ship it 🚢 and relax 🌴

Option F: Run as high-UID user

Run as a high-UID user to avoid conflicts with the host's user table. While this is not a high-risk issue it is recommended to set a UID higher than 10000.

Detailed Instructions

  1. Go through the issues that GuardRails identified

  2. Look for container definitions like this:

    apiVersion: v1
    kind: Pod
    metadata:
    name: run-as-user
    spec:
    containers:
    # specification of the pod’s containers
    # ...
    securityContext:
    runAsUser: 1000
  3. Change the value to a number higher than 10000

  4. Test it

  5. Ship it 🚢 and relax 🌴

Insecure Spec Settings

This category refers to Spec settings that are insecure.

Option A: Disable HostPID

Sharing the host's PID namespace allows visibility of processes on the host, potentially leaking information such as environment variables and configuration.

Detailed Instructions

  1. Go through the issues that GuardRails identified

  2. Look for spec definitions like this:

    apiVersion: v1
    kind: Pod
    metadata:
    name: run-as-user
    spec:
    hostPID: true
  3. Change the value of hostPID to false

  4. Test it

  5. Ship it 🚢 and relax 🌴

References:

Not Limited Capabilities For Pod Security Policy

Option A:

Usually the best approach when it comes to the set of capabilities that pods can run with is to remove them until something in your application stops working, or start with no capabilities and only add the ones you fnd you need. The fewer Linux capabilities you run with the less privileges and access the containers within the given pod have to the hosts kernel.

Detailed Instructions

At the Pod Security Policy level:

  1. Add as many capabilities to requiredDropCapabilities of your Pod Security Policy as possible, or even add ALL
  2. Test your application
  3. If everything is still working try adding more capabilities to requiredDropCapabilities
  4. Test your application, if something has stopped working, remove the capability you just added to requiredDropCapabilities
  5. Test your application
  6. If everything is still working, ship it 🚢 and relax 🌴

References:

More information: