Build a secure supply chain for ML model artifacts with attestations and provenance:…
- User
Build a secure supply chain for ML model artifacts with attestations and provenance: pipeline instrumentation, storage hardening, verification workflows, and compliance evidence.
Assistant
The user wants a guide or system design for building a secure supply chain specifically for Machine Learning (ML) model artifacts. Key requirements:
- Attestations & Provenance: Tracking where the model came from, who built it, and with what ingredients (data, code, dependencies).
- Pipeline Instrumentation: Integrating security and signing into the CI/CD process.
- Storage Hardening: Securing the model registry/storage.
- Verification Workflows: How to check the model before deployment.
- Compliance Evidence: Generating reports/proof for auditors.
This is a complex, multi-faceted topic. I should structure the response logically, likely following the lifecycle of an ML model, but focusing on the "supply chain" aspect (SLSA framework is a good reference here).
Plan:
- Introduction: Define the threat model (Why do we need this? e.g., model poisoning, unauthorized access).
- Architecture Overview: A high-level diagram (mental or ASCII) showing components (CI/CD, Registry, Deployment).
- Component 1: Pipeline Instrumentation (The Build Process).
- Focus on SLSA (Supply-chain Levels for Software Artifacts).
- Tools: GitHub Actions/GitLab CI + SLSA Generator, Sigstore/Cosign.
- Actions: Sign the model, record dependencies (SBOM).
- Component 2: Attestations & Provenance (The Metadata).
- What format? In-toto attestations.
- Content: Builder ID, build type, source hash, data hash (tricky part in ML), environment parameters.
- Component 3: Storage Hardening (The Registry).
- Not just S3/GCS buckets.
- Immutable storage.
- RBAC/ABAC (OPA?).
- Registry: MLflow, Weights & Biases, or OCI-compliant registries (Harbor, Artifactory) treated like containers.
- Component 4: Verification Workflows (The Gatekeeper).
- Policy as Code (Kyverno, OPA/Gatekeeper).
- Checking signatures.
- Checking vulnerabilities (scanning dependencies).
- Checking training data integrity (conceptually).
- Component 5: Compliance Evidence (The Audit).
- Exporting logs/attestations.
- Mapping to standards (NIST, ISO).
- Example Code/Implementation: Provide a concrete example using popular tools (e.g., Python, Cosign, GitHub Actions) to make it actionable.
Drafting Content - Details & Refinements:
- Provenance: In standard software, it's code -> binary. In ML, it's Code + Data -> Model. Data provenance is hard. I need to mention that the pipeline creates the provenance, ideally capturing the hash of the dataset version or the specific query used to fetch data.
- Signing: Use
cosign(part of Sigstore). It's the industry standard now. Models can be stored as OCI artifacts, makingcosignwork directly. - Verification: This happens before serving. Kubernetes admission controllers are a standard place for this.
- Hardening: Encryption at rest, signed commits on config.
Structure of the Response:
- Philosophy & Framework: Adopt SLSA (Supply-chain Levels for Software Artifacts).
- Phase 1: The Secure Build (Pipeline Instrumentation).
- Phase 2: Provenance Generation (Attestations).
- Phase 3: Secure Registry (Storage Hardening).
- Phase 4: Deployment Verification (Policy Enforcement).
- Phase 5: Audit & Compliance.
- Reference Implementation (Code snippets).
Self-Correction during drafting:
- Initial thought: Focus heavily on the ML algorithm.
- Correction: The prompt asks for supply chain, not model performance. Focus on the infrastructure, metadata, and integrity, not accuracy/Accuracy.
- Data Provenance: Don't promise full data lineage inside the model file, as that's technically very hard. Focus on the hash or reference to the data version used during training.
Key Technologies to mention:
- Sigstore / Cosign (Signing/Verification)
- In-toto (Attestation format)
- SLSA (Framework)
- OCI Registries (Storage)
- Kyverno / OPA (Policy)
- MLflow / DVC (ML specific tooling integration)
Let's assemble the technical guide. I will provide a comprehensive architecture and actionable steps. This guide outlines a reference architecture for a Secure ML Supply Chain based on the SLSA (Supply-chain Levels for Software Artifacts) framework. It treats model artifacts (weights, biases, and configs) with the same rigor as compiled software binaries.
1. Architecture Overview
We move away from "Trusting the Builder" to "Verifying the Provenance."
- Source of Truth: Git (Code) + Immutable Bucket (Data).
- Builder: Hardened CI/CD (GitHub Actions/GitLab CI/Cloud Build) with OIDC support.
- Registry: OCI-compliant registry (Artifactory, Harbor, HuggingFace Hub) supporting Cosign signatures.
- Policy Enforcer: Kubernetes Admission Controller (Kyverno) or Cluster Policy Engine.
2. Pipeline Instrumentation (The Build Process)
The pipeline must be non-falsifiable. It should generate a Software Bill of Materials (SBOM) and a Signed Attestation (Provenance) immediately after training.
The Workflow
- Checkout: Code is pulled at a specific commit SHA.
- Environment: The pipeline runs in an isolated environment (e.g., ephemeral container).
- Training: The model is trained. The output is a binary file (e.g.,
model.jobliborpytorch.bin). - Packaging: Convert the model into an OCI Artifact. This allows us to use standard container registry tools to store, tag, and sign models.
- Attestation: Generate metadata about how it was built.
Implementation: Generic CI/CD Script
This assumes you are packaging your model as an OCI image using tools like
koororas.# .github/workflows/train_and_release.yml name: Secure Model Supply Chain on: push: tags: ['v*'] permissions: id-token: write # Required for OIDC (Federated Identity) contents: read jobs: build: runs-on: ubuntu-latest outputs: digest: ${{ steps.push.outputs.digest }} steps: - name: Checkout Code uses: actions/checkout@v4 - name: Train Model run: | # Simulate training python train.py --input-data s3://secure-bucket/dataset-v1.parquet --output model.pkl # Generate SBOM for dependencies pip freeze > requirements.txt sbom-generator -o model-sbom.json . - name: Push Model to Registry (OCI) id: push # Using 'oras' to push standard files to a container registry run: | oras push ghcr.io/myorg/ml-model:${{ github.sha }} \ --artifact-type application/vnd.ml.model \ ./model.pkl \ ./model-sbom.json provenance: needs: build runs-on: ubuntu-latest steps: - name: Generate SLSA Provenance uses: slsa-framework/slsa-github-generator/.github/workflows/generator_generic_slsa3.yml@v1.9.0 with: base64-subjects: "${{ needs.build.outputs.digest }}" upload-assets: true # This creates an in-toto attestation linking the model hash to the build environment
3. Provenance and Attestations
Provenance answers: Who built this, on what machine, using what code, and when?
We use the in-toto standard. The attestation is a JSON envelope containing:
- Predicate: The build metadata (CI runner info, Git commit, build command).
- Subject: The SHA256 hash of the model artifact.
Example Attestation Payload (Conceptual)
{ "_type": "https://in-toto.io/Statement/v0.1", "subject": [ { "name": "ghcr.io/myorg/ml-model", "digest": { "sha256": "2ab14c7d..." } } ], "predicateType": "https://slsa.dev/provenance/v0.2", "predicate": { "builder": { "id": "https://github.com/slsa-framework/slsa-github-generator/.github/workflows/generator_generic_slsa3.yml@v1.9.0" }, "buildType": "https://github.com/slsa-framework/slsa-github-generator/generic@v1", "invocation": { "configSource": { "uri": "git+https://github.com/myorg/ml-repo@refs/heads/main", "digest": { "sha1": "d43e7bc..." }, "entryPoint": ".github/workflows/train_and_release.yml" } }, "materials": [ { "uri": "git+https://github.com/myorg/ml-repo", "digest": { "sha1": "d43e7bc..." } } ] } }
4. Storage Hardening
The model registry must be treated as a Critical Infrastructure component.
- Immutability: Once a model version is pushed, it cannot be overwritten. Tags (like
latest) can move, but SHA digests must be permanent. - Signature Storage: Signatures and attestations should be stored alongside the artifact (in the same registry) as "Attached Refs".
- Access Control:
- CI Role: Push/Tag permissions only.
- Verifier Role: Pull/Verify permissions only.
- Data Scientist Role: Read-only access to production tags.
Storage Layout Example (OCI Registry)
Repository: ml-models/fraud-detection ├── Sha256:abcde... (Model Binary) ├── Sha256:abcde... (SBOM - Dependency Graph) ├── Sha256:fghij... (Attestation - Build Provenance) └── Signature: sha256:abcde... (Cosign Signature)
5. Verification Workflows (The Gatekeeper)
Before a model is allowed to be deployed to an inference server (e.g., KServe, Seldon, or a Python Flask app), it must be verified.
Verification Logic:
- Integrity Check: Does the model hash match the hash in the attestation?
- Signature Check: Is the attestation signed by the trusted CI platform's OIDC key?
- Policy Check: Did the build come from the
mainbranch? Was the SBOM free of critical CVEs?
Implementation: Cosign & Kyverno
We use Cosign for signing/verification and Kyverno (a K8s policy engine) for enforcement.
Verification Script (CLI usage):
# Verify the model was signed by the CI workflow cosign verify \ --certificate-identity-regexp="^https://github.com/myorg/ml-repo" \ --certificate-oidc-issuer="https://token.actions.githubusercontent.com" \ ghcr.io/myorg/ml-model@sha256:abcde...Cluster Policy (Kubernetes Admission Controller): This policy prevents any model from being deployed unless it has a valid SLSA Level 3 provenance attestation.
# kyverno-policy.yaml apiVersion: kyverno.io/v1 kind: ClusterPolicy metadata: name: check-model-provenance spec: validationFailureAction: enforce background: false rules: - name: verify-slsa-attestation match: any: - resources: kinds: - Pod verifyImages: - imageReferences: - "ghcr.io/myorg/ml-model*" attestations: - predicateType: "https://slsa.dev/provenance/v0.2" conditions: - all: - key: "{{ builder.id }}" operator: Equals value: "https://github.com/slsa-framework/slsa-github-generator/.github/workflows/generator_generic_slsa3.yml@v1.9.0" - key: "{{ invocation.configSource.uri }}" operator: Equals value: "git+https://github.com/myorg/ml-repo@refs/heads/main"
6. Compliance Evidence
To satisfy auditors (SOC2, ISO 27001, or AI Act regulations), you need a dashboard or exportable report.
Automated Compliance Report Generator: This script runs periodically or on deployment to generate a PDF/JSON audit trail.
- Inputs: Model Digest, Registry Logs.
- Outputs: A "Software Supply Chain Card".
# generate_compliance_report.py import json from datetime import datetime def generate_report(model_digest, attestation_path): with open(attestation_path) as f: attestation = json.load(f) report = { "artifact_id": model_digest, "verification_timestamp": datetime.utcnow().isoformat(), "supply_chain_security": { "is_signed": True, # Logic to check cosign output "source_commit": attestation['predicate']['materials'][0]['digest']['sha1'], "builder_identity": attestation['predicate']['builder']['id'], "slsa_level": 3 }, "dependencies": { "vulnerabilities_critical": 0, "license_compliance": "Pass" # Logic to check SBOM } } return reportSummary Checklist
Component Requirement Tooling Artifact Stored as OCI Object, Immutable oras,docker,harborAttestation SLSA Provenance v0.2+, Signed cosign,in-totoBuilder Ephemeral, Federated Auth (OIDC) GitHub Actions, Tekton Chains Verification "Deny by Default" Policy Kyverno, OPA Gatekeeper Data Versioned, Hash-linked DVC, S3 Versioning (referenced in Attestation)
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.