Skip to main content

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 images
  • DockerComposeProvenanceVerifier - 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 workflows
  • verify_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 verification
  • ServiceVerificationResult - Result for a single service in docker-compose
  • ProvenanceVerificationResult - 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.yml workflow

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

docker_slsa-0.1.0.tar.gz (9.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

docker_slsa-0.1.0-py3-none-any.whl (12.2 kB view details)

Uploaded Python 3

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

Hashes for docker_slsa-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d62cb70bd4599e3d3767bb0d365621eacb89babd6161968fda02f852a9b3038d
MD5 42071b21e092c52a75d7bc98fb67a53b
BLAKE2b-256 29a78fddd8fcb9dcedfad02abffd675d1ad93caff3149cb9b1401151fdc761bf

See more details on using hashes here.

Provenance

The following attestation bundles were made for docker_slsa-0.1.0.tar.gz:

Publisher: publish.yml on concrete-security/docker-slsa

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for docker_slsa-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 afb0e529fdba8efc1dc6e9d212d8097d7bf3eda6074c109c400b735fc618585e
MD5 220bf359ee1e54ae4eec70cf3c4a291b
BLAKE2b-256 308c41c4937a3fd2d85aa65e01a42c3ca70e08c5a175e0eb7253e5beb0fd28a2

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page