Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ jobs:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0 # fix-class gate diffs base..head; a depth-1 clone cannot resolve the range
persist-credentials: false # no later step pushes or fetches a private ref; GH_TOKEN env covers gh

# Derived files (SHA256SUMS, size-budgets.tsv rows, INDEX.md, INDEX-scripts.md) are not committed by lane PRs, so two
# PRs never conflict on them. Rebuild them here, before any gate reads them; a land commit (VERSION
Expand All @@ -62,6 +63,7 @@ jobs:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0 # fix-class gate diffs base..head; a depth-1 clone cannot resolve the range
persist-credentials: false # no later step pushes or fetches a private ref; GH_TOKEN env covers gh

# Derived files (SHA256SUMS, size-budgets.tsv rows, INDEX.md, INDEX-scripts.md) are not committed by lane PRs, so two
# PRs never conflict on them. Rebuild them here, before any gate reads them; a land commit (VERSION
Expand Down Expand Up @@ -120,6 +122,7 @@ jobs:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0 # fix-class gate diffs base..head; a depth-1 clone cannot resolve the range
persist-credentials: false # no later step pushes or fetches a private ref; GH_TOKEN env covers gh

# Derived files (SHA256SUMS, size-budgets.tsv rows, INDEX.md, INDEX-scripts.md) are not committed by lane PRs, so two
# PRs never conflict on them. Rebuild them here, before any gate reads them; a land commit (VERSION
Expand Down Expand Up @@ -185,6 +188,7 @@ jobs:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0 # fix-class gate diffs base..head; a depth-1 clone cannot resolve the range
persist-credentials: false # no later step pushes or fetches a private ref; GH_TOKEN env covers gh

# Derived files (SHA256SUMS, size-budgets.tsv rows, INDEX.md, INDEX-scripts.md) are not committed by lane PRs, so two
# PRs never conflict on them. Rebuild them here, before any gate reads them; a land commit (VERSION
Expand Down Expand Up @@ -256,6 +260,7 @@ jobs:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0 # fix-class gate diffs base..head; a depth-1 clone cannot resolve the range
persist-credentials: false # no later step pushes or fetches a private ref; GH_TOKEN env covers gh

# Derived files (SHA256SUMS, size-budgets.tsv rows, INDEX.md, INDEX-scripts.md) are not committed by lane PRs, so two
# PRs never conflict on them. Rebuild them here, before any gate reads them; a land commit (VERSION
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ jobs:
steps:
# SHA-pinned, not a mutable tag (the skill's own rule for CI actions).
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false # only gh release create runs later, via GH_TOKEN env

# The tag must match the shipped VERSION and the top CHANGELOG heading, or
# the release would advertise a version the tree does not contain. This is
Expand Down
3 changes: 3 additions & 0 deletions changelog.d/persist-credentials.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### Fixed
- Every actions/checkout step in ci.yml and release.yml now sets `persist-credentials: false` (zizmor artipacked): no later step pushes or fetches a private ref, and gh uses GH_TOKEN from env. scripts/test_workflow_persist_credentials.py, registered in scripts/ci-tests.d, parses each workflow with `yaml.safe_load` and fails any checkout step (any case, quoted or flow-style) whose `with.persist-credentials` is not false. There is no ignore comment. It exits 2 when PyYAML, the directory or the workflow files are missing, so it never passes unparsed.
- The test also takes a directory argument and can scan the shipped workflow templates; the dcr-gates.yml template checkout still lacks `persist-credentials: false` (follow-up, needs a skills-tree edit).
1 change: 1 addition & 0 deletions scripts/ci-tests.d/workflow-persist-credentials.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
python3 scripts/test_workflow_persist_credentials.py
68 changes: 68 additions & 0 deletions scripts/test_workflow_persist_credentials.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/usr/bin/env python3
"""Every actions/checkout step in .github/workflows must set `persist-credentials: false` (zizmor artipacked).
The workflow is parsed with yaml.safe_load, so quoting, flow style, key order and `with:`/`uses:` text inside
run: blocks or comments cannot fool it. A step counts as a checkout when `str(uses).lower()` starts with
`actions/checkout@`; it passes only when `with.persist-credentials` is boolean False or the string "false".
There is no ignore comment. Fails closed (exit 2) when PyYAML is missing, the directory is missing, or no
workflow file is found; exit 1 lists offenders as `file: job[index]`. Offline.
Usage: python3 scripts/test_workflow_persist_credentials.py [dir ...] (default .github/workflows)"""
import pathlib, sys

try:
import yaml
except ImportError:
print("PyYAML is required (import yaml failed); refusing to pass without parsing the workflows", file=sys.stderr)
sys.exit(2)

def offenders(text):
"""Return `job[index]` for each checkout step in the workflow text lacking persist-credentials: false."""
bad = []
for job, body in ((yaml.safe_load(text) or {}).get("jobs") or {}).items():
for i, step in enumerate((body or {}).get("steps") or []):
if not isinstance(step, dict) or not str(step.get("uses", "")).lower().startswith("actions/checkout@"):
continue
pc = (step.get("with") or {}).get("persist-credentials")
if pc is not False and pc != "false":
bad.append(f"{job}[{i}]")
return bad

def _wf(steps):
return "jobs:\n j:\n steps:\n" + steps

def main():
# self-check: the detector must flag bare checkouts and accept the fixed forms
ok = " persist-credentials: false\n"
assert offenders(_wf(" - uses: actions/checkout@abc\n")) == ["j[0]"]
assert offenders(_wf(" - uses: actions/checkout@abc\n with:\n fetch-depth: 0\n")) == ["j[0]"]
assert offenders(_wf(" - uses: actions/checkout@abc\n with:\n" + ok)) == []
assert offenders(_wf(" - {uses: actions/checkout@abc}\n")) == ["j[0]"] # flow-style step
assert offenders(_wf(" - {uses: actions/checkout@abc, with: {persist-credentials: false}}\n")) == []
assert offenders(_wf(' - uses: "actions/checkout@abc"\n')) == ["j[0]"] # quoted uses
assert offenders(_wf(" - uses: Actions/Checkout@abc\n")) == ["j[0]"] # case-insensitive
assert offenders(_wf(" - uses: actions/checkout@abc\n with: {persist-credentials: false}\n")) == [] # flow with
assert offenders(_wf(" - uses: actions/checkout@abc\n with: {persist-credentials: \"false\"}\n")) == []
assert offenders(_wf(" - uses: actions/checkout@abc\n with: {persist-credentials: true}\n")) == ["j[0]"]
# text in run:/comments is not a with: key or a checkout
assert offenders(_wf(" - uses: actions/checkout@abc\n - run: |\n with:\n persist-credentials: false\n")) == ["j[0]"]
assert offenders(_wf(" - uses: actions/checkout@abc\n# persist-credentials: false\n")) == ["j[0]"] # col-0 comment
assert offenders(_wf(" - run: |\n uses: actions/checkout@abc\n")) == [] # uses text in run:
assert offenders(_wf(" - uses: actions/checkout@abc # zizmor: ignore[artipacked]\n")) == ["j[0]"] # no ignore comment
# a compliant step must not excuse a later bare one
assert offenders(_wf(" - uses: actions/checkout@a\n with:\n" + ok + " - uses: actions/checkout@b\n")) == ["j[1]"]
args = sys.argv[1:] or [".github/workflows"]
files = []
for d in args:
if not pathlib.Path(d).is_dir():
print(f"missing workflow directory: {d}", file=sys.stderr)
sys.exit(2)
files += sorted(pathlib.Path(d).glob("*.y*ml"))
if not files:
print("no workflow files found in: " + " ".join(args), file=sys.stderr)
sys.exit(2)
fails = [f"{p}: {n}" for p in files for n in offenders(p.read_text())]
if fails:
print("checkout without persist-credentials: false:", *fails, sep="\n ")
sys.exit(1)
print("ok")

main()
Loading