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.

Avoid rebuilding workflow trust patterns and unused YAML fallbacks

pulse-triage[bot]994ed8b9bc40
diff --git a/docs/release-control/v6/internal/subsystems/deployment-installability.md b/docs/release-control/v6/internal/subsystems/deployment-installability.md
index 857436e082..f2ad2f6176 100644
--- a/docs/release-control/v6/internal/subsystems/deployment-installability.md
+++ b/docs/release-control/v6/internal/subsystems/deployment-installability.md
@@ -1551,6 +1551,22 @@ before service operations. Neither this driver nor worker source tests install
host policy. Production activation still requires independent review and the
operational owner's acceptance of the native result and published-source path.
+### Workflow trust scanning reuses patterns, not decisions
+
+`scripts/check_workflow_trust.py` retains at most 64 escaped-key pattern strings
+for its fixed audit vocabulary. It still rereads and reparses every workflow
+on each audit; file contents, parsed documents and findings are never cached.
+Normal block jobs use their captured raw text alongside decoded YAML values
+for secret checks, without serialising an unused fallback. A job whose raw
+mapping cannot be read keeps both its shape rejection and its serialised
+fallback/decoded-secret checks. No permission, credential, runner, cache,
+action-pin, trigger or generated-code rule changes.
+
+`scripts/tests/test_workflow_trust.py` verifies bounded pattern reuse, changed
+content at the same path, raw/escaped decoded secrets without a fallback dump,
+and unreadable-job fallback rejection. The complete existing trust suite and
+whole-directory audit remain required through the discovered script smoke suite.
+
### Superseded pull request validation
Build and Test and Core E2E cancel an older run for the same pull request when
diff --git a/scripts/check_workflow_trust.py b/scripts/check_workflow_trust.py
index c0fff76a4a..9be848cef8 100644
--- a/scripts/check_workflow_trust.py
+++ b/scripts/check_workflow_trust.py
@@ -7,13 +7,17 @@ import argparse
import re
import sys
from dataclasses import dataclass
+from functools import lru_cache
from pathlib import Path
import yaml
+@lru_cache(maxsize=64)
def _yaml_key(name: str) -> str:
"""Return a pattern for equivalent plain, single-, or double-quoted keys."""
+ # Callers use this fixed vocabulary throughout per-line checks. Retain only
+ # bounded pattern strings, never workflow contents, parsed nodes or verdicts.
escaped = re.escape(name)
# YAML double-quoted scalars can spell any ASCII character through \x, \u,
# or \U escapes. GitHub decodes those spellings before interpreting the
@@ -1580,7 +1584,12 @@ def _audit_secret_environments(path: Path, lines: list[str]) -> list[Finding]:
reads_secrets = False
for name, job in jobs.items():
- start, text = texts.get(name, (0, yaml.safe_dump(job)))
+ # dict.get evaluates its default eagerly. Normal block jobs already
+ # have their source text; serialise only an unreadable job's fallback.
+ if name in texts:
+ start, text = texts[name]
+ else:
+ start, text = 0, yaml.safe_dump(job)
names, dynamic = _node_secret_names(text, job)
names.discard("GITHUB_TOKEN")
inherits = isinstance(job, dict) and job.get("secrets") == "inherit"
diff --git a/scripts/tests/test_workflow_trust.py b/scripts/tests/test_workflow_trust.py
index b4f675789f..cfe07c0e51 100644
--- a/scripts/tests/test_workflow_trust.py
+++ b/scripts/tests/test_workflow_trust.py
@@ -8,6 +8,7 @@ import sys
import tempfile
import unittest
from pathlib import Path
+from unittest import mock
REPO_ROOT = Path(__file__).resolve().parents[2]
@@ -36,6 +37,78 @@ class WorkflowTrustTest(unittest.TestCase):
path.write_text(content, encoding="utf-8")
return [finding.message for finding in workflow_trust.audit_workflow(path)]
+ def test_key_pattern_reuse_is_bounded_without_caching_workflow_verdicts(self) -> None:
+ expected = workflow_trust._yaml_key("uses")
+ for index in range(128):
+ workflow_trust._yaml_key(f"fixture-key-{index}")
+ cache = workflow_trust._yaml_key.cache_info()
+ self.assertEqual(cache.maxsize, 64)
+ self.assertLessEqual(cache.currsize, cache.maxsize)
+ self.assertEqual(workflow_trust._yaml_key("uses"), expected)
+ with tempfile.TemporaryDirectory() as temporary_directory:
+ path = Path(temporary_directory) / "test.yml"
+ safe = f"""permissions: {{}}
+jobs:
+ test:
+ runs-on: ubuntu-24.04
+ timeout-minutes: 10
+ steps:
+ - uses: owner/action@{PIN}
+"""
+ for source, rejected in ((safe, False), (safe.replace(PIN, "v2"), True),
+ (safe, False)):
+ path.write_text(source, encoding="utf-8")
+ findings = workflow_trust.audit_workflow(path)
+ self.assertEqual(bool(findings), rejected)
+ if rejected:
+ self.assertTrue(any("full commit SHA" in finding.message
+ for finding in findings))
+
+ def test_readable_jobs_use_raw_and_decoded_secrets_without_yaml_dump(self) -> None:
+ # No fallback is needed, but both raw and YAML-decoded secret access
+ # must still be checked. The escaped spelling exists only after decode.
+ source = r'''permissions: {}
+jobs:
+ test:
+ runs-on: ubuntu-24.04
+ timeout-minutes: 10
+ env:
+ RAW: ${{ secrets.TS_CI_DEPLOY_OAUTH_SECRET }}
+ DECODED: "${{ secre\x74s.WORKFLOW_PAT }}"
+ steps:
+ - run: echo safe
+'''
+ with mock.patch.object(workflow_trust.yaml, "safe_dump",
+ side_effect=AssertionError("unneeded fallback dump")):
+ findings = self.audit(source)
+ self.assertTrue(any("environment: release" in finding for finding in findings))
+ self.assertTrue(any("deployment environment" in finding for finding in findings))
+
+ def test_unreadable_job_keeps_fallback_and_decoded_secret_rejection(self) -> None:
+ # An escaped job key is rejected as a shape, not ignored. Its protected
+ # secret still needs the decoded-node check through the fallback path.
+ source = r'''permissions: {}
+jobs:
+ readable:
+ runs-on: ubuntu-24.04
+ timeout-minutes: 10
+ steps:
+ - run: echo safe
+ "\x75nreadable":
+ runs-on: ubuntu-24.04
+ timeout-minutes: 10
+ env:
+ DECODED: "${{ secre\x74s.WORKFLOW_PAT }}"
+ steps:
+ - run: echo safe
+'''
+ with mock.patch.object(workflow_trust.yaml, "safe_dump",
+ wraps=workflow_trust.yaml.safe_dump) as dump:
+ findings = self.audit(source)
+ self.assertEqual(dump.call_count, 1)
+ self.assertTrue(any("plain block mapping" in finding for finding in findings))
+ self.assertTrue(any("environment: release" in finding for finding in findings))
+
def test_setup_node_upgrade_preserves_consumer_contract(self) -> None:
# v7 changes its internal module format, not the Node 24 consumer ABI.
# No consumer may rely on the removed dummy NODE_AUTH_TOKEN export.