AWS from Zero to Production — Phase 7, Part 4 of 5 · See the full series roadmap
Most security problems that reach production were visible long before.
The vulnerable library was flagged in a public advisory months ago. The public S3 bucket was right there in the Terraform diff. The leaked API key sat in a commit for weeks. Nobody was looking at the right moment.
DevSecOps means making the pipeline look — automatically, on every change — and stopping the dangerous ones before they ship. Done badly, it’s a wall of false positives that teams learn to ignore. Done well, it’s a fast, quiet safety net.
This article covers the tools, where they belong in the pipeline, and how to keep them from grinding delivery to a halt.
What you’ll walk away with
- 🔍 SAST, SCA, container scanning, IaC scanning, and secret scanning — what each catches
- 🛡️ Amazon Inspector and ECR image scanning
- 🚧 Security gates that block the right things
- 📋 Software bills of materials (SBOMs)
- ✍️ Artifact signing and provenance
- 📜 Policy as code
- 🧾 A vulnerability exception process that doesn’t become a loophole
Where security checks fit
Developer laptop pre-commit hooks: secrets, linting
|
Pull request SAST, SCA, IaC scanning, secret scanning
|
Build container image scan, SBOM, signing
|
Deploy policy checks, signature verification
|
Runtime Amazon Inspector, GuardDuty, Security Hub
Shift left means catching issues as early as possible, when they’re cheapest to fix. But keep scanning at runtime too: new vulnerabilities are published every day for code that was clean yesterday.
Static application security testing (SAST)
SAST analyzes your source code for vulnerable patterns: SQL injection, command injection, unsafe deserialization, hard-coded credentials, and weak cryptography.
- Tools: GitHub CodeQL, Semgrep, Bandit for Python, SonarQube, and Amazon CodeGuru Security.
- Strengths: finds bugs in your code, before it runs.
- Weaknesses: false positives, and it can’t see runtime context.
pip install bandit
bandit -r src/ -ll
Tip: Start with a small, high-confidence rule set and block only on high severity. Expand once the team trusts the results.
Software composition analysis (SCA)
Most of your application is other people’s code. SCA checks your dependencies against vulnerability databases.
- Tools: Dependabot, pip-audit,
npm audit, OWASP Dependency-Check, and Snyk. - Also flags license issues in some tools.
pip install pip-audit
pip-audit -r requirements.txt
Dependabot goes further: it opens pull requests to update vulnerable dependencies automatically. Turn on Dependabot alerts and security updates in every repository.
Lock your dependencies. Without lock files or pinned versions, you can’t know what you shipped — or reproduce it.
Container scanning
A container image includes an operating system layer full of packages — each a potential vulnerability.
- Amazon ECR basic scanning: scans OS packages on push or on demand.
- Amazon ECR enhanced scanning, powered by Amazon Inspector: continuous scanning of OS and language packages, re-evaluated when new CVEs are published.
- Open-source tools: Trivy, Grype.
Reduce findings at the source:
- Use minimal base images:
-slim, distroless, or Alpine where appropriate. - Rebuild regularly, even without code changes, to pick up patched base images.
- Use multi-stage builds so compilers and build tools never ship.
Infrastructure-as-Code scanning
IaC scanners catch misconfigurations before they exist:
- A security group open to
0.0.0.0/0on port 22 - An unencrypted RDS instance or S3 bucket
- A bucket without Block Public Access
- An IAM policy with
"Action": "*"
Tools: Checkov, Trivy (which absorbed tfsec), KICS, cfn-lint and cfn-guard for CloudFormation, and cdk-nag for CDK.
pip install checkov
checkov -d infra/ --framework terraform
Engineer’s note: IaC scanners flag things like “RDS isn’t Multi-AZ” that may be acceptable in dev. Use inline suppressions with a reason — not blanket skips — so exceptions are visible in code review.
Secret scanning
A leaked credential can be exploited within minutes of being pushed to a public repository.
- GitHub secret scanning detects known token formats in your repositories — and push protection blocks the push before the secret ever lands.
- Gitleaks and TruffleHog scan history, and work as pre-commit hooks.
- AWS also scans public repositories for exposed AWS access keys and may restrict them automatically.
If a secret leaks: rotate it first, then clean up history. Assume it’s compromised the moment it’s pushed. And the best fix is structural: with OIDC, there are no AWS keys to leak.
Amazon Inspector
Amazon Inspector continuously scans workloads for vulnerabilities and unintended network exposure:
- EC2 instances: OS and application packages — via the SSM Agent, or agentless scanning of EBS snapshots.
- Container images in ECR: enhanced scanning, continuously re-evaluated.
- Lambda functions: package vulnerabilities, and optionally code vulnerabilities.
- Risk scoring that factors in network reachability and exploit availability.
- Findings flow to Security Hub and EventBridge, so you can alert or auto-remediate.
Inspector also offers CI/CD integration: generate an SBOM with the Inspector SBOM generator and scan it through the Inspector Scan API inside your pipeline, before the image is even pushed.
Security gates
A security gate is a pipeline step that fails the build when a check finds something above a threshold.
Good gates are:
- Specific: “block on CRITICAL or HIGH vulnerabilities with a fix available.”
- Fast: seconds or a few minutes, not an hour.
- Actionable: the failure message says what to fix.
- Focused on new issues: don’t block a typo fix because of a year-old finding that has an approved exception.
aws ecr wait image-scan-complete --repository-name orders --image-id imageTag=$TAG
CRITICAL=$(aws ecr describe-image-scan-findings \
--repository-name orders --image-id imageTag=$TAG \
--query 'imageScanFindings.findingSeverityCounts.CRITICAL' --output text)
if [ "$CRITICAL" != "None" ] && [ "$CRITICAL" -gt 0 ]; then
echo "Blocking deploy: $CRITICAL critical vulnerabilities"
exit 1
fi
Watch out: A gate that blocks on everything gets bypassed. A gate that blocks on nothing is theater. Start strict on a few things, and tighten over time.
Software bill of materials (SBOM)
An SBOM is an inventory of every component in your software: packages, versions, and licenses.
- Formats: SPDX and CycloneDX.
- Tools: Syft, Trivy, Docker’s built-in SBOM attestations, and the Amazon Inspector SBOM generator.
- Why it matters: when the next major vulnerability lands, you can answer “are we affected, and where?” in minutes, not days. Some customers and regulations also require SBOMs.
Generate an SBOM for every build, and store it alongside the artifact.
Artifact signing and provenance
How do you know the image running in production is the one your pipeline built — not something pushed by an attacker with stolen registry credentials?
Sign it.
- Sigstore cosign signs container images, with keyless signing based on OIDC identities.
- AWS Signer signs container images through the Notation CLI, with keys and signing profiles managed in AWS. Lambda code signing is also supported.
- GitHub artifact attestations create signed provenance: which workflow, commit, and repository produced an artifact.
Then verify before deploying — for example, with an admission controller in Kubernetes, or a verification step in your pipeline.
The SLSA framework describes levels of supply chain integrity, and is a useful roadmap.
Policy as code
Policy as code expresses rules in code that tools enforce automatically:
- Open Policy Agent (OPA) with Conftest — check Terraform plans, Kubernetes manifests, and Dockerfiles.
- AWS CloudFormation Guard — rules for CloudFormation templates.
- Kyverno or OPA Gatekeeper — Kubernetes admission policies.
- Service control policies and AWS Config rules — guardrails at the AWS account level (Phase 2).
package main
deny contains msg if {
some r in input.resource_changes
r.type == "aws_s3_bucket_public_access_block"
r.change.after.block_public_acls == false
msg := sprintf("%s must block public ACLs", [r.address])
}
Policies are reviewed, versioned, and tested — just like application code.
Vulnerability exception processes
Sometimes you can’t fix a finding right now: no patch exists, the vulnerable code path isn’t reachable, or the fix requires a major upgrade.
A healthy exception process has:
- An owner — a named person accountable for the risk.
- A justification — why it’s acceptable, including compensating controls.
- An expiry date — exceptions are temporary, and are reviewed again when they expire.
- Visibility — tracked in one place, like Security Hub suppressions or a reviewed suppression file in the repository.
- Approval — by someone other than the requester, for high-severity findings.
Red flag: An exception with no expiry date isn’t an exception. It’s a permanent hole with paperwork.
Putting it together
A practical pipeline for the orders API:
Pull request:
pytest + bandit (high only) + pip-audit + checkov (infra/) + secret scanning (push protection)
Main branch:
build image -> push to ECR -> wait for scan -> block on CRITICAL
generate SBOM -> upload as artifact
deploy -> smoke test -> roll back on failure
Runtime:
Amazon Inspector continuous scanning -> Security Hub -> alert on new CRITICAL findings
That’s exactly what you’ll build in Part 5.
Common mistakes
- Blocking on every finding, so teams disable the gate.
- Scanning only at build time, never at runtime.
- Rewriting Git history but not rotating a leaked secret.
- Blanket suppressions with no reason or expiry.
- Unpinned third-party actions and base images.
- Treating scanners as a substitute for secure design and code review.
Key takeaways
- SAST checks your code; SCA checks your dependencies; container and IaC scanners check what you ship and build.
- Push protection stops secrets before they land — and OIDC removes AWS keys entirely.
- Amazon Inspector keeps scanning after deployment, as new CVEs appear.
- Gates should be specific, fast, and actionable.
- SBOMs and signatures make your supply chain answerable and verifiable.
- Exceptions need an owner, a reason, and an expiry date.
Quick self-check
Test yourself before moving on:
- Which type of scanning finds a vulnerable version of a library you depend on?
- A developer pushed an API key an hour ago. What’s the first thing to do?
- Why keep scanning images that passed the build-time scan?
- What four things should every vulnerability exception have?
Answers
- Software composition analysis (SCA).
- Rotate (revoke) the key. Then clean up history.
- New CVEs are published daily for software that was clean yesterday.
- An owner, a justification, an expiry date, and approval — tracked visibly.
What’s next
In Part 5, the Phase 7 lab: one GitHub Actions pipeline that tests, scans, authenticates with OIDC, pushes to ECR, gates on vulnerabilities, deploys to ECS, smoke-tests, and rolls back automatically.
Which security gate has saved your team — or annoyed it the most? Tell me in the comments.