We are going to design a workflow for attestation of deployment artifacts.
The workflow should log signatures, SBOMs (Software Bill of Materials), and provenance.
Steps:
Build the artifact (e.g., a container image, binary, etc.)
Generate an SBOM for the artifact (e.g., using Syft, etc.)
Generate provenance information about the build (e.g., using in-toto, or a custom JSON with build details)
Sign the SBOM and provenance (and possibly the artifact itself) using a signing key (e.g., cosign, gpg, etc.)
Store the signatures, SBOM, and provenance in a registry (e.g., OCI registry for container images, or an artifact repository for binaries)
However, the problem asks for a "workflow logging" meaning we want to log these attestations in a way that they are part of the deployment artifact's metadata.
We can consider two main approaches:
Approach 1: Using an OCI registry and attaching attestations as artifacts to the image.
This is the modern approach for container images.
We can use cosign to attach SBOM and provenance as attestations.
Approach 2: Storing the attestations in a separate location and logging the references in a deployment log.
Since the question says "logging signatures, SBOMs, and provenance", we might interpret it as having a log (like a deployment record) that contains these.
However, the term "attestation" is often used in the context of in-toto and SLSA, and they are typically stored as artifacts in a registry.
Let me clarify the requirement:
"Compose a deployment artifact attestation workflow logging signatures, SBOMs, and provenance."
We are to design a workflow that, during deployment, logs (records) the signatures, SBOMs, and provenance of the artifact being deployed.
We can break down the workflow:
Pre-deployment (during build and push):
Build the artifact.
Generate SBOM.
Generate provenance (build details, source, etc.)
Sign the artifact (optional) and sign the SBOM and provenance (attestations).
Push the artifact and the attestations to a registry.
Deployment:
6. When deploying, we want to log (record) the fact that we are deploying a particular artifact along with its attestations.
But note: the attestations are already stored with the artifact in the registry. So what does "logging" mean here?
Perhaps we want to have an immutable log (like a database or a file) that records each deployment with the artifact's digest and the attestations.
Alternatively, we can think of the deployment step as:
Pull the artifact and its attestations from the registry.
Verify the signatures (if required) and then deploy.
Then, write a log entry that includes:
artifact reference (digest)
SBOM (or reference to it)
provenance (or reference)
signatures (or references)
deployment time, environment, etc.
However, storing the entire SBOM and provenance in a log might be too heavy. Instead, we can store references (like hashes) to these attestations.
But note: the attestations are already stored in the registry. So we can just log the artifact digest and then the attestations can be fetched by the digest.
However, the requirement says "logging signatures, SBOMs, and provenance". So we must log them, meaning we store them in the log.
Alternatively, we can store the attestations in the log as separate entries and then link them by the artifact digest.
Let me propose:
We have a deployment log (e.g., a database table) with the following columns:
deployment_id (primary key)
artifact_digest (the digest of the deployed artifact, e.g., sha256:... for container image)
artifact_type (container image, binary, etc.)
signed_by (who signed the artifact, or the key used)
sbom (the SBOM in JSON format, or a reference to where it is stored? If we store it in the log, it can be a JSONB field)
provenance (similarly, a JSON field for the provenance)
deployment_timestamp
environment (where it was deployed, e.g., production, staging)
operator (who deployed)
But note: the SBOM and provenance might be large. We might not want to store them in the log if they are huge.
Alternatively, we can store the attestations in a blob store and store the URLs in the log.
However, the requirement says "logging", so we must have a record. The record can be minimal (just the hashes) and then the attestations are stored elsewhere.
But then, if the attestations are stored in the registry, we can just log the artifact digest and then we can retrieve the attestations from the registry by the digest.
However, the attestations are stored as separate artifacts in the registry, so we would need to know their digests or the way they are attached.
In the OCI registry, attestations are stored as separate artifacts with a media type and a subject (the artifact they attest to). So we can query by subject.
So, in the deployment log, we can store:
deployment_id
artifact_digest (subject)
registry_url (where the artifact is stored)
Then, we can later fetch the attestations by querying the registry for artifacts that have the subject equal to our artifact_digest.
But the requirement says "logging signatures, SBOMs, and provenance". So we are logging the fact that we have these attestations, but not necessarily storing the content.
However, if we want to be independent of the registry, we might want to store the attestations in the log.
Let's re-read: "logging signatures, SBOMs, and provenance". It might mean that we are creating a log that contains these items.
Since the attestations are generated and signed at build time, we can store them in the log at deployment time.
But note: the attestations are already stored in the registry. So we are duplicating storage.
Alternatively, we can store only the hashes of the attestations in the log and then store the attestations in a separate store (like the registry).
However, the workflow might be:
Build and push:
artifact -> registry
sbom -> registry (as an attestation)
provenance -> registry (as an attestation)
signatures -> either as part of the attestation (if using cosign, the attestation is signed) or separate.
During deployment:
We pull the artifact and the attestations (by querying the registry for the subject).
We verify the signatures (if required).
Then we write a log entry that includes:
- artifact digest
- the digests of the sbom and provenance attestations (so we can check they are the same as in the registry)
- deployment details.
But then we are not logging the full SBOM and provenance, just their digests.
However, the requirement says "logging", which might imply storing the content. But in practice, we might not want to store large blobs in the log.
Let's assume we want to store the content in the log for auditability and independence from the registry.
Then we can:
During deployment, after pulling the attestations, we store:
artifact_digest
sbom_content (as JSON)
provenance_content (as JSON)
signature_content (the signature over the sbom and/or provenance, and/or artifact)
But note: the signature is over the digest of the sbom and/or provenance. So if we store the sbom and provenance, we can re-compute the digest and verify.
However, we might also want to store the signature itself.
Alternatively, we can store the entire attestation as it is stored in the registry (which is a signed JSON object).
In the case of cosign, an attestation is a JSON object with:
So we can store that entire attestation object for each attestation.
Then our log entry for a deployment might look like:
{
"deployment_id": "123",
"artifact_digest": "sha256:abcdef...",
"attestations": [
{
"type": "sbom",
"attestation": { ... } // the cosign attestation object for the SBOM
},
{
"type": "provenance",
"attestation": { ... } // the cosign attestation object for the provenance
}
],
"deployment_timestamp": "2024-01-01T00:00:00Z",
"environment": "production",
"operator": "admin"
}
This way, we have the full attestations (including the signatures) and the content of the SBOM and provenance (in the payload).
However, this is a lot of data and might be redundant with the registry.
But the requirement says "logging", so we are creating a log that is independent and can be used for audit.
Alternatively, we can store only the hashes and rely on the registry for the content, but then if the registry is compromised, we lose the attestations.
Since attestations are about the artifact, we want to keep them safe. Storing them in the deployment log (which might be write-once) is a good practice.
So, I propose:
We have a deployment log that stores for each deployment:
code
- The artifact digest (so we know which artifact)
- The environment and operator, etc.
- For each attestation (SBOM and provenance) we store:
* The type (sbom, provenance)
* The attestation object (the signed JSON)
We do not store the artifact itself in the log, only the digest.
We assume that the attestations are generated and signed at build time, and then attached to the artifact in the registry.
At deployment time, we fetch the attestations from the registry and store them in the log.
This way, even if the registry is compromised later, we have the original attestations in the log.
Steps in the workflow:
Build and push:
1. Build artifact.
2. Generate SBOM and provenance.
3. Sign the SBOM and provenance (using cosign, for example) and attach them as attestations to the artifact in the registry.
Deployment:
4. Pull the artifact (by digest) and the attestations (by querying the registry for the subject).
5. Verify the signatures on the attestations (optional, but recommended).
6. Write a deployment log entry that includes the artifact digest and the fetched attestations.
The deployment log can be a database, or an append-only file (like a log file), or a blockchain-like immutable storage.
We must ensure that the deployment log is write-once and tamper-evident.
Implementation:
We can use a simple database table with a JSONB column for the entire deployment record, including the attestations.
Example table schema (PostgreSQL):
code
CREATE TABLE deployment_log (
id SERIAL PRIMARY KEY,
deployment_id TEXT UNIQUE NOT NULL, -- a UUID for the deployment
artifact_digest TEXT NOT NULL, -- the digest of the deployed artifact
artifact_type TEXT NOT NULL, -- e.g., "container"
registry_url TEXT NOT NULL, -- where the artifact is stored
attestations JSONB NOT NULL, -- an array of attestation objects, each with type and attestation
deployment_timestamp TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
environment TEXT NOT NULL,
operator TEXT NOT NULL
);
The attestations JSONB would be an array of objects:
We can also store the signature of the artifact itself if we have one, but note that cosign can also sign the artifact (the image) and that is stored as a separate signature in the registry. We can include that as another attestation of type "signature".
However, the artifact signature is not an SBOM or provenance. So we might have:
But note: the requirement says "signatures, SBOMs, and provenance". So we are logging signatures of the artifact? Or signatures of the attestations?
In the cosign model, the attestations are signed. So we are logging the signed attestations.
We can also log the signature of the artifact (if any) as a separate attestation of type "artifact_signature".
Alternatively, we can have a field for the artifact signature and then the attested SBOM and provenance.
But to keep it simple, we can treat everything as an attestation and have a type field.
Alternatively, we can have:
code
artifact_signature: the signature of the artifact (if any) as a string or JSON.
sbom_attestation: the signed SBOM attestation.
provenance_attestation: the signed provenance attestation.
But then we are hard-coding the types. Better to have an array of attestations with a type.
However, note that the artifact signature might not be an attestation in the same format as the SBOM and provenance. The artifact signature (from cosign) is a simple signature over the digest.
So we might have two different formats.
Alternatively, we can store the artifact signature separately and then the other two as attestations.
But the requirement says "signatures", which could be the artifact signature and/or the signatures on the attestations.
Since the attestations are already signed, we are logging the signatures of the SBOM and provenance in the attestation objects.
We might not need to log the artifact signature separately if we consider that the artifact signature is just another attestation? Actually, an attestation is a statement about the artifact, and the signature is on that statement. The artifact signature is a signature on the artifact itself, which is a different kind of proof.
So, we have:
code
- Artifact signature: proves the artifact came from the signer.
- SBOM attestation: proves the SBOM is for the artifact and generated by the builder.
- Provenance attestation: proves how the artifact was built.
So we might want to log all three.
But note: the artifact signature is stored in the registry as a separate signature resource. We can fetch it and store it as an attestation of type "artifact_signature".
In cosign, the artifact signature is stored as a blob with media type "application/vnd.dev.cosign.sig". We can store that blob as the attestation for type "artifact_signature".
So, we can have:
code
For each deployment, we fetch:
- The artifact signature (if any) and store it as an attestation of type "artifact_signature".
- The SBOM attestation (by subject) and store it as type "sbom".
- The provenance attestation (by subject) and store it as type "provenance".
But note: the SBOM and provenance are stored as attestations (with payload and signatures) and the artifact signature is stored as a raw signature.
So we have two different formats. We can normalize them in our log.
Alternatively, we can store the artifact signature as a base64 string and then when verifying, we know that for type "artifact_signature" it's a raw signature, and for the others they are full attestation objects.
However, to keep it consistent, we can store everything as a JSON object with a type field and then the content.
Let's define:
code
{
"type": "artifact_signature",
"content": {
"signature": "base64 of the signature",
"key_id": "the key id used to sign" // if available
}
}
But cosign doesn't store the key id in the signature blob. We might get that from the registry or from the signature verification.
Alternatively, we can store the raw signature and then when we verify, we get the key id from the signature.
Since we are just logging, we can store the raw signature and then if we need to verify, we can re-verify with the public key.
But note: the attestations (SBOM and provenance) are already signed, and we have the signatures in the attestation object.
So, we can do:
code
For artifact_signature:
We store the raw signature (base64) and the algorithm (e.g., "ecdsa-sha2-nistp256") if we can get it.
For sbom and provenance:
We store the entire attestation object (with payload and signatures).
However, this is messy.
Alternatively, we can store everything as an attestation in the in-toto format? But the artifact signature is not in that format.
Given the complexity, maybe we should stick to logging:
code
- The artifact digest.
- The SBOM and provenance as they are stored in the registry (as attestations) and the artifact signature as a separate field.
But then we are not consistent.
Since the requirement is to log signatures, SBOMs, and provenance, we can do:
code
Log:
artifact_digest
artifact_signature (if any) as a string (base64)
sbom_attestation (the full attestation object, which includes the sbom and its signature)
provenance_attestation (the full attestation object)
This way, we have three separate fields.
But then if we have multiple signatures (e.g., multiple keys) for the artifact, we might have multiple artifact_signature strings? Or we can store them as an array.
Let's design the log entry as:
code
{
"deployment_id": "uuid",
"artifact_digest": "sha256:...",
"artifact_type": "container",
"registry_url": "registry.example.com/myimage:tag",
"artifact_signatures": [ "base64sig1", "base64sig2" ], // array of signatures (each is base64)
"sbom_attestation": { ... }, // the in-toto-style attestation object for the SBOM
"provenance_attestation": { ... }, // for provenance
"deployment_timestamp": "...",
"environment": "...",
"operator": "..."
}
We can also have a field for the algorithm for each signature? But the attestation objects already have the algorithm in the signature.
For the artifact_signatures, we don't have the algorithm. We can try to parse the signature? Or we can store the algorithm separately.
Alternatively, we can store the artifact signatures as an array of objects:
But we don't have the key_id and algorithm in the raw signature. We get that from the registry or from the signature verification.
Since we are just logging, we can store what we get from the registry. The registry (OCI) stores the signature as a blob with the media type and the digest. We can store the digest of the signature and the media type? But then we are storing references again.
Given the complexity, maybe we can do:
code
We store the entire signature resource from the registry for the artifact and for the attestations.
In OCI, each artifact (including signatures and attestations) is a blob with a digest and a media type.
We can store for each:
code
For the artifact signature:
We store the blob (the raw signature) and the media type (which includes the algorithm?).
For the attestations, we store the entire attestation blob.
But then we are storing the same data as in the registry, but in our log.
Alternatively, we can store the digests of the signature resources and then we can fetch them from the registry if needed.
However, the requirement is to log them, meaning we have a record. We can store the digests and the registry URL, and then we can fetch.
But then we are not independent of the registry.
Given the requirement of "attestation workflow", we want to have a tamper-evident log of what was deployed and what attestations were present at deployment time.
So, we want to store the actual bytes (or their hashes) in the log.
Let's store the actual bytes (or base64) for:
code
- The artifact signature (if any)
- The SBOM attestation (the entire attestation object)
- The provenance attestation
And we also store the artifact digest.
Then, we can verify:
code
- The artifact signature by verifying the signature over the artifact digest (using the public key).
- The SBOM and provenance by verifying the signatures in the attestation objects.
We also store the environment and operator.
So, the workflow:
Build and push (using cosign for example):
code
cosign build --attestation,type=cyclonedx ... # generates SBOM and attaches as attestation
cosign build --attach,type=slsaprovenance ... # generates provenance and attaches
cosign sign ... # signs the artifact (creates a signature resource)
Deployment:
code
We have the image:tag and we know the digest (we can resolve the tag to digest).
Then we fetch:
- The artifact signature:
cosign verify-attestation --type=cyclonedx <image> # to get the SBOM attestation
cosign verify-attestation --type=slsaprovenance <image> # to get the provenance attestation
cosign verify <image> # to get the artifact signature? Actually, `cosign verify` will verify the signature and not output the signature blob.
We need to fetch the signature blobs. We can use:
cosign verify --output=signature <image>
But that might not be available. Alternatively, we can use the OCI registry API to fetch the signature resource.
Alternatively, we can use:
cosign attest --download <image> --type=cyclonedx # to download the SBOM attestation
cosign attest --download <image> --type=slsaprovenance # for provenance
and for the artifact signature:
cosign verify --output=signature <image> # if available, or use the registry API.
Then we store in the log:
artifact_digest: the digest of the image we deployed.
artifact_signatures: [base64 of the signature blob from the registry]
sbom_attestation: the JSON object we got from `cosign attest --download` (which is the attestation object)
provenance_attestation: similarly.
But note: the cosign attest --download returns the attestation object (the signed JSON). We can store that.
So, the deployment script:
code
However, this is getting complex. We might want to use a tool that abstracts this.
But note: the content for the in-toto attestation is a JSON object that has the payload (base64) and signatures. We are storing the entire object.
This is a lot of data, but it's the full attestation.
Alternatively, we can store only the hashes and then the content in a separate blob store, but the requirement says logging, so we store it in the log.
Since the log might become huge, we might want to store only the hashes and then the content in a separate object store, but then we are not independent.
Given the requirement for an attestation workflow, we want to have a tamper-evident log. So we can store the hashes and then the content in a separate write-once storage.
But to simplify, we can store the entire content in the log (as a JSON field) and then the log itself is stored in a write-once database or a blockchain.
However, for practical purposes, we might store the entire content in the log entry as a JSONB field in PostgreSQL, and then the log is append-only (using triggers or application logic to prevent updates).
Steps in the deployment script:
code
This is a high-level design.
We must also consider:
code
- Error handling: what if there are no attestations? We still want to log the deployment without them? Or fail?
- We might want to verify the signatures at build time and then at deployment time we just log what we have.
But the attestations are signed, so we should verify them at deployment time to make sure they are valid and for the correct subject.
We can do:
code
For each artifact_signature: verify that it signs the artifact digest.
For each sbom_attestation: verify the signature and that the subject is the artifact digest.
But note: the in-toto attestation has a subject field that should be the artifact digest.
So, we should verify:
code
- The artifact_signature: the signature is over the digest of the artifact? Actually, cosign signs the digest of the config? Or the entire image?
In cosign, the artifact signature is over the digest of the image (the manifest digest). So we can verify that.
- The in-toto attestation: the subject should be the artifact digest, and the signature should be valid.
We can do these verifications and then only log if they pass.
So, the workflow becomes:
code
Build and push: generate and attach attestations and sign the artifact.
Deployment:
1. Resolve the artifact digest.
2. Fetch the referrers and the blobs.
3. Verify:
a. For each artifact_signature: verify the signature over the artifact digest (using the public key).
b. For each in-toto attestation: verify the signature and that the subject matches the artifact digest.
4. If all required attestations are present and valid, then log the deployment with the fetched attestations.
What are required? Maybe we require at least one artifact_signature and one sbom and one provenance? That depends on policy.
We can make the required list configurable.
Given the complexity, we might want to use a tool like slsa-verifier or cosign verify-attestation to verify and then we just log the ones that are valid.
But then we are re-doing the work of cosign.
Alternatively, we can use cosign to verify and then we trust the verification. But we want to log the attestations, so we need to fetch them anyway.
So, we fetch and verify in the deployment script.
We can use cosign to verify the artifact signature and the attestations, but then we don't get the blobs? We can use cosign to verify and then we fetch the blobs separately.
Or we can use cosign to verify and then use the registry to fetch the blobs (by digest) and then log them.
But note: the verification by cosign might require the public key, and we want to make sure we are using the same key as in the build.
So, we can have a policy: which keys are trusted for artifact_signatures and for attestations?
This is getting into a full SLSA implementation.
Given the scope, we can assume that we have a way to verify the signatures (with a set of trusted public keys) and then we log the attestations that are valid.
We can design the log to include only the valid attestations.
So, the steps:
code
For each artifact_signature blob:
verify it with the trusted public key for artifact signatures.
if valid, add to the log.
For each in-toto attestation blob:
verify the signature with the trusted public key for attestations (might be different keys for SBOM and provenance? or same?).
check the subject is the artifact digest.
if valid, and according to the payloadType, add to sbom_attestations or provenance_attestations.
Then log.
This is a complete workflow.
However, note: the artifact_signature might be stored in the registry without a standard way to get the public key? We need to have the public key out-of-band.
For in-toto attestations, the public key is stored in the attestation? No, the attestation has a signature and we need the public key to verify.
We can have a trust root: a set of public keys for our organization.
We can store the public keys in the deployment environment.
So, the deployment script must have access to the public keys.
This is a complex system.
Given the time, we can stop at the design of the log entry and the high-level steps.
We can summarize:
Workflow:
Build:
1. Build the artifact.
2. Generate SBOM and provenance.
3. Sign the SBOM and provenance and attach them as attestations to the artifact in the registry (using cosign).
4. Sign the artifact (using cosign) which creates a signature resource in the registry.
Deployment:
1. Resolve the artifact reference (tag) to a digest.
2. Use the OCI referrers API to list all artifacts that refer to the artifact digest.
3. For each referred artifact, fetch the blob.
4. Verify the signatures (artifact_signature with the artifact public key, and in-toto attestations with the attestation public key) and that the subject in the attestation matches the artifact digest.
5. Collect the valid artifact_signatures, sbom_attestations, and provenance_attestations.
6. Write a deployment log entry with:
- deployment_id (UUID)
- artifact_digest
- artifact_type (e.g., container)
- registry_url (the original image reference)
- artifact_signatures (array of base64 strings)
- sbom_attestations (array of in-toto attestation JSON objects)
- provenance_attestations (array of in-toto attestation JSON objects)
- deployment_timestamp
- environment
- operator
The log entry is stored in an append-only database (or a blockchain) to ensure tamper evidence.
This satisfies the requirement of logging signatures, SBOMs, and provenance.
We can also extend to other types of attestations.
Note: We are storing the entire blobs, which might be large. We might want to compress or store the hashes and then the blobs in a separate store, but the requirement says logging, so we store them in the log.
Alternatively, we can store the hashes and then the blobs in a separate object store that is write-once, and then in the log we store the URLs to the blobs.
But then we are not independent.
Given the trade-offs, we choose to store the blobs in the log for maximum independence.
However, if the blobs are too large, we might store only the hashes and then rely on the registry for the blobs, but then we are not independent.
We can do:
code
If the log storage is limited, we store the hashes and the media types and then we can fetch from the registry.
But then we are not logging the content, just the hashes.
The requirement says "logging", which might mean storing the content.
We'll assume we are to store the content.
End of design.
I'll design a comprehensive deployment artifact attestation workflow that logs signatures, SBOMs, and provenance information with cryptographic integrity. This follows modern secure software supply chain practices (SLSA, in-toto, sigstore).
# policies.yaml
policies:
- id: require-sbom
description: "All deployments must have a valid SBOM"
attestation_types: ["sbom"]
required_signing_keys: ["prod-signing-key-1", "prod-signing-key-2"]
- id: require-slsa-provenance
description: "Must have SLSA v1.0+ provenance"
attestation_types: ["provenance"]
min_slsa_level: 2
required_build_types: ["https://github.com/attestations/actions/workflow"]
- id: forbid-unapproved-sources
description: "Block deployments from unapproved repositories"
allowed_repositories:
- "https://github.com/company/app repo"
- "https://gitlab.com/company/app"
6.3 Monitoring & Alerting
python
class AttestationMonitor:
def check_deployment_compliance(self, deployment_id: str) -> Dict:
"""Check if deployment meets compliance policies"""
deployment = get_deployment(deployment_id)
results = {
"compliant": True,
"violations": []
}
for policy in load_policies():
if not self._evaluate_policy(deployment, policy):
results["compliant"] = False
results["violations"].append({
"policy": policy["id"],
"description": policy["description"]
})
return results
def alert_on_violation(self, violation: Dict):
"""Send alert to security team"""
send_slack_alert(
f"🚨 Deployment Policy Violation: {violation['policy']}\n"
f"Deployment: {violation['deployment_id']}\n"
f"Environment: {violation['environment']}"
)
7. Implementation Considerations
Storage Backends
Database: PostgreSQL with JSONB support
Immutable Storage: AWS S3 with Object Lock, GCS with retention policy
Blockchain: Hyperledger Fabric for maximum integrity (optional)
Key Management
Use sigstore Fulcio for short-lived certificates
Or Hardware Security Modules (HSMs) for long-term keys
Rotate keys regularly with key history tracking
Scalability
Index on: artifact_digest, deployment_timestamp, environment
Partition by date for large volumes
Compress old logs (>90 days)
Retention Policy
code
- Active logs: 90 days (hot storage)
- Archived logs: 7 years (cold storage, immutable)
- SBOMs: Indefinite (for vulnerability scanning)
8. Query Examples
Find all deployments of vulnerable artifact
sql
-- Find all deployments using vulnerable library version
SELECT d.deployment_id, d.environment, d.timestamp
FROM deployment_log d,
jsonb_array_elements(d.attestations) AS att,
jsonb_array_elements(att->'sbom'->'components') AS component
WHERE component->'name' = 'log4j'
AND component->'version' = '2.14.0'
AND d.timestamp > '2024-01-01';
Verify artifact chain of custody
bash
# 1. Get deployment
curl https://attestation-log.example.com/deployments/dep-123
# 2. Get artifact from registry
cosign verify myapp:v1.2.3
# 3. Get and verify SBOM attestation
cosign verify-attestation --type cyclonedx myapp:v1.2.3
# 4. Cross-check digests match
# (from deployment log and registry verification)
Key Benefits
Cryptographic Integrity: All entries hash-chained
Non-repudiation: Signatures on all attestations
Transparency: Anyone can verify deployments
Compliance Ready: SLSA, SBOM requirements met
Forensic Ready: Complete audit trail for incidents
Automation Friendly: API-first design
This workflow provides enterprise-grade attestation logging that meets modern supply chain security requirements while remaining practical for CI/CD integration.
#!/bin/bash
IMAGE=$1
ENVIRONMENT=$2
OPERATOR=$3
# Get the digest of the image
DIGEST=$(skopeo inspect docker://$IMAGE | jq -r '.Digest')
# Fetch the artifact signature (if any)
# We assume the image has at least one signature.
# We can fetch all signatures for the image.
# Using cosign, we can do:
# cosign verify --output=signature $IMAGE
# But that only verifies and doesn't output the signature. We need to fetch the signature blobs.
# Alternatively, use regctl or the OCI registry API.
# Let's use cosign to fetch the attestations and then we can fetch the signature via the registry.
# We'll use the OCI registry API to list and fetch the signature resources.
# We assume the image is in an OCI registry.
# Parse the registry, repo, and tag from the image.
REGISTRY=$(echo $IMAGE | cut -d/ -f1)
REPO=$(echo $IMAGE | cut -d/ -f2- | cut -d: -f1)
TAG=$(echo $IMAGE | cut -d: -f2)
# We need the digest, so we already have it.
# Now, list the artifacts that are referenced by the subject (the image digest).
# We can use:
# curl -H "Accept: application/vnd.oci.image.index.v1+json" https://$REGISTRY/v2/$REPO/manifests/$DIGEST
# But that returns the manifest. We need the references to the signature and attestation resources.
# Actually, the manifest has references to the blobs? No, the manifest for an image index or manifest has a list of layers and config, but not the signatures.
# The signatures and attestations are stored as separate artifacts in the registry, and they are linked by the subject (the image digest) in the OCI referrer API.
# We can use:
# curl -H "Accept: application/vnd.oci.artifact.v1+json" https://$REGISTRY/v2/$REPO/artifacts/$DIGEST
# But that's not standard.
# Alternatively, we can use the in-toto format and cosign's way of storing.
# Given the complexity, maybe we rely on cosign to download the attestations and then we use the registry to download the artifact signature.
# But note: cosign does not provide a way to download the artifact signature blob. It only verifies.
# We might have to use the registry API to list and fetch the signature resources.
# The OCI spec for referrers: https://github.com/opencontainers/distribution-spec/blob/main/spec.md#referrers
# We can do:
# curl -H "Accept: application/vnd.oci.referrers.v1+json" https://$REGISTRY/v2/$REPO/referrers/$DIGEST
# This returns a list of artifacts (by digest) that refer to the subject (our image). Each artifact has a mediaType.
# We can then fetch each artifact by its digest.
# Steps:
# 1. Get the list of referrers for the image digest.
# 2. For each referrer, fetch the artifact (which is a blob) and store it according to its mediaType.
# The mediaTypes we are interested in:
# - For artifact signature: "application/vnd.dev.cosign.sig"
# - For SBOM attestation: "application/vnd.in-toto+json" and the payloadType in the JSON is "application/vnd.cyclonedx+json" (for CycloneDX) or "application/vnd.spdx+json" (for SPDX)
# - For provenance attestation: "application/vnd.in-toto+json" and the payloadType is "application/vnd.slsa.provenance.v1+json"
# But note: the SBOM and provenance are both stored as in-toto attestations, so they have the same mediaType. We distinguish by the payloadType.
# So, we can:
# - Fetch the list of referrers.
# - For each referrer, get its digest and mediaType.
# - If mediaType is "application/vnd.dev.cosign.sig", then it's an artifact signature.
# - If mediaType is "application/vnd.in-toto+json", then fetch the blob and parse the payloadType to see if it's SBOM or provenance.
# Then we store:
# artifact_signatures: array of the sig blobs (base64)
# sbom_attestation: the JSON object (the in-toto attestation) for the SBOM
# provenance_attestation: the JSON object for the provenance
# We assume there is only one of each? But there could be multiple signatures and multiple attestations.
# We can store:
# artifact_signatures: [ sig1, sig2, ... ]
# sbom_attestations: [ att1, att2, ... ] // but typically one SBOM
# provenance_attestations: [ att1, att2, ... ]
# But the requirement says "SBOMs" and "provenance", so maybe multiple?
# We'll store arrays.
# Then, we write the log entry.
#!/bin/bash
set -e
IMAGE=$1
ENVIRONMENT=$2
OPERATOR=$3
# Resolve the image to a digest
DIGEST=$(skopeo inspect docker://$IMAGE | jq -r '.Digest')
# Get the registry, repository, and tag (if needed) from the image.
# We assume the image is in the format: registry/repo:tag or registry/repo@digest
# If it's already a digest, we don't need to resolve.
# We'll use the OCI referrers API to get the list of artifacts that refer to the subject (the image digest).
# We need to construct the URL for the referrers index.
# Let's assume the image is in the format: $REGISTRY/$REPO:$TAG
# We have the DIGEST.
# The referrers API endpoint: /v2/<name>/referrers/<digest>
# We need to get the name (repository) and the registry.
# We can parse the image:
# if the image has a tag, then we can get the repo and tag.
# if the image has a digest, then we have the digest and the repo.
# Let's assume we have the image in the format: [registry/][repo][:tag|@digest]
# We can use reggo or a simple parser.
# For simplicity, assume the image is given as: registry/repo:tag and we resolve the tag to digest.
# Then, the repository is the part after the registry and before the colon.
# We can do:
REGISTRY=$(echo $IMAGE | cut -d/ -f1)
REPO=$(echo $IMAGE | cut -d/ -f2- | cut -d: -f1)
# Now, get the referrers index:
REFERRERS_URL="https://${REGISTRY}/v2/${REPO}/referrers/${DIGEST}"
# We need to be authorized? We assume we have credentials.
# We can use curl with authentication. Let's assume we have a token or basic auth.
# For simplicity, we assume we are in an environment where we can access the registry without auth (or with a token in the environment).
# We'll use:
# curl -H "Accept: application/vnd.oci.referrers.index.v1+json" $REFERRERS_URL
# This returns a JSON with a list of artifact digests and their media types.
# Then for each artifact, we fetch the blob:
# https://$REGISTRY/v2/$REPO/blobs/<digest>
# We store each blob by its media type and digest.
# We'll group by media type:
# artifact_signature: media type "application/vnd.dev.cosign.sig"
# in-toto attestations: media type "application/vnd.in-toto+json"
# Then for each in-toto attestation, we parse the payloadType to determine if it's SBOM or provenance.
# We'll store:
# artifact_signatures: array of base64 of the sig blobs.
# sbom_attestations: array of the in-toto JSON objects (with payload and signatures) for SBOM.
# provenance_attestations: array of the in-toto JSON objects for provenance.
# Then we write the log entry.
# We must be cautious: the same attestation might be stored multiple times? We are fetching by referrers, so we get all.
# We'll assume we get at most one of each type? But there could be multiple signatures and multiple attestations.
# We'll store all.
# Then, we create a JSON object for the log entry.
# We can use jq to build the JSON.
# Let's do:
# deployment_id = uuidgen
# artifact_digest = $DIGEST
# artifact_type = "container" # we can get from the manifest? But for simplicity, we assume container.
# registry_url = $IMAGE # or the full URL with digest? We can store the original image reference and the digest.
# Then, the arrays for signatures and attestations.
# We'll write the JSON to stdout and then insert into the database.
# However, this script is getting long and complex.
# Given the constraints, we might want to use existing tools.
# Alternatively, we can use cosign to download the attestations and then we use the registry to download the signature.
# But cosign doesn't download the artifact signature blob.
# So we have to use the registry API.
# We can write a Go or Python script to do this.
# But since the problem is to compose the workflow, we can describe it in pseudocode.
# Let's write the steps in pseudocode:
# function deploy(image, environment, operator):
# digest = resolve_digest(image)
# registry, repo = parse_registry_and_repo(image)
# referrers = fetch_referrers(registry, repo, digest)
# artifact_signatures = []
# sbom_attestations = []
# provenance_attestations = []
# for each referrer in referrers:
# blob = fetch_blob(registry, repo, referrer.digest)
# if referrer.media_type == "application/vnd.dev.cosign.sig":
# artifact_signatures.append(blob)
# elif referrer.media_type == "application/vnd.in-toto+json":
# attestation = parse_json(blob)
# if attestation.payloadType == "application/vnd.cyclonedx+json" or ...:
# sbom_attestations.append(attestation)
# elif attestation.payloadType == "application/vnd.slsa.provenance.v1+json":
# provenance_attestations.append(attestation)
# deployment_id = generate_uuid()
# log_entry = {
# deployment_id: deployment_id,
# artifact_digest: digest,
# artifact_type: "container",
# registry_url: image, # or the original image reference
# artifact_signatures: artifact_signatures,
# sbom_attestations: sbom_attestations,
# provenance_attestations: provenance_attestations,
# deployment_timestamp: now(),
# environment: environment,
# operator: operator
# }
# store_in_log(log_entry)
# We assume the log is a database that can store JSON.