More Info:
Kubernetes supports mounting secrets as data volumes or as environment variables. Minimize the use of environment variable secrets.Risk Level
HighAddress
SecurityCompliance Standards
- APRA CPS 234 (Australia)
- AWS Startup Security Baseline
- BSI C5 (Germany)
- Brazil LGPD
- CCPA / CPRA (California)
- CIS Critical Security Controls v8
- CIS EKS
- CMMC 2.0
- CSA Cloud Controls Matrix v4
- DPDPA
- Digital Operational Resilience Act (EU)
- Essential 8
- ISO/IEC 27017
- ISO/IEC 27018
- ISO/IEC 27701
- KSA PDPL
- MAS Technology Risk Management (Singapore)
- MITRE ATT&CK (Cloud)
- NIST SP 800-171
- NYDFS 23 NYCRR 500
- SWIFT Customer Security Controls Framework
- Sarbanes-Oxley IT General Controls
- UK NCSC Cyber Assessment Framework
Triage and Remediation
- Remediation
Remediation
Manual Steps
Manual Steps
-
List all workloads using secrets as environment variables
- Run on: any machine with
kubectlaccess.
- Run on: any machine with
-
Inspect a specific workload’s env-based secret usage
- Pick one namespace/kind/name from step 1 and inspect its manifest:
- In the downloaded YAML, locate
env:entries that usevalueFrom.secretKeyRef.
-
Refactor the manifest to mount secrets as files instead of env vars
- Edit the saved manifest file on your local machine:
- Under
spec.template.spec, add or update avolumesentry referencing the secret:
- For each container that currently uses
env.valueFrom.secretKeyRef, remove thoseenventries and mount the secret as a volume:
- Ensure the application code/config is updated to read the secret from the mounted file path (for example,
/var/run/secrets/app/KEY_NAME). This requires application changes outside of Kubernetes and must be coordinated with the application owner.
-
Apply the updated manifest to the cluster
- Run on: any machine with
kubectlaccess.
- Repeat steps 2–4 for each resource reported in step 1 (
Deployment,StatefulSet,DaemonSet,Job,CronJob, etc.), adaptingkindand filenames as needed.
- Run on: any machine with
-
Optionally remove any remaining env-based secret refs programmatically (review required)
- To review all manifests currently using
secretKeyRefbefore final cleanup:
- Manually confirm each usage is safe to remove and that the application reads from files; then adjust the corresponding manifests as in steps 2–4. Do not delete
enventries without confirming application behavior.
- To review all manifests currently using
-
Verify no secrets are used as environment variables
- Run on: any machine with
kubectlaccess.
- Run on: any machine with
Using kubectl
Using kubectl
On any machine with kubectl access:Edit with volume-based access:Make sure Repeat step 2–3 for each Deployment/StatefulSet/DaemonSet/Pod reported in step 1.
- Identify workloads using
secretKeyRef(same as audit)
- For each listed object, switch from env-var secrets to volume-mounted secrets.
env.valueFrom.secretKeyRef to use a Secret volume.Before (env-var based):/tmp/my-app-deployment.yaml and replace:volumes: is under spec.template.spec and volumeMounts: is under the container spec. Adjust mountPath, name, and secretName as needed. Your application code must read from the file path (e.g., /var/run/secrets/db/password) instead of the environment variable.- Apply the updated manifest (this will roll the workload)
- Verification (no remaining
secretKeyRefin running workloads)
Automation
Automation

