Description
Kubernetes supports passing Secret values through environment variables. Check whether logs, debugging output or process dumps record the values and who can read that output.
Potential impact
Exposed credentials may grant access to other systems. A running container keeps its original environment values after a Secret changes, which can cause authentication to fail after rotation.
Remediation
- If the app reads files, mount only the required keys read-only. Verify file permissions and that the app reloads changed values.
- If environment variables are required, restrict output and restart containers during rotation. Limit Secret reads and Pod exec/debug access, and revoke credentials no longer in use.
Examples
The differently named Pods are separate resources. Create mysecret in their namespace and configure the app to read the variable or file. The Redis image alone does not configure authentication.
Before
apiVersion: v1
kind: Pod
metadata:
name: secret-env-pod
spec:
containers:
- name: mycontainer
image: redis
env:
- name: SECRET_USERNAME
valueFrom:
secretKeyRef:
name: mysecret
key: username
The username key from mysecret supplies SECRET_USERNAME.
After
apiVersion: v1
kind: Pod
metadata:
name: secret-file-pod
spec:
containers:
- name: mycontainer
image: redis
volumeMounts:
- name: app-secret
mountPath: /var/run/secrets/app
readOnly: true
volumes:
- name: app-secret
secret:
secretName: mysecret
All keys are mounted as files under /var/run/secrets/app. Processes and users with file access can read them.