How do you enforce "no public RDS, encryption on" for all Terraform changes across teams?
IntermediateScenarioContainer and IaC Security
Answer
Situation read → Per-team review does not scale. Put the rules in code that runs against the plan.
What I'd do →
- Produce a plan JSON:
terraform plan -out tfplan && terraform show -json tfplan > plan.json. - Evaluate with OPA/conftest:
package terraform
deny[msg] {
r := input.resource_changes[_]
r.type == "aws_db_instance"
r.change.after.publicly_accessible == true
msg := sprintf("%s must not be public", [r.address])
}
- Run
conftest test plan.jsonas a required check. - Backstop with AWS SCPs or Config rules for anything created outside Terraform.
Why → Plan-time checks give fast feedback, SCPs give hard enforcement.
Interview tip → Say "shift-left check plus cloud-side backstop".
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