Lesson 2 of 3 Amazon Inspector and Secure Pipelines

Building Security Gates into CI/CD Pipelines

This lesson explains how shifting security left finds vulnerabilities while code is written and built, when they are cheapest to fix, rather than after deployment.

Learning outcomes

After completing this lesson, you will be able to:

  • Identify the stages at which scanning takes place.
  • Design pipeline gates that stop insecure changes.
  • Describe how the pipeline is protected against supply chain attacks.

Where scanning happens

Security issues are cheapest to fix when found early, so scanning takes place at three stages. In the IDE, Amazon Q Developer security scans flag problems while the developer writes code and suggest fixes. In the repository, Inspector code security scans for code flaws, vulnerable dependencies and infrastructure-as-code misconfigurations. CodeGuru Security, which the exam guide names, provided similar scanning but has been discontinued, and Inspector code security replaces it. In the pipeline, gates in CodeBuild and CodePipeline, or a third-party CI system, fail the build when scans find serious issues, so vulnerable code is not deployed. The following table summarises the stages.

StageTool
IDEAmazon Q Developer security scans with suggested fixes
RepositoryInspector code security: code flaws, vulnerable dependencies, IaC misconfiguration. (CodeGuru Security, named in the exam guide, did similar but has been discontinued; Inspector code security replaces it)
PipelineGates in CodeBuild/CodePipeline or third-party CI
Sort into groups

Where does the scan happen?

Exam skills 3.2.6

Place each scanning activity at its stage.

Log in to try this activity Interactive activities are free with an account.

Pipeline gates

Every security problem caught in the pipeline is one that never reaches production. A secure pipeline therefore runs automated checks at each stage, scanning the application code, its dependencies, the infrastructure templates and the container images, and it stops the release when a check finds a serious problem. Checks that only report problems without blocking the release are easily ignored. The following list describes the recommended gates.

  • SAST (static analysis) and SCA (dependency scanning).
  • Secret detection.
  • IaC checks: cfn-lint, CloudFormation Guard, Access Analyzer custom policy checks.
  • Container image scanning (ECR and Inspector).

Fail the build on critical findings; manual approvals gate production.

The following diagram shows the three gates in order.

Three gates in a CodeBuild stage, each for a different class of problem: cfn-guard rules for infrastructure misconfiguration, IAM Access Analyzer check-no-new-access for privilege creep, and the ECR image scan for critical vulnerabilities. Any non-zero exit stops the pipeline before deployment.
The gates run in one CodeBuild stage.
Match the pairs

Pipeline gates

Exam skills 3.2.6 · 6.2.1

Match each pipeline gate with the problem it catches.

Log in to try this activity Interactive activities are free with an account.

Supply chain and pipeline security

Attackers increasingly target the software supply chain rather than the application: they publish malicious packages with names similar to popular ones, compromise public images, or attack the pipeline itself, which has permissions to deploy to production. Protecting the supply chain means controlling where dependencies come from, proving that artifacts were built by the pipeline, and treating the pipeline as a privileged system. The following list describes the relevant controls.

  • CodeArtifact with package origin controls blocks malicious package versions; the ECR pull-through cache proxies public images.
  • AWS Signer signs artifacts and images; enforce with Lambda code signing configurations and container admission controllers.
  • Least-privilege pipeline roles, secrets in Secrets Manager, separate build and production accounts.
True or false

Protecting the pipeline

Exam skills 3.2.6

Check the controls that protect the pipeline and its artefacts.

Log in to try this activity Interactive activities are free with an account.
Worked example

A pipeline that refuses insecure changes

A CodeBuild stage runs three gates before any deployment. If any command exits non-zero, the pipeline stops:

phases:
  build:
    commands:
      # 1. Templates must satisfy the organisation's Guard rules
      - cfn-guard validate --data template.yaml --rules rules/security.guard
      # 2. IAM policies in the template must not grant new access compared with the approved baseline
      - aws accessanalyzer check-no-new-access --policy-type IDENTITY_POLICY
          --new-policy-document file://policies/app-role.json
          --existing-policy-document file://policies/app-role.approved.json
          --query result --output text | grep -q PASS
      # 3. The container image must have no critical vulnerabilities
      - aws ecr wait image-scan-complete --repository-name app --image-id imageTag=$IMAGE_TAG
      - test "$(aws ecr describe-image-scan-findings --repository-name app --image-id imageTag=$IMAGE_TAG
          --query 'imageScanFindings.findingSeverityCounts.CRITICAL' --output text)" = "None"

Each gate addresses a different class of problem: infrastructure misconfiguration, privilege creep in IAM, and vulnerable dependencies. Combined with signed artifacts (AWS Signer) and least-privilege pipeline roles, they make the pipeline the only path to production and keep that path safe.

Check yourself

How can only signed code be deployed to Lambda?

Show answer

With AWS Signer and a code signing configuration on the function.

Exam Tips

Remember for the exam

  • For developers to see vulnerability findings while coding, use Amazon Q Developer.
  • To block deployment of images with critical CVEs, add a pipeline gate on Inspector and ECR findings.
  • To allow only signed code to be deployed to Lambda, use AWS Signer code signing.
  • To catch insecure templates before deployment, run CloudFormation Guard or cfn-lint in the pipeline.
  • To control which open-source packages builds can use, use CodeArtifact.