Skip to content

Commit

Permalink
build: add imagetools examples for inspecting attestations
Browse files Browse the repository at this point in the history
Signed-off-by: Justin Chadwell <[email protected]>
  • Loading branch information
jedevc committed Jan 10, 2023
1 parent 04c7027 commit 0536aeb
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 1 deletion.
32 changes: 32 additions & 0 deletions build/attestations/sbom.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,38 @@ sbom-hugo.spdx.json
sbom.spdx.json
```

## Inspecting SBOMs

To explore created SBOMs exported through the `image` exporter, you can use
[`imagetools inspect`](../../engine/reference/commandline/buildx_imagetools_inspect.md).

Using the `--format` option, you can specify a template for the output. All
SBOM-related data is available under the `.SBOM` attribute. For example, to get
the raw contents of an SBOM in SPDX format:

```console
$ docker buildx imagetools inspect <namespace>/<image>:<version> \
--format "{{ json .SBOM.SPDX }}"
{
"SPDXID": "SPDXRef-DOCUMENT",
...
}
```

You can also construct more complex expressions using the full functionality
of go templates. For example, you can list all the installed packages and their
version identifiers:

```console
$ docker buildx imagetools inspect <namespace>/<image>:<version> \
--format "{{ range .SBOM.SPDX.packages }}{{ .name }}@{{ .versionInfo }}{{ println }}{{ end }}"
[email protected]
[email protected]
[email protected]
[email protected]
...
```

## SBOM attestation example

The following JSON example shows what an SBOM attestation might look like.
Expand Down
32 changes: 31 additions & 1 deletion build/attestations/slsa-provenance.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,37 @@ using build arguments, consider refactoring builds to pass secret values using
[build secrets](../../engine/reference/commandline/buildx_build.md#secret), to
prevent leaking of sensitive information.

## Example
## Inspecting Provenance

To explore created Provenance exported through the `image` exporter, you can
use [`imagetools inspect`](../../engine/reference/commandline/buildx_imagetools_inspect.md).

Using the `--format` option, you can specify a template for the output. All
provenance-related data is available under the `.Provenance` attribute. For
example, to get the raw contents of the Provenance in the SLSA format:

```console
$ docker buildx imagetools inspect <namespace>/<image>:<version> \
--format "{{ json .Provenance.SLSA }}"
{
"buildType": "https://mobyproject.org/buildkit@v1",
...
}
```

You can also construct more complex expressions using the full functionality of
go templates. For example, for provenance generated with `mode=max`, you can
extract the full source code of the Dockerfile used to build the image:

```console
$ docker buildx imagetools inspect <namespace>/<image>:<version> \
--format '{{ range (index .Provenance.SLSA.metadata "https://mobyproject.org/buildkit@v1#metadata").source.infos }}{{ if eq .filename "Dockerfile" }}{{ .data }}{{ end }}{{ end }}' | base64 -d
FROM ubuntu:20.04
RUN apt-get update
...
```

## Provenance attestation example

<!-- TODO: add a link to the definitions page, imported from moby/buildkit -->

Expand Down

0 comments on commit 0536aeb

Please sign in to comment.