-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add secure checkout action Signed-off-by: Ian Lewis <[email protected]> * Update checkout pre-submit check Signed-off-by: Ian Lewis <[email protected]> * Rename script Signed-off-by: Ian Lewis <[email protected]> * Update checkout pre-submit Signed-off-by: Ian Lewis <[email protected]> * Don't call verify-checkout and add comment * Remove verify-checkout Signed-off-by: Ian Lewis <[email protected]> * fix script path Signed-off-by: Ian Lewis <[email protected]> * Update checkout.sh Signed-off-by: Ian Lewis <[email protected]>
- Loading branch information
Ian Lewis
authored
Oct 11, 2022
1 parent
62df09d
commit 5d257ff
Showing
6 changed files
with
97 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
name: "secure-checkout" | ||
description: "Checkout and verify a commit sha for a GitHub repo" | ||
|
||
input: | ||
repository: | ||
description: "The repository to check out." | ||
required: false | ||
default: ${{ github.repository }} }} | ||
sha: | ||
description: "The SHA to checkout." | ||
required: false | ||
# NOTE: different from actions/checkout which takes any git ref. | ||
# Users must provide a sha1 digest explicitly if not checking out the | ||
# commit that triggered the event. | ||
default: ${{ github.sha }} }} | ||
token: | ||
description: "Token used to fetch the repository." | ||
required: false | ||
default: ${{ github.token }} | ||
persist-credentials: | ||
description: "Whether to configure the token or SSH key with the local git config" | ||
# NOTE: different from actions/checkout which defaults to true. | ||
default: false | ||
fetch-depth: | ||
description: "Number of commits to fetch. 0 indicates all history for all branches and tags." | ||
default: 1 | ||
strict: | ||
description: "Whether to only allow checkouts from repositories that triggered the workflow." | ||
default: true | ||
runs: | ||
using: "composite" | ||
steps: | ||
- name: Verify input sha | ||
env: | ||
EXPECTED_SHA: "${{ inputs.sha }}" | ||
# Verify that the input sha is a git digest (sha1). | ||
run: | | ||
[[ "${EXPECTED_SHA}" =~ ^[a-fA-F0-9]{40}$ ]] | ||
- name: Checkout the repository | ||
uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # tag=v3.0.2 | ||
with: | ||
fetch-depth: 1 | ||
ref: ${{ inputs.sha }} | ||
persist-credentials: ${{ inputs.persist-credentials }} | ||
repository: ${{ inputs.repository }} | ||
token: ${{ inputs.token }} | ||
|
||
- name: Verify checkout | ||
shell: bash | ||
env: | ||
CONTEXT: "${{ toJSON(github) }}" | ||
EXPECTED_SHA: "${{ inputs.sha }}" | ||
run: | | ||
set -euo pipefail | ||
git_sha="$(git log -1 --format='%H')" | ||
if [[ "$git_sha" != "$EXPECTED_SHA" ]]; then | ||
echo "mismatch git sha \"$git_sha\" != \"$EXPECTED_SHA\"" | ||
echo "GitHub context:" | ||
echo "$CONTEXT" | ||
echo | ||
echo "Last 20 commits:" | ||
git log -20 | ||
exit 1 | ||
fi |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/bin/bash | ||
|
||
# Verify that no internal Actions are using `actions/checkout` | ||
# See reasoning in ./github/actions/README.md | ||
|
||
set -euo pipefail | ||
|
||
# NOTE: All actions and workflows should not use actions/checkout. They should | ||
# use an action that uses secure-checkout such as checkout-go, checkout-node | ||
# etc. or use secure-checkout directly. | ||
# TODO(github.com/slsa-framework/slsa-github-generator/issues/626): Check workflows as well and not just actions. | ||
# TODO(github.com/slsa-framework/slsa-github-generator/issues/626): Disallow checkouts for repos other than the repo that triggered the action(i.e. github.repository). | ||
results=$( | ||
grep -r \ | ||
--include='*.yml' \ | ||
--include='*.yaml' \ | ||
--exclude-dir='node_modules' \ | ||
--exclude-dir='secure-checkout' \ | ||
--exclude-dir='checkout-go' \ | ||
--exclude-dir='checkout-node' \ | ||
-e 'uses: *actions/checkout' \ | ||
.github/actions/* || true | ||
) | ||
if [[ "$results" != "" ]]; then | ||
echo "Some Actions are using 'actions/checkout'" | ||
echo "$results" | ||
exit 1 | ||
fi |