Zero Trust Pipeline Design

Production-grade guide to zero trust pipeline design covering architecture patterns, implementation strategies, testing approaches, and operational best practices for enterprise engineering teams.

A zero trust pipeline enforces identity, policy, and continuous verification at every stage of software delivery. It begins at code commit and ends at runtime, validating that every component — from developer laptop to containerized microservice — is trusted before it is allowed to act. This design matters when you deploy to multiple environments with varying trust levels, when services must communicate across boundaries without relying on network perimeter security, and when you must detect and respond to breaches in real time across a dynamic infrastructure.

Identity and Trust At Every Stage

The foundation of a zero trust pipeline is a consistent, machine-verifiable identity for every artifact and actor. Every service, build, deployment, and configuration must carry a signed identity claim, verified at runtime and during CI/CD.

Developer Commit: Provenance and Attestation

When a developer commits code, the pipeline must capture the provenance of the change and create a verifiable identity for the resulting artifact.

{
  "subject": {
    "id": "git:github.com/organization/project.git@abc123def456",
    "name": "main",
    "version": "abc123def4567890123456789012345678901234"
  },
  "builder": {
    "id": "https://github.com/organization/[email protected]",
    "name": "ci-toolkit"
  },
  "run": {
    "id": "https://github.com/organization/project/actions/runs/123456",
    "startedAt": "2023-10-04T12:00:00Z",
    "finishedAt": "2023-10-04T12:15:30Z"
  },
  "materials": [
    {
      "uri": "https://github.com/organization/project",
      "digest": {
        "sha256": "a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4"
      }
    }
  ],
  "metadata": {
    "version": "1.0.0",
    "environment": "dev"
  }
}

This provenance is signed using a *cosign* signature format (based on the cosign CLI from the sigstore project):

cosign sign \
  --key "cosign.key" \
  --certificate "cosign.crt" \
  --subject "git:github.com/organization/project.git@abc123def456" \
  --claim-file provenance.json \
  "ghcr.io/organization/project:abc123def456"

The signature is stored as a cosign artifact in the container registry, alongside the image.

Build Pipeline: Policy-Driven Verification

Each step in the build pipeline validates that the input artifact meets defined policies.

# .github/workflows/build.yml
name: Build
on:
  push:
    branches: [ main ]

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Build Docker Image
        run: |
          docker build -t ghcr.io/organization/project:latest .
          docker push ghcr.io/organization/project:latest
      - name: Verify Image Provenance
        run: |
          cosign verify \
            --certificate-oidc-issuer "https://oauth2.googleapis.com/token" \
            --certificate-oidc-audience "https://github.com/organization/project" \
            ghcr.io/organization/project:latest
      - name: Check Dependencies
        run: |
          dependency-scanner --input docker://ghcr.io/organization/project:latest --output report.json
          jq -e '.dependencies[].vulnerabilities | length > 0' report.json || exit 1

The dependency-scanner tool (a real CLI from the grype project) scans the image and emits a JSON report.

{
  "dependencies": [
    {
      "name": "node",
      "version": "18.12.0",
      "vulnerabilities": [
        {
          "id": "CVE-2023-1234",
          "severity": "high",
          "description": "Insecure deserialization in Node.js core"
        }
      ]
    }
  ]
}

If any dependency has a vulnerability, the pipeline fails with a clear error:

Error: Dependency vulnerabilities found in image
  - [email protected]: CVE-2023-1234 (high): Insecure deserialization in Node.js core
  - [email protected]: CVE-2023-5678 (medium): XSS in middleware chain

Deployment Pipeline: Trust Boundaries and Runtime Validation

Deployment is not a single step, but a sequence of trust validations across environments.

Pre-Deployment: Identity and Policy Checks

Before a new version is deployed, the pipeline checks that the image has:

The pipeline uses regctl (a CLI for container registry interactions) to fetch image metadata and validate the state.

# Fetch image manifest and signature
regctl image inspect ghcr.io/organization/project:latest \
  --format '{{json .}}' > image.json

# Extract signature from image
regctl image annotation get \
  --name "ghcr.io/organization/project:latest" \
  --key "cosign.sig" \
  --output signature.sig

# Verify signature against public key
cosign verify \
  --key "public-key.pem" \
  --signature-file signature.sig \
  --image "ghcr.io/organization/project:latest"

The pipeline also checks that the image has been built with a specific set of labels.

# Expected labels
labels:
  io.buildpacks.project.toml: "true"
  org.opencontainers.image.created: "2023-10-04T12:00:00Z"
  org.opencontainers.image.title: "Project Service"
  org.opencontainers.image.version: "1.0.0"

If any label is missing or has incorrect value, the pipeline fails with a list of mismatches:

Failed: Image labels do not match expected
  - Expected org.opencontainers.image.version: 1.0.0, got 1.0.1
  - Missing label: io.buildpacks.project.toml
  - Incorrect value: org.opencontainers.image.created: expected 2023-10-04T12:00:00Z, found 2023-10-04T12:05:00Z

Deployment to Staging: Conditional Trust

The staging environment requires an additional layer of trust: the service must be able to prove its identity and configuration at runtime.

# kubernetes/staging/deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: project-service
  labels:
    app: project
    environment: staging
spec:
  replicas: 3
  selector:
    matchLabels:
      app: project
  template:
    metadata:
      labels:
        app: project
    spec:
      serviceAccountName: project-service
      containers:
        - name: app
          image: ghcr.io/organization/project:latest
          env:
            - name: OIDC_ISSUER
              value: https://auth.example.com/oidc
            - name: OIDC_AUDIENCE
              value: https://project.example.com
          livenessProbe:
            httpGet:
              path: /health
              port: 8080
            initialDelaySeconds: 10
            periodSeconds: 30

The service’s startup logic includes a trust check:

func main() {
  issuer := os.Getenv("OIDC_ISSUER")
  audience := os.Getenv("OIDC_AUDIENCE")

  // Fetch OIDC discovery document
  resp, err := http.Get(issuer + "/.well-known/openid-configuration")
  if err != nil {
    log.Fatal("Failed to fetch OIDC config:", err)
  }

  var disco map[string]string
  if err := json.NewDecoder(resp.Body).Decode(&disco); err != nil {
    log.Fatal("Failed to parse OIDC config:", err)
  }

  // Fetch token from file or env
  token, err := jwt.Parse(os.Getenv("JWT_TOKEN"), jwt.Keyfunc(func(token *jwt.Token) (interface{}, error) {
    if _, ok := token.Method.(*jwt.SigningMethodRSA); !ok {
      return nil, fmt.Errorf("unexpected signing method: %v", token.Header["alg"])
    }
    return fetchPublicKey(disco["jwks_uri"]), nil
  }))

  if err != nil {
    log.Fatal("JWT validation failed:", err)
  }

  if !token.Claims.(jwt.MapClaims)["aud"].(string) == audience {
    log.Fatal("JWT audience mismatch")
  }

  if time.Now().After(token.Claims.(jwt.MapClaims)["exp"].(float64)) {
    log.Fatal("JWT token expired")
  }

  log.Println("Service identity verified successfully")
}

If any check fails, the deployment rolls back immediately. The error message includes the full JWT payload.

{
  "iss": "https://auth.example.com/oidc",
  "sub": "project-service@staging",
  "aud": "https://project.example.com",
  "exp": 1696545600,
  "iat": 1696542000,
  "nbf": 1696542000,
  "scope": "project:read project:write"
}

Runtime: Continuous Trust and Policy Enforcement

Once deployed, the service must continuously prove its trustworthiness.

Health Checks with Trust Proofs

The /health endpoint returns a trust report, which includes:

{
  "status": "healthy",
  "version": "1.0.0",
  "identity": {
    "serviceAccount": "project-service",
    "namespace": "staging",
    "pod": "project-service-7c9d5b8f4c",
    "jwt": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJodHRwczovL2F1dGguZXhhbXBsZS5jb20vb2lkYyIsInN1YiI6InByb2plY3Qtc2VydmljZUBzdGF0aW5nIiwiYXVkIjoiand0LXByb2plY3Quc3lzdGVtLmNvbSIsImV4cCI6MTY5NjU0NTYwMCwiaWF0IjoxNjk2NTQyMDAwLCJuYmYiOjE2OTY1NDIwMDAsInNjb3BlIjoicHJvamVjdFwvcmVhZCBwcm9qZWN0XC93cml0ZSJ9.xxxxxx"
  },
  "dependencies": [
    {
      "name": "node",
      "version": "18.12.0",
      "vulnerabilities": [
        {
          "id": "CVE-2023-1234",
          "severity": "high",
          "description": "Insecure deserialization in Node.js core"
        }
      ]
    }
  ],
  "lastVerified": "2023-10-04T12:30:00Z"
}

The /trust endpoint returns a full trust report.

GET /trust HTTP/1.1
Host: project.example.com
Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJodHRwczovL2F1dGguZXhhbXBsZS5jb20vb2lkYyIsInN1YiI6InByb2plY3Qtc2VydmljZUBzdGF0aW5nIiwiYXVkIjoiand0LXByb2plY3Quc3lzdGVtLmNvbSIsImV4cCI6MTY5NjU0NTYwMCwiaWF0IjoxNjk2NTQyMDAwLCJuYmYiOjE2OTY1NDIwMDAsInNjb3BlIjoicHJvamVjdFwvcmVhZCBwcm9qZWN0XC93cml0ZSJ9.xxxxxx

HTTP/1.1 200 OK
Content-Type: application/json

{
  "status": "trusted",
  "verifiedAt": "2023-10-04T12:30:00Z",
  "provenance": {
    "subject": "git:github.com/organization/project.git@abc123def456",
    "builder": "https://github.com/organization/[email protected]",
    "runId": "https://github.com/organization/project/actions/runs/123456"
  },
  "image": {
    "digest": "sha256:a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4",
    "signature": {
      "algorithm": "cosign",
      "signer": "[email protected]",
      "created": "2023-10-04T12:15:30Z"
    }
  },
  "policies": [
    {
      "name": "minimum-security-score",
      "passed": true,
      "score": 87,
      "threshold": 80
    },
    {
      "name": "required-labels",
      "passed": true,
      "missing": []
    }
  ]
}

Policy Enforcement at Runtime

The pipeline uses opa (Open Policy Agent) to enforce policies at runtime.

A policy defines conditions under which a service is trusted.

package trust

# Enforce that service has at least one vulnerability in critical dependencies
default trust = false

trust {
  input.dependencies[_].severity == "critical"
}

# Enforce that service has been built with a specific builder
trusted_builder {
  input.provenance.builder == "https://github.com/organization/[email protected]"
}

# Enforce that service runs on a specific environment
in_staging {
  input.identity.namespace == "staging"
}

# Enforce that service has been updated in the last 24 hours
recent_deployment {
  now := time.now()
  input.lastVerified > now - 86400
}

The OPA engine evaluates this policy against the trust report and returns a decision.

{
  "result": true,
  "explanation": [
    "Service has critical vulnerabilities in dependencies",
    "Service was built with the required builder",
    "Service is running in staging",
    "Service was updated within the last 24 hours"
  ],
  "metrics": {
    "evaluationTimeMs": 12,
    "policyVersion": "v1.0"
  }
}

If any policy fails, the service is marked as “untrusted,” and a notification is sent to the observability stack.

Common Pitfalls and Sharp Edges

These details, when overlooked, cause subtle but critical failures in production: a service may be deployed, but trusted only in theory.

This page was rewritten on 12 October 2026. It replaced a templated version that was not specific to its own title. How these pages are written and checked. If anything here is wrong, tell us at [email protected] and we will correct it.