Skip to content
SP StackPractices
intermediate By StackPractices

CI/CD Pipeline Security Template

A template for securing build and deployment pipelines against credential leaks, tampering, supply chain attacks, and unauthorized deployments.

Note: This guide follows English-language naming conventions and terminology standards common in international development teams. Examples use English identifiers and comments to maximize compatibility across codebases and tooling.

Overview

CI/CD pipelines are a high-value target for attackers because they have access to source code, build secrets, and production deployment paths. A compromised pipeline can introduce malware, exfiltrate data, or deploy unauthorized changes. This template defines controls to protect code integrity, runner security, secrets, and deployment approvals.

When to Use

  • Setting up a new CI/CD platform.
  • Reviewing or improving an existing pipeline.
  • Preparing for a supply chain security audit.
  • After a build system compromise or unauthorized deployment.
  • Integrating DevSecOps controls into engineering workflows.

Prerequisites

  • A version control system with branch protection and audit logging.
  • A CI/CD platform such as GitHub Actions, GitLab CI, Azure DevOps, or Jenkins.
  • A secret management solution for pipeline credentials.
  • A process for code review and approval before merging.
  • Ownership from platform engineering, security, and release management.

Solution

Template

1. Source Control Security

ControlRequirementVerification
Branch protectionRequired reviews before merge to mainRepository settings
Signed commitsRequire verified commits for privileged accountsGit configuration
Access controlLeast-privilege access to repositoriesRBAC review
Audit loggingAll pushes, merges, and permission changes loggedPlatform logs
Dependency pinningLockfiles and pinned versions for reproducible buildsRepository files
Secret scanningAutomated detection of secrets in commitsPre-commit hooks + CI

2. Pipeline Configuration

ControlRequirementVerification
Immutable pipeline definitionsPipelines stored as code and reviewedRepository files
No secrets in codeSecrets loaded from vault, CI variables, or OIDCSecret scanning
Input validationPipeline parameters validated and sanitizedCode review
Self-hosted runner isolationProduction runners isolated from dev runnersRunner configuration
Ephemeral runnersFresh runner per build to reduce persistenceRunner settings
Pipeline provenanceSLSA provenance generated for artifactsAttestation tool

3. Secrets Management

Secret TypeStorageRotationScope
Cloud credentialsExternal vault or OIDC90 daysPer environment
Container registry tokensVault or short-lived CI tokens90 daysPer pipeline
Signing keysHardware-backed or KMS180 daysLimited service accounts
API keysVault or secret manager90 daysMinimum required permissions
Database passwordsVault dynamic secrets24 hoursPer pipeline run

4. Build Security

ControlRequirementVerification
Dependency scanningAll dependencies scanned for known CVEsScanner in CI
Static analysisSAST run on every pull requestCI job
Container image scanningBase image and layers scanned before pushRegistry scan
Reproducible buildsSame source produces same artifactBuild verification
Artifact signingAll artifacts signed with build identitySignature verification
SBOM generationBill of materials generated per buildCI output

5. Deployment Security

ControlRequirementVerification
Deployment gatesManual or automated approval before productionPipeline rules
Environment separationProduction credentials not available in devSecret scoping
Rollback planAutomated rollback trigger on failurePipeline definition
Immutable deploymentsArtifacts deployed by reference, not rebuiltDeployment logs
Drift detectionUnauthorized production changes detectedMonitoring tool
Audit trailWho deployed what, when, and whyDeployment logs

6. Incident Response

ScenarioResponseOwner
Secret leakedRotate secret, revoke tokens, audit usageSecurity team
Malicious commitRevert, investigate, revoke credentialsPlatform team
Compromised runnerTerminate runner, rebuild, review logsPlatform team
Unauthorized deploymentRollback, freeze pipeline, auditRelease manager
Tampered artifactBlock deployment, trace provenanceSecurity team

Explanation

Pipeline security is a subset of supply chain security. By protecting the source, the build process, and the deployment path, the organization reduces the risk of malicious code reaching production. The template maps each control to a verification method, making it suitable for audits and continuous improvement.

Variants

  • GitHub Actions security checklist: Focuses on actions pinning, workflow permissions, and reusable workflows.
  • GitLab CI security template: Includes CI/CD job token scopes, protected runners, and compliance pipelines.
  • Jenkins hardening template: Covers plugin management, agent isolation, and Groovy sandboxing.
  • Container-native pipeline: Emphasizes image signing, registry scanning, and Kubernetes admission.
  • High-compliance pipeline: Adds SLSA Level 3, dual approval, and signed SBOMs for regulated environments.

Best Practices

  • Store pipeline definitions as code and review them like application code.
  • Use short-lived credentials and OIDC instead of long-lived secrets.
  • Scan dependencies before merging and before deploying.
  • Sign artifacts and verify signatures before deployment.
  • Separate build and production environments physically or logically.
  • Require human approval for production deployments.
  • Generate and retain SBOMs for every release.
  • Monitor pipeline activity for unusual behavior.

Common Mistakes

  • Storing secrets in environment variables or pipeline files.
  • Using third-party actions without pinning or reviewing them.
  • Allowing any branch to deploy to production.
  • Running production and dev workloads on the same runner.
  • Skipping security scans for hotfix deployments.
  • Not rotating pipeline credentials after a compromise.
  • Trusting artifacts without signature verification.

FAQs

What is the biggest risk in CI/CD?

The most common high-impact risk is credential theft from a runner or pipeline file, which allows attackers to access production or tamper with builds.

How do we balance security with fast deployments?

Automate security checks, use fast scanners, and require approval only for production. Shift-left scanning gives fast feedback without blocking the pipeline.

What is SLSA provenance?

SLSA is a framework for supply chain security. Provenance records how an artifact was built, including source repository, build command, and dependencies, making it easier to detect tampering.