Repository navigation
fix(ci): use published well-known paths and verify actions.lock-backed pins #69
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,13 +35,13 @@ jobs: | |
| failed=0 | ||
| for file in .github/workflows/*.yml .github/workflows/*.yaml; do | ||
| [ -f "$file" ] || continue | ||
| if ! head -1 "$file" | grep -q "^# SPDX-License-Identifier:"; then | ||
| if ! head -6 "$file" | grep -q "^# SPDX-License-Identifier:"; then | ||
| echo "ERROR: $file missing SPDX header" | ||
| failed=1 | ||
| fi | ||
| done | ||
| if [ $failed -eq 1 ]; then | ||
| echo "Add '# SPDX-License-Identifier: MPL-2.0' as first line" | ||
| echo "Require an SPDX identifier in the first six header lines (allow gh actions-lock managed preamble)" | ||
| exit 1 | ||
| fi | ||
| echo "All workflows have SPDX headers" | ||
|
|
@@ -63,24 +63,11 @@ jobs: | |
| fi | ||
| echo "All workflows have permissions declared" | ||
|
|
||
| - name: Check SHA-Pinned Actions | ||
| run: | | ||
| echo "=== Checking Action Pinning ===" | ||
| # Find any uses: lines that don't have @SHA format | ||
| # Pattern: uses: owner/repo@<40-char-hex> | ||
| unpinned=$(grep -rnE "^[[:space:]]+uses:" .github/workflows/ | \ | ||
| grep -v "@[a-f0-9]\{40\}" | \ | ||
| grep -v "uses: \./\|uses: docker://\|uses: actions/github-script" || true) | ||
|
|
||
| if [ -n "$unpinned" ]; then | ||
| echo "ERROR: Found unpinned actions:" | ||
| echo "$unpinned" | ||
| echo "" | ||
| echo "Replace version tags with SHA pins, e.g.:" | ||
| echo " uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6.0.1" | ||
| exit 1 | ||
| fi | ||
| echo "All actions are SHA-pinned" | ||
| - name: Self-test lock integrity checker (positive and negative) | ||
| run: bash tests/workflows/check-workflow-uses-lock_test.sh | ||
|
|
||
| - name: Check SHA-Pinned or generated lockfile-pinned Actions | ||
| run: bash scripts/check-workflow-uses-lock.sh . | ||
|
Comment on lines
+69
to
+70
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
After the self-test is fixed, this newly enabled command still exits with status 1 on the current tree: Useful? React with 👍 / 👎. |
||
|
|
||
| - name: Check for Duplicate Workflows | ||
| run: | | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| #!/usr/bin/env bash | ||
| # SPDX-License-Identifier: MPL-2.0 | ||
| # Verify that every non-local GitHub Action is pinned directly to a 40-hex | ||
| # commit or is resolved to a full commit in the generated gh actions-lock file. | ||
| # Do not modify actions.lock by hand. | ||
| set -euo pipefail | ||
|
|
||
| root="$(cd "$(dirname "$0")/.." && pwd)" | ||
| if [ "$#" -gt 0 ]; then root="$(cd "$1" && pwd)"; fi | ||
|
Check failure on line 9 in scripts/check-workflow-uses-lock.sh
|
||
| lock="$root/.github/workflows/actions.lock" | ||
| if [ ! -s "$lock" ]; then | ||
|
Check failure on line 11 in scripts/check-workflow-uses-lock.sh
|
||
| echo "FAIL: missing generated actions.lock: $lock" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| fail=0 | ||
| checked=0 | ||
| shopt -s nullglob | ||
| for file in "$root"/.github/workflows/*.yml "$root"/.github/workflows/*.yaml; do | ||
| rel=".github/workflows/$(basename "$file")" | ||
| while IFS= read -r line; do | ||
| # Comments (including workflow examples) do not match the anchored selector. | ||
| spec="$(printf '%s\n' "$line" | sed -nE 's/^[[:space:]]*(-[[:space:]]*)?uses:[[:space:]]*([^[:space:]#]+).*$/\2/p')" | ||
| [ -n "$spec" ] || continue | ||
|
Check failure on line 24 in scripts/check-workflow-uses-lock.sh
|
||
| checked=$((checked + 1)) | ||
| case "$spec" in | ||
|
Check failure on line 26 in scripts/check-workflow-uses-lock.sh
|
||
| ./*) continue ;; | ||
| docker://*) echo "FAIL: $rel uses a Docker action without a reviewed digest: $spec" >&2; fail=1; continue ;; | ||
| esac | ||
|
|
||
| source="$(printf '%s\n' "$spec" | cut -d@ -f1)" | ||
| version="$(printf '%s\n' "$spec" | awk -F@ '{print $NF}')" | ||
| if [ "$source" = "$spec" ] || ! [[ "$source" == */* ]]; then | ||
|
Check failure on line 33 in scripts/check-workflow-uses-lock.sh
|
||
| echo "FAIL: $rel uses an action without an immutable ref: $spec" >&2 | ||
| fail=1 | ||
| continue | ||
| fi | ||
| # Native full-SHA uses (including reusable workflows) are immutable. | ||
| if [[ "$version" =~ ^[0-9a-f]{40}$ ]]; then continue; fi | ||
| # A tag is allowed only when the generated lock includes a matching | ||
| # workflow reference AND an exact ref->sha1-40 dependency record. | ||
| owner="$(printf '%s\n' "$source" | cut -d/ -f1)" | ||
| name="$(printf '%s\n' "$source" | cut -d/ -f2)" | ||
| key="$owner/$name@$version" | ||
|
|
||
| if ! awk -v wf=" '$rel':" -v key=" - '$key'" ' | ||
| $0 == "dependencies:" {exit} | ||
| $0 == wf {inside=1; next} | ||
| inside && /^ [^ ]/ {inside=0} | ||
| inside && $0 == key {found=1} | ||
| END {exit(found ? 0 : 1)} | ||
| ' "$lock"; then | ||
| echo "FAIL: $rel: $key is missing from actions.lock workflow entries" >&2 | ||
| fail=1 | ||
| continue | ||
| fi | ||
|
|
||
| record="$(awk -v key=" '$key':" ' | ||
| $0 == "dependencies:" {deps=1; next} | ||
| deps && $0 == key {inside=1; next} | ||
| inside && /^ [^ ]/ {exit} | ||
| inside {print} | ||
| ' "$lock")" | ||
| if ! printf '%s\n' "$record" | grep -Fxq " ref: '$version'" || | ||
| ! printf '%s\n' "$record" | grep -Eq "^[[:space:]]+commit: 'sha1-[0-9a-f]{40}'$"; then | ||
| echo "FAIL: $rel: lock entry $key lacks matching ref and 40-hex SHA" >&2 | ||
| fail=1 | ||
| fi | ||
| done < "$file" | ||
| done | ||
| [ "$checked" -gt 0 ] || { echo "FAIL: no active action uses found" >&2; exit 1; } | ||
|
Check failure on line 71 in scripts/check-workflow-uses-lock.sh
|
||
| [ "$fail" -eq 0 ] || exit 1 | ||
|
Check failure on line 72 in scripts/check-workflow-uses-lock.sh
|
||
| echo "PASS: $checked uses resolve to direct 40-hex pins or generated actions.lock SHA records" | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| #!/usr/bin/env bash | ||
| # SPDX-License-Identifier: MPL-2.0 | ||
| # Offline positive/negative fixtures for the lock-aware workflow pin checker. | ||
| set -euo pipefail | ||
| root="$(cd "$(dirname "$0")/../.." && pwd)" | ||
| tmp="$(mktemp -d)" | ||
| trap 'rm -rf "$tmp"' EXIT | ||
| mkdir -p "$tmp/.github/workflows" | ||
| sha="$(printf 'a%.0s' {1..40})" | ||
| cat > "$tmp/.github/workflows/actions.lock" <<EOF | ||
| version: 'v0.0.3' | ||
| workflows: | ||
| '.github/workflows/fixture.yml': | ||
| - 'actions/checkout@v7.0.1' | ||
| dependencies: | ||
| 'actions/checkout@v7.0.1': | ||
| ref: 'v7.0.1' | ||
| commit: 'sha1-$sha' | ||
| owner_id: 1 | ||
| repo_id: 2 | ||
| EOF | ||
| printf '%s\n' 'name: fixture' 'jobs:' ' run:' ' steps:' ' - uses: actions/checkout@v7.0.1' > "$tmp/.github/workflows/fixture.yml" | ||
| bash "$root/scripts/check-workflow-uses-lock.sh" "$tmp" | ||
| sed -i 's/checkout@v7.0.1/checkout@v7.0.2/' "$tmp/.github/workflows/fixture.yml" | ||
| if bash "$root/scripts/check-workflow-uses-lock.sh" "$tmp" >/dev/null 2>&1; then | ||
| echo 'FAIL: mismatched workflow tag was wrongly accepted' >&2 | ||
| exit 1 | ||
| fi | ||
| printf '%s\n' 'name: fixture' 'jobs:' ' run:' ' steps:' " - uses: actions/checkout@$sha" > "$tmp/.github/workflows/fixture.yml" | ||
| bash "$root/scripts/check-workflow-uses-lock.sh" "$tmp" | ||
| printf '%s\n' 'PASS: matching lock, mismatched ref, and direct SHA cases verified' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When a PR modifies only
scripts/check-workflow-uses-lock.shortests/workflows/check-workflow-uses-lock_test.sh, this workflow is skipped because itspull_request.pathsandpush.pathssections still match only.github/workflows/**. A repository-wide search shows no other workflow invoking these new checks, so the enforcement or its tests can be changed without running either command; include both paths in the workflow triggers.Useful? React with 👍 / 👎.