mirror of
https://github.com/bitbaum/fleet.git
synced 2026-12-05 02:58:50 +01:00
fix(ci): the phantom check could only ever withhold in CI, which is decoration (#106)
* fix(ci): the phantom check could only ever withhold in CI, which is decoration #105 shipped the phantom-secret check correctly withholding when it cannot list secrets — the right fix for reporting 21 secrets as missing when it was merely unable to read them. But listing secrets needs a scope no token in these workflows has, so in CI it withheld EVERY time. A check that can only ever withhold produces no signal and no red, which is the decoration this whole file exists to delete. It was honest and useless. Actions can answer the question without that scope: `toJSON(secrets)` hands a run its own secrets context, and its KEYS are the names available to that run. The workflow passes them in SECRET_NAMES, one per line, via an env var — not interpolated into the script body, so no secret material is ever shell-quoted — and reduced to keys with jq before anything is printed. Actions masks the values regardless; none is ever echoed. When SECRET_NAMES is set it is authoritative and the API listings are not consulted. Unset, the previous behaviour stands: both listings must succeed or the check withholds out loud. So it bites on a PR, bites locally, and still refuses to invent a finding from an outage. Four cases pin it against the same blind stub used for the withhold test: a secret the context lists is not charged, one it does not list still is, the run FAILS rather than withholding, and the withheld banner is absent. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * chore: re-trigger checks Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
783207e68b
commit
14e5a65d3c
3 files changed
+61
-1
No files matched your search
@@ -73,7 +73,19 @@ jobs:
|
||||
if: github.event_name == 'pull_request'
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.FLEET_PAT || secrets.GITHUB_TOKEN }}
|
||||
run: bash scripts/ci/audit-health.sh --static
|
||||
# The secrets context, whose KEYS are the names this run can see.
|
||||
# Listing secrets through the API needs a scope no token here has, so
|
||||
# without this the check could only ever withhold — and a check that
|
||||
# can only withhold is decoration. Passed as an env var rather than
|
||||
# interpolated into the script body (no shell-quoting of secret
|
||||
# material) and reduced to keys before anything is printed. Actions
|
||||
# masks the values regardless; none is ever echoed.
|
||||
SECRETS_CONTEXT: ${{ toJSON(secrets) }}
|
||||
run: |
|
||||
set -uo pipefail
|
||||
SECRET_NAMES=$(printf '%s' "$SECRETS_CONTEXT" | jq -r 'keys[]')
|
||||
export SECRET_NAMES
|
||||
bash scripts/ci/audit-health.sh --static
|
||||
|
||||
- name: Is the layer that watches everything else awake
|
||||
if: github.event_name != 'pull_request'
|
||||
|
||||
@@ -153,8 +153,20 @@ fi
|
||||
# So both listings must SUCCEED before any verdict is drawn. If either cannot
|
||||
# be read the phantom check is withheld entirely, because a partial listing
|
||||
# charges every secret defined in the half we could not see.
|
||||
#
|
||||
# IN ACTIONS there is a way that needs no scope at all: `toJSON(secrets)` hands
|
||||
# the workflow its own secrets context, whose KEYS are the names available to
|
||||
# that run. The caller passes those names in SECRET_NAMES (one per line) via an
|
||||
# env var, never inline and never printed — Actions masks the values anyway,
|
||||
# but nothing here ever holds one. When SECRET_NAMES is set it is authoritative
|
||||
# and the API listings are not consulted, which is what lets this check bite on
|
||||
# a PR instead of withholding forever. A check that can only ever withhold is
|
||||
# decoration, and decoration is the thing this file exists to delete.
|
||||
known_secrets=$'GITHUB_TOKEN\ntoken'
|
||||
secrets_readable=yes
|
||||
if [ -n "${SECRET_NAMES:-}" ]; then
|
||||
known_secrets+=$'\n'"$SECRET_NAMES"
|
||||
else
|
||||
if s=$(gh secret list -R "$OWNER/$REPO" --json name --jq '.[].name' 2>/dev/null); then
|
||||
known_secrets+=$'\n'"$s"
|
||||
else
|
||||
@@ -165,6 +177,7 @@ if s=$(gh api "orgs/$OWNER/actions/secrets" --jq '.secrets[].name' 2>/dev/null);
|
||||
else
|
||||
secrets_readable=no
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$STATIC" = yes ]; then
|
||||
echo "static mode: checking only what this diff controls (secrets that exist)."
|
||||
|
||||
@@ -300,6 +300,41 @@ grep -q "REALLY_EXISTS" <<<"$out" && bad "charged a secret while unable to list
|
||||
grep -q "WITHHELD" <<<"$out" && ok "says the check was withheld" || bad "silently skipped instead of withholding out loud"
|
||||
[ $rc -eq 0 ] && ok "does not fail the run on an outage" || bad "an outage failed the check (exit $rc)"
|
||||
|
||||
# SECRET_NAMES (from toJSON(secrets) in Actions) is authoritative when set, so
|
||||
# the check BITES in CI instead of withholding forever. Same blind stub as
|
||||
# above — the API listings fail — but the names arrive by env var.
|
||||
d=$(new_case)
|
||||
mkwf "$d" ctx.yml '17 6 * * 1' " env:
|
||||
A: \${{ secrets.PROVIDED }}
|
||||
B: \${{ secrets.ABSENT_ONE }}"
|
||||
echo '{"workflows":[{"id":1,"path":".github/workflows/ctx.yml","name":"C","state":"active"}]}' > "$d/spec/WFLIST"
|
||||
runrow success 1 > "$d/spec/RUNS_1"
|
||||
cat > "$d/bin/gh" <<'BLIND2'
|
||||
#!/usr/bin/env bash
|
||||
spec="$GH_SPEC"
|
||||
case "$1 $2" in
|
||||
"secret list") echo "gh: insufficient scope" >&2; exit 1 ;;
|
||||
esac
|
||||
if [ "$1" = "api" ]; then
|
||||
case "$2" in
|
||||
*"actions/secrets") echo "gh: HTTP 403" >&2; exit 1 ;;
|
||||
*"/actions/workflows") cat "$spec/WFLIST"; exit 0 ;;
|
||||
*"/actions/workflows/"*"/runs"*)
|
||||
id=$(sed -E 's|.*/workflows/([0-9]+)/runs.*|\1|' <<<"$2")
|
||||
[ -f "$spec/RUNS_$id" ] && { cat "$spec/RUNS_$id"; exit 0; }
|
||||
echo '{"workflow_runs":[]}'; exit 0 ;;
|
||||
esac
|
||||
fi
|
||||
exit 0
|
||||
BLIND2
|
||||
chmod +x "$d/bin/gh"
|
||||
out=$( cd "$d" && PATH="$d/bin:$PATH" GH_SPEC="$d/spec" OWNER=acme REPO=widget \
|
||||
SECRET_NAMES=$'PROVIDED\nOTHER' bash "$AUDIT" --static 2>&1 ); rc=$?
|
||||
grep -q "PROVIDED" <<<"$out" && bad "charged a secret the context says exists" || ok "SECRET_NAMES satisfies a referenced secret"
|
||||
grep -q "ABSENT_ONE" <<<"$out" && ok "still bites on one the context does NOT list" || bad "SECRET_NAMES suppressed a real phantom"
|
||||
[ $rc -eq 1 ] && ok "the check BITES in CI rather than withholding forever" || bad "withheld despite having the names (exit $rc)"
|
||||
grep -q "WITHHELD" <<<"$out" && bad "withheld even though SECRET_NAMES was supplied" || ok "does not withhold when the names are supplied"
|
||||
|
||||
# =============================================================================
|
||||
echo
|
||||
echo "audit-health — --static judges the DIFF, never the world"
|
||||
|
||||
Reference in new issue
Block a user