Start with the job that can publish a release. What starts it, whose code does it run, and where do its credentials come from? Then follow the artifact: are the bytes deployed the same ones that passed testing? That’s where we’d begin a CI/CD security review, before adding another scanner.

A useful CI/CD security toolchain covers several different problems: unsafe workflow definitions, leaked credentials, vulnerable dependencies, application flaws, insecure infrastructure, and artifact substitution. The tools produce evidence. Repository settings, runner isolation, identity policies, and release gates determine whether someone can ignore that evidence or use the pipeline to gain access.

This guide uses GitHub Actions for workflow examples, with controls that also apply to GitLab CI, Jenkins, and other build systems. Product features and licensing differ. For a smaller starting point, our DevSecOps guide for small teams covers assigning ownership and introducing checks gradually.

Draw the trust boundaries before choosing tools

For a hypothetical containerized web service, separate these stages:

StageCode and inputs it receivesAuthority it needs
Pull-request checksContributor-controlled source, manifests, and dependency instructionsRead the required source; publish a check result through the CI platform
Release buildAn approved revision and recorded dependency inputsProduce a candidate artifact in an isolated build environment
Release assessmentThe candidate artifact, scan rules, and a policy revisionRead and assess the candidate; write assessment records
PromotionA specific candidate digest and accepted assessmentSign or attest that digest and publish it to the intended registry
DeploymentThe promoted digest and environment configurationChange one intended environment within a defined scope

A separate job name does not create a boundary if the jobs share a writable workspace, reusable machine, cache, or credential. Record those shared resources. In particular, a privileged workflow must not execute a script, deserialize a risky format, or restore executable content solely because a less-trusted job uploaded it.

The release record should identify the source revision, workflow revision, runner image, dependency lockfiles, artifact digest, tool versions, scan database or rule revisions, policy decision, and approving identity. Those identifiers let an investigator match the deployed bytes to the evidence used for release.

Pick a small toolchain with distinct responsibilities

Choose from these tools according to the evidence your release process needs. You may already have adequate coverage for some functions.

FunctionTools to evaluateUseful evidenceWhat the result does not establish
Workflow security analysiszizmor for GitHub ActionsFindings about supported workflow and action-definition patternsSafety of arbitrary shell scripts or every remote dependency
Secret discoveryGitleaksMatches in the scanned files or Git historyAbsence of every credential; revocation of a discovered credential
Dependency vulnerability checksOSV-Scanner or TrivyPackage versions matched against supported advisory dataDetection of arbitrary malicious package behavior or all application flaws
Application code analysisSemgrep or a language-specific analyzerFindings under the selected rules and language coverageComplete application behavior, authorization correctness, or exploitability
Infrastructure and image checksTrivySupported misconfigurations and package findings in the selected targetThe effective configuration of a running cloud account
Software inventorySyftAn SBOM for the scanned directory or imageA clean vulnerability assessment or complete runtime inventory
Artifact origin and integrityCosign or GitHub artifact attestationsA signature or provenance statement evaluated against an expected identityThat the signed software is safe or that its builder was uncompromised

Start with the gaps that affect your release path. Two overlapping vulnerability scanners can be less useful than one maintained scanner plus a functioning approval boundary. If you retain overlapping tools, document the additional coverage and who reconciles conflicting results.

Treat a scanner as software that processes potentially hostile input. Select its distribution source, inspect relevant advisories, pin a reviewed version or digest, and update it through a controlled process. A security tool does not need a production deployment credential merely because it runs in the production pipeline.

Protect workflow changes and their execution context

Require review for workflow files, reusable workflows, local actions, build scripts, dependency manifests, and security-rule changes. Include the code that generates the pipeline. A protected YAML file can still invoke an unprotected script.

On GitHub Actions, grant the token only the permissions needed by a job. Pin third-party actions to a reviewed full commit SHA, and review updates to that SHA. Inspect the actions and scripts they call as well. A pinned wrapper can still download mutable code during execution. GitHub’s secure-use reference documents these workflow risks.

Keep contributor-controlled values out of generated shell source. This step fragment passes a pull-request title as data instead of inserting it into a shell command:

- name: Print the pull request title
  env:
    PR_TITLE: ${{ github.event.pull_request.title }}
  run: printf '%s\n' "$PR_TITLE"

Quoting protects this particular shell use. It does not make the title safe to evaluate as code, a query, a template, or a filename in another step.

Review pull_request_target and privileged workflow_run consumers carefully. Do not run untrusted pull-request code with a privileged workflow’s credentials. A maintainer clicking an approval button does not change the behavior of the code that will execute.

Make runner isolation a deployment control

Keep untrusted contributor jobs away from machines that can reach production systems. Separate runner groups by trust level, limit which repositories and workflows may use them, and restrict their reachable networks.

For self-hosted execution, prefer a fresh environment for each untrusted job. Registration as an ephemeral runner is only part of that process: destroy or rebuild the underlying compute, clean up disks and credentials, and keep operational logs outside the job’s control. GitHub’s self-hosted runner reference describes runner lifecycle and connectivity requirements.

Review these paths explicitly:

  • A Docker or container-runtime socket mounted into the job.
  • A privileged container or host filesystem mount.
  • Credentials left in Git configuration, environment variables, tool caches, or cloud SDK files.
  • Caches writable by pull requests and later consumed by release jobs.
  • A runner identity that can register workers, alter policies, or create a more privileged execution environment.

If a build does not need a credential, leave it out. If it does not need network access during execution, consider an isolated execution phase with prepared inputs. The trust boundary must be enforced outside the code being built.

Run checks in a way that preserves failure

The following Bash example assumes reviewed versions of the tools are already installed in the job image. Run it from the repository root. It is a starting gate for a repository with Git history and GitHub workflows; it does not install tools, execute application tests, or replace language-specific analysis.

set -euo pipefail

zizmor --offline .github/workflows
gitleaks git --redact --exit-code 1 .
trivy fs --scanners vuln,misconfig \
  --severity HIGH,CRITICAL --exit-code 1 .
syft dir:. -o cyclonedx-json > sbom.cdx.json

The coverage needs to be part of the result. Zizmor’s offline mode skips audits that require online access. Gitleaks can inspect only the Git history actually present in the checkout; a shallow clone can omit older exposures. A directory scan serves a different purpose when reviewing generated or uncommitted files. Trivy’s misconfiguration scanner must be enabled explicitly for fs; the severity filter above is a policy example, not a reason to discard lower-severity findings. Syft records components it discovers and does not turn that inventory into a vulnerability decision.

Trivy may need to retrieve databases or other data. This command block is not a no-egress configuration. Prepare those inputs in a separate stage if execution must be offline, record their age, and fail visibly when required data is absent or too old for your policy.

Avoid || true, permissive error flags, or wrappers that turn a scanner crash into an empty report. If you pipe output through tee, keep pipefail enabled. Give jobs a timeout and treat interruption as an incomplete assessment. Protect reports and retention settings because findings can contain paths, source fragments, or sensitive values.

Separate a finding from the release decision

A green check can hide a skipped scan or an empty report. Keep these outcomes distinct:

StateRelease behavior
Completed, no blocking findingsContinue only if the other required controls also passed
Completed, blocking findingsHold the candidate until fixed or covered by an approved exception
Incomplete assessmentHold; show which target, data source, or tool failed
Approved exceptionContinue only for its named scope and validity period
Required job missing or skippedHold unless the release policy explicitly expects that state

An exception should name the affected component or finding, owner, justification, compensating control, expiry, and required retest. Blanket ignore files tend to outlive the reason they were created. Review who can edit suppressions and whether the same change can also approve its own release.

Configure the repository’s required checks and release rules to match this policy. Inspect path filters, job conditions, and dependencies so a workflow edit cannot silently remove the gate. Test the actual merge or promotion operation, not only the status shown inside a job log.

Use short-lived identity with narrow trust conditions

OIDC federation can remove the need to store a long-lived cloud key in the repository’s secret store. The cloud provider must still restrict which token claims are accepted and what the resulting role can do. Bind that trust to the intended repository and release context, and use additional supported claims where needed. GitHub’s OIDC documentation explains the exchange.

Give the deployment identity access to one environment and keep it out of build and scan jobs. A trusted release job can still be dangerous if it runs attacker-controlled code after acquiring that identity.

Secret masking is a logging aid. Do not use it as a data-loss boundary. If a credential is exposed, revoke or rotate it and review its use; deleting a report does not invalidate the credential. Review secret availability by event and environment using the provider’s secrets documentation.

Assess the artifact you will deploy

Generate an inventory and run the relevant assessment against the final artifact, not only the source directory. An image build can add packages, download tools, or change files after source scanning.

Promote by immutable digest where the platform supports it. At the deployment boundary, check the expected artifact digest, signing identity, issuer, and provenance policy. A successful signature check against an overly broad identity rule is a weak gate. Cosign’s verification reference shows how identity and issuer constrain verification.

A clean build using the same source can still produce different bytes if its inputs change. If you rebuild after approval, treat the new digest as a new candidate that needs its own assessment. Keep release artifacts separate from untrusted pull-request artifacts and caches.

For infrastructure, pair source checks with a view of the deployed resources. Our Terraform drift and security-scanning guide explains why an empty plan and a clean configuration scan answer different questions.

Test the gates before relying on them

Use a disposable repository or test branch with synthetic fixtures. Do not introduce real credentials or vulnerable production deployments for a demonstration.

TestExpected evidence
A fake secret matching a configured test ruleSecret gate blocks; report is access-controlled and redacted as intended
A known rule violation in a fixtureThe expected rule fires on the intended file
Scanner cannot read a required database or exits unexpectedlyAssessment is incomplete and promotion is blocked
A contributor changes a workflow to skip scanningRepository or promotion policy still requires the assessment
An artifact is changed after scanningDigest or signature policy rejects the substituted candidate
A valid signature comes from an unapproved identityVerification rejects it
An untrusted job attempts to use release credentialsIdentity issuance or authorization denies the request
A job is cancelled before producing a reportNo stale report is accepted for the new run
A test exception expiresThe same finding blocks again

Keep the positive controls too: a clean candidate must reach the intended test environment, and an authorized release identity must be able to perform its limited task. Otherwise a broken pipeline can appear secure simply because nothing works.

Keep a recent release record, a failed-candidate record, the current exception list, and a demonstrated recovery path accessible to the operator. If the release credential or runner is compromised, the operator needs to know how to stop promotion, replace the runner, revoke access, and identify affected artifacts. Record the recovery owner and exercise that procedure before relying on it during an incident.

DevSecOps services from Libre Labs View all posts