Skip to main content
Security guideReviewed

CI/CD security: who can run your pipeline, what each job can reach, and how a deployer checks what it ships

A CI/CD pipeline holds the keys to production: a repository token, cloud credentials and the right to deploy without anyone touching a server.

This guide explains who and what can make yours run, what each job and each third-party action can reach once it does, and what an approval, a short-lived identity and an attested artefact each prove. GitHub Actions is the worked example, with GitLab CI/CD as a section of its own. It comes with a pipeline trust map, a six-part threat test pack, a sample least-privilege workflow and a local checker you can run against your own workflow files.

Pipeline trust map, threat test pack and least-privilege workflow

Part A maps eight actors and stages in a GitHub Actions pipeline to what each is trusted to do, what it can reach and the control that limits it, with a source for each control or a note that it is this page's advice. Part B is a threat test pack for untrusted pull requests, third-party actions, build secrets, artefact signing, environment approvals and deployment identity, each with steps you run in your own repository, a passing result and what a failure means.

How to use it

Part C is a sample workflow with permissions declared at workflow and job level, and Part D is a local checker with a regression test, shown with its real output. Every owner, action and commit SHA in it is invented.

cicd-security.txt

Introduction9 lines

ILLUSTRATION ONLY. The repository, the owner example-owner, the action cloud-deploy-action, the environment production and every 40-character commit SHA in this asset are invented for this page. They are not a client's pipeline. The tests in Part B are for repositories you own, using a test secret that unlocks nothing. What is here: Part A Pipeline trust map: who and what is trusted to do what, what each can reach, and the control that limits it, with the source behind each control or a note that it is this page's advice. Part B Threat test pack: one test for each of untrusted pull requests, third-party actions, build secrets, artefact signing, environment approvals and deployment identity. Part C Sample least-privilege permission set: a complete GitHub Actions workflow with permissions at workflow and job level. Part D Local lab: a workflow checker and a regression test that run with Node.js alone, with their real output. GitHub Actions is the worked platform throughout. Settings named here are as GitHub's documentation described them on 14 November 2026.

What a CI/CD pipeline is, and why it is worth attacking

A CI/CD pipeline is the automation that turns a commit into a running release.

Continuous integration builds and tests each change; continuous delivery or deployment packages the result and puts it where users can reach it. NIST SP 800-204D, NIST's guidance on supply chain security in DevSecOps pipelines, describes CI/CD pipelines as using processes called workflows to transform source artefacts into deployable packages in production environments. On GitHub those workflows are YAML files in .github/workflows; on GitLab the pipeline is defined in .gitlab-ci.yml.

Two things make a pipeline worth attacking. It holds credentials: a token for the repository, keys or roles for the cloud account, tokens for the package registry. And it is allowed to change production on its own. OWASP's entry on poisoned pipeline execution (CICD-SEC-4), in its Top 10 CI/CD Security Risks, spells out what a successful attack gives an attacker: the same abilities and level of access as the build job, including any secret available to it, and the ability to ship code and artefacts further down the pipeline in the guise of legitimate code built by the build process.

OWASP Top 10:2025, in A03 Software Supply Chain Failures, lists a CI/CD pipeline with weaker security than the systems it builds and deploys among the signs that you are likely vulnerable.

So this page treats the pipeline as a system that holds the right to deploy, and asks three questions of it. Who and what can make it run, and with whose code? What can each job reach once it runs?

What proves that an artefact came from it? NIST SP 800-204D frames the same work as two goals: actively defend the CI/CD pipeline and build processes, and ensure the integrity of upstream sources and artefacts.

Neighbouring guides take the rest. The supply chain attacks guide covers how a compromised package, build step or browser script reaches a site. The dependency security guide covers finding and updating vulnerable packages. The secrets exposure guide covers finding a leaked key and rotating it. The SAST and DAST guides cover the scanners that run inside a pipeline. The SBOM guide covers the inventory of what a build contains.

Who can make the pipeline run, and with whose code

A pipeline runs when an event says so: a push, a pull request, a schedule, a comment, a person pressing a button.

Each trigger decides two things at once: whose code runs, and with which token and secrets. OWASP's entry on poisoned pipeline execution (CICD-SEC-4) says pipelines that execute unreviewed code, such as those triggered directly off pull requests or commits to arbitrary branches, are more susceptible, because that code has not been through any review or approval.

Pull requests from forks

On GitHub, the pull_request event runs the workflow from the pull request's merge commit. 2 min read

pull_request_target: a trusted context that is easy to misuse

pull_request_target exists for automation that must respond to forks with privileges, such as labelling or commenting. 2 min read

Untrusted text inside a run script

Code is not the only thing a pull request author controls. 1 min read

Changes to the pipeline itself

Whoever can change a workflow file can change what the pipeline does with everything it holds. 1 min read

What each job can reach: the token, the secrets and the runner

Once a job runs, everything in it can reach everything the job was given.

That makes the job, not the workflow, the unit to limit.

The GITHUB_TOKEN and why its default matters

At the start of each job, GitHub creates a unique GITHUB_TOKEN: an installation access token whose permissions are limited to the repository that contains the workflow, and which expires when the job finishes or reaches its maximum lifetime. 1 min read

How secrets reach a job, and which jobs should never see them

A secret reaches a job only through the workflow: GitHub Actions can read a secret only if you explicitly include it in a workflow, and to pass one to an action you set it as an input or an environment variable. 2 min read

The runner

The runner is the machine that executes the job, and it holds everything the job was given: the checked-out code, the token, the secrets and network access. 1 min read

What a third-party action can do once it runs

An action is someone else's code running inside your job.

OWASP's CICD-SEC-8 points out how little that takes: adding a third party to a build is usually one or two lines in the pipeline file, and its code then runs with full access to whatever the pipeline stage can reach. In GitHub Actions that means the job's token through github.token, the job's files and network access, and every secret the job was given.

GitHub's secure use reference goes further for a compromised action: it would have access to all secrets configured on the repository, and may be able to use the GITHUB_TOKEN to write to the repository.

The reference you write decides which code arrives. A tag or branch is resolved at run time, and GitHub warns that tags can move: if an upstream maintainer's account is compromised and a tag is repointed, your repositories could run malicious code.

GitHub's advisory GHSA-mrrh-fwg8-r2c3 (CVE-2025-30066) describes a case: attackers retroactively modified multiple version tags of tj-actions/changed-files to reference a malicious commit. The attack ran a script that extracted secrets from the Runner Worker process memory and printed them in the workflow logs, making them publicly accessible in repositories with public logs, and the advisory gives the period as between 14 and 15 March 2025.

CISA's alert says the compromise allows disclosure of secrets including, but not limited to, valid access keys, GitHub personal access tokens, npm tokens and private RSA keys, that the compromise was potentially enabled by the compromise of another action, reviewdog/action-setup@v1, and that affected organisations should rotate all identified secrets immediately.

GitHub calls a workflow dependency lockfile the strongest protection. The file, .github/workflows/actions.lock, is generated by the gh actions-lock extension and pins every action your workflows depend on, transitive dependencies included, to a commit, records the identity of each source repository, and rejects a commit that exists only in a fork.

It does not pin calls to reusable workflows, which should be referenced by full commit SHA, and it does not control other build inputs, such as input parameters, secrets or the runner image. For repositories that cannot adopt a lockfile, GitHub advises pinning each action to a full-length commit SHA, taken from the action's own repository rather than a fork; an abbreviated SHA does not count.

A repository setting, "Require actions to be pinned to a full-length commit SHA", enforces this for every action, GitHub's own included, while reusable workflows can still be referenced by tag.

Pinning has costs GitHub states plainly. GitHub says that with a SHA you will not automatically receive updates for an action, including important bug fixes and security updates, and that Dependabot only creates alerts for vulnerable actions that use semantic versioning, not for actions pinned to SHA values.

GitHub's secure use reference also says Dependabot version updates open pull requests to update actions when a new version is released, and that Dependabot supports references written as a commit SHA. A tool can propose the new pin, but a person still has to review it.

A pin also says nothing about what the pinned code does. GitHub's guidance is to audit an action's source code regardless of your measures, for example checking that secrets are not sent to unintended hosts or inadvertently logged.

Where you can, keep third-party actions out of the jobs that hold deployment secrets or write scopes: a lint or comment action has no reason to share a job with a production credential.

What an environment approval checks, and what it does not

On GitHub, an environment is a named deployment target, such as production, with its own secrets and protection rules.

All of an environment's deployment protection rules must pass before a job that references it is sent to a runner, and its secrets reach only jobs that reference it, after the rules pass. The rules include required reviewers (up to six people or teams, any one of whom can approve), an option to prevent self-review so the person who started a deployment cannot approve it, a wait timer, limits on which branches and tags can deploy, and custom rules from GitHub Apps, which GitHub labels public preview.

Check your plan before relying on them. GitHub's documentation says that on its Free, Pro and Team plans, required reviewers and wait timers are only available for public repositories, deployment branch and tag rules reach private repositories on Pro and Team, and on Free, environments can only be configured for public repositories at all.

By default, administrators can bypass the protection rules, and each environment has to be set to disallow that.

An approval answers one question: did a named person agree that this job may run now? It does not tell the reviewer what the job will do, which commit it was built from, or whether the workflow file changed on the way.

For an approval to mean more than a click, the reviewer has to look at the run's commit, its workflow file and the artefact it will deploy. OWASP's CICD-SEC-1 recommends, where applicable, preventing accounts from triggering production build and deployment pipelines without additional approval or review; required reviewers with self-review prevented is one way to do that for a deploy job on GitHub.

Two details catch teams out. A deploy job that names an environment which does not exist does not fail: GitHub creates a new environment with that name and no protection rules or secrets, and anyone who can edit workflows can do this, while only repository admins can configure it.

And branch rules are matched against the run's GITHUB_REF: adding refs/pull/*/merge as a deployment branch rule lets pull_request events deploy too, and "protected branches only" lets every branch deploy if no branch in the repository has protection rules.

Deployment identity: short-lived tokens instead of stored keys

The deploy job has to prove to the cloud provider, registry or host that it may deploy.

The traditional answer is a key stored as a secret, which GitHub's documentation describes as a credential presented to the cloud provider every time the workflow runs, created in the provider and duplicated in GitHub. With OpenID Connect (OIDC), the job instead requests a token from GitHub's OIDC provider and exchanges it for a short-lived cloud access token, which GitHub says is only valid for a single job and then expires. There is no long-lived cloud credential stored in GitHub to be printed, copied or stolen.

OWASP's CICD-SEC-6 recommends the same direction for every pipeline: prefer temporary credentials over static ones, rotate the static ones you have to keep, and avoid sharing one credential across contexts. npm's trusted publishing applies it to packages, publishing from a CI/CD workflow through OIDC with short-lived tokens specific to that workflow, in place of long-lived npm tokens.

A short-lived token is only as narrow as the trust condition behind it. The cloud provider checks the token's subject and other claims against conditions you configure on the role, and GitHub says you must define at least one condition so that untrusted repositories cannot request access tokens for your cloud resources.

The subject is the useful claim. When the job references an environment, the subject includes the environment name, as in GitHub's example repo:octo-org/octo-repo:environment:Production, and a pull request event appears in the subject only when the job references no environment. A condition that names your repository and the production environment therefore matches only jobs that reference that environment, which are jobs whose protection rules have already passed.

GitHub notes that repositories created after 15 July 2026 use an immutable default subject format that includes the owner ID and repository ID, that repositories created before that date keep the previous format unless you opt in, and that repository renames and transfers after that date also move to the immutable format.

The rollout does not include GitHub's self-hosted server edition. Check which format your repository produces before writing the condition.

The permission that unlocks all this is id-token: write. GitHub's reference says it only enables fetching the OIDC token and does not grant write access to other resources. It is still the way into the deployment role, so grant it in the deploy job, and in any other job that uses it, such as one that signs an attestation, and nowhere else.

For reusable workflows owned outside your organisation, and outside any business account above it, GitHub says to set id-token: write explicitly at the caller, so the token is only available to intended callers.

What a signed or attested artefact lets a deployer check

Between the build and the deployment, the artefact sits somewhere: an artifact store, a container registry, a release page.

OWASP's CICD-SEC-9 describes the risk at that hand-over, an attacker with access to one system in the pipeline pushing malicious but seemingly benign code or artefacts down it, and recommends signing a resource when it is generated and validating it against the signing authority before the next step consumes it.

NIST SP 800-204D gives the deploy-side rule, written for container images: where a secure build environment and process exist, it should be possible to require that the image being deployed was generated by that process before it is cleared for deployment. OWASP Top 10:2025's A03 entry asks for artefacts whose integrity is ensured through provenance, signing and time stamping, promoted between environments rather than rebuilt for each, and its A08 entry gives as an example a CI/CD pipeline that pulls code or artefacts from untrusted places and/or does not verify them before use.

GitHub's artifact attestations are one implementation. The attest action creates cryptographically signed claims about a build, including a link to the workflow, and the repository, organisation, environment, commit SHA and triggering event. GitHub signs them with Sigstore; public repositories use the Sigstore Public Good Instance and a publicly readable transparency log, while private repositories use GitHub's own instance, which has no transparency log.

A deployer runs gh attestation verify on the artefact with the expected repository, and can then check that what it is about to deploy was built by that repository's workflow, at a commit it recognises, and has not changed since.

Sigstore describes what verification establishes: the artefact comes from its expected source and has not been tampered with after its creation.

Be exact about what that does not prove. GitHub says attestations by themselves provide SLSA v1.0 Build Level 2, and that building in a reusable workflow isolated from the calling workflow can meet Build Level 3. In the current SLSA specification, version 1.2, Build L2 means a hosted build platform generates and signs the provenance, and the first benefit it lists is preventing tampering after the build.

Build L3 adds a hardened platform that stops runs influencing one another and keeps the provenance signing material away from user-defined build steps, preventing tampering during the build.

Neither level says the source was free of flaws or malice. GitHub says attestations link you to the source and build instructions, that the policy you check them against is yours to define, and that generating them gives no security benefit until someone verifies them. Sigstore adds that misbehaviour by its certificate authority or log might go undetected if no third parties monitor the logs, and that monitoring the log for certificates issued to your identities is up to you. The supply chain attacks guide covers the same limits for npm provenance.

The frameworks that describe pipeline risk

Several public documents cover this ground.

Each is worth reading beside this page, and none is a certificate for a pipeline:

  • OWASP Top 10 CI/CD Security Risks, an OWASP lab project: CICD-SEC-1 Insufficient Flow Control Mechanisms, CICD-SEC-2 Inadequate Identity and Access Management, CICD-SEC-3 Dependency Chain Abuse, CICD-SEC-4 Poisoned Pipeline Execution (PPE), CICD-SEC-5 Insufficient PBAC (Pipeline-Based Access Controls), CICD-SEC-6 Insufficient Credential Hygiene, CICD-SEC-7 Insecure System Configuration, CICD-SEC-8 Ungoverned Usage of 3rd Party Services, CICD-SEC-9 Improper Artifact Integrity Validation and CICD-SEC-10 Insufficient Logging and Visibility.
  • NIST SP 800-204D, Strategies for the Integration of Software Supply Chain Security in DevSecOps CI/CD Pipelines, published in February 2024, with numbered requirements such as PULL-PUSH-REQ-3 for outside contributors' pull requests and DEPLOY-REQ-3 for deploying only container images the established build process produced.
  • CISA and the NSA's joint guidance on defending CI/CD environments, a Cybersecurity Information Sheet released on 28 June 2023 with recommendations and best practices for strengthening CI/CD pipelines, and a list of common risks and attack surfaces in them.
  • The SLSA specification, version 1.2, whose Build track runs from L0, which represents the lack of SLSA, through L1, provenance exists, and L2, a hosted build platform that generates and signs provenance, to L3, a hardened build platform.
  • OWASP Top 10:2025 A03 Software Supply Chain Failures, which lists a pipeline weaker than the systems it deploys among the signs you are likely vulnerable, and A08 Software or Data Integrity Failures, which gives as an example a CI/CD pipeline that pulls code or artefacts from untrusted places and/or does not verify them before use.
  • OWASP ASVS 5.0, chapter V13 Configuration, whose requirements 13.3.1 and 13.3.2 cover keeping secrets out of source code and build artefacts and least-privilege access to them.

GitLab CI/CD: the same questions, different mechanisms

The questions are the same on every platform; the mechanisms are not, and parity should not be assumed.

GitLab's documentation answers them like this:

  • Forks. A merge request from a fork triggers a pipeline that runs in the fork project, with the fork's CI/CD configuration, resources and variables. A member of the parent project can run it in the parent project instead, where it uses the fork's configuration with the parent project's variables and resources and the permissions of the member who triggers it. GitLab warns that such a merge request can contain code that tries to steal the parent project's secrets, and its CI/CD variables documentation says reviewers should never trigger a pipeline when they find malicious code, because it can compromise both masked and protected variables.
  • Secrets. A protected variable is available only to pipelines on protected branches or protected tags, though merge request pipelines can optionally be given access. GitLab says masking a variable cannot be relied on to stop malicious users reading its value.
  • The job token. GitLab generates CI_JOB_TOKEN for each job, valid only while the job runs, with the same access level as the user who triggered the pipeline but fewer resources than a personal access token. By default, each project's job token allowlist includes only the project itself.
  • Identity. ID tokens are JSON web tokens generated by GitLab CI/CD for OIDC with third-party services, such as secrets providers and cloud services, declared per job with the id_tokens keyword, where each token can set its own audience.
  • Approvals. Protected environments and deployment approvals are on GitLab's Premium and Ultimate tiers, and deployments to a protected environment that requires approval are blocked until all required approvals are given. GitLab administrators can use all environments, protected ones included.

Questions to ask of any other CI service

For a CI service not covered here, ask its own documentation five questions before trusting it with a deployment.

What runs for an outside contribution, and with which credentials? How is a job's token scoped, and can each job be given less than the default? How are third-party steps referenced, and can they be pinned to something that cannot move?

How is a deployment gated, and who can bypass the gate? Can a job use a short-lived identity instead of a stored key? This page does not describe services whose documentation it has not checked.

Checking your own workflow files

The asset on this page has four parts.

The trust map lists who and what in a pipeline is trusted to do what, what each can reach, and the control that limits it. The threat test pack turns six of those controls into tests you run in your own repository, with a test secret that unlocks nothing.

The sample permission set is a complete workflow with permissions declared at workflow and job level. The local lab is a small checker, importing only node:fs, node:test and node:assert, that reads a careless and a careful workflow file and reports seven rules.

The checker is an illustration. It reads lines in the simple shape the two sample files use; it is not a YAML parser, it does not read lockfiles or repository settings, and a file that passes it can still be unsafe in ways it does not look at.

GitHub's secure use reference points to code scanning with CodeQL, which can detect potentially vulnerable workflows, and to OpenSSF Scorecards, whose checks include script injection, token permissions and pinned actions.

On careless.yml all seven rules failed and the check exited with code 1. On careful.yml six passed, and the pull_request_target rule did not apply because the file never uses that trigger. The regression test, which uses node:test, failed all seven of its tests on careless.yml and passed all seven on careful.yml.

The Node.js documentation says that if any tests fail, the process exit code is set to 1. A pipeline step that treats a non-zero exit code as a failure stops on it.

Where a security review fits

Clever Ops tests what customers reach through a browser or an API, so a pipeline comes into its work through the code.

A secure code review, with read-only access to the repository, reads what runs on its own at install, build or deploy time, such as package scripts and CI workflow files, in the branch or commit in scope. Repository settings, environment rules and cloud trust policies are not in those files, which is why the test pack is written for your own team to run.

If Clever Ops built or hosts the application, the work is a security review rather than an independent test, and the report says who built it and who hosts it.

If you think your pipeline has already been used against you, for example a secret appeared in a public log or a deployment ran that nobody started, call your host and an incident response specialist first. Clever Ops does not provide incident response or monitoring, so it is not the right first call.

Frequently asked questions

Protecting the pipeline that builds and deploys your software as a system in its own right, because it holds credentials and the right to change production. In practice that means controlling who and what can make it run and with whose code, limiting what each job can reach, and being able to show that what you deploy came from it. NIST SP 800-204D names actively defending the CI/CD pipeline and build processes as one of its two security goals.

On the pull_request event, GitHub passes no secrets other than the GITHUB_TOKEN to a run triggered from a fork, and that token is read-only, unless a private repository's settings send write tokens or secrets to fork pull requests. On pull_request_target, the job holds the base repository's secrets and a read/write token, and runs regardless of approval settings, so it must never run code from the pull request. On a self-hosted runner, an approved fork pull request also runs on that machine.

As few as each job needs, declared in the workflow file. Set permissions: {} at the top, then give each job only the scopes it uses, such as contents: read to check out code. GitHub says a new repository in a personal account defaults to read access for contents and packages, while an organisation repository inherits the organisation's setting, which may be the permissive one, so a workflow without a permissions key depends on a setting outside the file.

It stops a moved tag from changing the code you run; GitHub's advisory GHSA-mrrh-fwg8-r2c3 describes attackers modifying tj-actions/changed-files version tags to point at a malicious commit. It is not enough on its own. GitHub calls a workflow dependency lockfile the strongest protection available; it records the exact commit for every action your workflows depend on, transitive dependencies included. GitHub also advises auditing an action's source code regardless of your measures, and says a SHA-pinned action does not receive updates automatically. GitHub says Dependabot version updates can open pull requests that update a SHA-pinned action, but a person still has to review each one.

It stops the deploy job, and keeps the environment's secrets from it, until a required reviewer approves. Whether that catches anything depends on what the reviewer looks at: the commit, the workflow file and the artefact. Turn on prevent self-review, switch off administrator bypass, limit which branches can deploy, and check that every environment named in a workflow exists, because a name that does not exist creates an environment with no rules.

GitHub says OIDC removes the need to duplicate cloud credentials as long-lived GitHub secrets: each job exchanges an OIDC token for a short-lived cloud access token that is valid for that job only. Its value depends on the cloud role's trust condition, which should name your repository and the production environment, and on granting id-token: write only to the jobs that use it. OWASP's CICD-SEC-6 likewise recommends temporary credentials over static ones.

It means you can check where and how the artefact was built: which repository and workflow produced it and at which commit. Sigstore, which GitHub uses to sign attestations, says verification also shows the artefact has not been tampered with since its creation. GitHub says attestations provide SLSA v1.0 Build Level 2 on their own, that generating them gives no benefit until someone verifies them, and that the policy you verify against is yours to define. They say nothing about whether the source code was free of flaws.

Scope the right test for your application

Tell us what you have built, who uses it and when it needs to launch. You will get a plain-English recommendation: a website audit, a web application test or a referral to a specialist.