Terraform state contains database passwords in plain text. How do you handle it?
IntermediateScenarioContainer and IaC Security
Answer
Situation read → State stores resource attributes, including sensitive ones, even if marked sensitive = true in outputs.
What I'd do →
- Use a remote backend with encryption and versioning: S3 with SSE-KMS, bucket policy restricting principals, DynamoDB or S3 native lockfile.
- Restrict read access to state to the CI role and a few admins.
- Avoid creating secrets in Terraform: use
manage_master_user_password = truefor RDS or reference Secrets Manager. - Enable ephemeral resources/values on Terraform 1.10+ where supported.
- Audit access through CloudTrail data events.
Why → State is as sensitive as the secrets inside it.
Interview tip → Note that sensitive = true hides CLI output only.
More on Container and IaC Security
A team asks whether to use `ubuntu`, `alpine` or a distroless base image. How do you advise?Beginner`trivy image` shows 300 vulnerabilities in your app image. How do you bring this down?BeginnerA Dockerfile runs the app as root. How do you fix it and prove the fix?IntermediateCheckov fails a Terraform PR because an S3 bucket allows public access. What do you change?BeginnerHow do you set up image scanning so nothing vulnerable reaches production?IntermediateAn image passed scanning three weeks ago and runs in production. A new critical CVE is published today. What happens next?Intermediate