Skip to content

Commit 531ca81

Browse files
committed
cache: sign and verify only if oidc token available
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
1 parent 2ba0b6d commit 531ca81

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

.github/workflows/bake.yml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ jobs:
152152
outputs:
153153
includes: ${{ steps.set.outputs.includes }}
154154
sign: ${{ steps.set.outputs.sign }}
155-
privateRepo: ${{ steps.set.outputs.privateRepo }}
155+
ghaCacheSign: ${{ steps.set.outputs.ghaCacheSign }}
156156
steps:
157157
-
158158
name: Install @docker/actions-toolkit
@@ -162,13 +162,17 @@ jobs:
162162
with:
163163
script: |
164164
await exec.exec('npm', ['install', '--prefer-offline', '--ignore-scripts', core.getInput('dat-module')]);
165+
-
166+
name: Expose GitHub Runtime
167+
uses: crazy-max/ghaction-github-runtime@3cb05d89e1f492524af3d41a1c98c83bc3025124 # v3.1.0
165168
-
166169
name: Set outputs
167170
id: set
168171
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
169172
env:
170173
INPUT_SBOM-IMAGE: ${{ env.SBOM_IMAGE }}
171174
INPUT_MATRIX-SIZE-LIMIT: ${{ env.MATRIX_SIZE_LIMIT }}
175+
INPUT_ACTIONS-ID-TOKEN-SET: ${{ env.ACTIONS_ID_TOKEN_REQUEST_TOKEN != '' && env.ACTIONS_ID_TOKEN_REQUEST_URL != '' }}
172176
INPUT_RUNNER: ${{ inputs.runner }}
173177
INPUT_ARTIFACT-UPLOAD: ${{ inputs.artifact-upload }}
174178
INPUT_CONTEXT: ${{ inputs.context }}
@@ -189,6 +193,7 @@ jobs:
189193
190194
const inpSbomImage = core.getInput('sbom-image');
191195
const inpMatrixSizeLimit = parseInt(core.getInput('matrix-size-limit'), 10);
196+
const inpActionsIdTokenSet = core.getBooleanInput('actions-id-token-set');
192197
193198
const inpRunner = core.getInput('runner');
194199
const inpArtifactUpload = core.getBooleanInput('artifact-upload');
@@ -271,6 +276,8 @@ jobs:
271276
core.setOutput('privateRepo', privateRepo);
272277
});
273278
279+
core.setOutput('ghaCacheSign', inpActionsIdTokenSet ? 'true' : 'false');
280+
274281
await core.group(`Set includes output`, async () => {
275282
let includes = [];
276283
if (platforms.length === 0) {
@@ -373,9 +380,9 @@ jobs:
373380
[cache]
374381
[cache.gha]
375382
[cache.gha.sign]
376-
command = ["ghacache-sign-script.sh"]
383+
command = [${{ needs.prepare.outputs.ghaCacheSign == 'true' && '"ghacache-sign-script.sh"' || '' }}]
377384
[cache.gha.verify]
378-
required = true
385+
required = ${{ needs.prepare.outputs.ghaCacheSign }}
379386
[cache.gha.verify.policy]
380387
timestampThreshold = 1
381388
tlogThreshold = ${{ needs.prepare.outputs.privateRepo == 'true' && '0' || '1' }}

.github/workflows/build.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ jobs:
160160
includes: ${{ steps.set.outputs.includes }}
161161
sign: ${{ steps.set.outputs.sign }}
162162
privateRepo: ${{ steps.set.outputs.privateRepo }}
163+
ghaCacheSign: ${{ steps.set.outputs.ghaCacheSign }}
163164
steps:
164165
-
165166
name: Install @docker/actions-toolkit
@@ -175,6 +176,7 @@ jobs:
175176
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
176177
env:
177178
INPUT_MATRIX-SIZE-LIMIT: ${{ env.MATRIX_SIZE_LIMIT }}
179+
INPUT_ACTIONS-ID-TOKEN-SET: ${{ env.ACTIONS_ID_TOKEN_REQUEST_TOKEN != '' && env.ACTIONS_ID_TOKEN_REQUEST_URL != '' }}
178180
INPUT_RUNNER: ${{ inputs.runner }}
179181
INPUT_ARTIFACT-UPLOAD: ${{ inputs.artifact-upload }}
180182
INPUT_OUTPUT: ${{ inputs.output }}
@@ -187,6 +189,7 @@ jobs:
187189
const { Util } = require('@docker/actions-toolkit/lib/util');
188190
189191
const inpMatrixSizeLimit = parseInt(core.getInput('matrix-size-limit'), 10);
192+
const inpActionsIdTokenSet = core.getBooleanInput('actions-id-token-set');
190193
191194
const inpRunner = core.getInput('runner');
192195
const inpArtifactUpload = core.getBooleanInput('artifact-upload');
@@ -231,6 +234,8 @@ jobs:
231234
core.setOutput('privateRepo', privateRepo);
232235
});
233236
237+
core.setOutput('ghaCacheSign', inpActionsIdTokenSet ? 'true' : 'false');
238+
234239
await core.group(`Set includes output`, async () => {
235240
let includes = [];
236241
if (inpPlatforms.length === 0) {
@@ -332,9 +337,9 @@ jobs:
332337
[cache]
333338
[cache.gha]
334339
[cache.gha.sign]
335-
command = ["ghacache-sign-script.sh"]
340+
command = [${{ needs.prepare.outputs.ghaCacheSign == 'true' && '"ghacache-sign-script.sh"' || '' }}]
336341
[cache.gha.verify]
337-
required = true
342+
required = ${{ needs.prepare.outputs.ghaCacheSign }}
338343
[cache.gha.verify.policy]
339344
timestampThreshold = 1
340345
tlogThreshold = ${{ needs.prepare.outputs.privateRepo == 'true' && '0' || '1' }}

0 commit comments

Comments
 (0)