Skip to content

Commit 20c6d52

Browse files
authored
feat: add Docker attest-images action for build provenance attestation
1 parent 80e3c63 commit 20c6d52

5 files changed

Lines changed: 455 additions & 1 deletion

File tree

.github/workflows/docker-build-images.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ This includes [multi-platform](https://docs.docker.com/build/building/multi-plat
3535
- **`issues`**: `read`
3636
- **`packages`**: `write`
3737
- **`pull-requests`**: `read`
38+
- **`attestations`**: `write` (only required when `attest: true`)
3839

3940
<!-- overview:end -->
4041

@@ -58,6 +59,7 @@ jobs:
5859
issues: read
5960
packages: write
6061
pull-requests: read
62+
attestations: write # only required when `attest: true`
6163
secrets:
6264
# Password or GitHub token (`packages:read` and `packages:write` scopes) configuration used to log against OCI registries.
6365
# Accepts either a single password/token string (default format) or a JSON object using the same keys as `oci-registry`.
@@ -178,6 +180,12 @@ jobs:
178180
#
179181
# Default: `true`
180182
sign: true
183+
184+
# Generate build provenance attestations for built images.
185+
# See [attest-images](../../actions/docker/attest-images/README.md).
186+
#
187+
# Default: `false`
188+
attest: false
181189
````
182190

183191
<!-- usage:end -->
@@ -229,6 +237,8 @@ jobs:
229237
| | <!-- textlint-disable --><pre lang="ini">[registry."my-registry.local:5000"]&#13; http = true&#13; insecure = true</pre><!-- textlint-enable --> | | | |
230238
| **`sign`** | Sign built images. | **false** | **boolean** | `true` |
231239
| | See [sign-images](../../actions/docker/sign-images/README.md). | | | |
240+
| **`attest`** | Generate build provenance attestations for built images. | **false** | **boolean** | `false` |
241+
| | See [attest-images](../../actions/docker/attest-images/README.md). | | | |
232242

233243
<!-- inputs:end -->
234244

.github/workflows/docker-build-images.yml

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,13 @@ on: # yamllint disable-line rule:truthy
123123
type: boolean
124124
default: true
125125
required: false
126+
attest:
127+
description: |
128+
Generate build provenance attestations for built images.
129+
See [attest-images](../../actions/docker/attest-images/README.md).
130+
type: boolean
131+
default: false
132+
required: false
126133
secrets:
127134
oci-registry-password:
128135
description: |
@@ -461,7 +468,8 @@ jobs:
461468
permissions:
462469
contents: read
463470
packages: write
464-
id-token: write # Needed for signing images
471+
id-token: write # Needed for signing and attesting images
472+
attestations: write # Needed for attesting images
465473
needs: [prepare-variables, build-images]
466474
runs-on: ${{ fromJson(inputs.runs-on) }}
467475
outputs:
@@ -542,3 +550,28 @@ jobs:
542550
with:
543551
images: ${{ steps.get-images-to-sign.outputs.images-to-sign }}
544552
github-token: ${{ secrets.GITHUB_TOKEN }}
553+
554+
- id: get-images-to-attest
555+
if: inputs.attest
556+
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
557+
env:
558+
BUILT_IMAGES_INPUT: ${{ steps.create-images-manifests.outputs.built-images }}
559+
with:
560+
script: |
561+
const builtImagesInput = process.env.BUILT_IMAGES_INPUT;
562+
let builtImages = null;
563+
try {
564+
builtImages = JSON.parse(builtImagesInput);
565+
} catch (error) {
566+
throw new Error(`"built-images" input is not a valid JSON: ${error}`);
567+
}
568+
569+
// Get images to attest
570+
const imagesToAttest = Object.values(builtImages).map(image => image.images).flat();
571+
core.setOutput('images-to-attest', JSON.stringify(imagesToAttest));
572+
573+
- uses: ./../self-workflow/actions/docker/attest-images
574+
if: steps.get-images-to-attest.outputs.images-to-attest
575+
with:
576+
images: ${{ steps.get-images-to-attest.outputs.images-to-attest }}
577+
github-token: ${{ secrets.GITHUB_TOKEN }}

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ _Actions that operate on OCI images across their build, metadata, and lifecycle
3939

4040
#### - [Setup](actions/docker/setup/README.md)
4141

42+
#### - [Attest images](actions/docker/attest-images/README.md)
43+
4244
#### - [Sign images](actions/docker/sign-images/README.md)
4345

4446
### Helm

0 commit comments

Comments
 (0)