Skip to content

Commit d29544e

Browse files
authored
Remove ref for internal action calls (#1075)
* Remove ref for actions and checkout the builder repo instead * fixes * update * pre submits * update * update * update
1 parent 82a20d3 commit d29544e

File tree

9 files changed

+117
-88
lines changed

9 files changed

+117
-88
lines changed

.github/actions/generate-builder/action.yml

+9-4
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,16 @@ outputs:
3333
runs:
3434
using: "composite"
3535
steps:
36-
- name: Checkout the Go builder repository
37-
uses: slsa-framework/slsa-github-generator/.github/actions/checkout-go@c2e7da4c53f2703d9af77f8d1483078c8fd3477e
36+
- name: Checkout builder repository
37+
uses: slsa-framework/slsa-github-generator/.github/actions/secure-builder-checkout@main
3838
with:
3939
repository: ${{ inputs.repository }}
4040
ref: ${{ inputs.ref }}
41+
path: __BUILDER_CHECKOUT_DIR__
42+
43+
- name: Set up Go environment
44+
uses: actions/setup-go@268d8c0ca0432bb2cf416faae41297df9d262d7f # tag=v3.3.0
45+
with:
4146
go-version: ${{ inputs.go-version }}
4247

4348
- name: Generate builder
@@ -59,10 +64,10 @@ runs:
5964
BUILDER_DIR: "${{ inputs.directory }}"
6065
# Needed for the gh CLI used in builder-fetch.sh.
6166
GH_TOKEN: "${{ inputs.token }}"
62-
run: ./.github/actions/generate-builder/generate-builder.sh
67+
run: ./__BUILDER_CHECKOUT_DIR__/.github/actions/generate-builder/generate-builder.sh
6368

6469
- name: Compute sha256 of builder
65-
uses: slsa-framework/slsa-github-generator/.github/actions/compute-sha256@e3220805577deb9d193f64e519abcb3b50851df5
70+
uses: ./__BUILDER_CHECKOUT_DIR__/.github/actions/compute-sha256
6671
id: compute
6772
with:
6873
path: "${{ inputs.binary }}"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: "secure-builder-checkout"
2+
description: "Checkout the builder repository"
3+
4+
inputs:
5+
repository:
6+
description: "The repository to check out."
7+
required: true
8+
ref:
9+
description: "The ref to checkout."
10+
required: true
11+
path:
12+
# Same argument to https://github.com/actions/checkout.
13+
description: "Relative path under $GITHUB_WORKSPACE to place the repository."
14+
required: true
15+
token:
16+
description: "Token used to fetch the repository."
17+
required: false
18+
default: ${{ github.token }}
19+
runs:
20+
using: "composite"
21+
steps:
22+
# TODO(968): verify the hash is on the main branch
23+
# and has an associated release. This will require exceptions
24+
# for e2e tests.
25+
- name: Checkout the repository
26+
uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # tag=v3.0.2
27+
with:
28+
repository: ${{ inputs.repository }}
29+
ref: ${{ inputs.ref }}
30+
token: ${{ inputs.token }}
31+
path: ${{ inputs.path }}
32+
persist-credentials: false
33+
fetch-depth: 1

.github/actions/secure-checkout/action.yaml

-78
This file was deleted.

.github/actions/secure-download-artifact/action.yml

+14-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@ runs:
2424
run: |
2525
set -euo pipefail
2626
27+
# Check that the name of the path does not clash with the
28+
# directory where the builder code is stored.
29+
echo "$UNTRUSTED_PATH" | grep __BUILDER_CHECKOUT_DIR__
30+
exit_status=$?
31+
if [ $exit_status -eq 0 ]; then
32+
echo "\"$UNTRUSTED_PATH\" contains '__BUILDER_CHECKOUT_DIR__'"
33+
exit 1
34+
fi
35+
36+
# Ensure we don't overwrite existing files.
2737
if [ -e "$UNTRUSTED_PATH" ]; then
2838
echo "Path $UNTRUSTED_PATH already exists"
2939
exit 5
@@ -36,10 +46,13 @@ runs:
3646

3747
- name: Compute the hash
3848
id: compute
39-
uses: slsa-framework/slsa-github-generator/.github/actions/compute-sha256@e3220805577deb9d193f64e519abcb3b50851df5
49+
uses: ./__BUILDER_CHECKOUT_DIR__/.github/actions/compute-sha256
4050
with:
4151
path: "${{ inputs.path }}"
4252

53+
# Note: this assumes to top-level re-usable workflow
54+
# has checkout'ed the builder repository using
55+
# `.github/actions/secure-builder-checkout`.
4356
- name: Verify the SHA256
4457
env:
4558
UNTRUSTED_EXPECTED_HASH: "${{ inputs.sha256 }}"

.github/actions/checkout-go/action.yml renamed to .github/actions/secure-project-checkout-go/action.yml

+5-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,11 @@ inputs:
2222
runs:
2323
using: "composite"
2424
steps:
25-
- name: Checkout the repository with user SHA
26-
uses: slsa-framework/slsa-github-generator/.github/actions/secure-checkout@ea457948e6a989e9818304dcb4f15fb4ce6765d6
25+
# Note: this assumes to top-level re-usable workflow
26+
# has checkout'ed the builder repository using
27+
# `.github/actions/secure-builder-checkout`.
28+
- name: Checkout the repository with user ref
29+
uses: ./__BUILDER_CHECKOUT_DIR__/.github/actions/secure-project-checkout
2730
with:
2831
repository: ${{ inputs.repository }}
2932
ref: ${{ inputs.ref }}

.github/actions/checkout-node/action.yml renamed to .github/actions/secure-project-checkout-node/action.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,11 @@ inputs:
2222
runs:
2323
using: "composite"
2424
steps:
25+
# Note: this assumes to top-level re-usable workflow
26+
# has checkout'ed the builder repository using
27+
# `.github/actions/secure-builder-checkout`.
2528
- name: Checkout the repository with user ref
26-
uses: slsa-framework/slsa-github-generator/.github/actions/secure-checkout@ea457948e6a989e9818304dcb4f15fb4ce6765d6
29+
uses: ./__BUILDER_CHECKOUT_DIR__/.github/actions/secure-project-checkout
2730
with:
2831
repository: ${{ inputs.repository }}
2932
ref: ${{ inputs.ref }}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: "secure-project-checkout"
2+
description: "Checkout a project and verify its commit sha"
3+
4+
inputs:
5+
# the token is not available to actions by defaults, so we need to
6+
# share it explicitly. The token is needed to checkout private repositories.
7+
token:
8+
description: "Token used to fetch the repository."
9+
required: false
10+
default: ${{ github.token }}
11+
runs:
12+
using: "composite"
13+
steps:
14+
- name: Checkout the repository
15+
uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # tag=v3.0.2
16+
with:
17+
fetch-depth: 1
18+
# Different from default actions/checkout which defaults to `true`.
19+
persist-credentials: false
20+
token: ${{ inputs.token }}
21+
22+
- name: Verify commit sha
23+
shell: bash
24+
env:
25+
CONTEXT: "${{ toJSON(github) }}"
26+
# Exception for pull requests: https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows
27+
PULL_REQUEST_SHA: "${{ github.event.pull_request.head.sha }}"
28+
run: |
29+
set -euo pipefail
30+
31+
git_sha="$(git log -1 --format='%H')"
32+
github_sha="$GITHUB_SHA"
33+
34+
if [[ "$GITHUB_EVENT_NAME" == "pull_request" ]]; then
35+
github_sha="$PULL_REQUEST_SHA"
36+
fi
37+
38+
if [[ "$git_sha" != "$github_sha" ]]; then
39+
echo "mismatch git sha \"$git_sha\" != \"$github_sha\""
40+
echo "GitHub context:"
41+
echo "$CONTEXT"
42+
echo
43+
echo "Last 20 commits:"
44+
git log -20
45+
exit 1
46+
fi

.github/actions/secure-upload-artifact/action.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,12 @@ outputs:
1616
runs:
1717
using: "composite"
1818
steps:
19+
# Note: this assumes to top-level re-usable workflow
20+
# has checkout'ed the builder repository using
21+
# `.github/actions/secure-builder-checkout`.
1922
- name: Compute binary hash
2023
id: compute-digest
21-
uses: slsa-framework/slsa-github-generator/.github/actions/compute-sha256@e3220805577deb9d193f64e519abcb3b50851df5
24+
uses: ./__BUILDER_CHECKOUT_DIR__/.github/actions/compute-sha256
2225
with:
2326
path: "${{ inputs.path }}"
2427

.github/workflows/scripts/pre-submit.actions/checkout.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ results=$(
1515
--include='*.yml' \
1616
--include='*.yaml' \
1717
--exclude-dir='node_modules' \
18-
--exclude-dir='secure-checkout' \
18+
--exclude-dir='secure-project-checkout' \
19+
--exclude-dir='secure-builder-checkout' \
1920
-e 'uses: *actions/checkout' \
2021
.github/actions/* || true
2122
)

0 commit comments

Comments
 (0)