Skip to content

Commit b6d7cbf

Browse files
authored
chore: make build dirs of java builders unique (#2665)
Fixes the following from #2662: - The internal Action. It must add randomization and return a new output - The publish / download Actions. They need an additional input for the randomized name. --------- Signed-off-by: AdamKorcz <[email protected]>
1 parent 7e31fad commit b6d7cbf

File tree

8 files changed

+60
-15
lines changed

8 files changed

+60
-15
lines changed

.github/workflows/builder_gradle_slsa3.yml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,17 @@ on:
5050
description: "The sha256 of the provenance attestation uploaded to the workflow run."
5151
value: "${{ jobs.slsa-run.outputs.attestations-download-sha256 }}"
5252

53-
target-download-sha256:
54-
description: "The sha256 of the target uploaded to the workflow run."
53+
build-download-name:
54+
description: "The name of the build directory uploaded to the workflow run."
55+
# NOTE: This is an "untrusted" value returned from the build. Technically
56+
# the build could provide a build directory that doesn't match the
57+
# provenance but it would fail validation.
58+
value: "${{ fromJSON(jobs.slsa-run.outputs.build-artifacts-outputs).build-download-name }}"
59+
60+
build-download-sha256:
61+
description: "The sha256 of the build directory uploaded to the workflow run."
5562
# NOTE: This is an "untrusted" value returned from the build.
56-
value: "${{ fromJSON(jobs.slsa-run.outputs.build-artifacts-outputs).target-download-sha256 }}"
63+
value: "${{ fromJSON(jobs.slsa-run.outputs.build-artifacts-outputs).build-download-sha256 }}"
5764
jobs:
5865
slsa-setup:
5966
permissions:

.github/workflows/builder_maven_slsa3.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@ on:
4747
description: "The sha256 of the provenance attestation uploaded to the workflow run."
4848
value: "${{ jobs.slsa-run.outputs.attestations-download-sha256 }}"
4949

50+
target-download-name:
51+
description: "The name of the target directory uploaded to the workflow run."
52+
# NOTE: This is an "untrusted" value returned from the build. Technically
53+
# the build could provide a target directory that doesn't match the
54+
# provenance but it would fail validation.
55+
value: ${{ fromJSON(jobs.slsa-run.outputs.build-artifacts-outputs).package-download-name }}
56+
5057
target-download-sha256:
5158
description: "The sha256 of the target uploaded to the workflow run."
5259
value: "${{ fromJSON(jobs.slsa-run.outputs.build-artifacts-outputs).target-download-sha256 }}"

actions/gradle/publish/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,15 +260,16 @@ publish:
260260
with:
261261
provenance-download-name: "${{ needs.build.outputs.provenance-download-name }}"
262262
provenance-download-sha256: "${{ needs.build.outputs.provenance-download-sha256 }}"
263-
target-download-sha256: "${{ needs.build.outputs.target-download-sha256 }}"
263+
build-download-name: "${{ needs.build.outputs.build-download-name }}"
264+
build-download-sha256: "${{ needs.build.outputs.build-download-sha256 }}"
264265
maven-username: ${{ secrets.OSSRH_USERNAME }}
265266
maven-password: ${{ secrets.OSSRH_PASSWORD }}
266267
gpg-key-pass: ${{ secrets.GPG_PASSPHRASE }}
267268
gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }}
268269
jdk-version: "17"
269270
```
270271
271-
Set the values of "maven-username", "maven-password", "gpg-key-pass" and " gpg-private-key" for your account. The parameters to `provenance-download-name`, `provenance-download-sha256` and `target-download-sha256` should not be changed.
272+
Set the values of "maven-username", "maven-password", "gpg-key-pass" and " gpg-private-key" for your account. The parameters to `provenance-download-name`, `provenance-download-sha256`, `target-download-name`, and `target-download-sha256` should not be changed.
272273

273274
Once you trigger this workflow, your artifacts and provenance files will be added to a staging repository in Maven Central. You need to close the staging repository and then release:
274275

actions/gradle/publish/action.yml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,12 @@ inputs:
2222
description: "The sha256 of the package provenance artifact."
2323
required: false
2424
type: string
25-
target-download-sha256:
26-
description: "The sha256 of the target directory."
25+
build-download-name:
26+
description: "The name of the build directory from the build action."
27+
required: true
28+
type: string
29+
build-download-sha256:
30+
description: "The sha256 of the build directory."
2731
required: true
2832
type: string
2933
jdk-version:
@@ -68,12 +72,12 @@ runs:
6872
path: ./
6973
sha256: "${{ inputs.provenance-download-sha256 }}"
7074

71-
- name: Download the target dir
75+
- name: Download the build dir
7276
uses: slsa-framework/slsa-github-generator/.github/actions/secure-download-folder@main
7377
with:
74-
name: build
78+
name: "${{ inputs.build-download-name }}"
7579
path: ./
76-
sha256: "${{ inputs.target-download-sha256 }}"
80+
sha256: "${{ inputs.build-download-sha256 }}"
7781
- name: Upload to Maven Central
7882
shell: bash
7983
env:

actions/maven/publish/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,15 @@ publish:
4949
with:
5050
provenance-download-name: "${{ needs.build.outputs.provenance-download-name }}"
5151
provenance-download-sha256: "${{ needs.build.outputs.provenance-download-sha256 }}"
52+
target-download-name: "${{ needs.build.outputs.target-download-name }}"
5253
target-download-sha256: "${{ needs.build.outputs.target-download-sha256 }}"
5354
maven-username: ${{ secrets.OSSRH_USERNAME }}
5455
maven-password: ${{ secrets.OSSRH_PASSWORD }}
5556
gpg-key-pass: ${{ secrets.GPG_PASSPHRASE }}
5657
gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }}
5758
```
5859
59-
Set the values of "maven-username", "maven-password", "gpg-key-pass" and " gpg-private-key" for your account. The parameters to `provenance-download-name`, `provenance-download-sha256` and `target-download-sha256` should not be changed.
60+
Set the values of "maven-username", "maven-password", "gpg-key-pass" and " gpg-private-key" for your account. The parameters to `provenance-download-name`, `provenance-download-sha256`, `target-download-name`, and `target-download-sha256` should not be changed.
6061

6162
Once you trigger this workflow, your artifacts and provenance files will be added to a staging repository in Maven Central. You need to close the staging repository and then release:
6263

actions/maven/publish/action.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ inputs:
2121
description: "The sha256 of the package provenance artifact."
2222
required: true
2323
type: string
24+
target-download-name:
25+
description: "The name of the target directory."
26+
required: true
27+
type: string
2428
target-download-sha256:
2529
description: "The sha256 of the target directory."
2630
required: true
@@ -67,7 +71,7 @@ runs:
6771
- name: Download the target dir
6872
uses: slsa-framework/slsa-github-generator/.github/actions/secure-download-folder@main
6973
with:
70-
name: target
74+
name: "${{ inputs.target-download-name }}"
7175
path: ./
7276
sha256: "${{ inputs.target-download-sha256 }}"
7377

internal/builders/gradle/action.yml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,17 @@ inputs:
4040
slsa-workflow-secret14: {}
4141
slsa-workflow-secret15: {}
4242
outputs:
43-
target-download-sha256:
43+
build-download-sha256:
4444
description: >
4545
The sha256 digest of the "build" directory.
4646
4747
Users should verify the download against this digest to prevent tampering.
4848
value: ${{ steps.upload-build-dir.outputs.sha256 }}
4949

50+
build-download-name:
51+
description: "Name of the artifact to download the build directory."
52+
value: "${{ steps.rng.outputs.random }}-build"
53+
5054
on:
5155
workflow_call:
5256
runs:
@@ -93,6 +97,12 @@ runs:
9397
cd "${project_root}" \
9498
&& ./gradlew build -x test
9599
100+
# rng generates a random number to avoid name collision in artifacts
101+
# when multiple workflows run concurrently.
102+
- name: Generate random 16-byte value (32-char hex encoded)
103+
id: rng
104+
uses: slsa-framework/slsa-github-generator/.github/actions/rng@main
105+
96106
- name: Put release artifacts in one directory
97107
shell: bash
98108
env:
@@ -119,5 +129,5 @@ runs:
119129
id: upload-build-dir
120130
uses: slsa-framework/slsa-github-generator/.github/actions/secure-upload-folder@main
121131
with:
122-
name: build
132+
name: "${{ steps.rng.outputs.random }}-build"
123133
path: build

internal/builders/maven/action.yml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ outputs:
4747
Users should verify the download against this digest to prevent tampering.
4848
value: ${{ steps.upload-target.outputs.sha256 }}
4949

50+
target-download-name:
51+
description: "Name of the artifact to download the target directory."
52+
value: "${{ steps.rng.outputs.random }}-target"
53+
5054
on:
5155
workflow_call:
5256
runs:
@@ -103,9 +107,16 @@ runs:
103107
# not be in GITHUB_WORKSPACE, so we need to move the file.
104108
mv $(dirname "${SLSA_OUTPUTS_ARTIFACTS_FILE}") "${GITHUB_WORKSPACE}/../"
105109
mv target "${GITHUB_WORKSPACE}/"
110+
111+
# rng generates a random number to avoid name collision in artifacts
112+
# when multiple workflows run concurrently.
113+
- name: Generate random 16-byte value (32-char hex encoded)
114+
id: rng
115+
uses: slsa-framework/slsa-github-generator/.github/actions/rng@main
116+
106117
- name: Upload target
107118
id: upload-target
108119
uses: slsa-framework/slsa-github-generator/.github/actions/secure-upload-folder@main
109120
with:
110-
name: target
121+
name: "${{ steps.rng.outputs.random }}-target"
111122
path: target

0 commit comments

Comments
 (0)