Someone opened a security group manually in the console, bypassing Terraform. How do you detect and prevent it?
IntermediateScenarioContainer and IaC Security
Answer
Situation read → Drift means your reviewed code is no longer the truth.
What I'd do →
- Detect: scheduled
terraform plan -detailed-exitcode(exit 2 means changes) and AWS Config rules. - Alert via CloudTrail and EventBridge on
AuthorizeSecurityGroupIngressfrom non-pipeline principals. - Remediate: re-apply Terraform, or auto-remediate with Config and SSM Automation.
- Prevent: remove write permissions from humans, use read-only console roles plus a break-glass role, add SCPs.
Why → If humans cannot change prod directly, drift becomes rare.
Interview tip → "Detect, remediate, then remove the permission that allowed it."
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