Artifact attestations enable you to increase the supply chain security of your builds by establishing where and how your software was built.
Before you start generating artifact attestations, you need to understand what they are and when you should use them. See Artifact attestations.
You can use GitHub Actions to generate artifact attestations that establish build provenance for artifacts such as binaries and container images.
To generate an artifact attestation, you must:
- Ensure you have the appropriate permissions configured in your workflow.
- Include a step in your workflow that uses the
attest-build-provenanceaction.
When you run your updated workflows, they will build your artifacts and generate an artifact attestation that establishes build provenance. You can view attestations in your repository's Actions tab. For more information, see the attest-build-provenance repository.
-
In the workflow that builds the binary you would like to attest, add 2.719a.749.749 87.128 3.internal-network- permissions: actions github.com id-token: write contents: read attestations: write
-
After the step where the binary has been built, add the following step.
- name: Generate artifact attestation uses: actions/attest-build-provenance@v3 with: subject-path: 'PATH/TO/ARTIFACT'
The value of the
subject-pathparameter should be set to the path to the binary you want to attest.
-
In the workflow that builds the container image you would like to attest, add the following permissions.
permissions: id-token: write contents: read attestations: write packages: write
-
After the step where the image has been built, add the following step.
- name: Generate artifact attestation uses: actions/attest-build-provenance@v3 with: subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} subject-digest: 'sha256:fedcba0...' push-to-registry: true
The value of the
subject-nameparameter should specify the fully-qualified image name. For example,ghcr.io/user/apporacme.azurecr.io/user/app. Do not include a tag as part of the image name.The value of the
subject-digestparameter should be set to the SHA256 digest of the subject for the attestation, in the formsha256:HEX_DIGEST. If your workflow usesdocker/build-push-action, you can use thedigestoutput from that step to supply the value. For more information on using outputs, see Workflow syntax for GitHub Actions.
You can generate signed SBOM attestations for workflow artifacts.
To generate an attestation for an SBOM, you must:
- Ensure you have the appropriate permissions configured in your workflow.
- Create an SBOM for your artifact. For more information, see
anchore-sbom-actionin the GitHub Marketplace. - Include a step in your workflow that uses the
attest-sbomaction.
When you run your updated workflows, they will build your artifacts and generate an SBOM attestation. You can view attestations in your repository's Actions tab. For more information, see the attest-sbom action repository.
-
In the workflow that builds the binary you would like to attest, add the following permissions.
permissions: id-token: write contents: read attestations: write
-
After the step where the binary has been built, add the following step.
- name: Generate SBOM attestation uses: actions/attest-sbom@v2 with: subject-path: 'PATH/TO/ARTIFACT' sbom-path: 'PATH/TO/SBOM'
The value of the
subject-pathparameter should be set to the path of the binary the SBOM describes. The value of thesbom-pathparameter should be set to the path of the SBOM file you generated.
-
In the workflow that builds the container image you would like to attest, add the following permissions.
permissions: id-token: write contents: read attestations: write packages: write
-
After the step where the image has been built, add the following step.
- name: Generate SBOM attestation uses: actions/attest-sbom@v2 with: subject-name: ${{ env.REGISTRY }}/PATH/TO/IMAGE subject-digest: 'sha256:fedcba0...' sbom-path: 'sbom.json' push-to-registry: true
The value of the
subject-nameparameter should specify the fully-qualified image name. For example,ghcr.io/user/apporacme.azurecr.io/user/app. Do not include a tag as part of the image name.The value of the
subject-digestparameter should be set to the SHA256 digest of the subject for the attestation, in the formsha256:HEX_DIGEST. If your workflow usesdocker/build-push-action, you can use thedigestoutput from that step to supply the value. For more information on using outputs, see Workflow syntax for GitHub Actions.The value of the
sbom-pathparameter should be set to the path to the JSON-formatted SBOM file you want to attest.
We recommend uploading attested assets to your organization's linked artifacts page. This page displays artifacts' build history, deployment records, and storage details. You can use this data to prioritize security alerts or quickly connect vulnerable artifacts to their owning team, source code, and build run. For more information, see About linked artifacts.
The attest and attest-build-provenance actions automatically create storage records on the linked artifacts page if both:
- The
push-to-registryoption is set totrue - The workflow that includes the action has the
artifact-metadata: writepermission
For an example workflow, see Uploading storage and deployment data to the linked artifacts page.
You can validate artifact attestations for binaries and container images and validate SBOM attestations using the GitHub CLI. For more information, see the attestation section of the GitHub CLI manual.
[!NOTE]These commands assume you are in an online environment. If you are in an offline or air-gapped environment, see Verifying attestations offline.
To verify artifact attestations for binaries, use the following GitHub CLI command.
gh attestation verify PATH/TO/YOUR/BUILD/ARTIFACT-BINARY -R ORGANIZATION_NAME/REPOSITORY_NAMETo verify artifact attestations for container images, you must provide the image's FQDN prefixed with oci:// instead of the path to a binary. You can use the following GitHub CLI command.
docker login ghcr.io
gh attestation verify oci://ghcr.io/ORGANIZATION_NAME/IMAGE_NAME:test -R ORGANIZATION_NAME/REPOSITORY_NAMETo verify SBOM attestations, you have to provide the --predicate-type flag to reference a non-default predicate. For more information, see Vetted predicates in the in-toto/attestation repository.
For example, the attest-sbom action currently supports either SPDX or CycloneDX SBOM predicates. To verify an SBOM attestation in the SPDX format, you can use the following GitHub CLI command.
gh attestation verify PATH/TO/YOUR/BUILD/ARTIFACT-BINARY \
-R ORGANIZATION_NAME/REPOSITORY_NAME \
--predicate-type https://spdx.dev/Document/v2.3To view more information on the attestation, reference the --format json flag. This can be especially helpful when reviewing SBOM attestations.
gh attestation verify PATH/TO/YOUR/BUILD/ARTIFACT-BINARY \
-R ORGANIZATION_NAME/REPOSITORY_NAME \
--predicate-type https://spdx.dev/Document/v2.3 \
--format json \
--jq '.[].verificationResult.statement.predicate'To keep your attestations relevant and manageable, you should delete attestations that are no longer needed. See Managing the lifecycle of artifact attestations.
You can also generate release attestations to help consumers verify the integrity and origin of your releases. For more information, see Immutable releases.