Skip to main content


4.4.1 Prefer using secrets as files over secrets as environment variables (Manual)

Profile Applicability

• Level 2


Kubernetes supports mounting secrets as data volumes or as environment variables. Minimize the use of environment variable secrets.


It is reasonably common for application code to log out its environment (particularly in the event of an error). This will include any secret values passed in as environment variables, so secrets can easily be exposed to any user or entity who has access to the logs.


Application code which expects to read secrets in the form of environment variables would need modification


Run the following command to find references to objects which use environment variables defined from secrets.

kubectl get all -o jsonpath='{range .items[?(@..secretKeyRef)]} {.kind} {} {"\n"}{end}' -A


If possible, rewrite application code to read secrets from mounted secret files, rather than from environment variables.


Additional Information

Mounting secrets as volumes has the additional benefit that secret values can be updated without restarting the pod