Interview Prep/DevSecOps/Container image and IaC scanning

CI image scan fails with `unable to inspect the image: ... unauthorized: authentication required` for a private ECR repo

BeginnerTroubleshootingContainer image and IaC scanning
Answer

Likely causes → Trivy is not logged in to the registry, or the ECR token (valid 12 hours) expired in a long pipeline.

Diagnose → aws sts get-caller-identity and aws ecr get-login-password | docker login ... result.

Fix →

aws ecr get-login-password --region ap-south-1 | docker login --username AWS --password-stdin 123456789012.dkr.ecr.ap-south-1.amazonaws.com
trivy image 123456789012.dkr.ecr.ap-south-1.amazonaws.com/myapp:1.4

Or scan the local image before push.

Prevent → Scan in the build job right after docker build and before docker push.

All DevSecOps questions

More on Container image and IaC scanning