The user wants a "zero-trust deployment pipeline."
This pipeline needs to sign three specific types of artifacts:
- SPA (Single Page Application) bundles.
- API containers (likely Docker images).
- ML (Machine Learning) artifacts (models, datasets).
I need to design a CI/CD architecture that enforces "zero-trust" principles. Zero-trust in a pipeline context usually means "never trust, always verify." Every step must authenticate and authorize the previous step, and artifacts must be cryptographically signed and verified before use. Identity is the new perimeter.
Key Components/Technologies:
- Identity/Signature: Sigstore (Cosign), Spiffe/Spire (for workload identity), or Cloud KMS.
- Artifact Storage: OCI registry (for containers), S3/GCS (for ML models), maybe an OCI registry for everything (S bundles and ML models can be stored in OCI registries too).
- Pipeline: GitHub Actions, GitLab CI, or Tekton (cloud-native).
- Verification: Policy controllers (Kyverno, OPA Gatekeeper).
- SBOM (Software Bill of Materials): Syft, Grype (for scanning).
Plan of Action:
- Define the Zero-Trust Architecture: Explain the philosophy (Identity, Integrity, Attestation).
- Toolchain Selection:
- Signing: Sigstore (Cosign) is the industry standard now.
- SBOM/Vuln Scanning: Syft/Grype.
- Policy: Open Policy Agent (OPA) or Kyverno.
- Storage: OCI-compliant registry (covers containers, Helm, and even generic artifacts).
- Pipeline Stages (The Workflow):
- Build: Compile code, build images.
- Generate Provenance: Create SBOMs.
- Scan: Check for vulnerabilities.
- Sign: Cryptographically sign artifacts using ephemeral keys (Sigstore/Fulcio).
- Attest: Attach metadata (this artifact passed tests).
- Verify (Enforcement): The cluster/registry rejects unsigned or untrusted artifacts.
- Specific Artifact Handling:
- SPA: Build static files -> tarball -> push to OCI registry (using ORAS or similar) -> Sign.
- API Container: Standard Docker build -> Push -> Sign.
- ML Artifact: Serialize model -> Push to registry (or S3 with digest) -> Sign.
- Implementation Example (GitHub Actions + Cosign): Concrete code snippets are essential.
- Runtime Enforcement: How does the cluster verify this? (Kyverno/Policy Controller).
Refining the Content:
- Zero Trust implies workload identity: I should mention OIDC token exchange (GitHub Actions OIDC -> AWS/GCP/Azure or Sigstore). This eliminates stored secrets.
- The "Signing" part:
- SPA: Usually deployed to CDN/Storage. How do we sign? We sign the hash of the bundle manifest. Or we package the SPA into a generic OCI artifact and sign that. Let's stick to OCI for consistency, or SRI hashes in an HTML file signed via a separate process. Decision: Let's push SPAs to an OCI registry as a package (like AWS ECR or Docker Hub supports generic artifacts) to unify the signing workflow. It's cleaner.
- ML: MLflow or DVC are common, but for signing, we need a cryptographic binding. Storing models in an OCI registry is becoming a best practice (e.g.,
kubeFlow model registry). Let's use an OCI registry for the model artifact.
Drafting the Pipeline Steps:
- Step 1: Identity. Use OIDC. No long-lived keys.
- Step 2: Build & Test.
- Step 3: SBOM & Attestations. Generate metadata about how it was built.
- Step 4: Signing. Use
cosign sign.
- Step 5: Verification. The cluster uses a ValidatingWebhook to check signatures before admission.
Structuring the Response:
- High-Level Architecture Diagram (Mental or ASCII): Identity -> Build -> Attest -> Sign -> Enforce.
- Prerequisites: The tools needed.
- The Pipeline (Code): A YAML file showing the flow.
- Deep Dive into Artifacts:
- Container: Standard Cosign.
- SPA: Treat as static assets, hash them, sign the manifest. Or wrap in Nginx container (simpler for "zero trust deployment" to k8s). Let's assume the SPA is served by a container or we sign the tarball pushed to storage. I'll treat it as a generic OCI artifact for maximum security uniformity.
- ML: Model stored as OCI artifact.
- The "Trust" aspect (Policy Enforcement): The Verify stage.
Self-Correction during drafting:
Initial thought: Just sign the docker image.
Correction: The user asked for SPA bundles and ML artifacts. These aren't always Docker images.
Solution: Use OCI Registries for everything.
- SPA -> OCI Artifact (using
oras or helm packaging).
- ML -> OCI Artifact (using
kaniko or just skopeo/oras).
- API -> OCI Image.
This allows a unified signing and verification policy using
cosign.
Detailed Workflow:
- Authentication: Pipeline gets an OIDC token from the CI provider (e.g., GitHub).
- Sigstore: Uses that token to get a short-lived certificate from Fulcio.
- Signing: Signs the artifact digest (SHA256) with the private key associated with that cert.
- Transparency Log: Rekor logs the signature (audit trail).
- Enforcement: The deployment target checks Rekor and the signature against a public key/identity policy.
Let's write the solution.
Outline:
- Concept: "Identity-based Supply Chain."
- Stack: Sigstore (Cosign/Fulcio/Rekor), OCI Registry, GitHub Actions (OIDC), Kyverno (Enforcer).
- The Unified Strategy: Store everything in an OCI registry to standardize signing.
- Pipeline Implementation: Detailed YAML.
- Enforcement: Kyverno policy example.
Let's refine the SPA part. If the SPA is deployed to S3/CloudFront, we sign the tarball before upload, or upload the signature alongside it. The CDN doesn't verify signatures; the deployer verifies the signature before pushing to CDN. I will stick to the OCI registry approach as it's the most "pipeline-native" way to handle versioning and signing, even for non-containers.
ML Specifics: ML models are big. Sometimes we don't want to move them. We sign the hash and store the signature.
Final Polish: Ensure the "Zero Trust" terminology is correct. (Verify identity, verify integrity, least privilege). Use "Keyless" signing to avoid managing secrets.
Code Snippets:
- GitHub Actions workflow.
cosign commands.
- Kyverno policy.
Let's go.
To implement a Zero-Trust deployment pipeline, we must shift from "trust the network" to "trust the artifact." This requires Identity-based Signing (removing long-lived secrets) and Verifiable Attestations (proving how something was built).
We will use Sigstore (Cosign, Fulcio, Rekor) because it allows keyless signing via OIDC (OpenID Connect), ensuring that only your authenticated CI pipeline can sign artifacts.
Architecture Overview
In this architecture, the CI/CD platform acts as the "Identity Provider." No private keys are stored on disk.
- SPA (React/Vue/Angular): Packaged as an OCI Artifact (Docker image without OS) and signed.
- API (Go/Node/Python): Packaged as a standard Docker container, signed, and accompanied by a Software Bill of Materials (SBOM).
- ML Artifacts (Models): Packaged as OCI Artifacts (using tools like
oras or mlflow) to utilize the same verification infrastructure as containers.
- Policy Enforcement: A Kubernetes Admission Controller (e.g., Kyverno) verifies signatures before resources are created.
1. The Unified Artifact Strategy (OCI-First)
To apply Zero Trust uniformly, we treat every output as an OCI Artifact. This allows us to use the same tooling (cosign, crane) for ML models and static files as we do for Docker containers.
- SPA:
ghcr.io/org/frontend-app:v1 (Contains Nginx + Static Files)
- API:
ghcr.io/org/backend-api:v1 (Standard Container)
- ML Model:
ghcr.io/org/ml-models/classifier:v1 (Raw binary/weights packaged as an artifact)
2. The Pipeline Implementation (GitHub Actions)
This pipeline uses Keyless Signing. The CI job requests an ephemeral certificate from Sigstore's Fulcio CA using the GitHub OIDC token.
Prerequisites:
- The
cosign policy controller is installed on the destination cluster.
- The
COSIGN_YES=true environment variable is set to automate signing (non-interactive).
.github/workflows/zero-trust-release.yml
name: Zero-Trust Release Pipeline
on:
push:
branches: [main]
permissions:
id-token: write # REQUIRED: Request OIDC token for keyless signing
contents: read
packages: write # Push artifacts to GHCR
jobs:
build-and-sign:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
# --- TOOLING SETUP ---
- name: Setup Tools
uses: sigstore/cosign-installer@v3
with:
cosign-release: 'v2.2.2'
- name: Login to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# --- 1. API CONTAINER ---
- name: Build & Push API Image
id: build-api
run: |
docker build -t ghcr.io/${{ github.repository }}/api:${{ github.sha }} ./api
docker push ghcr.io/${{ github.repository }}/api:${{ github.sha }}
- name: Sign API Image (Keyless)
env:
DIGEST: ${{ steps.build-api.outputs.digest }}
run: |
cosign sign --yes ghcr.io/${{ github.repository }}/api@${DIGEST}
# --- 2. SPA BUNDLE (Packaged as OCI Artifact) ---
# We treat the static site as a container image for consistent signing
- name: Build & Push SPA Bundle
id: build-spa
run: |
docker build -t ghcr.io/${{ github.repository }}/spa:${{ github.sha }} ./frontend
docker push ghcr.io/${{ github.repository }}/spa:${{ github.sha }}:
- name: Sign SPA Bundle (Keyless)
env:
DIGEST: ${{ steps.build-spa.outputs.digest }}
run: |
cosign sign --yes ghcr.io/${{ github.repository }}/spa@${DIGEST}
# --- 3. ML ARTIFACT (Packaged as Generic OCI Artifact) ---
- name: Package & Push ML Model
id: push-ml
run: |
# We attach the model file to an empty image using 'cosign attach'
# This allows us to sign a raw file like a container image
IMG=ghcr.io/${{ github.repository }}/ml-model:${{ github.sha }}
# 1. Create a dummy image layer containing the model
crane append --base scratch --new_file ./models/trained_model.pkl --output ${IMG}
# 2. Get the digest
DIGEST=$(crane digest ${IMG})
echo "ML_DIGEST=${DIGEST}" >> $GITHUB_ENV
- name: Sign ML Artifact (Keyless)
run: |
cosign sign --yes ghcr.io/${{ github.repository }}/ml-model@${{ env.ML_DIGEST }}
3. The Verification Layer (Cluster Policy)
Zero Trust ends not at the build, but at the deployment. We use Kyverno (or Sigstore Policy Controller) to enforce that only artifacts signed by this repository's OIDC identity can run.
This policy enforces that:
- The image has a valid signature.
- The signature was generated by the GitHub Actions workflow of this specific repo.
cluster-policy.yaml
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
name: verify-zero-trust-artifacts
spec:
validationFailureAction: enforce
background: false
rules:
- name: verify-signature
match:
any:
- resources:
kinds:
- Pod
verifyImages:
- imageReferences:
- "ghcr.io/my-org/*" # Scope to your registry
attestors:
- entries:
- keyless:
# ZERO TRUST IDENTITY:
# Only trust images signed by THIS GitHub repo workflow
issuer: https://token.actions.githubusercontent.com
subject: "https://github.com/my-org/my-repo/.github/workflows/zero-trust-release.yml@refs/heads/main"
required: true
4. How to Verify ML Artifacts at Runtime
Since ML models aren't standard containers, your inference service needs to verify the signature before loading the weights.
Here is a Python snippet for a secure model loader:
import subprocess
import sys
def load_model_securely(model_ref):
"""
model_ref: 'ghcr.io/org/ml-model@sha256:...'
"""
print(f"Verifying model integrity for {model_ref}...")
# Use cosign programmatically or via subprocess
# We verify against the specific GitHub OIDC Issuer
try:
# This command verifies the signature was created by the CI job
subprocess.run([
"cosign", "verify",
model_ref,
"--certificate-identity", "https://github.com/my-org/my-repo/.github/workflows/zero-trust-release.yml@refs/heads/main",
"--certificate-oidc-issuer", "https://token.actions.githubusercontent.com"
], check=True, capture_output=True)
print("Signature verified. Trust established.")
# Proceed to download and load model...
except subprocess.CalledProcessError:
print("SECURITY ALERT: Model signature verification failed!")
sys.exit(1)
Summary of the Zero-Trust Mechanism
- Integrity: The
cosign sign step cryptographically binds the artifact hash to the signature.
- Authenticity (Keyless): We do not use stored GPG keys. We use Fulcio (Certificate Authority) which issues a short-lived certificate based on the GitHub OIDC token.
- Auditability: Every signature is stored in Rekor (Transparency Log), providing immutable proof of when and who signed the artifact.
- Enforcement: The Kyverno policy ensures that even if an attacker gains write access to the container registry, they cannot deploy code or models because they cannot forge the CI system's OIDC identity.