Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add provenance.jq #76

Merged
merged 6 commits into from
Sep 19, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions provenance.jq
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# input: "build" object (with "buildId" top level key)
# output: array of image tags
def tags:
.source.arches[].tags[],
.source.arches[].archTags[],
.build.img
;
mrjoelkamp marked this conversation as resolved.
Show resolved Hide resolved

# input: "build" object (with "buildId" top level key)
# output: purl platform query string
def platform_string:
.source.arches[].platformString | gsub("/"; "%2F")
;
mrjoelkamp marked this conversation as resolved.
Show resolved Hide resolved

# input: "tags" object with image digest and platform arguments
# output: json object for in-toto provenance subject field
def subjects($platform; $digest):
{
"name": ("pkg:docker/" + . + "?platform=" + $platform),
mrjoelkamp marked this conversation as resolved.
Show resolved Hide resolved
"digest": {
"sha256": $digest
mrjoelkamp marked this conversation as resolved.
Show resolved Hide resolved
}
}
;

# input: GITHUB context argument
# output: json object for in-toto provenance external parameters field
def github_external_parameters($context):
($context.workflow_ref | gsub( $context.repository + "/"; "")) as $workflowPathRef |
{
inputs: $context.event.inputs,
workflow: {
ref: ($workflowPathRef | split("@")[1]),
repository: ($context.server_url + "/" + $context.repository),
path: ($workflowPathRef | split("@")[0]),
digest: {sha256: $context.workflow_sha}
}
}
;

# input: GITHUB context argument
# output: json object for in-toto provenance internal parameters field
def github_internal_parameters($context):
{
github: {
event_name: $context.event_name,
repository_id: $context.repository_id,
repository_owner_id: $context.repository_owner_id,
}
}
;
mrjoelkamp marked this conversation as resolved.
Show resolved Hide resolved

# input: "tags" object with platform, image digest and GITHUB context arguments
# output: json object for in-toto provenance statement
def github_actions_provenance($platform; $digest; $context):
mrjoelkamp marked this conversation as resolved.
Show resolved Hide resolved
{
_type: "https://in-toto.io/Statement/v1",
subject: . | map(subjects($platform; $digest)),
predicateType: "https://slsa.dev/provenance/v1",
predicate: {
buildDefinition: {
buildType: "https://slsa-framework.github.io/github-actions-buildtypes/workflow/v1",
mrjoelkamp marked this conversation as resolved.
Show resolved Hide resolved
externalParameters: github_external_parameters($context),
internalParameters: github_internal_parameters($context),
resolvedDependencies: [{
uri: ("git+"+$context.server_url+"/"+$context.repository+"@"+$context.ref),
digest: { "gitCommit": $context.sha }
}]
},
runDetails: {
builder: {
id: ($context.server_url+"/"+$context.workflow_ref),
mrjoelkamp marked this conversation as resolved.
Show resolved Hide resolved
},
mrjoelkamp marked this conversation as resolved.
Show resolved Hide resolved
metadata: {
invocationId: ($context.server_url+"/"+$context.repository+"/actions/runs/"+$context.run_id+"/attempts/"+$context.run_attempt),
mrjoelkamp marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
}
;