CI/CD
Security
Learn how to protect your continuous integration and continuous delivery pipelines with least privilege, code signing, and vulnerability scanning.
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
Three Pillars of CI/CD Security
The Principle of Least Privilege
Code Signing and Verification
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
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:
How to Secure a Pipeline
Example: Hardcoded API Key
Example: Vulnerable Dependency
Example: Supply Chain Attack
Defense in Depth in CI/CD
Common Mistakes in CI/CD Security
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
Scenario: A company's CI/CD pipeline builds and deploys a web application. The build runner has full administrator access to the production database, the secrets vault, and the cloud infrastructure. A junior developer accidentally pushes a commit that includes a reverse shell payload hidden in a test file. The SAST scanner is disabled because "it slows down builds." The artifact is not signed.
The malicious commit passes all stages and deploys to production. The reverse shell activates, giving the attacker full access to the production database and cloud infrastructure.
Which combination of controls would have most effectively prevented this breach?