Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

Block privileged workflow code ingress

pulse-triage[bot]0f7a8683c259
diff --git a/.github/workflows/README.md b/.github/workflows/README.md
index 5225630f49..81a8b751e6 100644
--- a/.github/workflows/README.md
+++ b/.github/workflows/README.md
@@ -15,9 +15,11 @@ pull-request code rather than bypassing the upstream guard.
`workflow_run` is also a privileged trigger. Every handler must filter its
upstream workflow to the literal canonical branch `main`, and checkout steps
-must not select code through triggering-run head metadata. Upstream artifacts
-remain untrusted data and require an independently authenticated handoff before
-any privileged consumer can execute their contents.
+must not select code through triggering-run head metadata. These handlers also
+cannot download upstream workflow artifacts or reacquire repository code with
+command-line Git/GitHub clients or Actions artifact APIs. Upstream artifacts
+remain untrusted data; move any future artifact consumer behind an independently
+authenticated, non-`workflow_run` handoff before privileged use.
Every `actions/checkout` step must also set `persist-credentials` explicitly.
Use `false` unless a later command in the same job performs an authenticated
diff --git a/scripts/check_workflow_trust.py b/scripts/check_workflow_trust.py
index a336f08da3..04e1c7e031 100644
--- a/scripts/check_workflow_trust.py
+++ b/scripts/check_workflow_trust.py
@@ -47,6 +47,19 @@ WORKFLOW_RUN_CODE_REF_RE = re.compile(
r"(?<![\w.])github\.event\.workflow_run\."
r"(?:head_branch|head_repository|head_sha|pull_requests)\b"
)
+# A canonical checkout is not enough if a later step reacquires code or an
+# artifact from a less-trusted run. GitHub calls out artifact downloads and
+# command-line PR fetches as equivalent privileged-workflow ingress paths.
+WORKFLOW_RUN_ARTIFACT_ACTION_PREFIX = "actions/download-artifact@"
+WORKFLOW_RUN_INGRESS_COMMAND_RE = re.compile(
+ r"(?:"
+ r"\bgh\s+(?:pr\s+checkout|run\s+download)\b|"
+ r"\bgit\s+(?:clone|fetch|pull)\b|"
+ r"/actions/artifacts/[^/\s'\"]+/zip(?:[?'\"\s]|$)|"
+ r"refs/pull/"
+ r")",
+ re.IGNORECASE,
+)
SECRET_CONTEXT_RE = re.compile(
r"(?<![\w.])secrets(?:"
r"\.([A-Za-z_][A-Za-z0-9_]*)\b|"
@@ -400,6 +413,17 @@ def audit_workflow(path: Path) -> list[Finding]:
if RUN_RE.match(code):
for script_index, script_line in _run_script_lines(lines, index):
+ if has_workflow_run_trigger and WORKFLOW_RUN_INGRESS_COMMAND_RE.search(
+ script_line
+ ):
+ findings.append(
+ Finding(
+ path,
+ script_index + 1,
+ "workflow_run scripts must not acquire upstream "
+ "workflow artifacts or repository code",
+ )
+ )
for expression in EXPRESSION_RE.findall(script_line):
if SHELL_DATA_CONTEXT_RE.search(expression):
findings.append(
@@ -424,6 +448,16 @@ def audit_workflow(path: Path) -> list[Finding]:
dependency = match.group(1).strip("'\"")
if dependency.startswith("./"):
continue
+ if has_workflow_run_trigger and dependency.lower().startswith(
+ WORKFLOW_RUN_ARTIFACT_ACTION_PREFIX
+ ):
+ findings.append(
+ Finding(
+ path,
+ line_number,
+ "workflow_run must not download upstream workflow artifacts",
+ )
+ )
if dependency.startswith("docker://"):
if not CONTAINER_DIGEST_RE.fullmatch(dependency):
findings.append(
diff --git a/scripts/tests/test_workflow_trust.py b/scripts/tests/test_workflow_trust.py
index 2462095c6e..f2befd5cdd 100644
--- a/scripts/tests/test_workflow_trust.py
+++ b/scripts/tests/test_workflow_trust.py
@@ -268,6 +268,48 @@ steps:
any("must not select code" in finding for finding in untrusted_checkout)
)
+ def test_workflow_run_rejects_artifact_and_code_ingress(self) -> None:
+ findings = self.audit(
+ f"""on:
+ workflow_run:
+ workflows: [Build]
+ branches: [main]
+permissions: {{}}
+steps:
+ - uses: actions/download-artifact@{PIN}
+ - run: gh run download "$RUN_ID"
+ - run: gh pr checkout 17
+ - run: git fetch origin refs/pull/17/head
+ - run: curl -fsS https://api.github.com/repos/o/r/actions/artifacts/17/zip
+"""
+ )
+ self.assertEqual(
+ sum(
+ "workflow artifacts or repository code" in finding
+ for finding in findings
+ ),
+ 4,
+ )
+ self.assertTrue(
+ any(
+ "must not download upstream workflow artifacts" in finding
+ for finding in findings
+ )
+ )
+
+ release_data_only = self.audit(
+ """on:
+ workflow_run:
+ workflows: [Release]
+ branches: [main]
+permissions: {}
+steps:
+ - run: gh release download v1.2.3 --pattern release-activation.json
+ - run: gh api --method POST repos/o/r/actions/runs/17/rerun
+"""
+ )
+ self.assertEqual(release_data_only, [])
+
def test_accepts_documented_authenticated_git_write(self) -> None:
findings = self.audit(
f"""permissions: {{}}