CI/CD Security
Securing your CI/CD pipeline - secrets management, security gates, secure deployment, and integrating security scanners into your release process.

Why is CI/CD Security Important?
What is CI/CD security? CI/CD security is the set of practices and controls that protect the pipeline that builds, tests and deploys your software. It covers secrets management, access control for pipelines and runners, integrity checks for dependencies and artifacts, and automated security gates (SAST, SCA, container scanning) that stop vulnerable code from reaching production.
Your CI/CD pipeline has access to source code, credentials, production environments, and artifact repositories. A compromised pipeline can be used to deploy malware, steal secrets, or gain access to production. Pipeline security is a critical component of your DevSecOps strategy.
March 2026 showed this is not theoretical: attackers force-pushed almost all version tags of the trivy-action GitHub Action to malicious commits and published a rogue Trivy v0.69.4. Aqua Security advises treating every secret reachable from runners that used mutable tags at the time as compromised (Aqua Security).
DevSecOps Pipeline Architecture
Security Gates in CI/CD
1. Pre-commit
Checks before code is committed
- Pre-commit hooks (secrets detection)
- Linting and formatting
- Local SAST scan
2. Build Stage
Checks during build
- SAST - static code analysis
- SCA - dependency analysis
- Secret scanning (Gitleaks)
- License compliance
3. Test Stage
Security tests
- Unit tests with security assertions
- Container image scanning (Trivy)
- IaC scanning (Trivy
trivy config, Checkov); tfsec is now part of Trivy
4. Deploy Stage
Pre-deployment checks
- DAST - dynamic testing
- Approval gates for production
- Deployment verification
5. Post-deploy
Continuous monitoring
- Runtime security monitoring
- Vulnerability alerts
- Compliance checks
Secrets Management
Proper handling of secrets (API keys, passwords, certificates) is one of the most important aspects of CI/CD security.
NEVER do this
- Hardcoded secrets in code or pipeline configurations
- Secrets in environment variables without encryption
- Sharing secrets between environments (dev/prod)
- Long-lived static access keys
- Secrets in Docker images
Proper Secrets Handling
GitLab issues the job a short-lived OIDC token (id_tokens), which AWS STS exchanges for temporary credentials. The approach follows the GitLab documentation:
Example: Secure DevSecOps Pipeline
The example uses rules instead of the deprecated only/except keywords (GitLab Docs), gitleaks git instead of detect, which is deprecated since version 8.19.0 (Gitleaks), and semgrep scan, which unlike semgrep ci needs no Semgrep AppSec Platform account (Semgrep Docs). Without an NVD API key, Dependency-Check waits much longer between requests (OWASP Dependency-Check). The trivy image options are described in the Trivy CLI reference.
CI/CD Security Best Practices
Pipeline Configuration
- Pipeline as Code in Git repository
- Protected branches - no direct pushes to main
- Required code reviews
- Signed commits
- Pinned versions of tools and images: GitHub Actions to a full commit SHA (GitHub Docs), container images to a digest
- Build artifact provenance following SLSA v1.2
Secrets & Access
- OIDC/Workload Identity instead of static keys
- External secrets manager (Vault, AWS Secrets Manager)
- Secrets rotation
- Least privilege for pipeline service accounts
- Audit logging of all access
Security Gates
- Fail pipeline on critical findings
- Manual approval for production deploys
- Security review for infrastructure changes
- Rollback mechanisms
- Deployment windows
Security Risks in CI/CD
Based on the OWASP Top 10 CI/CD Security Risks:
- Poisoned Pipeline Execution (PPE, CICD-SEC-4) - pipeline configuration manipulation
- Dependency Confusion as part of Dependency Chain Abuse (CICD-SEC-3) - package manager exploitation
- Credential theft from pipeline logs (Insufficient Credential Hygiene, CICD-SEC-6)
- Supply chain attacks via build tools
- Privilege escalation through self-hosted runners
Sources
- OWASP: Top 10 CI/CD Security Risks (October 2026)
- Aqua Security: Trivy Supply Chain Attack: What You Need to Know (April 2026)
- GitLab Docs: Configure OpenID Connect in AWS to retrieve temporary credentials (October 2026)
- GitLab Docs: Deprecated keywords (October 2026)
- GitHub Docs: Secure use reference (October 2026)
- Gitleaks: README (GitHub) (March 2026)
- Aqua Security: tfsec is now part of Trivy (GitHub) (October 2026)
- Trivy Docs: trivy image CLI reference (October 2026)
- Semgrep Docs: Semgrep Community Edition in CI (October 2026)
- OWASP Dependency-Check: CLI arguments (October 2026)
- SLSA: Specification v1.2 (October 2026)