Container Image Provenance Verification Pipeline with Sigstore in GitOps
This design outlines a secure, end-to-end pipeline for verifying container image provenance (build metadata, SLSA-compliant attestations) using Sigstore (Cosign for signing/attestations, Rekor for transparency logs, Fulcio for keyless signing) within a GitOps workflow. It assumes:
CI/CD : Tekton (Kubernetes-native) or GitHub Actions.
GitOps : ArgoCD (primary) or Flux; manifests use image digests for immutability.
Cluster Policy : Kyverno for admission control.
Registry : OCI-compatible (e.g., GHCR, Harbor) supporting Sigstore bundles.
Provenance : SLSA Level 2+ attestations (in-toto format) for build reproducibility.
The pipeline ensures only signed, attested images from trusted builders deploy, with tamper-proof verification and audit trails.
1. High-Level Pipeline Flow
code Copy code
Developer Push → CI (Build/Sign/Attest) → GitOps Repo Update → Verification Gates → Deploy → Audit
Stage Tools Actions CI Build & Sign Tekton/GitHub Actions + cosign, slsa-verifier Build image → Generate SLSA provenance → Sign image + attestation → Push to registry. GitOps Update ArgoCD Image Updater / Flux Image Reflector Automate manifest update with verified digest. Pre-Deploy Verify ArgoCD PreSync Hooks + Cosign Verify sig/provenance before sync. Admission Verify Kyverno Policy Block pods/deployments with unverified images. Runtime Audit Cluster Auditor (e.g., Falco) + Rekor Log events, query transparency log.
2. Integration Points
A. CI/CD Pipeline (Signing & Attestation)
Trigger : Git push/PR merge to main.
Steps (Tekton Pipeline example YAML snippet):
yaml Copy code
apiVersion: tekton.dev/v1beta1
kind: Pipeline
metadata:
name: build-sign-provenance
spec:
tasks:
- name: build
taskRef:
name: kaniko-build # Builds image
- name: generate-provenance
taskRef:
name: slsa-generator # Creates SLSA v0.2 attestation (in-toto)
- name: sign-image
params:
- name: image
value: "$(tasks.build.results.image-digest)"
- name: attestation
value: "$(tasks.generate-provenance.results.attestation-digest)"
taskRef:
name: cosign-sign # cosign sign --yes -a build-platform=linux/amd64 ...
- name: push-signatures
taskRef:
name: cosign-copy # Copies sigs/attestations to prod registry
Sigstore Config : Keyless signing (cosign sign --identity-token $OIDC_TOKEN via GitHub OIDC or similar).
Output : Image digest (sha256:...), signed attestation bundle in registry (index.docker.io/...@sha256:...).
B. GitOps Controller (Pre-Sync Verification)
ArgoCD App of Apps : Monitors GitOps repo (e.g., app/manifests.yaml).
Image Updater : Bot (ArgoCD Image Updater) polls registry, verifies sig/provenance, commits digest update to Git.
yaml Copy code
# image-updater-config.yaml
apiVersion: imgpkg.in/v1alpha1
kind: ImageUpdateConfiguration
spec:
updatePolicy: semver:latest # Or digest-only
verification:
cosign:
identity: "https://github.com/org/repo/.github/workflows/ci.yaml@refs/tags/v1.0.0" # Git commit SHA
issuer: "https://token.actions.githubusercontent.com" # OIDC issuer
PreSync Hook (ArgoCD Application spec):
yaml Copy code
spec:
syncPolicy:
syncOptions:
- VerifySignature=true # Native ArgoCD + Cosign plugin
preSync:
hooks:
- hookType: PreSync
templateRef:
name: cosign-verify-hook
params:
- name: image-uri
value: "{{.app.spec.source.helm.values.image.repository}}:{{.app.spec.source.helm.values.image.tag}}"
Hook runs: cosign verify --certificate-identity <identity> --certificate-oidc-issuer <issuer> --ignore-tlog <image-digest> && slsa-verifier verify <attestation> --source-git <repo-url> --workflow <ci.yaml>.
C. Kubernetes Admission Control
Kyverno Policy (Cluster-wide enforcement):
yaml Copy code
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
name: verify-image-provenance
spec:
validationFailureAction: Enforce # Block invalid images
rules:
- name: check-sigstore
match:
any:
- resources:
kinds:
- Pod
- Deployment
validate:
message: "Image must be Sigstore-signed with valid provenance"
pattern:
spec:
=(initContainers):
- name: "*"
image: "ghcr.io/org/app@sha256:..."
X-Kyverno-Image-Verify: "cosign:identity=https://github.com/org/app|oidc-issuer=https://token.actions.githubusercontent.com|provenance=true"
containers:
- name: "*"
image: "ghcr.io/org/app@sha256:..."
X-Kyverno-Image-Verify: "cosign:identity=https://github.com/org/app|oidc-issuer=https://token.actions.githubusercontent.com|provenance=true"
Kyverno integrates Cosign via kyverno-verify-image (mutates/validates with --policy sigstore).
3. Rollback Strategy
GitOps' declarative nature enables safe, Git-based rollbacks . Use image digests to prevent drift.
Scenario Detection Rollback Action Automation Verify Fail (CI/GitOps) Cosign returns non-zero; ArgoCD sync fails. Image Updater skips commit; ArgoCD stays on prior commit. ArgoCD autoRollback: true + notify Slack/Teams. Admission Fail (Cluster) Kyverno denies pod creation. Deployment rolls back to last healthy revision (K8s native). ArgoCD sync wave: syncWave: -1 for verify hook. Compromised Image Rekor timetravel attack or issuer mismatch. Pin to known-good digest in GitOps repo. Flux HealthChecks or ArgoCD Rollout (progressive canary + auto-rollback on metrics). Zero-Downtime Rollback Manual revert Git commit. ArgoCD/Flux syncs to prior state (<1min). GitHub Actions workflow on revert: argocd app sync --revision <old-commit>.
Automation Script (ArgoCD Rollback CR):
bash Copy code
argocd app rollback app-name 5 # To 5th revision
Prevention : Use registry.k8s.io/pause sidecars for init verification; multi-region registries.
4. Auditing Artifacts
All actions produce immutable, queryable artifacts for compliance (e.g., SOC2, SLSA).
Artifact Storage Query/Example Retention Signatures/Attestations OCI Registry (.attest & .sig blobs) cosign verify --list <image>Indefinite Transparency Log Rekor (public) rekor-cli search --sha <digest> → Entry UUIDImmutable Verification Logs ArgoCD Events + ELK Stack kubectl logs -n argocd argo-cd-server | grep "cosign verify"90 days Kyverno Reports Kyverno PolicyReport CRDs kubectl get policyreport -o yaml (pass/fail per resource)30 days SLSA Metadata Attestation payload (JSON) oras pull <registry>/<image>@sha256:... attest:latestWith image Audit Trail K8s Audit Logs + Falco falco query "container image with signature=verified"7-90 days Rekor Bundle Bundle in CI artifacts (S3/Git LFS) rekor-cli get --entry-uuid <uuid> --bundle (includes root hash)1 year
Dashboard : Prometheus + Grafana for metrics (e.g., verify_failures_total); integrate with Open Policy Agent (OPA) for custom queries.
Export : CronJob to archive Rekor entries: rekor-cli entry export --include-sigs > audit-$(date).json.
Benefits & Considerations
Security : End-to-end trust (CI → Cluster); detects supply-chain attacks.
Scalability : Parallel verification; works with multi-tenant clusters.
Cost : Minimal (Sigstore free/public); ~10s per verify.
Edge Cases : Offline mode (bundle verification); air-gapped (private Fulcio/Rekor).
Testing : Use cosign generate for mocks; e2e with Kind cluster.
This pipeline is production-ready; start with a PoC using ArgoCD + Kyverno on a minikube setup. For customizations, provide your stack details!