@@ -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+
281302function getProvenanceInput ( name : string ) : string {
282303 const input = core . getInput ( name ) ;
283304 if ( ! input ) {
0 commit comments