Verify SLSA provenance attestations for Docker container images
Project description
docker-slsa
Verify SLSA provenance attestations for Docker container images using Sigstore.
This library verifies container images built with the SLSA GitHub Generator for containers (generator_container_slsa3.yml).
Features
- Verify SLSA provenance for individual container images
- Batch verification for all images in a docker-compose file
- Built-in support for GitHub Actions SLSA container generator workflow
- Custom verification policies using sigstore's policy API
Installation
pip install docker-slsa
Quick Start
Verify a single container image
from docker_slsa import ContainerSLSAVerifier, build_default_policy
# Create a policy for GitHub Actions SLSA provenance
policy = build_default_policy(
expected_repo="org/repo",
expected_commit="abc123def456", # optional
)
# Verify the image
verifier = ContainerSLSAVerifier()
result = verifier.verify(
image_ref="ghcr.io/org/repo/image@sha256:...",
policy=policy,
)
if result.verified:
print("Verification passed!")
print(f"Provenance: {result.provenance}")
else:
print(f"Verification failed: {result.error}")
Verify all images in a docker-compose file
from docker_slsa import verify_docker_compose_provenance, build_default_policy
# Read your docker-compose file
with open("docker-compose.yml") as f:
docker_compose = f.read()
# Define policies for each service
service_policies = {
"web": build_default_policy("org/web-app"),
"api": build_default_policy("org/api-server"),
}
# Verify all services (raises ProvenanceVerificationError on failure)
result = verify_docker_compose_provenance(
docker_compose=docker_compose,
service_policies=service_policies,
ignore=["redis", "postgres"], # skip third-party images
)
print(f"All {len(result.service_results)} services verified!")
Custom verification policies
For advanced use cases, create custom policies using sigstore's policy API:
from sigstore.verify.policy import AllOf, AnyOf, OIDCIssuer, GitHubWorkflowRepository, Identity
policy = AllOf([
OIDCIssuer("https://token.actions.githubusercontent.com"),
GitHubWorkflowRepository("org/repo"),
AnyOf([
Identity(
identity="https://github.com/slsa-framework/slsa-github-generator/.github/workflows/generator_container_slsa3.yml@refs/tags/v2.0.0",
issuer="https://token.actions.githubusercontent.com",
),
Identity(
identity="https://github.com/slsa-framework/slsa-github-generator/.github/workflows/generator_container_slsa3.yml@refs/tags/v2.1.0",
issuer="https://token.actions.githubusercontent.com",
),
]),
])
API Reference
Classes
ContainerSLSAVerifier- Low-level verifier for individual container imagesDockerComposeProvenanceVerifier- Verifies all images in a docker-compose file
Functions
build_default_policy(expected_repo, expected_commit=None, expected_workflow_name=None)- Create a verification policy for GitHub Actions SLSA workflowsverify_docker_compose_provenance(docker_compose, service_policies, ignore=None)- Convenience function to verify a docker-compose file
Result Types
VerificationResult- Result for a single image verificationServiceVerificationResult- Result for a single service in docker-composeProvenanceVerificationResult- Aggregate result for all services
Exceptions
ProvenanceVerificationError- Raised when verification fails
Requirements
- Python 3.10+
- Network access to container registries and Sigstore services
- Container images must have SLSA provenance attestations generated by the SLSA GitHub Generator
generator_container_slsa3.ymlworkflow
Development
# Install dependencies
uv sync --group dev --group test
# Run tests
make test
# Run tests with coverage (95% required)
make test-coverage
# Format code
make format
# Lint code
make lint
# Run all QA checks
make qa-all
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file docker_slsa-0.1.0.tar.gz.
File metadata
- Download URL: docker_slsa-0.1.0.tar.gz
- Upload date:
- Size: 9.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d62cb70bd4599e3d3767bb0d365621eacb89babd6161968fda02f852a9b3038d
|
|
| MD5 |
42071b21e092c52a75d7bc98fb67a53b
|
|
| BLAKE2b-256 |
29a78fddd8fcb9dcedfad02abffd675d1ad93caff3149cb9b1401151fdc761bf
|
Provenance
The following attestation bundles were made for docker_slsa-0.1.0.tar.gz:
Publisher:
publish.yml on concrete-security/docker-slsa
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
docker_slsa-0.1.0.tar.gz -
Subject digest:
d62cb70bd4599e3d3767bb0d365621eacb89babd6161968fda02f852a9b3038d - Sigstore transparency entry: 799598833
- Sigstore integration time:
-
Permalink:
concrete-security/docker-slsa@6674949998009fffd0c35ff27fc6708725421486 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/concrete-security
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@6674949998009fffd0c35ff27fc6708725421486 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file docker_slsa-0.1.0-py3-none-any.whl.
File metadata
- Download URL: docker_slsa-0.1.0-py3-none-any.whl
- Upload date:
- Size: 12.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
afb0e529fdba8efc1dc6e9d212d8097d7bf3eda6074c109c400b735fc618585e
|
|
| MD5 |
220bf359ee1e54ae4eec70cf3c4a291b
|
|
| BLAKE2b-256 |
308c41c4937a3fd2d85aa65e01a42c3ca70e08c5a175e0eb7253e5beb0fd28a2
|
Provenance
The following attestation bundles were made for docker_slsa-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on concrete-security/docker-slsa
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
docker_slsa-0.1.0-py3-none-any.whl -
Subject digest:
afb0e529fdba8efc1dc6e9d212d8097d7bf3eda6074c109c400b735fc618585e - Sigstore transparency entry: 799598898
- Sigstore integration time:
-
Permalink:
concrete-security/docker-slsa@6674949998009fffd0c35ff27fc6708725421486 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/concrete-security
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@6674949998009fffd0c35ff27fc6708725421486 -
Trigger Event:
workflow_dispatch
-
Statement type: