How do you inject a Secret as a file with strict permissions?
IntermediateScenarioConfiguration, Secrets and storage
Answer
Situation read → An app needs a TLS key file readable only by its user.
What I'd do →
- Mount the Secret as a volume with
defaultMode: 0400 - Set
securityContext.fsGroupandrunAsUserso the file is readable by the process - Prefer files over env vars, since env vars leak in
/procand crash dumps - Verify with
kubectl exec -- ls -l /etc/tls - Rotate by updating the Secret; mounted files refresh
Why → File mounts have permissions and are updated automatically, env vars have neither.
Interview tip → Mention that mode in YAML is octal in YAML 1.1 but decimal in JSON.
More on Configuration, Secrets and storage
How do you inject configuration into pods and what are the options?BeginnerA ConfigMap was updated but the pod still shows old values. Why?IntermediateHow do you store a database password safely in Kubernetes?BeginnerHow do you manage secrets in GitOps without committing them in plain text?IntermediateA pod fails with `CreateContainerConfigError` and a missing key. What happened?BeginnerWhat is the difference between emptyDir, hostPath, PV/PVC and when do you use each?Beginner