Skip to content

Commit f403daf

Browse files
committed
revert disable provenance by default if not set
This partially reverts 337a09d but keeps the newly added tests. Signed-off-by: CrazyMax <[email protected]>
1 parent 1104d47 commit f403daf

File tree

3 files changed

+34
-8
lines changed

3 files changed

+34
-8
lines changed

.github/workflows/ci.yml

+5
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,11 @@ jobs:
606606
if: matrix.target == 'binary'
607607
run: |
608608
tree /tmp/buildx-build
609+
-
610+
name: Print provenance
611+
if: matrix.target == 'binary'
612+
run: |
613+
cat /tmp/buildx-build/provenance.json | jq
609614
-
610615
name: Print SBOM
611616
if: matrix.target == 'binary'

__tests__/context.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ nproc=3`],
557557
[
558558
'build',
559559
'--iidfile', '/tmp/.docker-build-push-jest/iidfile',
560-
"--provenance", 'false',
560+
"--provenance", `mode=min,inline-only=true,builder-id=https://github.com/docker/build-push-action/actions/runs/123456789`,
561561
'--metadata-file', '/tmp/.docker-build-push-jest/metadata-file',
562562
'.'
563563
]

src/context.ts

+28-7
Original file line numberDiff line numberDiff line change
@@ -169,14 +169,17 @@ async function getBuildArgs(inputs: Inputs, defaultContext: string, context: str
169169
if (inputs.provenance) {
170170
args.push('--provenance', inputs.provenance);
171171
} else if ((await buildx.satisfiesBuildKitVersion(inputs.builder, '>=0.11.0', standalone)) && !hasDockerExport(inputs)) {
172-
// If provenance not specified but BuildKit version compatible for
173-
// attestation, disable provenance anyway. Also needs to make sure user
172+
// if provenance not specified and BuildKit version compatible for
173+
// attestation, set default provenance. Also needs to make sure user
174174
// doesn't want to explicitly load the image to docker.
175-
// While this action successfully pushes OCI compliant images to
176-
// well-known registries, some runtimes (e.g. Google Cloud Run and AWS
177-
// Lambda) are not able to pull resulting image from their own registry...
178-
// See also https://github.com/docker/buildx/issues/1533
179-
args.push('--provenance', 'false');
175+
if (fromPayload('repository.private') !== false) {
176+
// if this is a private repository, we set the default provenance
177+
// attributes being set in buildx: https://github.com/docker/buildx/blob/fb27e3f919dcbf614d7126b10c2bc2d0b1927eb6/build/build.go#L603
178+
args.push('--provenance', getProvenanceAttrs(`mode=min,inline-only=true`));
179+
} else {
180+
// for a public repository, we set max provenance mode.
181+
args.push('--provenance', getProvenanceAttrs(`mode=max`));
182+
}
180183
}
181184
if (inputs.sbom) {
182185
args.push('--sbom', inputs.sbom);
@@ -278,6 +281,24 @@ export const asyncForEach = async (array, callback) => {
278281
}
279282
};
280283

284+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
285+
function fromPayload(path: string): any {
286+
return select(github.context.payload, path);
287+
}
288+
289+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
290+
function select(obj: any, path: string): any {
291+
if (!obj) {
292+
return undefined;
293+
}
294+
const i = path.indexOf('.');
295+
if (i < 0) {
296+
return obj[path];
297+
}
298+
const key = path.slice(0, i);
299+
return select(obj[key], path.slice(i + 1));
300+
}
301+
281302
function getProvenanceInput(name: string): string {
282303
const input = core.getInput(name);
283304
if (!input) {

0 commit comments

Comments
 (0)