Skip to content

Commit d107281

Browse files
sxdmnenciagbartolini
authored
chore: add SLSA provenance to release binaries and container images (#10048)
Add SLSA3 provenance attestation for release binaries (via slsa-framework generator_generic_slsa3) and container images (via generator_container_slsa3) in both the release and CI workflows, satisfying the OpenSSF Scorecard signed-releases check. Closes #9440 Signed-off-by: Jonathan Gonzalez V. <[email protected]> Signed-off-by: Marco Nenciarini <[email protected]> Signed-off-by: Gabriele Bartolini <[email protected]> Co-authored-by: Marco Nenciarini <[email protected]> Co-authored-by: Gabriele Bartolini <[email protected]>
1 parent aa240d8 commit d107281

6 files changed

Lines changed: 158 additions & 4 deletions

File tree

‎.github/workflows/continuous-integration.yml‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,7 @@ jobs:
424424
bundle_img: ${{ env.BUNDLE_IMG }}
425425
catalog_img: ${{ env.CATALOG_IMG }}
426426
push: ${{ env.PUSH }}
427+
images_matrix: ${{ steps.images_matrix.outputs.images_matrix }}
427428
steps:
428429
- name: Checkout
429430
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
@@ -645,6 +646,47 @@ jobs:
645646
)
646647
cosign sign --yes ${images}
647648
649+
- name: Prepare images matrix
650+
if: env.PUSH == 'true'
651+
id: images_matrix
652+
env:
653+
BAKE_METADATA: ${{ steps.bake-push.outputs.metadata }}
654+
shell: bash
655+
run: |
656+
images_matrix=$(echo "$BAKE_METADATA" |
657+
jq -r -c '
658+
del(.[].["containerimage.descriptor", "buildx.build.ref"])
659+
| to_entries
660+
| map({variant: .key} + .value + {"image.name": (.value["image.name"] | split(",")[0] | sub(":[^/]+$"; ""))})
661+
'
662+
)
663+
echo "images_matrix=${images_matrix}" >> "$GITHUB_OUTPUT"
664+
665+
provenance:
666+
name: Provenance for images
667+
if: |
668+
(always() && !cancelled()) &&
669+
needs.buildx.result == 'success' &&
670+
needs.buildx.outputs.push == 'true'
671+
needs:
672+
- buildx
673+
permissions:
674+
actions: read
675+
id-token: write
676+
packages: write
677+
strategy:
678+
matrix:
679+
include: ${{ fromJson(needs.buildx.outputs.images_matrix) }}
680+
# NOTE: pinned by tag, not SHA — the SLSA generator's builder-fetch.sh
681+
# resolves the binary download URL from the git ref and breaks with SHA pins.
682+
# See: https://github.com/slsa-framework/slsa-github-generator/issues/4216
683+
uses: slsa-framework/slsa-github-generator/.github/workflows/[email protected]
684+
with:
685+
image: ${{ matrix['image.name'] }}
686+
digest: ${{ matrix['containerimage.digest'] }}
687+
registry-username: ${{ github.actor }}
688+
secrets:
689+
registry-password: ${{ secrets.GITHUB_TOKEN }}
648690

649691
olm-bundle:
650692
name: Create OLM bundle and catalog

‎.github/workflows/release-publish.yml‎

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ jobs:
122122
author_email: ${{ steps.build-meta.outputs.author_email }}
123123
platforms: ${{ env.PLATFORMS }}
124124
olm_img: ${{ steps.olm-image.outputs.olm_image }}
125+
hashes: ${{ steps.hashes.outputs.hashes }}
126+
images_matrix: ${{ steps.images_matrix.outputs.images_matrix }}
125127
steps:
126128
-
127129
name: Checkout
@@ -175,6 +177,7 @@ jobs:
175177
echo "$GPG_PRIVATE_KEY" > gpg_signing_key.asc
176178
-
177179
name: Run GoReleaser
180+
id: goreleaser
178181
uses: goreleaser/goreleaser-action@e435ccd777264be153ace6237001ef4d979d3a7a # v6
179182
with:
180183
distribution: goreleaser
@@ -187,6 +190,16 @@ jobs:
187190
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
188191
GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }}
189192
NFPM_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
193+
194+
- name: Build checksum file
195+
id: hashes
196+
env:
197+
ARTIFACTS: "${{ steps.goreleaser.outputs.artifacts }}"
198+
shell: bash
199+
run: |
200+
checksum_file=$(echo "$ARTIFACTS" | jq -r '.[] | select (.type=="Checksum") | .path')
201+
echo "hashes=$(cat $checksum_file | base64 -w0)" >> "$GITHUB_OUTPUT"
202+
190203
-
191204
name: Publish Krew
192205
if: |
@@ -257,6 +270,58 @@ jobs:
257270
ubi_tags: ${{ fromJSON(steps.bake-push.outputs.metadata)['ubi']['image.name'] }}
258271
run: |
259272
echo "olm_image=$(echo "$ubi_tags" | tr ',' '\n' | grep -v 'latest' | sed 's/^ *//g' | head -n 1)" >> $GITHUB_OUTPUT
273+
-
274+
name: Prepare images matrix
275+
id: images_matrix
276+
env:
277+
BAKE_METADATA: ${{ steps.bake-push.outputs.metadata }}
278+
shell: bash
279+
run: |
280+
images_matrix=$(echo "$BAKE_METADATA" |
281+
jq -r -c '
282+
del(.[].["containerimage.descriptor", "buildx.build.ref"])
283+
| to_entries
284+
| map({variant: .key} + .value + {"image.name": (.value["image.name"] | split(",")[0] | sub(":[^/]+$"; ""))})
285+
'
286+
)
287+
echo "images_matrix=${images_matrix}" >> "$GITHUB_OUTPUT"
288+
289+
provenance-binaries:
290+
name: Add provenance to binaries
291+
needs:
292+
- release-binaries
293+
permissions:
294+
actions: read
295+
id-token: write
296+
contents: write
297+
# NOTE: pinned by tag, not SHA — the SLSA generator's builder-fetch.sh
298+
# resolves the binary download URL from the git ref and breaks with SHA pins.
299+
# See: https://github.com/slsa-framework/slsa-github-generator/issues/4216
300+
uses: slsa-framework/slsa-github-generator/.github/workflows/[email protected]
301+
with:
302+
base64-subjects: "${{ needs.release-binaries.outputs.hashes }}"
303+
upload-assets: true
304+
305+
provenance-images:
306+
name: Provenance for images
307+
needs:
308+
- release-binaries
309+
permissions:
310+
actions: read
311+
id-token: write
312+
packages: write
313+
strategy:
314+
matrix:
315+
include: ${{ fromJson(needs.release-binaries.outputs.images_matrix) }}
316+
# NOTE: pinned by tag, not SHA — see comment on provenance-binaries above.
317+
uses: slsa-framework/slsa-github-generator/.github/workflows/[email protected]
318+
with:
319+
image: ${{ matrix['image.name'] }}
320+
digest: ${{ matrix['containerimage.digest'] }}
321+
registry-username: ${{ github.actor }}
322+
secrets:
323+
registry-password: ${{ secrets.GITHUB_TOKEN }}
324+
260325

261326
olm-bundle:
262327
name: Create OLM bundle and catalog

‎.wordlist-en-custom.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1405,6 +1405,7 @@ sigs
14051405
sigstore
14061406
singlenamespace
14071407
slotPrefix
1408+
slsa
14081409
smartShutdownTimeout
14091410
snapshotBackupStatus
14101411
snapshotOwnerReference

‎SECURITY-INSIGHTS.yml‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,19 @@ repository:
203203
adhoc: true
204204
ci: true
205205
release: true
206+
- name: SLSA GitHub Generator Action
207+
type: automated-tooling
208+
rulesets: ["default"]
209+
comment: >-
210+
Generates non-falsifiable SLSA Level 3 provenance attestations for
211+
release assets. This ensures that the binary artifacts and images are traced
212+
back to the specific source commit and build environment without manual
213+
intervention.
214+
215+
integration:
216+
adhoc: false
217+
ci: true
218+
release: true
206219

207220
assessments:
208221
self:

‎docs/src/installation_upgrade.md‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,19 @@ cosign verify-blob \
391391
--certificate-oidc-issuer "https://token.actions.githubusercontent.com"
392392
```
393393

394+
#### Verifying SLSA provenance
395+
396+
To verify a release binary, download both the artifact and the provenance file
397+
(`multiple.intoto.jsonl`) from the
398+
[GitHub release](https://github.com/cloudnative-pg/cloudnative-pg/releases),
399+
then run:
400+
401+
```shell
402+
slsa-verifier verify-artifact <ARTIFACT> \
403+
--provenance-path multiple.intoto.jsonl \
404+
--source-uri github.com/cloudnative-pg/cloudnative-pg
405+
```
406+
394407
### Verifying the operator container images
395408

396409
Run the following command to verify the signature of the CloudNativePG operator
@@ -420,6 +433,11 @@ docker buildx imagetools inspect ghcr.io/cloudnative-pg/cloudnative-pg:{tag} \
420433
--format '{{ json (index .Provenance "linux/amd64").SLSA }}'
421434
```
422435

436+
:::info
437+
Refer to ["Verifying SLSA provenance"](security.md#verifying-slsa-provenance)
438+
for SLSA Build Level 3 compliance verification.
439+
:::
440+
423441
### Verifying PostgreSQL operand images
424442

425443
CloudNativePG maintains container images for all supported PostgreSQL versions

‎docs/src/security.md‎

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,11 @@ traceability:
149149
comprehensive list of software artifacts included in the image or used during
150150
its build process, formatted using the
151151
[in-toto SPDX predicate standard](https://github.com/in-toto/attestation/blob/main/spec/predicates/spdx.md).
152-
- **[Provenance](https://docs.docker.com/build/metadata/attestations/slsa-provenance/):**
153-
Metadata detailing how the image was built, following the [SLSA Provenance](https://slsa.dev)
154-
framework.
152+
- **Provenance:** Metadata detailing the build process, generated via the
153+
[SLSA GitHub Generator Github action](https://github.com/slsa-framework/slsa-github-generator).
154+
This provides [SLSA Level 3 assurance](https://slsa.dev/spec/v1.0/levels)
155+
that the artifact was built on a trusted, isolated GitHub Actions runner
156+
directly from the project's source.
155157

156158
You can retrieve the SBOM for a specific image and platform using the following
157159
command:
@@ -164,13 +166,26 @@ docker buildx imagetools inspect <IMAGE> \
164166
This command outputs the SBOM in JSON format, providing a detailed view of the
165167
software components and build dependencies.
166168

167-
For the provenance, use:
169+
For the build-level provenance, use:
168170

169171
```shell
170172
docker buildx imagetools inspect <IMAGE> \
171173
--format '{{ json (index .Provenance "<PLATFORM>").SLSA }}'
172174
```
173175

176+
#### Verifying SLSA provenance
177+
178+
You can verify SLSA Level 3 provenance using
179+
[`slsa-verifier`](https://github.com/slsa-framework/slsa-verifier).
180+
181+
To verify a container image, pass its digest reference:
182+
183+
```shell
184+
slsa-verifier verify-image \
185+
ghcr.io/cloudnative-pg/cloudnative-pg@sha256:<DIGEST> \
186+
--source-uri github.com/cloudnative-pg/cloudnative-pg
187+
```
188+
174189
### Guidelines and Frameworks for Container Security
175190

176191
The following guidelines and frameworks have been considered for ensuring

0 commit comments

Comments
 (0)