Security in CI/CD Pipelines

CNPA Domain: Platform Observability, Security, and Conformance (20%) Topic: Security in CI/CD Pipelines

Overview

CI/CD pipelines have become a high-value attack target. A compromised pipeline can push malicious code to production, steal secrets, or poison artifacts used by downstream teams. Supply chain security β€” ensuring the integrity of code and artifacts from commit to production β€” is a top priority for platform engineering teams in 2025 and beyond.


The CI/CD Attack Surface

Developer       CI Pipeline              Registry         Production
   β”‚                β”‚                       β”‚                  β”‚
   │─── push ──▢    β”‚                       β”‚                  β”‚
   β”‚           [build + test]               β”‚                  β”‚
   β”‚           [image scan]                 β”‚                  β”‚
   β”‚           [sign artifact] ──push──▢    β”‚                  β”‚
   β”‚                                   [verify sig] ──deploy──▢│
   
Attack vectors:
  ↑ Code injection     ↑ Dependency confusion   ↑ Image tampering
  ↑ Secrets theft      ↑ Malicious dependencies ↑ Registry hijack

Secrets Management in Pipelines

Never Store Secrets as Plain Text

OIDC for Cloud Authentication

Modern CI systems support OpenID Connect (OIDC) β€” the CI runner proves its identity to cloud providers using a short-lived JWT token. No long-lived credentials needed.


Container Image Scanning

Every container image must be scanned for known vulnerabilities before being pushed to production.

Trivy in CI

Scanning at Multiple Stages

Stage
What
Tool

Pre-commit

IaC misconfigurations

Checkov, tfsec

CI build

Dependencies (SCA)

Trivy, Snyk, Grype

CI build

Container image

Trivy, Grype, Clair

Registry

Continuous after push

Prisma Cloud, Snyk

Runtime

Live threat detection

Falco


Software Bill of Materials (SBOM)

An SBOM is a machine-readable inventory of all components in a software artifact β€” like a supply chain manifest.

Consumers can query the SBOM to quickly determine if a vulnerable library (e.g., Log4j) is present in any image.


Image Signing and Verification (Cosign / Sigstore)

Cosignarrow-up-right (part of the Sigstorearrow-up-right project) provides tools for signing and verifying container images.

Signing in CI

Keyless Signing with OIDC

Sigstore supports keyless signing β€” no private key to manage. The CI identity (GitHub Actions OIDC) is recorded in a public transparency log:

Verifying Signatures with Kyverno


SLSA Framework

SLSA (Supply-chain Levels for Software Artifacts)arrow-up-right is a security framework defining levels of supply chain integrity:

Level
Requirements
Protection

SLSA 1

Build process documented

Basic provenance

SLSA 2

Version controlled, authenticated build service

Tamper evidence

SLSA 3

Hardened build, isolated, non-forgeable provenance

Stronger tamper protection

SLSA 4

Two-person review, hermetic builds

Full supply chain integrity


Dependency Security

Pinning Dependencies

Dependency Confusion Attacks

Configure npm/pip/Maven to use internal registries first:


Pipeline Security Best Practices

Practice
Description

Pin action versions

Use commit SHA in GitHub Actions, not mutable tags

Minimal permissions

Use OIDC; scope IAM roles to specific actions

Ephemeral runners

Fresh runner per job, no persistent credentials

Secret rotation

Rotate all long-lived secrets regularly

Audit pipeline changes

Require PR review for workflow file changes

Block eval patterns

Prevent shell injection in pipeline expressions


Key Takeaways

  • Use OIDC instead of long-lived secrets in CI pipelines

  • Scan container images with Trivy/Grype at build time; fail the pipeline on critical CVEs

  • Generate SBOMs for every artifact to enable rapid vulnerability assessment

  • Sign images with Cosign/Sigstore and verify signatures in Kubernetes via Kyverno

  • Follow the SLSA framework to progressively improve supply chain integrity

  • Pin base images to digests and use npm ci / pip install --require-hashes to lock dependencies


Further Reading

Last updated