kubernetes: Improper Permissions on ConfigMap and Secret Mounts

What would you like to be added?

Hey, I am opening this issue publicly as it was approved by a member of the Kubernetes staff on HackerOne (#2867563) to be discussed with the larger community. Since addressing it would break existing users, it may require a Kubernetes Enhancement Proposal (KEP). The staff member also agreed that it is a poor default.

Description

Kubernetes mounts ConfigMaps and Secrets to containers with default permissions -rw-r–r-- (644) also the permission on the ConfigMaps and Secrets directories mounted to the container is set to -rwxrwxrwx (777), This configuration allows any user in the container, not just the root user, to read these files, exposing sensitive data and violating the principle of least privilege. In multi-user containers, any non-root user can access these ConfigMaps and Secrets, further increasing the risk of unauthorized data exposure. To prevent this, users can use the defaultMode parameter to set stricter permissions, such as 600/750, ensuring only the root user has access. The current default behavior conflicts with the principle of least privilege, making manual adjustment necessary to protect sensitive data.

Steps To Reproduce:

  1. Create a Kubernetes ConfigMap or Secret.
  2. Mount the ConfigMap or Secret into a container.
apiVersion: v1
kind: Pod
metadata:
  name: secret-mounted-pod
spec:
  containers:
    - name: my-app
      image: nginx:latest
      securityContext:
        runAsUser: 1000
      volumeMounts:
        - name: secret-volume
          mountPath: "/etc/secret"
          readOnly: true
  volumes:
    - name: secret-volume
      secret:
        secretName: my-secret
  1. Run the container with multiple users, including a non-root user (e.g., user ID 1000).
  2. Observe that the default permissions are -rw-r–r-- and that any non-root user can read the mounted data.

Why is this needed?

To mitigate this risk, we need to ensure that the directory and the mounted files of Configmaps/Secrets have permissions set to 750. This setting allows only the root user and the group owner to read and execute, while preventing access by other users. his approach limits read access to the root/owner only, thereby following the principle of least privilege and reducing unauthorized exposure of sensitive data.

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Reactions: 4
  • Comments: 16 (8 by maintainers)

Most upvoted comments

+1 to @BenTheElder

Related issues:

In general, Kubernetes hasn’t prioritized sub-pod isolation or multi-user pods, and even less so multi-user containers.

This configuration allows any user in the container, not just the root user, to read these files, exposing sensitive data and violating the principle of least privilege.

Many containers do not run as root and should reasonably be able to read mounted configs and secrets. I don’t think defaulting to “root only” is an improvement because it encourages running as root for deployments that otherwise had no need to?

In multi-user containers, any non-root user can access these ConfigMaps and Secrets, further increasing the risk of unauthorized data exposure.

multi-user containers are … unusual? most are single-process in addition to single-user, and instead a separate container (or pod) is used for root etc.

I think a change with this much impact to consider would require an accepted enhancement proposal: https://github.com/kubernetes/enhancements (so the plan for safely introducing it, testing it, etc is outlined and agreed to)

Since this is a feature that would likely require a KEP, and not a clear bug (where we’d just merge a fix if it were provided), I don’t think keeping the issue open will help, unless someone here plans to work on it.

Personally: I don’t recommend having a multi-user environment within a single container, and I don’t recommend mounting secrets to a container that shouldn’t be able to read them. I personally don’t think this is in the intended scope for Kubernetes (versus eg using a different containers within a pod and only mounting it to some of them), and I don’t think this would be safe to change without it being opt-in, along with the requisite design, development, and testing work.

If anyone is interested in working on such a feature, I’d reach out to one of the listed SIGs (via slack or the mailinglist, see github.com/kubernetes/community) to discuss how I would like to write a KEP and implement this feature.

In a future minor release of Kubernetes, we can change our Pod security standards.

After the redefinition, any Pods that mount either a ConfigMap or a Secret, and don’t specify a defaultMode for every such mount, wouldn’t meet the updated restricted Pod Security Standard.

Only a partial solution, but it could be worth doing. Kubernetes’ compatibility guarantees allow the Pod security standards to evolve over time.