|
| 1 | +#!/usr/bin/env bash |
| 2 | +# |
| 3 | +# This file contains tests for common fields of Github Actions provenance. |
| 4 | + |
| 5 | +source "./.github/workflows/scripts/e2e-utils.sh" |
| 6 | + |
| 7 | +# Runs all generic SLSA checks that shouldn't change on a per-builder basis. |
| 8 | +# $1: the attestation content |
| 9 | +e2e_verify_common_all() { |
| 10 | + e2e_verify_common_builder "$1" |
| 11 | + e2e_verify_common_invocation "$1" |
| 12 | + e2e_verify_common_metadata "$1" |
| 13 | + e2e_verify_common_materials "$1" |
| 14 | +} |
| 15 | + |
| 16 | +# Verifies the builder for generic provenance. |
| 17 | +# $1: the attestation content |
| 18 | +e2e_verify_common_builder() { |
| 19 | + e2e_verify_predicate_builder_id "$1" "https://github.com/Attestations/GitHubHostedActions@v1" |
| 20 | +} |
| 21 | + |
| 22 | +# Verifies the invocation for generic provenance. |
| 23 | +# $1: the attestation content |
| 24 | +e2e_verify_common_invocation() { |
| 25 | + # NOTE: We set GITHUB_WORKFLOW to the entryPoint for pull_requests. |
| 26 | + # TODO(github.com/slsa-framework/slsa-github-generator/issues/131): support retrieving entryPoint in pull requests. |
| 27 | + e2e_verify_predicate_invocation_configSource "$1" "{\"uri\":\"git+https://github.com/$GITHUB_REPOSITORY@$GITHUB_REF\",\"digest\":{\"sha1\":\"$GITHUB_SHA\"},\"entryPoint\":\"$GITHUB_WORKFLOW\"}" |
| 28 | + |
| 29 | + e2e_verify_predicate_invocation_environment "$1" "github_actor" "$GITHUB_ACTOR" |
| 30 | + e2e_verify_predicate_invocation_environment "$1" "github_sha1" "$GITHUB_SHA" |
| 31 | + # e2e_verify_predicate_invocation_environment "$1" "os" "ubuntu20" |
| 32 | + # e2e_verify_predicate_invocation_environment "$1" "arch" "X64" |
| 33 | + e2e_verify_predicate_invocation_environment "$1" "github_event_name" "$GITHUB_EVENT_NAME" |
| 34 | + e2e_verify_predicate_invocation_environment "$1" "github_ref" "$GITHUB_REF" |
| 35 | + e2e_verify_predicate_invocation_environment "$1" "github_ref_type" "$GITHUB_REF_TYPE" |
| 36 | + e2e_verify_predicate_invocation_environment "$1" "github_run_id" "$GITHUB_RUN_ID" |
| 37 | + e2e_verify_predicate_invocation_environment "$1" "github_run_number" "$GITHUB_RUN_NUMBER" |
| 38 | + e2e_verify_predicate_invocation_environment "$1" "github_run_attempt" "$GITHUB_RUN_ATTEMPT" |
| 39 | + # The checks below are commented out because they are populated via the OIDC token, which is not available in PRs. |
| 40 | + #ACTOR_ID=$(gh api -H "Accept: application/vnd.github.v3+json" /users/"$GITHUB_ACTOR" | jq -r '.id') |
| 41 | + #OWNER_ID=$(gh api -H "Accept: application/vnd.github.v3+json" /users/"$GITHUB_REPOSITORY_OWNER" | jq -r '.id') |
| 42 | + #REPO_ID=$(gh api -H "Accept: application/vnd.github.v3+json" /repos/"$GITHUB_REPOSITORY" | jq -r '.id') |
| 43 | + #e2e_verify_predicate_invocation_environment "$1" "github_actor_id" "$ACTOR_ID" |
| 44 | + #e2e_verify_predicate_invocation_environment "$1" "github_repository_owner_id" "$OWNER_ID" |
| 45 | + #e2e_verify_predicate_invocation_environment "$1" "github_repository_id" "$REPO_ID" |
| 46 | +} |
| 47 | + |
| 48 | +# Verifies the expected metadata. |
| 49 | +# $1: the attestation content |
| 50 | +e2e_verify_common_metadata() { |
| 51 | + e2e_verify_predicate_metadata "$1" "{\"buildInvocationID\":\"$GITHUB_RUN_ID-$GITHUB_RUN_ATTEMPT\",\"completeness\":{\"parameters\":true,\"environment\":false,\"materials\":false},\"reproducible\":false}" |
| 52 | +} |
| 53 | + |
| 54 | +# Verifies the materials include the GitHub repository. |
| 55 | +# $1: the attestation content |
| 56 | +e2e_verify_common_materials() { |
| 57 | + e2e_verify_predicate_materials "$1" "{\"uri\":\"git+https://github.com/$GITHUB_REPOSITORY@$GITHUB_REF\",\"digest\":{\"sha1\":\"$GITHUB_SHA\"}}" |
| 58 | +} |
0 commit comments