File tree 9 files changed +117
-88
lines changed
secure-project-checkout-go
secure-project-checkout-node
workflows/scripts/pre-submit.actions
9 files changed +117
-88
lines changed Original file line number Diff line number Diff line change @@ -33,11 +33,16 @@ outputs:
33
33
runs :
34
34
using : " composite"
35
35
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
38
38
with :
39
39
repository : ${{ inputs.repository }}
40
40
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 :
41
46
go-version : ${{ inputs.go-version }}
42
47
43
48
- name : Generate builder
@@ -59,10 +64,10 @@ runs:
59
64
BUILDER_DIR : " ${{ inputs.directory }}"
60
65
# Needed for the gh CLI used in builder-fetch.sh.
61
66
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
63
68
64
69
- 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
66
71
id : compute
67
72
with :
68
73
path : " ${{ inputs.binary }}"
Original file line number Diff line number Diff line change
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
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 24
24
run : |
25
25
set -euo pipefail
26
26
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.
27
37
if [ -e "$UNTRUSTED_PATH" ]; then
28
38
echo "Path $UNTRUSTED_PATH already exists"
29
39
exit 5
@@ -36,10 +46,13 @@ runs:
36
46
37
47
- name : Compute the hash
38
48
id : compute
39
- uses : slsa-framework/slsa-github-generator /.github/actions/compute-sha256@e3220805577deb9d193f64e519abcb3b50851df5
49
+ uses : ./__BUILDER_CHECKOUT_DIR__ /.github/actions/compute-sha256
40
50
with :
41
51
path : " ${{ inputs.path }}"
42
52
53
+ # Note: this assumes to top-level re-usable workflow
54
+ # has checkout'ed the builder repository using
55
+ # `.github/actions/secure-builder-checkout`.
43
56
- name : Verify the SHA256
44
57
env :
45
58
UNTRUSTED_EXPECTED_HASH : " ${{ inputs.sha256 }}"
Original file line number Diff line number Diff line change @@ -22,8 +22,11 @@ inputs:
22
22
runs :
23
23
using : " composite"
24
24
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
27
30
with :
28
31
repository : ${{ inputs.repository }}
29
32
ref : ${{ inputs.ref }}
Original file line number Diff line number Diff line change @@ -22,8 +22,11 @@ inputs:
22
22
runs :
23
23
using : " composite"
24
24
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`.
25
28
- 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
27
30
with :
28
31
repository : ${{ inputs.repository }}
29
32
ref : ${{ inputs.ref }}
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change @@ -16,9 +16,12 @@ outputs:
16
16
runs :
17
17
using : " composite"
18
18
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`.
19
22
- name : Compute binary hash
20
23
id : compute-digest
21
- uses : slsa-framework/slsa-github-generator /.github/actions/compute-sha256@e3220805577deb9d193f64e519abcb3b50851df5
24
+ uses : ./__BUILDER_CHECKOUT_DIR__ /.github/actions/compute-sha256
22
25
with :
23
26
path : " ${{ inputs.path }}"
24
27
Original file line number Diff line number Diff line change @@ -15,7 +15,8 @@ results=$(
15
15
--include=' *.yml' \
16
16
--include=' *.yaml' \
17
17
--exclude-dir=' node_modules' \
18
- --exclude-dir=' secure-checkout' \
18
+ --exclude-dir=' secure-project-checkout' \
19
+ --exclude-dir=' secure-builder-checkout' \
19
20
-e ' uses: *actions/checkout' \
20
21
.github/actions/* || true
21
22
)
You can’t perform that action at this time.
0 commit comments