Finding and Fixing Vulnerabilities in a Pipeline
In the SCS-C03 exam, Domain 3 (Infrastructure Security) expects you to know how to embed vulnerability detection and remediation into CI/CD pipelines, an approach often called "shifting security left." The goal is to catch flaws before they reach production, where fixing them costs more and exposes more risk. Finding vulnerabilities: A typical AWS pipeline uses AWS CodePipeline to orchestrate stages and AWS CodeBuild to compile, test, and scan. Key detection layers include: 1. Static code analysis: Amazon CodeGuru Security (or third-party SAST tools) reviews source code for issues such as injection flaws, hardcoded credentials, and weak cryptography. 2. Dependency and image scanning: Amazon Inspector integrates with CodeBuild and CI tools through its SBOM generator and ScanSbom API to identify vulnerable packages. Amazon ECR enhanced scanning, powered by Inspector, continuously checks container images for CVEs on push and when new CVEs are published. 3. Infrastructure as Code (IaC) checks: AWS CloudFormation Guard, cfn-nag, or Checkov validate templates against policies, flagging open security groups, unencrypted storage, or overly permissive IAM policies. 4. Secrets detection: Tools such as git-secrets prevent credentials from being committed, and AWS Secrets Manager supplies secrets at build time. Fixing vulnerabilities: Configure quality gates so that a build fails when findings exceed a severity threshold (for example, Critical or High CVEs). Findings flow to AWS Security Hub for centralized visibility. Amazon EventBridge rules can trigger AWS Lambda functions or Systems Manager Automation runbooks to open tickets, notify teams through Amazon SNS, or rebuild images with patched base layers. EC2 Image Builder produces hardened, regularly patched golden AMIs and container images, while Systems Manager Patch Manager keeps running instances current. Pipeline hardening: Secure the pipeline itself by granting least-privilege IAM roles to CodeBuild and CodePipeline, encrypting artifacts in S3 with AWS KMS, requiring manual approval stages for production, signing images with AWS Signer, and logging activity with AWS CloudTrail. Exam tip: When a question asks for automated, scalable, low-overhead vulnerability management in pipelines, favor managed services such as Inspector, ECR enhanced scanning, Security Hub, and EventBridge-driven remediation.
Finding and Fixing Vulnerabilities in a Pipeline (AWS Certified Security - Specialty: Infrastructure Security)
Modern workloads on AWS are built, tested and deployed through automated CI/CD pipelines. Every artifact a pipeline produces, such as container images, Lambda packages, AMIs, application binaries and Infrastructure as Code (IaC) templates, can carry vulnerabilities into production. Finding and fixing vulnerabilities in a pipeline means embedding security scanning, policy checks and remediation workflows into each stage of the software delivery lifecycle, so that flaws are caught early (shift left) and fixed in a repeatable, automated way.
Why It Is Important
1. Cost and speed of remediation: A vulnerability found at commit time costs far less to fix than one found in production after an incident.
2. Scale and consistency: Manual reviews cannot keep pace with dozens of deployments per day. Automated gates enforce the same standard on every build.
3. Supply chain risk: Third-party packages, base images and open-source libraries are a major attack vector (for example, Log4Shell). Pipelines are the natural control point for inspecting dependencies.
4. Compliance and auditability: Frameworks such as PCI DSS, SOC 2 and NIST require evidence of vulnerability management. Pipeline scan results, approvals and SBOMs provide that evidence.
5. Pipeline as a target: The pipeline itself holds credentials, signing keys and deployment permissions. A compromised pipeline can push malicious code into every environment, so the pipeline must also be hardened.
The exam tests whether you can pick the right AWS service for each type of vulnerability and design an automated, least-operational-overhead detection and remediation flow.
What It Is: The Building Blocks
Source and code stage
- Amazon CodeGuru Reviewer / CodeGuru Security: Static Application Security Testing (SAST) that detects issues such as injection flaws, insecure crypto, resource leaks and hardcoded secrets in Java and Python (CodeGuru Security supports more languages). Integrates with CodeCommit, GitHub, Bitbucket and CI tools.
- Secrets scanning: Tools such as git-secrets or CodeGuru secrets detection stop credentials from being committed. The fix is to move secrets into AWS Secrets Manager or SSM Parameter Store (SecureString) and rotate exposed keys.
- Branch protection and approvals: Pull request approval rules in source repositories and IAM conditions restrict who can push to main branches.
Dependency and package stage
- AWS CodeArtifact: A managed artifact repository that lets you control which upstream packages (npm, PyPI, Maven, NuGet) are allowed, so builds pull from a vetted internal source.
- Software Composition Analysis (SCA): Amazon Inspector can scan dependencies and generate a Software Bill of Materials (SBOM) in CycloneDX or SPDX format.
Build stage
- AWS CodeBuild: Runs tests and scanners as buildspec commands. A build can fail when findings exceed a severity threshold, which stops the pipeline.
- Amazon Inspector CI/CD integration: The Inspector SBOM generator (inspector-sbomgen) and the Inspector Scan API (ScanSbom) let you scan container images and packages inside CodeBuild, Jenkins, GitHub Actions or other CI tools before the image is pushed to a registry.
- IaC scanning: AWS CloudFormation Guard (cfn-guard), cfn-nag and Checkov check templates for misconfigurations such as unencrypted S3 buckets, open security groups or wildcard IAM policies. CloudFormation Hooks can enforce checks at deploy time.
Artifact and registry stage
- Amazon ECR image scanning:
- Basic scanning: OS package CVE scanning on push or manual.
- Enhanced scanning: Powered by Amazon Inspector, continuous scanning of OS and programming language packages, with rescans when new CVEs are published.
- ECR tag immutability prevents a scanned image from being overwritten by an unscanned one with the same tag.
- AWS Signer: Signs container images (with Notation) and Lambda code. Lambda code signing configurations reject unsigned or tampered packages.
Image and AMI stage
- EC2 Image Builder: Builds golden AMIs and container images with hardening components (for example, CIS benchmarks, STIG) and built-in test stages. It integrates with Amazon Inspector to scan images and can be scheduled to rebuild when base images or patches change.
Deploy and runtime stage
- Amazon Inspector: Continuously scans EC2 instances (agent via SSM, or agentless), ECR images and Lambda functions (standard and code scanning). Findings include CVSS and an Inspector risk score that accounts for network reachability.
- AWS Systems Manager Patch Manager: Applies patches to EC2 and on-premises instances using patch baselines and maintenance windows.
- AWS Config: Detects configuration drift and noncompliant resources. Remediation can run through SSM Automation documents.
- AWS Security Hub: Aggregates findings from Inspector, GuardDuty, Config, Macie and third-party tools into a single view using the AWS Security Finding Format (ASFF), with cross-account and cross-Region aggregation.
How It Works: An End-to-End Flow
Step 1 - Commit: A developer pushes code. CodeGuru Reviewer analyzes the pull request and comments on security issues. A pre-commit hook blocks secrets.
Step 2 - Source trigger: AWS CodePipeline detects the change and starts the pipeline.
Step 3 - Build and test: CodeBuild pulls dependencies from CodeArtifact, runs unit tests, runs cfn-guard against templates, builds the container image and runs inspector-sbomgen plus the Inspector Scan API. If critical or high CVEs are found, the build exits with a non-zero code and the pipeline stops.
Step 4 - Publish: The clean image is pushed to ECR (immutable tags, KMS encryption) and signed with AWS Signer.
Step 5 - Approval gate: A manual approval action in CodePipeline (with SNS notification) or an automated Lambda check confirms the security results before production.
Step 6 - Deploy: CodeDeploy, ECS, EKS or CloudFormation deploys the artifact. Admission controls verify signatures.
Step 7 - Continuous monitoring: Inspector enhanced scanning keeps rescanning the image in ECR and the running workloads as new CVEs appear.
Step 8 - Automated response: Inspector sends findings to Amazon EventBridge and Security Hub. An EventBridge rule triggers a Lambda function, an SSM Automation runbook or a new pipeline execution (for example, rebuild the image with an updated base, or patch EC2 with Patch Manager). Notifications go to SNS, chat channels or ticketing systems.
Step 9 - Feedback: Findings are tracked in Security Hub and fixed in source, so the next build is clean. Inspector suppression rules handle accepted risks; they hide findings that match criteria but do not change the underlying risk.
Securing the Pipeline Itself
- Give CodePipeline and CodeBuild service roles least privilege, scoped to specific resources.
- Run CodeBuild in a VPC with VPC endpoints when it needs private resources, and restrict outbound access.
- Encrypt pipeline artifact buckets with AWS KMS customer managed keys; use cross-account KMS key policies for multi-account pipelines.
- Store build secrets in Secrets Manager or Parameter Store and reference them in the buildspec, never in plain text environment variables.
- Log all API activity with AWS CloudTrail and send build logs to CloudWatch Logs.
- Use separate AWS accounts (tooling, dev, prod) with cross-account roles, governed by AWS Organizations and SCPs.
Common Vulnerability Types and Matching Fixes
- OS package CVEs in images: Rebuild from an updated base image; use ECR enhanced scanning / Inspector.
- Vulnerable application libraries: Update dependency versions; control sources with CodeArtifact; scan with Inspector or CodeGuru.
- Code flaws (SQL injection, weak crypto): CodeGuru Reviewer / Security; fix in code and rerun pipeline.
- Hardcoded credentials: Rotate the credential first, then move it to Secrets Manager and add secret scanning.
- IaC misconfigurations: cfn-guard, cfn-nag, CloudFormation Hooks; AWS Config rules for drift at runtime.
- Unpatched EC2 fleet: Inspector to detect, Patch Manager to remediate, Image Builder to refresh golden AMIs.
- Lambda vulnerabilities: Inspector Lambda standard and code scanning; Lambda code signing to block tampered code.
Exam Tips: Answering Questions on Finding and Fixing Vulnerabilities in a Pipeline
1. Map keywords to services:
- Continuous scanning of container images / rescan when new CVEs are published = ECR enhanced scanning (Amazon Inspector).
- Scan on push, OS packages only, lowest cost = ECR basic scanning.
- Scan images in the CI tool before pushing to a registry = Inspector SBOM generator + Inspector Scan API in CodeBuild or Jenkins.
- Detect code defects or hardcoded secrets in source = CodeGuru Reviewer / CodeGuru Security.
- Validate CloudFormation templates against policy = CloudFormation Guard or CloudFormation Hooks.
- Golden AMI with hardening and scheduled rebuilds = EC2 Image Builder.
- Patch running instances = SSM Patch Manager.
- Single view of findings across accounts = Security Hub with a delegated administrator.
- Ensure only trusted code runs = AWS Signer and Lambda code signing.
- Control third-party packages = CodeArtifact.
2. Favor automation and least operational overhead: When a question asks for the most efficient or least effort option, choose managed services connected through EventBridge (Inspector finding to EventBridge to Lambda or SSM Automation) over custom scripts on EC2 or manual review.
3. Fail the build early: Answers that stop the pipeline in CodeBuild when severity thresholds are exceeded are usually preferred over answers that detect issues only after deployment.
4. Distinguish detection from remediation: Inspector, CodeGuru and ECR scanning find problems; Patch Manager, SSM Automation, Image Builder rebuilds and pipeline reruns fix them. Read whether the question asks to detect, prevent or remediate.
5. Fix at the source for immutable infrastructure: For containers and AMIs, the correct remediation is to update the base image or dependency and redeploy, not to patch a running container in place.
6. Exposed secrets: The first priority is to rotate or revoke the leaked credential, then remove it from code and history, store it in Secrets Manager and add scanning to prevent recurrence. Deleting the commit alone is never enough.
7. Watch for Inspector details: Inspector uses the SSM Agent for EC2 (or agentless scanning via EBS snapshots), is enabled per Region, and supports multi-account management through AWS Organizations with a delegated administrator. Suppression rules filter findings; they do not fix them.
8. Protect the pipeline: If a scenario mentions a compromised build role or leaked artifacts, look for least-privilege IAM roles, KMS-encrypted artifact stores, CodeBuild in a VPC, CloudTrail logging and separate tooling accounts.
9. Eliminate distractors: GuardDuty detects threats such as malicious activity, not package CVEs; Macie discovers sensitive data in S3, not code flaws; Trusted Advisor gives best-practice checks, not CVE scanning. These are frequent wrong answers.
10. Read the constraint words: Before deployment points to build-stage scanning; continuously points to Inspector enhanced scanning; across all accounts points to Organizations plus Security Hub or Inspector delegated admin; prove compliance points to SBOM exports, Security Hub standards and CloudTrail evidence.
Summary
Finding and fixing vulnerabilities in a pipeline combines shift-left scanning (CodeGuru, Inspector CI/CD scanning, cfn-guard, CodeArtifact), registry and runtime scanning (ECR enhanced scanning, Inspector), centralized visibility (Security Hub), and automated remediation (EventBridge, Lambda, SSM Automation, Patch Manager, Image Builder rebuilds). On the exam, choose the managed, automated, earliest-in-the-lifecycle control that matches the artifact type, and remember that the pipeline itself must be secured with least privilege, encryption and logging.