top of page

How to Build a Secure CI/CD Pipeline

5 hours ago
6 min read

Most security teams spend their time protecting the applications that reach production. Fewer look closely at the system that builds and ships those applications. Yet a CI/CD pipeline holds source code, cloud credentials, signing keys and direct access to production. If an attacker controls the pipeline, they can push their own code into every release, signed and trusted.


That is why securing the pipeline itself is now as important as securing the code that runs through it.


Quick answer: A secure CI/CD pipeline protects both the code moving through it and the pipeline system itself.

It means controlling who can change code and pipeline settings, keeping secrets out of code, scanning every change for vulnerabilities, building in isolated and repeatable environments, signing and verifying what you release, deploying only approved artifacts, and logging every step. CMEx helps enterprises build secure CI/CD pipelines through its DevSecOps practice.


What is a CI/CD pipeline?


Continuous integration (CI) is the practice of merging code changes often and automatically building and testing them. Continuous delivery or deployment (CD) takes those tested changes and releases them to test, staging or production environments automatically.


Together, CI/CD replaces manual handoffs with an automated path from a developer's commit to a running application. That speed is the benefit. It is also why the pipeline needs strong protection: anything that gets into it can reach production quickly.


Why are CI/CD pipelines a target for attackers?


  • They hold the keys. Pipelines store credentials for code repositories, cloud accounts, container registries and production systems.

  • They are trusted. Whatever the pipeline builds and signs is treated as legitimate by everything downstream.

  • They pull in outside code. Builds download open-source libraries, plugins and base images, any of which could be compromised.

  • They are often under-protected. Build servers and pipeline settings are frequently managed with less care than production systems.

Government agencies have taken note. In June 2023, NSA and CISA published joint guidance on Defending Continuous Integration/Continuous Delivery (CI/CD) Environments, warning that software supply chains and CI/CD environments are attractive targets for attackers.


What are the main CI/CD security risks?


The OWASP Top 10 CI/CD Security Risks, which became an official OWASP project in November 2022, lists the most common weak points. In plain terms, they include:


  • Weak flow control: code or pipeline changes can reach production without proper review or approval.

  • Too much access: people and systems have more permissions than they need in repositories and pipelines.

  • Risky dependencies: builds pull in open-source packages that are vulnerable, malicious or impersonating real ones.

  • Poisoned pipeline execution: attackers change build scripts or settings to run their own commands.

  • Exposed credentials: secrets are stored in code, logs or pipeline settings where they can be stolen.

  • Insecure configuration: build servers, runners and tools use default or weak settings.

  • Untrusted third-party services: plugins and integrations get broad access with little oversight.

  • Unverified artifacts: nothing confirms that what is deployed is exactly what was built and approved.

  • Poor logging: there is not enough visibility to detect or investigate an attack.


What does a secure CI/CD pipeline include?


  • Protected source control: branch protection, required code reviews, signed commits and multi-factor authentication for everyone with access.

  • Pipeline as code under review: pipeline definitions live in version control and changes to them need the same review as application code.

  • Least-privilege access: each person, job and service account has only the permissions it needs, with short-lived credentials where possible.

  • Centralized secrets management: passwords, keys and tokens are kept in a secrets vault, injected only at run time, and never stored in code or logs.

  • Automated security testing: static analysis, software composition analysis, secrets scanning and dynamic testing run on every change.

  • Trusted dependencies: packages and base images come from approved sources and are scanned before use.

  • Isolated, repeatable builds: each build runs in a clean, temporary environment that cannot be changed by earlier jobs.

  • Signed artifacts and provenance: builds are signed and record where they came from, so deployments can verify them. The OpenSSF SLSA framework gives a common way to measure this.

  • Policy gates: automated rules decide whether a build can move forward, based on test results, vulnerabilities and approvals.

  • Secure deployment: only signed, approved artifacts can be deployed, using infrastructure as code and controlled credentials.

  • Logging and monitoring: every pipeline action is logged and watched for unusual activity.


How do you build a secure CI/CD pipeline step by step?


  1. Map your pipeline. List repositories, build tools, runners, plugins, registries, credentials and deployment targets, and who can access each.

  2. Lock down source control. Turn on multi-factor authentication, branch protection and required reviews, and remove unused accounts.

  3. Move secrets into a vault. Remove secrets from code and pipeline settings, rotate any that were exposed, and inject them only when needed.

  4. Add automated security checks. Start with secrets scanning, static analysis and dependency scanning, with clear rules on which findings block a build.

  5. Harden build infrastructure. Use temporary, isolated runners, keep build tools patched and limit network access from builds.

  6. Sign and verify artifacts. Sign build outputs, record their origin and allow deployments only of verified artifacts.

  7. Add policy and approval gates. Require approvals for production releases, especially for regulated systems.

  8. Monitor and improve. Log pipeline activity, alert on unusual changes and review access regularly.


How do you keep a secure pipeline fast?


  • Run quick checks first. Fast scans on every commit, deeper scans on merges and nightly builds.

  • Block only on what matters. Fail builds for critical and high-risk issues, and track the rest as work items.

  • Use reusable templates. Give teams a standard, secure pipeline template so they do not each build their own.

  • Give developers clear feedback. Show findings in the tools developers already use, with guidance on how to fix them.


How CMEx builds secure CI/CD pipelines


CMEx's DevSecOps practice designs CI/CD pipelines where security is built in and releases stay fast.

In practice, that covers:

  • CI/CD pipeline design with security checks, policy gates and approvals built in.

  • Application security and vulnerability management across code, open-source components and containers.

  • Quality engineering and performance engineering as part of every pipeline.

  • The GoldenPath accelerator and the DevSecOps & Quality Engineering Center of Excellence, which provide tested, reusable pipeline patterns.

  • Partner technologies including HashiCorp Vault for secrets, Red Hat OpenShift and Ansible, HCL AppScan for application security testing, SUSE NeuVector for container security and Atlassian tools.


This connects with CMEx's Secure Infrastructure Automation work on infrastructure as code, secrets, identity and zero-trust networking. For the basics of the approach, see our guide on what DevSecOps is.


Frequently asked questions


What is the difference between CI/CD security and application security? 


Application security protects the software you build. CI/CD security protects the system that builds and releases it, including repositories, build servers, credentials and deployment steps. Both are needed, because a compromised pipeline can insert malicious code into otherwise secure applications.


Where should we store secrets used by the pipeline?


 In a dedicated secrets management tool, not in code, configuration files or pipeline variables visible to many people. Secrets should be injected only when a job needs them, limited to that job, and rotated regularly.


What is artifact signing and why does it matter? 

Artifact signing adds a digital signature to build outputs such as container images and packages. Before deployment, the signature is checked to confirm the artifact came from your trusted pipeline and has not been changed. It stops tampered or unknown software from reaching production.


What is a software bill of materials (SBOM)? 


An SBOM is a list of all the components and libraries inside a piece of software. Generating one in the pipeline helps teams find affected applications quickly when a new vulnerability is announced in a component.


Will adding security checks slow our pipeline down? 


It can if done poorly. Running fast checks on every commit, deeper scans less often, and blocking only on serious issues keeps pipelines quick. Reusable secure templates also save teams time.


Do secure pipelines work with cloud-hosted CI/CD tools? 


Yes. The same principles apply to cloud-hosted and self-hosted tools: strong identity, least-privilege access, secrets management, isolated builds, signed artifacts and logging. Cloud-hosted tools still need careful configuration of permissions and integrations.

How does a secure pipeline help with audits? 


It records who changed what, which checks ran, what they found and who approved each release. That evidence helps banks, telecom operators and public sector bodies show auditors that software changes are controlled.


Conclusion


Your CI/CD pipeline is part of your attack surface, and often one of the most valuable parts. Securing it means protecting source control, secrets, builds, artifacts and deployments, while keeping releases fast through automation and reusable templates. Start by mapping your pipeline and fixing the biggest gaps, such as exposed secrets and excessive access, then build from there.


Want to know how secure your delivery pipeline really is? A CMEx practice principal, not a sales rep, will review your CI/CD setup and show where the biggest risks and quick wins are.



 
 
bottom of page