Repository navigation
CLA: use release-workflows v1.3.0 - #470
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #470 +/- ##
=======================================
Coverage 99.29% 99.29%
=======================================
Files 31 31
Lines 3259 3259
=======================================
Hits 3236 3236
Misses 23 23 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
en0f
left a comment
There was a problem hiding this comment.
Reviewed at f72cbd9.
🟢 Secrets narrowed to exactly what the called workflow declares
secrets: inherit is gone, and the caller passes only APP_ID and APP_PRIVATE_KEY, the two secrets cla-reusable.yml v1.3.0 declares (lines 4-8), so CODECOV_TOKEN and PYPI_API_TOKEN no longer reach a pull_request_target job. The pin 3fe35ff9 is the v1.3.0 tag's commit (ci.md § Pin everything to a SHA), and both secrets are org secrets visible to this repository (V01-V03, V06).
🟢 Dropping contents: read is safe now
#456 added it only because CLA's reusable job asked for it and failed at startup without it. The v1.3.0 job asks for pull-requests: write and statuses: write only (lines 21-23), both granted here, and never checks out code, so this caller is at least privilege for pull_request_target (ci.md § Permissions; V04, V05).
📝 Test artifact owed: a run of this cla.yml
This PR's green CLA check (run 43447647960) ran dev's cla.yml, which called CLA/cla-reusable.yml@main, because pull_request_target reads the base branch. No run here has called v1.3.0 yet (V07). A throwaway PR with base feat/cla-v1.3.0 opened by a member proves the App token and the exemption step, but takes the all-exempt path and skips the save. The save to CLA's signatures branch needs a run where a non-exempt contributor signs: a non-member test account, or the first outside contribution after merge. Link either run here or in a comment.
📝 Format: conventional subject
This PR has one commit, and squash uses the commit subject when there is one, so CLA: use release-workflows v1.3.0 is what lands in the changelog. Set the subject to ci(cla): use release-workflows v1.3.0 in the squash dialog (git.md § Commit messages).
Reproduce this review
# save the script below as verify-470.sh and the patch as control-470.patch, then:
bash verify-470.sh blacklanternsecurity/badsecrets f72cbd96a5fa828b7527fdc20995b3e755a25036
# expected: SUMMARY 6 PASS, 1 FAIL, 0 SKIP, 0 BROKEN (V07 fails until a run of this cla.yml exists)
# control: bash verify-470.sh blacklanternsecurity/badsecrets f72cbd96a5fa828b7527fdc20995b3e755a25036 "$PWD/control-470.patch" -> V01 V02 V03 V04 FAIL#!/usr/bin/env bash
# verify-470.sh: reproducible checks for blacklanternsecurity/badsecrets#470
# Usage: bash verify-470.sh <owner/repo> <sha> [<control-patch>]
# Changes nothing outside a mktemp directory and nothing on GitHub (PR-VF-02).
#
# CONTROL: patch control-470.patch
# CONTROL-EXPECT: V01=FAIL V02=FAIL V03=FAIL V04=FAIL
# AUTHOR-CODE: none
set -uo pipefail
REPO="${1:?owner/repo}"; SHA="${2:?sha}"; PATCH="${3:-}"
PASS=0; FAIL=0; SKIP=0; BROKEN=0
pass() { echo "PASS $1 $2"; PASS=$((PASS+1)); }
fail() { echo "FAIL $1 $2 -- $3"; FAIL=$((FAIL+1)); }
skip() { echo "SKIP $1 $2 -- $3"; SKIP=$((SKIP+1)); }
broken() { echo "BROKEN $1 $2 -- $3"; BROKEN=$((BROKEN+1)); }
summary() { echo "SUMMARY $PASS PASS, $FAIL FAIL, $SKIP SKIP, $BROKEN BROKEN"; [ "$FAIL" -eq 0 ] && [ "$BROKEN" -eq 0 ]; }
echo "script_sha256 $(shasum -a 256 "$0" | cut -d' ' -f1)"
echo "git $(git --version | cut -d' ' -f3)"
echo "gh $(gh --version | head -1 | cut -d' ' -f3)"
echo "jq $(jq --version)"
WORK="$(mktemp -d)"; trap 'rm -rf "$WORK"' EXIT
export GIT_CONFIG_GLOBAL=/dev/null GIT_CONFIG_NOSYSTEM=1 GIT_TERMINAL_PROMPT=0
GIT=(git -c credential.helper= -c 'credential.helper=!gh auth git-credential')
"${GIT[@]}" clone --quiet --filter=blob:none --no-checkout "https://github.com/$REPO.git" "$WORK/src" || { broken V00 "clone" "clone failed"; summary; exit 1; }
cd "$WORK/src"
"${GIT[@]}" cat-file -e "$SHA^{commit}" 2>/dev/null || "${GIT[@]}" fetch --quiet origin "+refs/pull/*/head:refs/remotes/pr/*" || true
"${GIT[@]}" checkout --quiet --detach "$SHA" || { broken V00 "checkout $SHA" "checkout failed"; summary; exit 1; }
[ "$(git rev-parse HEAD)" = "$SHA" ] || { broken V00 "HEAD is $SHA" "HEAD mismatch"; summary; exit 1; }
if [ -n "$PATCH" ]; then git apply "$PATCH" || { broken V00 "apply control patch" "git apply failed"; summary; exit 1; }; fi
CALLER=.github/workflows/cla.yml
[ -f "$CALLER" ] || { broken V00 "caller exists" "$CALLER missing"; summary; exit 1; }
RW=blacklanternsecurity/release-workflows
USES=$(awk '/^[[:space:]]*uses:[[:space:]]/{sub(/^[[:space:]]*uses:[[:space:]]*/,""); sub(/[[:space:]]*#.*/,""); print; exit}' "$CALLER")
echo "caller uses: $USES"
# V01: the caller pins release-workflows' cla-reusable.yml by full SHA, and that SHA is tag v1.3.0
TAG_SHA=$(gh api --method GET "repos/$RW/git/ref/tags/v1.3.0" --jq '.object.sha' 2>/dev/null || true)
PIN=${USES##*@}
if [ -z "$TAG_SHA" ]; then skip V01 "cla.yml pins cla-reusable.yml to the v1.3.0 commit" "could not read tag v1.3.0"
elif [ "${USES%@*}" = "$RW/.github/workflows/cla-reusable.yml" ] && [[ "$PIN" =~ ^[0-9a-f]{40}$ ]] && [ "$PIN" = "$TAG_SHA" ]; then
pass V01 "cla.yml pins cla-reusable.yml to the v1.3.0 commit ($TAG_SHA)"
else fail V01 "cla.yml pins cla-reusable.yml to the v1.3.0 commit" "uses=$USES tag=$TAG_SHA"; fi
# V02: no secrets: inherit
if grep -Eq '^[[:space:]]*secrets:[[:space:]]*inherit' "$CALLER"; then fail V02 "cla.yml does not pass secrets: inherit" "secrets: inherit present"
else pass V02 "cla.yml does not pass secrets: inherit"; fi
# Fetch the called workflow at the caller's pinned ref (whatever it is)
CALLED="$WORK/called.yml"
CREPO=$(cut -d/ -f1-2 <<<"${USES%@*}"); CPATH=$(cut -d/ -f3- <<<"${USES%@*}")
if ! gh api --method GET "repos/$CREPO/contents/$CPATH" -f ref="$PIN" -H 'Accept: application/vnd.github.raw+json' > "$CALLED" 2>/dev/null; then : > "$CALLED"; fi
# V03: caller passes exactly the secrets the called workflow declares
DECL=$(awk '/^ workflow_call:/{w=1;next} w&&/^ secrets:/{s=1;next} s&&/^ [A-Za-z_]+:/{gsub(/[ :]/,"");print;next} s&&/^ [a-z]/{exit} /^[a-z]/&&w{exit}' "$CALLED" | sort | tr '\n' ' ')
PASSED=$(awk '/^ secrets:[[:space:]]*$/{s=1;next} s&&/^ [A-Za-z_]+:/{sub(/^ /,"");sub(/:.*/,"");print;next} s{exit}' "$CALLER" | sort | tr '\n' ' ')
echo "declared: [$DECL] passed: [$PASSED]"
if [ -z "$DECL" ]; then fail V03 "cla.yml passes exactly the secrets cla-reusable.yml declares" "called workflow declares none (or unreadable)"
elif [ "$DECL" = "$PASSED" ]; then pass V03 "cla.yml passes exactly the secrets cla-reusable.yml declares ($DECL)"
else fail V03 "cla.yml passes exactly the secrets cla-reusable.yml declares" "declared=[$DECL] passed=[$PASSED]"; fi
# V04: every permission the called job asks for is granted by the caller at the same or higher level
rank() { case "$1" in write) echo 2;; read) echo 1;; *) echo 0;; esac; }
CALLER_PERMS=$(awk '/^permissions:/{p=1;next} p&&/^ [a-z-]+:/{gsub(/ /,"");print;next} p&&!/^ /{exit}' "$CALLER")
JOB_PERMS=$(awk '/^jobs:/{j=1} j&&/^ permissions:/{p=1;next} p&&/^ [a-z-]+:/{gsub(/ /,"");print;next} p&&!/^ /{exit}' "$CALLED")
echo "caller perms: $(tr '\n' ' ' <<<"$CALLER_PERMS")| called job perms: $(tr '\n' ' ' <<<"$JOB_PERMS")"
OK=1; MISS=""
if [ -z "$JOB_PERMS" ]; then OK=0; MISS="called job declares no permissions (or unreadable)"; fi
while IFS=: read -r k v; do
[ -n "$k" ] || continue
have=$(awk -F: -v k="$k" '$1==k{print $2}' <<<"$CALLER_PERMS")
if [ "$(rank "$have")" -lt "$(rank "$v")" ]; then OK=0; MISS="$MISS $k:$v(caller:${have:-none})"; fi
done <<<"$JOB_PERMS"
if [ "$OK" = 1 ]; then pass V04 "caller grants every permission the called job requests"
else fail V04 "caller grants every permission the called job requests" "$MISS"; fi
# V05: the called job never checks out code (pull_request_target safety, ci.md)
if [ ! -s "$CALLED" ]; then skip V05 "called workflow checks out no code" "called workflow unreadable"
elif grep -Eq 'actions/checkout|git (clone|checkout|fetch)' "$CALLED"; then fail V05 "called workflow checks out no code" "checkout found"
else pass V05 "called workflow checks out no code"; fi
# V06: APP_ID and APP_PRIVATE_KEY are available to this repository (org secrets)
NAMES=$(gh api --method GET "repos/$REPO/actions/organization-secrets" --jq '[.secrets[].name]|sort|join(" ")' 2>/dev/null || true)
if [ -z "$NAMES" ]; then skip V06 "APP_ID and APP_PRIVATE_KEY reach this repository" "secrets list unreadable with this token"
elif grep -qw APP_ID <<<"$NAMES" && grep -qw APP_PRIVATE_KEY <<<"$NAMES"; then pass V06 "APP_ID and APP_PRIVATE_KEY reach this repository as org secrets"
else fail V06 "APP_ID and APP_PRIVATE_KEY reach this repository" "org secrets: $NAMES"; fi
# V07: some cla.yml run in this repository has exercised release-workflows cla-reusable.yml at the v1.3.0 commit
REFS=$(gh api --method GET "repos/$REPO/actions/workflows/cla.yml/runs" -f per_page=50 --jq '[.workflow_runs[].referenced_workflows[]?.path]|unique|join(" ")' 2>/dev/null || true)
echo "referenced by recent cla.yml runs: $REFS"
if [ -z "$REFS" ]; then skip V07 "a cla.yml run has exercised cla-reusable.yml@v1.3.0" "runs unreadable"
elif grep -q "release-workflows/.github/workflows/cla-reusable.yml@3fe35ff9c43f61c98bd8c93182686b6be97d2759" <<<"$REFS"; then pass V07 "a cla.yml run has exercised cla-reusable.yml@v1.3.0"
else fail V07 "a cla.yml run has exercised cla-reusable.yml@v1.3.0" "every recent run called $REFS (pull_request_target reads the base branch's cla.yml)"; fi
summarydiff --git a/.github/workflows/cla.yml b/.github/workflows/cla.yml
--- a/.github/workflows/cla.yml
+++ b/.github/workflows/cla.yml
@@ -9,11 +9,8 @@ on:
permissions:
pull-requests: write
- statuses: write
jobs:
cla:
- uses: blacklanternsecurity/release-workflows/.github/workflows/cla-reusable.yml@3fe35ff9c43f61c98bd8c93182686b6be97d2759 # v1.3.0
- secrets:
- APP_ID: ${{ secrets.APP_ID }}
- APP_PRIVATE_KEY: ${{ secrets.APP_PRIVATE_KEY }}
+ uses: blacklanternsecurity/release-workflows/.github/workflows/cla-reusable.yml@v1.3.0
+ secrets: inherit
Moves the CLA check from
CLA/cla-reusable.yml@mainto release-workflows v1.3.0, and passes onlyAPP_IDandAPP_PRIVATE_KEYinstead ofsecrets: inherit.signaturesbranch. None have saved since 10-27: CLAmainrefuses the bot's push.recheckcomments, and only for the CLA repository.Comments run the workflow on the default branch (
main), which keeps the old copy until the next promotion. Until then, after a contributor signs, a maintainer re-runs the pull request's CLA check ("Re-run all jobs").Details: blacklanternsecurity/release-workflows#18 and #20.