01 / 20

CI/CD
Security

Learn how to protect your continuous integration and continuous delivery pipelines with least privilege, code signing, and vulnerability scanning.

Cyber Security

What is CI/CD?

Continuous Integration (CI) is the practice of automatically building and testing code every time a developer pushes changes. Continuous Delivery (CD) extends this by automatically deploying tested code to production or staging environments.

Why Pipeline Security Matters

Developer CI Build & Test CD Deploy Staging/Prod Production Attack Surface Attack Surface A compromised pipeline = compromised production Every stage must be secured independently

Three Pillars of CI/CD Security

Least Privilege
Every component gets only the minimum permissions it needs to function: nothing more.
Signing
Cryptographically verify that code and artifacts have not been tampered with in transit.
Scanning
Automatically detect vulnerabilities, misconfigurations, and secrets before deployment.

The Principle of Least Privilege

✕ Overprivileged Admin Access Write to Prod DB Network Full Access Secret Store Access Build agent has everything ✓ Least Privilege Read Source Code Write Build Artifacts No DB Access No Network Access Build agent has minimum

Code Signing and Verification

Build Output Sign Artifact Private Key generates signature Verify Signature Public Key confirms artifact is untampered Tampering detected: signature mismatch = deploy blocked

Code signing uses cryptographic keys to create a digital signature for every build artifact. Before deployment, the signature is verified. If the artifact was modified after signing, the signature will not match and deployment is halted.

Automated Vulnerability Scanning

SAST
Static Analysis: Scans source code for vulnerabilities before the program runs. Finds SQL injection, buffer overflows, and hardcoded secrets.
DAST
Dynamic Analysis: Tests a running application by simulating attacks. Finds XSS, authentication flaws, and misconfigured headers.
SCA
Software Composition Analysis: Checks third-party libraries and dependencies for known CVEs and license issues.

Signing vs. Scanning

Signing Scanning
Purpose Verify integrity: artifact unchanged Find vulnerabilities in code/dependencies
When After build, before deploy During build, before merge
Protects Against Tampering, supply chain injection Known CVEs, secrets, misconfigurations
Mechanism Cryptographic signatures (e.g., GPG, Sigstore) Pattern matching, CVE databases
Analogy Tamper-evident seal on a package X-ray machine inspecting contents

Protecting Secrets in Pipelines

CI/CD pipelines often need API keys, database passwords, and tokens. If these secrets are exposed, attackers gain direct access to your infrastructure. Here's how to manage them securely:

1
Never hardcode secrets in source code or pipeline configuration files. Automated scanners can find them in version history.
2
Use a secrets manager (e.g., HashiCorp Vault, AWS Secrets Manager) to inject secrets at runtime, not at build time.
3
Rotate secrets regularly and revoke immediately if a pipeline is compromised.
4
Mask secrets in logs: configure your CI platform to automatically redact secret values from build output.

How to Secure a Pipeline

1
Audit permissions: List every credential, token, and role used in the pipeline. Remove anything not strictly needed.
2
Add SAST scanning: Integrate a static analysis tool into the CI build step. Block merges if critical vulnerabilities are found.
3
Add SCA scanning: Configure dependency checks to flag known CVEs in third-party libraries.
4
Sign build artifacts: Generate a cryptographic signature after a successful build. Store the public key separately from the pipeline.
5
Verify before deploying: The CD stage must verify the artifact signature before deploying to any environment.
6
Monitor and alert: Log all pipeline activity and set up alerts for failed signature checks, permission escalation, or unexpected changes.

Example: Hardcoded API Key

✕ Insecure config.yml: API_KEY: "sk-abc123xyz" DB_PASS: "admin1234" Visible in git history forever ✓ Secure config.yml: API_KEY: ${VAULT_API_KEY} DB_PASS: ${VAULT_DB_PASS} Injected at runtime from vault → SAST scanner detects hardcoded secrets Build fails → developer fixes → pipeline continues Vulnerability caught before it reaches production

Example: Vulnerable Dependency

Your Application Library A v2.1 Library B v1.3 Library C v4.0 CVE-2024-XXXX Critical: Remote Code Exec SCA Scanner Flags CVE → blocks build → team updates Library B

Example: Supply Chain Attack

Step 1 Attacker compromises build server Step 2 Malicious code injected into build artifact Step 3 Artifact deployed to thousands of customers Defense Signature check would have caught the tampering How Signing Prevents This 1. Build server produces artifact + cryptographic signature 2. Attacker modifies artifact → signature no longer matches 3. Deploy stage verifies signature → mismatch detected → deploy blocked

Defense in Depth in CI/CD

Layer 1: Access Controls (Least Privilege) Layer 2: Automated Scanning Layer 3: Code Signing Artifact Each layer catches threats the others might miss

Common Mistakes in CI/CD Security

✕ Overprivileged Runners
Giving CI/CD runners admin or root access "for convenience." If compromised, attackers own the entire infrastructure.
✕ Secrets in Git
Committing API keys, passwords, or tokens to version control. Even if removed, they live in git history permanently.
✕ Skipping Scans
Disabling security scans to "speed up the pipeline." This trades short-term velocity for serious long-term risk.
✕ Unsigned Artifacts
Deploying build artifacts without verifying their integrity. Supply chain attacks exploit exactly this gap.

CI/CD Security Summary

Control What It Does When to Apply Threat Blocked
Least Privilege Limits permissions Always (pipeline config) Lateral movement
SAST Scans source code CI build step Code vulnerabilities
SCA Checks dependencies Dependency resolution Known CVEs
DAST Tests running app Staging environment Runtime flaws
Code Signing Verifies integrity After build, before deploy Supply chain attacks
Secrets Manager Protects credentials Runtime injection Credential exposure

Question 1 of 5

What does the principle of least privilege mean in the context of CI/CD pipelines?

Question 2 of 5

Which type of scanning analyzes source code without running it to find vulnerabilities like SQL injection or hardcoded secrets?

Question 3 of 5

A development team discovers that a third-party library in their project has a known critical vulnerability (CVE). Which CI/CD security control would have caught this before deployment?

Question 4 of 5

In a supply chain attack like SolarWinds, an attacker injects malicious code into a build artifact. Which security control directly prevents tampered artifacts from being deployed?

Question 5 of 5

Which combination of controls would have most effectively prevented this breach?