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 externalParameters.source for v1 specs for BYOB #2193

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 6 additions & 0 deletions .github/actions/verify-token/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,12 @@ function createPredicate(rawTokenObj, toolURI, token, isGenerator) {
inputs: Object.fromEntries(rawTokenObj.tool.inputs),
// Variables are always empty for BYOB / builders.
vars: {},
source: {
uri: sourceURI,
digest: {
gitCommit: sourceSha1,
},
},
};
}
// Put GitHub event payload into internalParameters.
Expand Down
2 changes: 1 addition & 1 deletion .github/actions/verify-token/dist/index.js.map

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions .github/actions/verify-token/src/predicate1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,12 @@ export async function createPredicate(
inputs: Object.fromEntries(rawTokenObj.tool.inputs),
// Variables are always empty for BYOB / builders.
vars: {},
source: {
uri: sourceURI,
digest: {
gitCommit: sourceSha1,
},
},
};
}

Expand Down
44 changes: 42 additions & 2 deletions .github/workflows/e2e.verify-token.reusable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ name: verify-token schedule
on:
workflow_call:

permissions: read-all
permissions: {}

env:
GH_TOKEN: ${{ github.token }}
Expand All @@ -31,6 +31,7 @@ jobs:
runs-on: ubuntu-latest
outputs:
valid-token: ${{ steps.verify.outputs.slsa-token }}
valid-token-sha1: ${{ steps.verify-sha1.outputs.slsa-token }}
invalid-mask-token: ${{ steps.verify-invalid-mask.outputs.slsa-token }}
invalid-sha1-token: ${{ steps.verify-invalid-sha1.outputs.slsa-token }}
steps:
Expand All @@ -53,12 +54,34 @@ jobs:
# The Action should trim the spaces automatically.
slsa-workflow-masked-inputs: name2, name4,name6
slsa-checkout-fetch-depth: 4
slsa-checkout-sha1: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"

- id: verify
env:
SLSA_TOKEN: ${{ steps.setup.outputs.slsa-token }}
CHECKOUT_FETCH_DEPTH: 4
run: |
set -euo pipefail
./.github/workflows/scripts/schedule.actions/verify-setup-token.sh
echo "slsa-token=$SLSA_TOKEN" >> "$GITHUB_OUTPUT"

- id: setup-sha1
uses: ./actions/delegator/setup-token
with:
slsa-workflow-recipient: "delegator_generic_slsa3.yml"
slsa-rekor-log-public: true
slsa-runner-label: "ubuntu-latest"
slsa-build-action-path: "./actions/build-artifacts-composite"
slsa-workflow-inputs: '{"name1":"value1","name2":"value2","name3":"value3","name4":"","name5":"value5","name6":"value6","private-repository":true}'
# name4 has empty value and won't be obfuscated even though it's in the list.
# The Action should trim the spaces automatically.
slsa-workflow-masked-inputs: name2, name4,name6
slsa-checkout-fetch-depth: 4
slsa-checkout-sha1: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"

- id: verify-sha1
env:
SLSA_TOKEN: ${{ steps.setup-sha1.outputs.slsa-token }}
CHECKOUT_FETCH_DEPTH: 4
CHECKOUT_SHA1: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
run: |
set -euo pipefail
Expand Down Expand Up @@ -129,6 +152,23 @@ jobs:
TOOL_REF: ${{ steps.verify-builder.outputs.tool-ref }}
PREDICATE: predicate.json
CHECKOUT_FETCH_DEPTH: 4
BUILDER_INTERFACE_TYPE: "builder"
run: ./.github/workflows/scripts/schedule.actions/verify-verified-token.sh

- id: verify-builder-sha1
uses: ./.github/actions/verify-token
with:
slsa-unverified-token: ${{ needs.setup-token.outputs.valid-token-sha1 }}
slsa-workflow-recipient: "delegator_generic_slsa3.yml"
output-predicate: predicate.json
builder-interface-type: "builder"

- env:
VERIFIED_TOKEN: ${{ steps.verify-builder-sha1.outputs.slsa-verified-token }}
TOOL_REPOSITORY: ${{ steps.verify-builder.outputs.tool-repository }}
TOOL_REF: ${{ steps.verify-builder.outputs.tool-ref }}
PREDICATE: predicate.json
CHECKOUT_FETCH_DEPTH: 4
CHECKOUT_SHA1: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
BUILDER_INTERFACE_TYPE: "builder"
run: ./.github/workflows/scripts/schedule.actions/verify-verified-token.sh
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/e2e.verify-token.schedule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ on:
- cron: "0 4 * * *"
workflow_dispatch:

permissions: read-all
permissions: {}

env:
GH_TOKEN: ${{ github.token }}
Expand Down
9 changes: 9 additions & 0 deletions .github/workflows/scripts/e2e-utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,12 @@ e2e_verify_predicate_v1_runDetails_builder_id() {
e2e_verify_predicate_v1_runDetails_metadata_invocationId() {
_e2e_verify_query "$1" "$2" '.runDetails.metadata.invocationId'
}

e2e_get_source_sha1() {
local digest="$GITHUB_SHA"
if [[ -n "${CHECKOUT_SHA1:-}" ]]; then
# If the TRW provided a sha1 for checkout, the predicate should use it instead.
digest="${CHECKOUT_SHA1}"
fi
echo "$digest"
}
6 changes: 1 addition & 5 deletions .github/workflows/scripts/e2e-verify.common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,7 @@ e2e_verify_common_metadata() {
# $1: the attestation content
e2e_verify_common_materials() {
# By default, we use the digest from the GitHub event.
local digest="$GITHUB_SHA"
if [[ -n "${CHECKOUT_SHA1:-}" ]]; then
# If the TRW provided a sha1 for checkout, the predicate should use it instead.
digest="${CHECKOUT_SHA1}"
fi
digest=$(e2e_get_source_sha1)
e2e_verify_predicate_materials "$1" "{\"uri\":\"git+https://github.com/$GITHUB_REPOSITORY@$GITHUB_REF\",\"digest\":{\"sha1\":\"$digest\"}}"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,6 @@ e2e_verify_predicate_v1_runDetails_builder_id "$PREDICATE_CONTENT" "https://gith
e2e_verify_predicate_v1_buildDefinition_externalParameters_workflow "$PREDICATE_CONTENT" "$(e2e_this_file_full_path)" "$GITHUB_REF" "git+https://github.com/$GITHUB_REPOSITORY"

# Verify external parameters source
e2e_verify_predicate_v1_buildDefinition_externalParameters_source "$PREDICATE_CONTENT" "{\"uri\":\"git+https://github.com/$GITHUB_REPOSITORY@$GITHUB_REF\",\"digest\":{\"sha1\":\"$GITHUB_SHA\"}}"
digest=$(e2e_get_source_sha1)
e2e_verify_predicate_v1_buildDefinition_externalParameters_source "$PREDICATE_CONTENT" "{\"uri\":\"git+https://github.com/$GITHUB_REPOSITORY@$GITHUB_REF\",\"digest\":{\"sha1\":\"$digest\"}}"
Copy link
Collaborator Author

@laurentsimon laurentsimon May 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this check should have been failing. The daily runs were not working due to permission errors https://github.com/slsa-framework/slsa-github-generator/actions/runs/5125842921
I've tried addressing this in this PR by changing the default perms to permissions: {} in the workflows

e2e_verify_predicate_v1_buildDefinition_externalParameters_inputs "$PREDICATE_CONTENT" '{"name1":"value1","name2":"***","name3":"value3","name4":"***","name5":"value5","name6":"***","private-repository":true}'