Other Articles

Secure Build Pipeline Controls: How to Protect Your CI/CD Process

Support > Tech Best Practices

Overview

This article explains how to secure the build and deployment pipeline that turns your source code into running software. It describes the most important controls and explains how to apply them, regardless of which CI/CD tool your team uses.

This guidance applies to GitHub Actions, GitLab CI/CD, Jenkins, CircleCI, Bitbucket Pipelines, Azure Pipelines, AWS CodePipeline, and similar platforms. Although settings have different names across platforms, the underlying principles are the same.

What Is a Secure Build Pipeline?

A build pipeline is an automated process that takes code changes, tests them, and releases them to staging and production environments. It has two parts. Continuous Integration (CI) runs automated quality and security checks on every change. Continuous Deployment (CD) releases approved code to your servers automatically.

A secure build pipeline ensures that only authorized people can change the code and pipeline, every change is reviewed and checked before release, and credentials are protected and short-lived.

Why Secure Your Build Pipeline?

  • The pipeline has direct access to your production environment. An attacker who compromises it could deploy malicious code to your servers and customers.
  • Long-lived credentials stored in a pipeline are common targets and can leak through logs or repositories.
  • Unreviewed changes can introduce vulnerabilities or errors directly into production.
  • Vulnerable third-party dependencies are a common way for known flaws to reach production.
  • Customers and partners increasingly expect releases to be controlled and traceable.
  • Frameworks such as ISO 27001 and SOC 2 expect controlled change management and separation between environments.

Benefits

  • Every change is reviewed, tested, and traceable to a person.
  • Production releases occur only after the required checks pass.
  • Secrets are kept out of code and are inaccessible to people who do not need them.
  • Known vulnerabilities are detected early, when they are less expensive to fix.
  • Teams can see who changed what and when, making problems easier to investigate and resolve.

How It Works

A secure pipeline combines the following six controls.

1. Control Who Can Change the Code and Pipeline

  • Protect release branches, such as the main and production branches, so that nobody can push to them directly.
  • Limit merge permissions for release branches to a small, named group of people.
  • Store pipeline definition files in the same protected branches so that pipeline changes undergo the same review process as code changes.

2. Require Reviews Before Merging

  • Require at least one approval before a pull request or merge request can be merged.
  • Do not allow authors to approve their own changes.
  • Require automated checks to pass before allowing a merge.

3. Run Automated Checks on Every Change

  • Run tests and code-quality checks.
  • Run static application security testing (SAST) to identify insecure code patterns.
  • Run dependency scanning to identify libraries with known vulnerabilities.
  • Enable automated dependency updates so that fixes arrive as reviewable pull requests.

4. Deploy Only After the Checks Pass

  • Make every deployment step depend on the successful completion of the required checks.
  • Deploy to staging first, test the deployment there, and promote it to production only after the tests pass.
  • Require a designated approver to authorize production deployments.

5. Protect Secrets and Credentials

  • Avoid long-lived cloud access keys in the pipeline. Where supported, use short-lived tokens issued for each run, such as tokens obtained through OpenID Connect (OIDC).
  • Restrict the cloud role so that it can be used only by your own repositories and authorized branches.
  • Store application secrets in a secrets manager and inject them at runtime. Never store them in code.
  • Use masked and protected variables to prevent secrets from appearing in logs and to make them available only to protected branches.
  • Limit who can view or change secrets, and rotate them regularly.

6. Control Manual Deployments and Server Access

  • If deployments are performed manually, restrict them to a small group of people using authorized SSH keys.
  • Do not give developers or testers access to production servers unless they need it for their roles.
  • Review authorized keys regularly and remove access for people who have left the organization or changed teams.

Applying These Controls in Your Tool

The six controls apply across CI/CD platforms, but the relevant settings are located in different places. The examples below show where to start with some common tools. Features vary by plan and version, so consult your tool's documentation.

  • GitHub Actions: Use branch protection rules, required reviews, environments with required reviewers, and OpenID Connect (OIDC) to authenticate to your cloud provider with short-lived credentials.
  • GitLab CI/CD: Use protected branches, merge request approvals, protected environments and variables, and ID tokens for short-lived credentials.
  • Jenkins: Protect branches on your Git hosting platform, store secrets in the credentials store, add an input step to approve production releases, and use plugins or agents with an attached cloud role instead of stored keys.
  • CircleCI: Use contexts to restrict access to secrets, add an approval job before production deployment, and use OIDC tokens for short-lived credentials.
  • Other tools, including Bitbucket Pipelines, Azure Pipelines, and AWS CodePipeline: Look for equivalent features, such as protected branches, approval gates, secret variables, and token-based cloud access.

Common Use Cases

  • Securing the release process before launching a new product.
  • Moving safely from manual deployments to automated deployments.
  • Onboarding a new project or repository onto a standard pipeline.
  • Replacing stored cloud keys with short-lived credentials.
  • Reviewing the pipeline after a team change or security incident.

Example Scenario

  • A team stores its code in a Git hosting service and uses a CI/CD tool to deploy to staging and production.
  • A developer works on a feature branch and opens a pull request. The pull request requires one approval, and CI runs the required checks.
  • After the change is merged, CI runs again and the code is deployed to staging, where the QA team tests it.
  • After QA confirms that staging works as expected, a senior team member approves the production release. Only a small, named group can push to the production branch.
  • The deployment job runs only if CI has passed and authenticates to the cloud using a short-lived token instead of a stored key.
  • Application secrets are injected at runtime from a secrets manager.
  • Dependency and code scans run automatically on every change, and the team reviews and acts on the results.

Best Practices

  • Start with the highest-risk controls: protect release branches, require reviews, and remove long-lived keys.
  • Treat pipeline definition files like production code, and review every change to them.
  • Give the pipeline only the permissions it needs, using separate roles for staging and production.
  • Review third-party actions, plugins, and images before using them because they run within your pipeline.
  • Fail the build when a scan finds a high-severity issue, and define who is responsible for triaging the findings.
  • Review access to the pipeline, secrets, and deployment servers regularly, such as every quarter.
  • Document the release process so that everyone knows who can approve and promote a change.

Common Mistakes to Avoid

  • Storing cloud access keys or passwords in code, or keeping them in long-lived pipeline variables without rotating them.
  • Allowing direct pushes to release branches or allowing administrators to bypass rules without recording the action.
  • Allowing a pipeline to deploy when checks fail or are skipped.
  • Giving the pipeline broader permissions than necessary, such as full administrator access.
  • Running scans without reviewing the results or acting on the findings.
  • Leaving access enabled for people who have left the team or moved to other roles.
  • Trusting third-party plugins or actions without reviewing them.
  • Printing secrets in build logs.

Updated on 28 October, 2026