In the last eighteen months, I've led two separate incident reviews that both traced back to the same root cause: a compromised CI/CD pipeline. One was a leaked long-lived AWS key that had been sitting in a GitHub Actions secret for two years, the other was a typosquatted npm package that made it into a build because we weren't generating or verifying any provenance. Neither team thought of themselves as insecure. They had scanning, they had code review, they had branch protection. What they didn't have was a supply chain that could answer a simple question: can you prove where this artifact came from, who built it, and what went into it? This article is the hardening guide I wish we had before those incidents. It covers how I now lock down pipeline execution, implement SLSA conformance, and use Sigstore to make our software supply chain verifiable rather than hopeful.
Locking Down Execution: Ephemeral Runners, OIDC and Least-Privilege Tokens
The most dangerous place in your infrastructure is often the CI runner. It has access to source code, secrets, cloud credentials, and the ability to push artifacts. In my experience, the default configuration for most CI systems is far too permissive. A classic GitHub Actions workflow runs with a GITHUB_TOKEN that can write to contents and packages by default, uses persistent self-hosted runners that accumulate state, and authenticates to AWS with a static access key stored as an encrypted secret. Each of those choices expands the blast radius of a single vulnerability.
I now treat all runners as ephemeral and untrusted. For GitHub, that means using ephemeral ARC (Actions Runner Controller) pods on Kubernetes or GitHub-hosted runners with a clean VM per job. For GitLab, it means using the Kubernetes executor or Docker autoscaler with --rm and no privileged mode unless absolutely necessary. The goal is to ensure no secrets, file system artifacts, or compromised binaries persist between jobs. If you are still using a long-lived VM with a runner daemon, you are carrying over risk from every previous execution.
Eliminating Static Secrets with OIDC Federation
The single highest-leverage change you can make is replacing long-lived cloud credentials with OpenID Connect federation. Instead of storing an AWS access key, you let your CI provider mint a short-lived JWT and let AWS IAM trust that issuer. The credential lives for 5-15 minutes and cannot be exfiltrated and reused later.
I've found that teams adopting OIDC for the first time struggle with the IAM trust policy. You need to be precise about the subject claim. Don't trust repo:* — trust a specific repository, environment, or branch pattern. Here is a hardened GitHub Actions workflow pattern I use as a baseline. Note the pinned actions by SHA, the minimal permissions block, and the use of OIDC instead of secrets:
name: hardened-build-and-push
on:
push:
branches: [main]
permissions:
contents: read
id-token: write # required for OIDC
packages: write
attestations: write
jobs:
build:
runs-on: ubuntu-latest
environment: production
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
persist-credentials: false
- name: Configure AWS credentials via OIDC
uses: aws-actions/configure-aws-credentials@e3dd6a429d7300a6a4c196c26e071d42e0343502 # v4
with:
role-to-assume: arn:aws:iam::123456789012:role/github-actions-deployer
aws-region: us-east-1
- name: Build image with hermetic flag
run: |
docker build --no-cache --pull -t ghcr.io/org/app:${{ github.sha }} .
- uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.1.0
with:
push: true
tags: ghcr.io/org/app:${{ github.sha }}
sbom: true
provenance: mode=max
This approach extends beyond AWS. The same OIDC pattern works for GCP Workload Identity Federation, Azure Federated Credentials, and Vault. The principle is consistent: no human ever sees the credential, and the token is bound to the specific workflow run. If you are using reusable workflows, I strongly recommend reading the patterns in GitHub Actions Advanced Workflows: Matrix Builds, Reusable Actions and OIDC — particularly the section on passing OIDC permissions through workflow_call, which is easy to misconfigure. For teams on GitLab, the equivalent is id_tokens with JWT, which pairs well with the optimization techniques described in GitLab CI Pipeline Optimization: DAG, Cache and Parallel Jobs.
Runner Hardening Checklist
Beyond OIDC, I enforce three non-negotiables on every runner fleet: disable privileged containers, mount the workspace as noexec where possible, and egress-filter the runner network. A compromised build step that tries to curl an exfiltration endpoint should hit a network policy. According to the Kubernetes Documentation, you can achieve this with a Kubernetes NetworkPolicy that only allows egress to your registry, package manager, and OIDC provider. It adds friction, but the first time it blocks a malicious dependency trying to phone home, it pays for itself.
Poisoned Pipelines: Preventing Secret Exfiltration and Script Injection
Most pipeline attacks I see are not sophisticated zero-days. They are script injection via untrusted input. Any time you do echo "${{ github.event.pull_request.title }}" or use an unpinned third-party action, you are executing code controlled by an external contributor. The classic pull_request_target abuse is well-documented, but I still audit it in almost every client environment.
There are two attack surfaces to separate: direct secret exfiltration and indirect persistence. Direct exfiltration attempts to print secrets to logs, send them to an external server, or embed them in an artifact. Indirect persistence tries to modify a downstream artifact — for example, patching a Dockerfile, altering a Helm chart value, or injecting a post-install script into a tarball that later gets deployed to production.
Concrete Controls I Enforce in Pull Request Pipelines
First, never inject untrusted context into a run: block. Use environment variables with intermediate assignment, or better, use actions that treat inputs as data rather than code. Second, split your pipeline into two jobs: an unprivileged job that builds and tests the PR with pull_request (no write permissions, no secrets), and a privileged job that only runs after manual approval or on push to main with attestation. Third, pin every third-party action to a full commit SHA. Tags can be moved; SHAs cannot.
For secrets management, I use two complementary tools: push protection and runtime masking with restricted environments. GitHub's secret push protection and GitLab's secret detection are helpful, but they are not enforcement. I also run gitleaks and trufflehog as a pre-merge check, but I treat them as a safety net. The real control is to ensure PR builds simply do not have access to production secrets at all. Use OpenID Connect with an environment: staging for mainline builds and no environment for PR builds. If a PR job is compromised, there is nothing valuable to steal.
I also recommend disabling the automatic persistence of credentials after checkout (persist-credentials: false). I have seen malware that modifies the git remote URL during a build and then pushes a backdoored commit using the automatically persisted token. It is a subtle and effective persistence technique that takes one line to prevent.
Generating SLSA Level 3 Provenance with Sigstore Cosign and Fulcio
SLSA (Supply-chain Levels for Software Artifacts, now v1.1) gave our team a common language to describe maturity. Most organizations I assess are at SLSA Level 1 or 2: they have a scripted build, but provenance is either absent or self-signed by the builder with no isolation. The jump to Level 3 is where supply chain security becomes real: the build is hardened against tampering, runs on a trusted builder, and produces non-falsifiable provenance that the consumer can verify.
In practice, Level 3 means three things: 1) An ephemeral, isolated builder that cannot be influenced by prior runs, 2) Provenance that is signed with a key that is not accessible to the build job itself, and 3) All build steps, materials, and parameters are declared in the attestation.
Implementing Keyless Signing with Sigstore
I have shifted all new projects to keyless signing with Sigstore, specifically Cosign, Fulcio, and Rekor. The reason is operational: managing long-lived GPG or Cosign private keys is painful, rotation is often skipped, and keys inevitably end up in 1Password or a CI secret. With keyless, the CI runner authenticates via OIDC to Fulcio, which issues a short-lived certificate bound to the workload identity (e.g., https://github.com/org/repo/.github/workflows/release.yml@refs/heads/main). Cosign uses that certificate to sign, and the signature is logged in Rekor, the transparency log. There is no private key to manage.
Here is the pattern I use for container signing and SLSA provenance generation directly in GitHub Actions. This uses the official SLSA generator and Cosign together:
name: slsa-provenance-and-sign
permissions:
contents: read
id-token: write
packages: write
jobs:
build-and-attest:
runs-on: ubuntu-latest
outputs:
image: ${{ steps.build.outputs.image }}
digest: ${{ steps.build.outputs.digest }}
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
with:
persist-credentials: false
- name: Build and push
id: build
uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09
with:
push: true
tags: ghcr.io/org/app:${{ github.sha }}
provenance: false # we generate SLSA provenance separately
- name: Install Cosign
uses: sigstore/cosign-installer@11086d25041ad190534b0bc334a74f26b9c30be2
- name: Sign image keylessly
run: |
cosign sign --yes ghcr.io/org/app@${{ steps.build.outputs.digest }}
- name: Generate SLSA provenance
uses: slsa-framework/slsa-github-generator/.github/workflows/generator_container_slsa3.yml@v2.0.0
with:
image: ghcr.io/org/app
digest: ${{ steps.build.outputs.digest }}
registry-username: ${{ github.actor }}
secrets:
registry-password: ${{ secrets.GITHUB_TOKEN }}
What you get from this is two verifiable artifacts: a Cosign signature that can be verified with cosign verify against your OIDC issuer, and an in-toto SLSA provenance attestation that lists every material (base image digest, commit SHA, build config) and is signed and stored in Rekor. In my experience, the most common mistake here is generating provenance but never verifying it. An attestation that no one validates is just expensive metadata.
Store the SBOM alongside this. I generate a CycloneDX or SPDX SBOM with Syft or Trivy during the build and attach it as an attestation with cosign attest --predicate-type https://cyclonedx.org/bom. That way the SBOM is bound to the image digest and cannot be swapped without breaking the signature.
Verifying Artifacts Before Deploy: Admission Controllers and Policy as Code
Generating attestations is only half the job. You need a gate that refuses to deploy anything that is not signed and attested. I have implemented this in Kubernetes using admission controllers, and in VMs/serverless with a deployment wrapper script. The Kubernetes path is more mature.
The architecture I recommend is: the CI system signs and attests, the registry stores the signatures (Cosign stores them as OCI artifacts alongside the image), and the cluster verifies at admission time. If verification fails, the pod never schedules. This closes the loop and makes the pipeline's security guarantees enforceable at runtime.
Example Policy with Kyverno and Sigstore
You have two main options in Kubernetes: Sigstore Policy Controller and Kyverno/OPA Gatekeeper. I prefer Kyverno for its simplicity if you already use it for other policies, but Sigstore's policy-controller is purpose-built and integrates directly with Rekor. Here is a Kyverno ClusterPolicy that requires Cosign keyless verification for all images from ghcr.io/org/:
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
name: require-image-signature
spec:
validationFailureAction: Enforce
background: false
rules:
- name: verify-cosign-signature
match:
resources:
kinds: ["Pod"]
verifyImages:
- imageRefs:
- "ghcr.io/org/*"
attestors:
- entries:
- keys:
rekor:
url: https://rekor.sigstore.dev
certificates:
certificate: |
-----BEGIN CERTIFICATE-----
# Fulcio root CA - fetch from https://fulcio.sigstore.dev/api/v1/rootCert
-----END CERTIFICATE-----
ctlog:
url: https://ctfe.sigstore.dev/test
issuer: https://token.actions.githubusercontent.com
subject: https://github.com/org/*
For a thorough setup, combine this with a second rule that verifies the SLSA attestation predicate type and the builder identity. This ensures not just that the image was signed by your repo, but that it was built by your trusted builder (the SLSA generator) and has the expected source commit. According to the Docker Documentation, you can also enforce content trust at the registry level, but I find admission control is a stronger last line of defense because it applies regardless of how the image got to the cluster.
Outside Kubernetes, you can use cosign verify and slsa-verifier verify-image in your deployment script or in your CD tool. ArgoCD, for example, can run a custom verification step before sync, and I have used a simple wrapper around kubectl apply that verifies first and fails closed. Whatever your platform, the principle is the same: verify cryptographically, not by tag or timestamp. If your deployment strategy involves progressive rollouts, this verification should happen before any canary receives traffic. The patterns discussed in Artifact Management: Container Registries, Helm Charts and Build Caching for storing and promoting immutable artifacts pair well here — you promote by digest, not by mutable tag.
Dependency Firewalling: SBOM Generation, Vulnerability Gating and Hermetic Builds
Your supply chain is not just your own code. In a typical Node or Python service I audit, 95% of the bytes in the final image come from dependencies and base layers. Without an SBOM and a hermetic build, you cannot answer which version of log4j or openssl is inside your production image.
I now generate an SBOM at build time and treat it as a first-class artifact. Tools like Syft, Trivy, and CDXGen can emit SPDX 2.3 or CycloneDX 1.5. The key is to generate it from the actual image that will be deployed, not from the source manifest. A source SBOM misses transitive system packages installed via apt-get or apk add in the Dockerfile. I also gate on SBOM content: if a critical CVE appears in a direct dependency, the build fails, but if it is in a transitive dev dependency not present in the runtime image, it warns without blocking. This distinction reduces alert fatigue significantly.
Building Hermetically
A hermetic build is one where all inputs are declared and fetched through a controlled channel, and network access during the build is restricted or fully disabled. Bazel and Nix are the gold standards here, but you can get 80% of the benefit in Docker by pinning every input: base image by digest (FROM alpine@sha256:...), language packages with a lockfile (package-lock.json, poetry.lock), and system packages with a versioned apt-get install package=1.2.3. I also run builds with --network=none where possible after the dependency fetch step, or at minimum enforce egress filtering on the builder.
To create a dependency firewall, I proxy all package managers through an internal registry: Artifactory, Nexus, or a cloud solution like AWS CodeArtifact. The proxy is configured to block packages that have not been scanned, quarantine new versions for 24 hours (to catch newly reported malicious packages), and prevent dependency confusion attacks by namespacing internal packages. In my experience, the quarantine period has caught two malicious updates that were published and then removed within hours — without it, we would have consumed them automatically.
From Attestation to Audit: Operationalizing Supply Chain Evidence in Production
Once you have signatures, provenance, and SBOMs, you need to make them useful day-to-day. I have seen teams generate all the right artifacts and then store them in a place no one looks. The evidence needs to be where auditors, developers, and incident responders can query it.
I store all attestations in the OCI registry alongside the artifact (Cosign's default), and I also push a copy to an immutable evidence store. A simple S3 bucket with object lock or a dedicated registry repository works. Every deployment logs the image digest and the verification result to our SIEM. During an incident, we can ask: which workloads are running an image that contains pkg:npm/lodash@4.17.20? The SBOM answers that; the signature proves the SBOM is trustworthy.
| SLSA Level | Build Requirements | Provenance Guarantees | Typical Use Case |
|---|---|---|---|
| L1 - Build Script | Scripted build, no guarantees on provenance generation | Provenance exists but may be incomplete or unsigned | Small OSS projects, ad-hoc scripts |
| L2 - Hosted Builder | Build runs on hosted service, provenance generated automatically | Provenance signed by builder, but builder can be influenced by user | Standard GitHub Actions / GitLab CI with provenance preview |
| L3 - Hardened Builder | Isolated ephemeral builder, non-falsifiable provenance, secrets inaccessible to user steps | Provenance signed by trusted builder, integrity protected, verifiable by consumer | Production services requiring verifiable supply chain |
| L4 - Hermetic & Reproducible | Hermetic, fully parameterized, reproducible build with two-party review | Provenance enables bit-for-bit reproduction and audit by third party | High-assurance systems, regulated workloads, base image providers |
For operationalizing this, I create a simple dashboard that tracks three metrics: percentage of deployed images with valid signatures, percentage with SBOMs present, and mean time to block a vulnerable dependency. These metrics are surprisingly motivating. When the security team can show engineering leadership that 12% of production pods were running unsigned images last month and 0% this month, the value is tangible.
Finally, plan for key and identity rotation. With keyless Sigstore, rotation is largely handled by Fulcio's short-lived certificates, but you still need to rotate the root trust anchor in your admission controller and handle issuer migration (e.g., moving from one GitHub Enterprise to another). I rehearse this quarterly. If you cannot rotate your trust root without downtime, you are not ready for a supply chain incident.
Frequently Asked Questions
Do I need SLSA Level 4 or is Level 3 sufficient for most organizations?
For almost every production environment I work with, Level 3 is the right target. It gives you a hardened, ephemeral builder and non-falsifiable provenance that can be verified at deployment time, which blocks the majority of supply chain attacks including builder compromise and artifact tampering. Level 4 adds hermetic, reproducible builds and two-person review, which is extremely valuable for base images, compilers, and regulated workloads, but requires significant investment in build system design (often Bazel or Nix) and is overkill for typical application services. I advise teams to achieve consistent Level 3 coverage across all services before pursuing Level 4 for a small set of critical artifacts.
How do you handle signing for short-lived ephemeral images and pull request builds?
I do not require keyless signing for every pull request build. Instead, I sign and attest only artifacts that are eligible for deployment — typically images built from the default branch or from release tags. PR builds run with minimal permissions, generate an SBOM and scan results as build artifacts, but do not produce a trusted provenance. This keeps Rekor and the registry clean and avoids giving untrusted PR code access to the OIDC identity that can sign. If you need to deploy a PR image to a preview environment, build it again from the merged result on the main branch pipeline rather than promoting the PR's image.
What is the difference between Cosign signatures and SLSA provenance? Do I need both?
Yes, you ideally need both because they answer different questions. A Cosign signature answers who produced the artifact and that it has not been modified since signing — it is an integrity and authenticity guarantee bound to an OIDC identity. SLSA provenance answers how the artifact was built, including the source repository, commit, build parameters, and materials (base images and dependencies). In practice, I use Cosign to sign the image and a separate in-toto attestation (often generated by the SLSA generator) to carry the provenance predicate. Your admission controller should verify both: that the expected builder signed it and that the provenance matches your policy.
Will supply chain hardening slow down our pipeline significantly?
In my measurements, the overhead is modest when implemented correctly. Generating an SBOM with Syft or Trivy adds 15-40 seconds, keyless signing with Cosign adds 5-10 seconds, and generating SLSA provenance with the official generator adds roughly 30-60 seconds because it performs a separate build. Verification at admission time adds 1-3 seconds to pod scheduling, which is negligible. The larger cost is the initial migration to pinned dependencies, OIDC, and ephemeral runners. I recommend rolling it out incrementally: start with OIDC and runner hardening, then add signing and verification, then provenance. Teams that bundle all changes at once tend to stall; incremental adoption keeps delivery moving.