|
| 1 | +# input: "build" object (with "buildId" top level key) |
| 2 | +# output: array of image tags |
| 3 | +def tags: |
| 4 | + .source.arches[].tags[], |
| 5 | + .source.arches[].archTags[], |
| 6 | + .build.img |
| 7 | +; |
| 8 | + |
| 9 | +# input: "build" object (with "buildId" top level key) |
| 10 | +# output: purl platform query string |
| 11 | +def platform_string: |
| 12 | + .source.arches[].platformString | gsub("/"; "%2F") |
| 13 | +; |
| 14 | + |
| 15 | +# input: "tags" object with image digest and platform arguments |
| 16 | +# output: json object for in-toto provenance subject field |
| 17 | +def subjects($platform; $digest): |
| 18 | + { |
| 19 | + "name": ("pkg:docker/" + . + "?platform=" + $platform), |
| 20 | + "digest": { |
| 21 | + "sha256": $digest |
| 22 | + } |
| 23 | + } |
| 24 | +; |
| 25 | + |
| 26 | +# input: GITHUB context argument |
| 27 | +# output: json object for in-toto provenance external parameters field |
| 28 | +def github_external_parameters($context): |
| 29 | +($context.workflow_ref | gsub( $context.repository + "/"; "")) as $workflowPathRef | |
| 30 | +{ |
| 31 | + inputs: $context.event.inputs, |
| 32 | + workflow: { |
| 33 | + ref: ($workflowPathRef | split("@")[1]), |
| 34 | + repository: ($context.server_url + "/" + $context.repository), |
| 35 | + path: ($workflowPathRef | split("@")[0]), |
| 36 | + digest: {sha256: $context.workflow_sha} |
| 37 | + } |
| 38 | +} |
| 39 | +; |
| 40 | + |
| 41 | +# input: GITHUB context argument |
| 42 | +# output: json object for in-toto provenance internal parameters field |
| 43 | +def github_internal_parameters($context): |
| 44 | +{ |
| 45 | + github: { |
| 46 | + event_name: $context.event_name, |
| 47 | + repository_id: $context.repository_id, |
| 48 | + repository_owner_id: $context.repository_owner_id, |
| 49 | + } |
| 50 | +} |
| 51 | +; |
| 52 | + |
| 53 | +# input: "tags" object with platform, image digest and GITHUB context arguments |
| 54 | +# output: json object for in-toto provenance statement |
| 55 | +def github_actions_provenance($platform; $digest; $context): |
| 56 | +{ |
| 57 | + _type: "https://in-toto.io/Statement/v1", |
| 58 | + subject: . | map(subjects($platform; $digest)), |
| 59 | + predicateType: "https://slsa.dev/provenance/v1", |
| 60 | + predicate: { |
| 61 | + buildDefinition: { |
| 62 | + buildType: "https://slsa-framework.github.io/github-actions-buildtypes/workflow/v1", |
| 63 | + externalParameters: github_external_parameters($context), |
| 64 | + internalParameters: github_internal_parameters($context), |
| 65 | + resolvedDependencies: [{ |
| 66 | + uri: ("git+"+$context.server_url+"/"+$context.repository+"@"+$context.ref), |
| 67 | + digest: { "gitCommit": $context.sha } |
| 68 | + }] |
| 69 | + }, |
| 70 | + runDetails: { |
| 71 | + builder: { |
| 72 | + id: ($context.server_url+"/"+$context.workflow_ref), |
| 73 | + }, |
| 74 | + metadata: { |
| 75 | + invocationId: ($context.server_url+"/"+$context.repository+"/actions/runs/"+$context.run_id+"/attempts/"+$context.run_attempt), |
| 76 | + } |
| 77 | + } |
| 78 | + } |
| 79 | +} |
| 80 | +; |
0 commit comments