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.

Confine release credentials to the release environment

rcourtman69354b9d20ce
diff --git a/.github/workflows/README.md b/.github/workflows/README.md
index 59d7bcea90..5d9d07ab33 100644
--- a/.github/workflows/README.md
+++ b/.github/workflows/README.md
@@ -22,6 +22,19 @@ That exception can only run the protected default-branch helper, has no shell,
cache, artifact, container, secret, or pull-request checkout ingress, and is
machine-checked down to its permissions, dependencies, and generated program.
+Release, signing and registry credentials (update signing, Apple, SignPath,
+Windows signing, Docker Hub and `WORKFLOW_PAT`) may be read only by a job that
+declares the literal `environment: release`. That environment admits `main`
+and post-merge `release-dispatch/*` branches, which only the release
+dispatcher App can create, so a run on an unmerged branch never receives them.
+Demo-host and CI-tailnet credentials likewise need a deployment environment
+(`demo-stable`, `demo-preview-v6`, `infra`, or the demo workflow's resolved
+choice). The audit matches secret expressions across lines and comments,
+rejects dynamic `secrets[...]` access and workflow-level secret env, and
+requires any push workflow that reads a secret to admit exactly
+`branches: [main]`, because a pushed branch runs before any review. The public
+license verification key is not a credential and stays repository-wide.
+
JavaScript action pins that previously selected Node 20 also belong to a
reviewed Node 24 allowlist. Release-candidate artifact downloads use
`actions/download-artifact` v8.0.1 and issue automation uses
diff --git a/.github/workflows/backfill-release-assets.yml b/.github/workflows/backfill-release-assets.yml
index 1c34b6b211..62956e13f4 100644
--- a/.github/workflows/backfill-release-assets.yml
+++ b/.github/workflows/backfill-release-assets.yml
@@ -17,6 +17,7 @@ concurrency:
jobs:
backfill:
+ environment: release
runs-on: ubuntu-24.04
timeout-minutes: 30
permissions:
diff --git a/.github/workflows/build-release-candidate.yml b/.github/workflows/build-release-candidate.yml
index ce019fbc88..d0c2c9098a 100644
--- a/.github/workflows/build-release-candidate.yml
+++ b/.github/workflows/build-release-candidate.yml
@@ -196,6 +196,7 @@ jobs:
python3 scripts/write_github_output.py secure_runtime_artifact_name "${secure_runtime_artifact_name}"
signing-configuration:
+ environment: release
name: Verify Native Signing Configuration
if: ${{ inputs.require_macos_signing || inputs.require_windows_signing }}
runs-on: ubuntu-24.04
@@ -270,6 +271,7 @@ jobs:
exit "$missing"
sign-macos-agent:
+ environment: release
name: Sign and Notarize macOS Agent
needs: signing-configuration
if: ${{ inputs.require_macos_signing && needs.signing-configuration.result == 'success' }}
@@ -371,6 +373,7 @@ jobs:
compression-level: 0
sign-windows-agent:
+ environment: release
name: Build and Submit Windows Agent Signing
needs: signing-configuration
if: ${{ inputs.require_windows_signing && needs.signing-configuration.result == 'success' }}
@@ -512,6 +515,7 @@ jobs:
# recorded signing request is collected as-is, with no rebuild and no
# second submission or approval.
collect-windows-signing:
+ environment: release
name: Collect and Verify Windows Authenticode
needs: sign-windows-agent
if: ${{ inputs.require_windows_signing && needs.sign-windows-agent.result == 'success' }}
@@ -657,6 +661,7 @@ jobs:
retention-days: 30
build:
+ environment: release
name: Build and Validate Release Candidate
needs: [obtain-release-payload, sign-macos-agent, collect-windows-signing]
if: ${{ always() && needs.obtain-release-payload.result == 'success' && (!inputs.require_macos_signing || needs.sign-macos-agent.result == 'success') && (!inputs.require_windows_signing || needs.collect-windows-signing.result == 'success') }}
diff --git a/.github/workflows/canonical-private-governance.yml b/.github/workflows/canonical-private-governance.yml
index 69f5b9b78f..57f72e8cbf 100644
--- a/.github/workflows/canonical-private-governance.yml
+++ b/.github/workflows/canonical-private-governance.yml
@@ -18,6 +18,7 @@ concurrency:
jobs:
private-governance:
+ environment: release
runs-on: ubuntu-24.04
timeout-minutes: 30
defaults:
diff --git a/.github/workflows/create-release.yml b/.github/workflows/create-release.yml
index 4e3030c187..ee3f525c00 100644
--- a/.github/workflows/create-release.yml
+++ b/.github/workflows/create-release.yml
@@ -93,6 +93,7 @@ permissions:
jobs:
# Combined version extraction and validation (saves a checkout)
prepare:
+ environment: release
permissions:
actions: read
contents: read
@@ -371,6 +372,7 @@ jobs:
# closed. Inert draft-only and historical-backfill runs do not publish and
# therefore do not require this repository setting.
publication_trust_preflight:
+ environment: release
name: Publication Trust Preflight
needs: prepare
runs-on: ubuntu-24.04
@@ -1399,6 +1401,7 @@ jobs:
echo "URL: ${WORKFLOW_OUTPUT_2}"
backfill_release_assets:
+ environment: release
needs:
- prepare
- publication_trust_preflight
@@ -1643,6 +1646,7 @@ jobs:
# remain inert until public readiness and activation allow the separate
# convergence workflow to update the live paid-runtime broker manifest.
stage_private_pro_runtime:
+ environment: release
needs:
- prepare
- publication_trust_preflight
@@ -1848,6 +1852,7 @@ jobs:
# digests directly: the tag, both Docker images and the Helm chart must all
# have published before the GitHub release may be activated.
activate_release:
+ environment: release
needs:
- prepare
- publication_trust_preflight
diff --git a/.github/workflows/promote-floating-tags.yml b/.github/workflows/promote-floating-tags.yml
index 972aed2147..91c37709a8 100644
--- a/.github/workflows/promote-floating-tags.yml
+++ b/.github/workflows/promote-floating-tags.yml
@@ -38,6 +38,7 @@ permissions:
jobs:
promote-images:
+ environment: release
runs-on: ubuntu-24.04
timeout-minutes: 30
permissions:
diff --git a/.github/workflows/promote-private-pro-runtime.yml b/.github/workflows/promote-private-pro-runtime.yml
index 5534e295bc..5b25db795b 100644
--- a/.github/workflows/promote-private-pro-runtime.yml
+++ b/.github/workflows/promote-private-pro-runtime.yml
@@ -42,6 +42,7 @@ permissions:
jobs:
promote:
+ environment: release
runs-on: ubuntu-24.04
timeout-minutes: 65
steps:
diff --git a/.github/workflows/publish-docker.yml b/.github/workflows/publish-docker.yml
index 2ebeb4919b..ad7f1b3f97 100644
--- a/.github/workflows/publish-docker.yml
+++ b/.github/workflows/publish-docker.yml
@@ -36,6 +36,7 @@ permissions:
jobs:
publish:
+ environment: release
name: Publish ${{ matrix.image }} image
runs-on: ubuntu-24.04
timeout-minutes: 60 # Increased for multi-arch builds with QEMU
@@ -231,6 +232,7 @@ jobs:
echo "Floating aliases are promoted separately at the activation barrier."
verify:
+ environment: release
name: Verify exact image identities and provenance
needs: publish
runs-on: ubuntu-24.04
diff --git a/.github/workflows/qualify-browser-update-release.yml b/.github/workflows/qualify-browser-update-release.yml
index 75cc9372d9..9b0741e472 100644
--- a/.github/workflows/qualify-browser-update-release.yml
+++ b/.github/workflows/qualify-browser-update-release.yml
@@ -21,6 +21,7 @@ concurrency:
cancel-in-progress: false
jobs:
journey:
+ environment: infra
runs-on: ubuntu-24.04
timeout-minutes: 40
steps:
diff --git a/.github/workflows/recover-release-activation.yml b/.github/workflows/recover-release-activation.yml
index 8f5c774199..e66ec67264 100644
--- a/.github/workflows/recover-release-activation.yml
+++ b/.github/workflows/recover-release-activation.yml
@@ -28,6 +28,7 @@ permissions:
jobs:
recover_activation:
+ environment: release
name: Revalidate and recover activation
runs-on: ubuntu-24.04
timeout-minutes: 30
diff --git a/.github/workflows/release-signing-preflight.yml b/.github/workflows/release-signing-preflight.yml
index f05fdd92f7..0f5430d6b2 100644
--- a/.github/workflows/release-signing-preflight.yml
+++ b/.github/workflows/release-signing-preflight.yml
@@ -34,6 +34,7 @@ concurrency:
jobs:
apple-signing-preflight:
+ environment: release
name: Apple Developer ID and Notary Access
runs-on: macos-15
timeout-minutes: 15
diff --git a/.github/workflows/retry-release-convergence.yml b/.github/workflows/retry-release-convergence.yml
index 23785326e3..9630300e4e 100644
--- a/.github/workflows/retry-release-convergence.yml
+++ b/.github/workflows/retry-release-convergence.yml
@@ -30,6 +30,7 @@ concurrency:
jobs:
reconcile_channel_heads:
+ environment: release
runs-on: ubuntu-24.04
timeout-minutes: 10
steps:
diff --git a/.github/workflows/signpath-test-signing.yml b/.github/workflows/signpath-test-signing.yml
index f30f943b14..4ffad14a2f 100644
--- a/.github/workflows/signpath-test-signing.yml
+++ b/.github/workflows/signpath-test-signing.yml
@@ -18,6 +18,7 @@ concurrency:
jobs:
test-signing-proof:
+ environment: release
name: SignPath Test Signing Proof (Never Publish)
runs-on: windows-2025
timeout-minutes: 50
diff --git a/docs/release-control/v6/internal/subsystems/deployment-installability.md b/docs/release-control/v6/internal/subsystems/deployment-installability.md
index ca9fb4b75d..096e017bb4 100644
--- a/docs/release-control/v6/internal/subsystems/deployment-installability.md
+++ b/docs/release-control/v6/internal/subsystems/deployment-installability.md
@@ -1283,7 +1283,10 @@ dispatched commit, so release secrets can be confined to refs that exist only
after merge while unmerged `release-candidate/*` heads stay outside them. The
snapshot check validates identity only; restricting who can create or move
`release-dispatch/*` refs belongs to a repository ruleset, and until that
-ruleset is active the namespace carries no extra trust. Qualification, workflow execution, compiler dispatch
+ruleset is active the namespace carries no extra trust. Every job that reads a
+release, signing or registry credential declares `environment: release`, whose
+deployment branch policy admits only `main` and `release-dispatch/*`;
+`scripts/check_workflow_trust.py` enforces the declaration. Qualification, workflow execution, compiler dispatch
and published artifacts bind to that head, not a later merge or branch tip.
The source workflow must implement the snapshot input and provenance contract
before the release train spends an exact qualification run on it. Later
diff --git a/scripts/check_workflow_trust.py b/scripts/check_workflow_trust.py
index 58697446d0..c0fff76a4a 100644
--- a/scripts/check_workflow_trust.py
+++ b/scripts/check_workflow_trust.py
@@ -9,6 +9,8 @@ import sys
from dataclasses import dataclass
from pathlib import Path
+import yaml
+
def _yaml_key(name: str) -> str:
"""Return a pattern for equivalent plain, single-, or double-quoted keys."""
@@ -119,6 +121,54 @@ SECRET_CONTEXT_RE = re.compile(
r")"
)
SECRET_CONTEXT_TOKEN_RE = re.compile(r"(?<![\w.])secrets\b")
+# GitHub matches context and secret names case-insensitively.
+SECRET_REFERENCE_RE = re.compile(
+ r"(?<![\w.])secrets(?:"
+ r"\s*\.\s*([A-Za-z_][A-Za-z0-9_]*)\b|"
+ r"\s*\[\s*(['\"])([A-Za-z_][A-Za-z0-9_]*)\2\s*\]"
+ r")",
+ re.IGNORECASE,
+)
+SECRET_TOKEN_RE = re.compile(r"(?<![\w.])secrets\b", re.IGNORECASE)
+# Release, signing and registry credentials live only in the protected
+# `release` environment, which admits `main` and post-merge `release-dispatch/*`
+# branches, so no run on an unmerged branch can read them. The public license
+# verification key is not a credential and stays repository-wide.
+RELEASE_ENVIRONMENT = "release"
+RELEASE_ENVIRONMENT_SECRETS = frozenset(
+ {
+ "APPLE_DEVELOPER_ID_APPLICATION_IDENTITY",
+ "APPLE_DEVELOPER_ID_CERTIFICATE_P12_BASE64",
+ "APPLE_DEVELOPER_ID_CERTIFICATE_PASSWORD",
+ "APPLE_NOTARY_ISSUER_ID",
+ "APPLE_NOTARY_KEY_ID",
+ "APPLE_NOTARY_KEY_P8_BASE64",
+ "DOCKER_PASSWORD",
+ "DOCKER_USERNAME",
+ "PULSE_UPDATE_SIGNING_KEY",
+ "SIGNPATH_API_TOKEN",
+ "WINDOWS_CODE_SIGNING_CERTIFICATE_PASSWORD",
+ "WINDOWS_CODE_SIGNING_CERTIFICATE_PFX_BASE64",
+ "WORKFLOW_PAT",
+ }
+)
+# Demo-host and CI-tailnet credentials live in deployment environments.
+# Only update-demo-server.yml may pick its demo environment from a resolved output.
+DEPLOYMENT_ENVIRONMENT_SECRETS = frozenset(
+ {
+ "DEMO_SERVER_HOST",
+ "DEMO_SERVER_SSH_KEY",
+ "DEMO_SERVER_USER",
+ "TS_CI_DEPLOY_OAUTH_CLIENT_ID",
+ "TS_CI_DEPLOY_OAUTH_SECRET",
+ }
+)
+DEPLOYMENT_ENVIRONMENTS = frozenset({"demo-preview-v6", "demo-stable", "infra"})
+DEPLOYMENT_ENVIRONMENT_CHOICES = {
+ ("update-demo-server.yml", "update-demo"): frozenset(
+ {"${{ needs.resolve.outputs.environment_name }}"}
+ ),
+}
CACHE_ACTION_PREFIXES = ("actions/cache@", "actions/cache/")
SETUP_CACHE_ACTION_PREFIXES = (
"actions/setup-go@",
@@ -1393,6 +1443,197 @@ def _audit_privileged_job_caches(path: Path, lines: list[str]) -> list[Finding]:
return findings
+def _unquoted(value: str) -> str:
+ value = value.strip()
+ if len(value) >= 2 and value[0] == value[-1] and value[0] in {"'", '"'}:
+ return value[1:-1]
+ return value
+
+
+class _UniqueKeyLoader(yaml.BaseLoader):
+ """Load every scalar as a string and refuse duplicate keys, as GitHub does."""
+
+
+def _construct_unique_mapping(loader, node, deep=False):
+ mapping = {}
+ for key_node, value_node in node.value:
+ key = loader.construct_object(key_node, deep=deep)
+ if key in mapping:
+ raise yaml.constructor.ConstructorError(
+ None, None, f"duplicate key {key!r}", key_node.start_mark
+ )
+ mapping[key] = loader.construct_object(value_node, deep=deep)
+ return mapping
+
+
+_UniqueKeyLoader.add_constructor(
+ yaml.resolver.BaseResolver.DEFAULT_MAPPING_TAG, _construct_unique_mapping
+)
+
+
+def _expressions(text: str) -> list[str]:
+ """Return every ${{ }} expression body in *text*.
+
+ Expressions may span lines and contain `#`, and a `}}` inside a quoted
+ string does not end one. An unterminated expression runs to the end.
+ """
+ found: list[str] = []
+ index = 0
+ while (start := text.find("${{", index)) != -1:
+ cursor = start + 3
+ quote = ""
+ while cursor < len(text):
+ char = text[cursor]
+ if quote:
+ if char == quote:
+ if text[cursor + 1 : cursor + 2] == quote:
+ cursor += 2
+ continue
+ quote = ""
+ elif char in {"'", '"'}:
+ quote = char
+ elif text.startswith("}}", cursor):
+ break
+ cursor += 1
+ found.append(text[start + 3 : cursor])
+ index = cursor + 2
+ return found
+
+
+def _secret_names(text: str) -> tuple[set[str], bool]:
+ """Return the secrets (upper-cased, as GitHub matches them) that *text* names,
+ and whether any access is dynamic."""
+ names: set[str] = set()
+ dynamic = False
+ for expression in _expressions(text):
+ references = list(SECRET_REFERENCE_RE.finditer(expression))
+ names.update((match.group(1) or match.group(3)).upper() for match in references)
+ if len(SECRET_TOKEN_RE.findall(expression)) != len(references):
+ dynamic = True
+ return names, dynamic
+
+
+def _scalars(node: object) -> list[str]:
+ """Return every decoded string key and value in a parsed YAML node."""
+ if isinstance(node, dict):
+ return [text for key, value in node.items() for text in (*_scalars(key), *_scalars(value))]
+ if isinstance(node, list):
+ return [text for item in node for text in _scalars(item)]
+ return [node] if isinstance(node, str) else []
+
+
+def _node_secret_names(raw: str, node: object) -> tuple[set[str], bool]:
+ """Scan both the raw text and the decoded YAML values GitHub evaluates.
+
+ YAML quoting can change where an expression's strings end (`''` decodes to
+ `'`), so the decoded values are authoritative and the raw text a backstop.
+ """
+ raw_names, raw_dynamic = _secret_names(raw)
+ decoded_names, decoded_dynamic = _secret_names("\n".join(_scalars(node)))
+ return raw_names | decoded_names, raw_dynamic or decoded_dynamic
+
+
+def _environment_name(job: object) -> str | None:
+ environment = job.get("environment") if isinstance(job, dict) else None
+ if isinstance(environment, dict):
+ environment = environment.get("name")
+ return environment if isinstance(environment, str) else None
+
+
+def _push_is_main_only(document: dict) -> bool:
+ """Return whether the push trigger admits exactly the literal branch main."""
+ push = document.get("on", {}).get("push") if isinstance(document.get("on"), dict) else None
+ return (
+ isinstance(push, dict)
+ and set(push) == {"branches"}
+ and push["branches"] == ["main"]
+ )
+
+
+def _has_push_trigger(document: dict) -> bool:
+ on = document.get("on")
+ if isinstance(on, str):
+ return on == "push"
+ return "push" in on if isinstance(on, (list, dict)) else False
+
+
+def _audit_secret_environments(path: Path, lines: list[str]) -> list[Finding]:
+ """Keep protected credentials inside the environments that admit only merged refs."""
+ try:
+ document = yaml.load("\n".join(lines), Loader=_UniqueKeyLoader)
+ except yaml.YAMLError as error:
+ return [Finding(path, 1, f"workflow must be valid YAML without duplicate keys: {error}")]
+ if not isinstance(document, dict):
+ return [Finding(path, 1, "workflow must be a YAML mapping")]
+ jobs = document.get("jobs") if isinstance(document.get("jobs"), dict) else {}
+
+ findings: list[Finding] = []
+ ranges = _runner_job_ranges(lines)
+ texts = {
+ _unquoted(lines[start].split("#", 1)[0].strip().removesuffix(":")): (start, "\n".join(lines[start:end]))
+ for start, end, _ in ranges
+ }
+ if set(texts) != set(jobs):
+ findings.append(Finding(
+ path, 1, "jobs must be a plain block mapping whose keys the trust audit can read",
+ ))
+
+ reads_secrets = False
+ for name, job in jobs.items():
+ start, text = texts.get(name, (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"
+ reads_secrets = reads_secrets or bool(names) or dynamic or inherits
+ environment = _environment_name(job)
+ if dynamic:
+ findings.append(Finding(
+ path, start + 1,
+ "jobs must name secrets statically; dynamic secrets[...] access "
+ "cannot be confined to an environment",
+ ))
+ release = sorted(names & RELEASE_ENVIRONMENT_SECRETS)
+ if release and environment != RELEASE_ENVIRONMENT:
+ findings.append(Finding(
+ path, start + 1,
+ f"job reads release credentials {', '.join(release)} and must "
+ f"declare the literal environment: {RELEASE_ENVIRONMENT}",
+ ))
+ deployment = sorted(names & DEPLOYMENT_ENVIRONMENT_SECRETS)
+ allowed = DEPLOYMENT_ENVIRONMENTS | DEPLOYMENT_ENVIRONMENT_CHOICES.get((path.name, name), frozenset())
+ if deployment and environment not in allowed:
+ findings.append(Finding(
+ path, start + 1,
+ f"job reads deployment credentials {', '.join(deployment)} and must "
+ "declare a deployment environment",
+ ))
+
+ # Workflow-level env and other text outside jobs applies to every job.
+ covered = {index for start, end, _ in ranges for index in range(start, end)}
+ outside = "\n".join(line for index, line in enumerate(lines) if index not in covered)
+ names, dynamic = _node_secret_names(
+ outside, {key: value for key, value in document.items() if key != "jobs"}
+ )
+ protected = sorted(names & (RELEASE_ENVIRONMENT_SECRETS | DEPLOYMENT_ENVIRONMENT_SECRETS))
+ if protected or dynamic:
+ findings.append(Finding(
+ path, 1,
+ "release and deployment credentials may only be read inside a job "
+ "that declares their environment",
+ ))
+ names.discard("GITHUB_TOKEN")
+ reads_secrets = reads_secrets or bool(names) or dynamic
+
+ # A pushed proposal branch runs push workflows before any review or merge.
+ if reads_secrets and _has_push_trigger(document) and not _push_is_main_only(document):
+ findings.append(Finding(
+ path, 1,
+ "push workflows that read secrets must restrict push to exactly "
+ "branches: [main], with no tag or ignore filters",
+ ))
+ return findings
+
+
def audit_workflow(path: Path) -> list[Finding]:
lines = path.read_text(encoding="utf-8").splitlines()
findings = _audit_yaml_trust_shape(path, lines)
@@ -1401,6 +1642,7 @@ def audit_workflow(path: Path) -> list[Finding]:
findings.extend(_audit_privileged_runner_trust(path, lines))
findings.extend(_audit_privileged_job_caches(path, lines))
findings.extend(_audit_workflow_run_trigger(path, lines))
+ findings.extend(_audit_secret_environments(path, lines))
has_workflow_run_trigger = _has_trigger(lines, "workflow_run")
if (
diff --git a/scripts/release_control/release_promotion_policy_test.py b/scripts/release_control/release_promotion_policy_test.py
index b2c7f30009..9b2d748d73 100644
--- a/scripts/release_control/release_promotion_policy_test.py
+++ b/scripts/release_control/release_promotion_policy_test.py
@@ -750,6 +750,36 @@ class ReleasePromotionPolicyTest(unittest.TestCase):
self.assertFalse(qualifies(replaced(new_shape, "backend_tests", "failure")))
self.assertFalse(qualifies(replaced(old_shape, "backend_tests", "failure")))
+ def test_release_credential_jobs_run_only_in_the_release_environment(self) -> None:
+ # The release environment admits main and post-merge release-dispatch/*
+ # refs, so these jobs, and only runs on those refs, receive signing,
+ # registry and PAT credentials. Every release path that publishes or
+ # signs must keep them there.
+ expected = {
+ ".github/workflows/create-release.yml": (
+ "prepare", "publication_trust_preflight", "backfill_release_assets",
+ "stage_private_pro_runtime", "activate_release",
+ ),
+ ".github/workflows/build-release-candidate.yml": (
+ "signing-configuration", "sign-macos-agent", "sign-windows-agent",
+ "collect-windows-signing", "build",
+ ),
+ ".github/workflows/publish-docker.yml": ("publish", "verify"),
+ ".github/workflows/promote-floating-tags.yml": ("promote-images",),
+ ".github/workflows/promote-private-pro-runtime.yml": ("promote",),
+ ".github/workflows/recover-release-activation.yml": ("recover_activation",),
+ ".github/workflows/backfill-release-assets.yml": ("backfill",),
+ ".github/workflows/retry-release-convergence.yml": ("reconcile_channel_heads",),
+ }
+ for path, jobs in expected.items():
+ jobs_by_name = yaml.safe_load(read(path))["jobs"]
+ for job in jobs:
+ with self.subTest(workflow=path, job=job):
+ self.assertEqual("release", jobs_by_name[job].get("environment"))
+ # The smoke job reads only the public license key, so it stays outside.
+ create = yaml.safe_load(read(".github/workflows/create-release.yml"))["jobs"]
+ self.assertNotIn("environment", create["release_smoke"])
+
def test_activation_recovery_admits_snapshot_runs_only_with_merged_provenance(self) -> None:
# Execute the recovery's source-run admission. Release-train runs are
# dispatched on release-candidate/ or release-dispatch/ snapshot refs,
diff --git a/scripts/tests/test_workflow_trust.py b/scripts/tests/test_workflow_trust.py
index 0aca1bb9c1..ecee712360 100644
--- a/scripts/tests/test_workflow_trust.py
+++ b/scripts/tests/test_workflow_trust.py
@@ -1323,7 +1323,9 @@ jobs:
6,
)
- trusted_push = self.audit(
+ # A push to any branch runs before review, so only main may carry
+ # secrets, and release credentials need the release environment.
+ unfiltered_push = self.audit(
"""on: push
permissions: {}
jobs:
@@ -1334,10 +1336,175 @@ jobs:
- env:
GH_TOKEN: ${{ secrets.WORKFLOW_PAT }}
run: echo checked
+"""
+ )
+ self.assertTrue(any("branches: [main]" in finding for finding in unfiltered_push))
+ self.assertTrue(any("environment: release" in finding for finding in unfiltered_push))
+ trusted_push = self.audit(
+ """on:
+ push:
+ branches: [main]
+permissions: {}
+jobs:
+ trusted:
+ environment: release
+ runs-on: ubuntu-24.04
+ timeout-minutes: 10
+ steps:
+ - env:
+ GH_TOKEN: ${{ secrets.WORKFLOW_PAT }}
+ run: echo checked
"""
)
self.assertEqual(trusted_push, [])
+ def release_job(self, environment: str, secret: str = "${{ secrets.PULSE_UPDATE_SIGNING_KEY }}",
+ trigger: str = "on: workflow_dispatch", header: str = "") -> list[str]:
+ return self.audit(
+ f"""{trigger}
+permissions: {{}}
+{header}jobs:
+ sign:
+{environment} runs-on: ubuntu-24.04
+ timeout-minutes: 10
+ steps:
+ - env:
+ KEY: {secret}
+ run: echo checked
+"""
+ )
+
+ def test_release_credentials_require_the_release_environment(self) -> None:
+ for environment in (" environment: release\n", " environment: 'release'\n",
+ " environment:\n name: release\n url: https://example.invalid\n"):
+ with self.subTest(environment=environment):
+ self.assertEqual(self.release_job(environment), [])
+ for environment in ("", " environment: production\n", " environment: ${{ inputs.env }}\n",
+ " environment:\n url: https://example.invalid\n"):
+ with self.subTest(environment=environment):
+ self.assertTrue(any("environment: release" in finding
+ for finding in self.release_job(environment)))
+ # Every protected credential is covered, including registry and PAT.
+ for name in sorted(workflow_trust.RELEASE_ENVIRONMENT_SECRETS):
+ with self.subTest(secret=name):
+ self.assertTrue(any(name in finding and "environment: release" in finding
+ for finding in self.release_job("", f"${{{{ secrets.{name} }}}}")))
+ # The public license verification key is not a credential.
+ self.assertEqual(self.release_job("", "${{ secrets.PULSE_LICENSE_PUBLIC_KEY }}"), [])
+
+ def test_release_credentials_cannot_hide_from_the_environment_rule(self) -> None:
+ hidden = {
+ "bracket": "${{ secrets['WORKFLOW_PAT'] }}",
+ "dynamic": "${{ secrets[vars.NAME] }}",
+ "whole context": "${{ toJSON(secrets) }}",
+ "multi-line": "${{\n secrets.WORKFLOW_PAT }}",
+ "quoted hash": "${{ format('#{0}', secrets.WORKFLOW_PAT) }}",
+ }
+ for name, secret in hidden.items():
+ with self.subTest(hidden=name):
+ self.assertTrue(any("environment: release" in finding or "dynamic secrets" in finding
+ for finding in self.release_job("", secret)))
+ self.assertTrue(any("dynamic secrets" in finding
+ for finding in self.release_job(" environment: release\n",
+ "${{ toJSON(secrets) }}")))
+ workflow_env = self.release_job(
+ " environment: release\n", "plain",
+ header="env:\n KEY: ${{ secrets.WORKFLOW_PAT }}\n")
+ self.assertTrue(any("inside a job" in finding for finding in workflow_env))
+
+ def test_deployment_credentials_require_a_deployment_environment(self) -> None:
+ secret = "${{ secrets.TS_CI_DEPLOY_OAUTH_SECRET }}"
+ for environment in (" environment: infra\n", " environment: demo-stable\n"):
+ with self.subTest(environment=environment):
+ self.assertEqual(self.release_job(environment, secret), [])
+ resolved = " environment: ${{ needs.resolve.outputs.environment_name }}\n"
+ for environment in ("", " environment: release\n", " environment: ${{ inputs.env }}\n", resolved):
+ with self.subTest(environment=environment):
+ self.assertTrue(any("deployment environment" in finding
+ for finding in self.release_job(environment, secret)))
+ # Only the demo workflow's own job may choose its demo environment at runtime.
+ demo = f"""on: workflow_call
+permissions: {{}}
+jobs:
+ update-demo:
+{resolved} runs-on: ubuntu-24.04
+ timeout-minutes: 10
+ steps:
+ - env:
+ KEY: {secret}
+ run: echo checked
+"""
+ self.assertEqual(self.audit(demo, name="update-demo-server.yml"), [])
+ self.assertTrue(self.audit(demo, name="other.yml"))
+
+ def test_structural_bypasses_are_rejected(self) -> None:
+ release = "environment: release"
+ cases = {
+ "lower-case secret name": self.release_job("", "${{ secrets.workflow_pat }}"),
+ "closing braces in a string": self.release_job(
+ "", "${{ format('}}{0}', secrets.WORKFLOW_PAT) }}"),
+ "YAML-escaped quote before closing braces": self.release_job(
+ "", "'${{ format(''}}{0}'', secrets.WORKFLOW_PAT) }}'"),
+ "hash glued to the environment name": self.release_job(
+ " environment: release#unprotected\n"),
+ "duplicate environment key": self.release_job(
+ " environment: production\n environment: release\n"),
+ }
+ for name, findings in cases.items():
+ with self.subTest(case=name):
+ self.assertTrue(any(release in finding or "duplicate key" in finding
+ for finding in findings), findings)
+ env = " environment: release\n"
+ pushes = {
+ "quoted tags filter": "on:\n push:\n branches: [main]\n \"tags\": ['**']",
+ "push hidden behind a description": (
+ "on:\n workflow_dispatch:\n inputs:\n note:\n description: |\n"
+ " push:\n branches: [main]\n push:"),
+ }
+ for name, trigger in pushes.items():
+ with self.subTest(case=name):
+ self.assertTrue(any("branches: [main]" in finding
+ for finding in self.release_job(env, trigger=trigger)))
+ quoted_inherit = self.audit("""on: push
+permissions: {}
+jobs:
+ call:
+ uses: ./.github/workflows/reusable.yml
+ secrets: 'inherit'
+""")
+ self.assertTrue(any("branches: [main]" in finding for finding in quoted_inherit))
+
+ def test_push_workflows_with_secrets_admit_only_main(self) -> None:
+ env = " environment: release\n"
+ main_only = "on:\n push:\n branches: [main]"
+ self.assertEqual(self.release_job(env, trigger=main_only), [])
+ self.assertEqual(self.release_job(env, trigger="on:\n push:\n branches:\n - main"), [])
+ for trigger in ("on: push", "on: [push, workflow_dispatch]", "on:\n push:",
+ "on:\n push:\n branches: [main, 'release/**']",
+ "on:\n push:\n branches: ['**']",
+ "on:\n push:\n branches: [main]\n tags: ['v*']",
+ "on:\n push:\n branches-ignore: [feature]"):
+ with self.subTest(trigger=trigger):
+ self.assertTrue(any("branches: [main]" in finding
+ for finding in self.release_job(env, trigger=trigger)))
+ # GITHUB_TOKEN alone is not a repository secret.
+ self.assertEqual(self.release_job("", "${{ secrets.GITHUB_TOKEN }}", trigger="on: push"), [])
+ inherit = self.audit("""on: push
+permissions: {}
+jobs:
+ call:
+ uses: ./.github/workflows/reusable.yml
+ secrets: inherit
+""")
+ self.assertTrue(any("branches: [main]" in finding for finding in inherit))
+
+ def test_live_release_and_deployment_credentials_are_confined(self) -> None:
+ for path in sorted((REPO_ROOT / ".github/workflows").glob("*.yml")):
+ with self.subTest(workflow=path.name):
+ findings = workflow_trust._audit_secret_environments(
+ path, path.read_text(encoding="utf-8").splitlines())
+ self.assertEqual([finding.render() for finding in findings], [])
+
def test_repository_workflows_satisfy_contract(self) -> None:
findings = workflow_trust.audit_directory(REPO_ROOT / ".github" / "workflows")
self.assertEqual([finding.render() for finding in findings], [])