mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-26 12:21:08 +01:00
nightly-tests: read quoted flow keys, and state the signer-environment prerequisite
The trust-closure flow-mapping reader split its masked copy, so a quoted key (`{"environment":
release}`, `{'uses': ...}`) became `''` and the scan accepted a route it must refuse. It now splits
the original bracket-free mapping and keeps the mask only for the shape check. New cases cover a
double- and single-quoted `environment` key, a quoted `uses` key, and a harmless quoted key that
must still be read rather than masked.
The activation notes and the signer caller said the `release` environment already trusts
`nightly-signer`. It admits only `release` today, so both now state that the environment must
admit `nightly-signer` before the first dispatch.
The Sonar shape test reads the accepted security bound as a Decimal, with a regression case: `5.0000000000000001` must not round to `5.0`. The registry notes no longer call this app's row Linux-only now that #370 carries the Windows and macOS rows.
This commit is contained in:
1 parent
d157c3000c
commit
91c7634e7f
4 files changed
+62
-28
No files matched your search
@@ -41,5 +41,5 @@ jobs:
|
||||
producer_run_id: ${{ inputs.producer_run_id }}
|
||||
producer_run_attempt: ${{ inputs.producer_run_attempt }}
|
||||
# No secrets: inherit or raw platform values in this caller. Only the isolated native
|
||||
# callee job may bind the existing release environment (which trusts release and
|
||||
# nightly-signer) and export keys in its signing step.
|
||||
# callee job may bind the release environment and export its keys; that environment must
|
||||
# admit nightly-signer alongside release before the first dispatch.
|
||||
@@ -39,21 +39,20 @@ branch, so nightly signer files never need a stable release sync. The policy's `
|
||||
names it, the signer's guard requires it and the dispatcher targets it. The branch only
|
||||
fast-forwards to reviewed main commits, through the settings script's `advance` (no queued signer
|
||||
run, a trust-closure scan, then the full diff of `.github/` and `packaging/`), and the existing
|
||||
`release` environment trusts it alongside `release`. Its trust closure is all of `.github/` and
|
||||
`packaging/`, including `packaging/env.sh`, which `packaging/macos/import-cert.sh` sources with
|
||||
the Apple keys. On that branch only the pinned `nightly-sign.yml` caller may reach an environment:
|
||||
no app workflow binds one, nothing else calls `nightly-release.yml`, and the only caller of the
|
||||
shared stable `release.yml` is `release.yml`, whose callee must carry the stable-only environment
|
||||
guard. The contract tests check the in-repo part on every main PR; the settings scan also resolves
|
||||
the callee. Stable releases still come only from `refs/heads/release`. History does not carry over
|
||||
a switch between `release` and `nightly-signer`, so the switch happens before the first
|
||||
publication.
|
||||
`release` environment must admit `nightly-signer` alongside `release` before the first dispatch (a
|
||||
repository settings change, not a workflow one). Its trust closure is all of `.github/` and
|
||||
`packaging/`, including `packaging/env.sh`, which `packaging/macos/import-cert.sh` sources with the
|
||||
Apple keys. On that branch only the pinned `nightly-sign.yml` caller may reach an environment: no
|
||||
app workflow binds one, nothing else calls `nightly-release.yml`, and the only caller of the shared
|
||||
stable `release.yml` is `release.yml`, whose callee must carry the stable-only environment guard.
|
||||
The contract tests check the in-repo part on every main PR; the settings scan also resolves the
|
||||
callee. Stable releases still come only from `refs/heads/release`. History does not carry over a
|
||||
switch between `release` and `nightly-signer`, so the switch happens before the first publication.
|
||||
|
||||
**Registry admission.** The signer requires the protected policy's `platforms` map to equal the
|
||||
run app's admitted targets in craft-common-actions' `nightly-apps.json`, and it refuses rather
|
||||
than sign a subset. VectorCraft's row admits `linux-x86_64`; the matching `windows-x86_64` and
|
||||
`macos-aarch64` targets and entrypoints are a craft-common-actions follow-up, and the first
|
||||
signer run stops at admission until they merge.
|
||||
than sign a subset. VectorCraft's row admits `linux-x86_64`, `windows-x86_64` and `macos-aarch64`, with
|
||||
each target's entrypoint and asset pattern, since craft-common-actions #370 (in the pin).
|
||||
|
||||
**Manual actors.** `bflatastic`, `dylanmtaylor`, `echelon`, `FredApps` and `skylartaylor`, in the
|
||||
producer's `manual-actors` and the policy's `manual_actors`. The list mirrors the release-managers
|
||||
@@ -91,8 +90,8 @@ Read on 2026-11-24; re-read anything that may have moved before `nightly-signer`
|
||||
and only ever fast-forwards to reviewed main commits. It rejects wrong repository/event/actual branch,
|
||||
including same-name tags. Its constant whole-run concurrency (`vectorcraft-nightly-release`) is distinct
|
||||
from stable, cancellation is off and `queue: max` must be hosted-qualified. The caller itself passes no
|
||||
credentials; only the shared callee's sign jobs bind the `release` environment, which trusts `release` and
|
||||
`nightly-signer`.
|
||||
credentials; only the shared callee's sign jobs bind the `release` environment, which must admit
|
||||
`nightly-signer` alongside `release` before the first dispatch.
|
||||
- `.github/workflows/nightly-dispatch.yml`: transport only, never authorization. It is literally
|
||||
off (`false &&`) and forwards only a first-attempt scheduled producer to `nightly-sign.yml` on
|
||||
`nightly-signer`. No schedule is registered until activation is reviewed.
|
||||
|
||||
+6
-5
@@ -243,15 +243,16 @@ the job fails and asks for a version bump (`cargo xtask version set`).
|
||||
## Secrets
|
||||
|
||||
The jobs that sign (macOS, Windows) and the draft-release job run in the `release` environment,
|
||||
which only the `release` branch can use and which holds the signing secrets. The other jobs get no
|
||||
which only the `release` branch can use today and which holds the signing secrets. The other jobs get no
|
||||
secrets. Every secret is optional: a missing one produces unsigned artifacts and a
|
||||
warning, never a failed build.
|
||||
|
||||
The supervised nightly signer does not sign from `release`: it runs on `refs/heads/nightly-signer`,
|
||||
which only ever fast-forwards to reviewed main commits, and the `release` environment trusts both
|
||||
branches. Everything that can reach it is the trust closure: all of `.github/` and `packaging/`,
|
||||
including `packaging/env.sh`, which `packaging/macos/import-cert.sh` sources with the Apple keys.
|
||||
Stable releases still come only from `refs/heads/release`.
|
||||
which only ever fast-forwards to reviewed main commits, and the `release` environment must admit
|
||||
`nightly-signer` alongside `release` before the first dispatch. Everything that can reach it is the
|
||||
trust closure: all of `.github/` and `packaging/`, including `packaging/env.sh`, which
|
||||
`packaging/macos/import-cert.sh` sources with the Apple keys. Stable releases still come only from
|
||||
`refs/heads/release`.
|
||||
|
||||
| Secret | Used for |
|
||||
|---|---|
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Local regression checks for VectorCraft nightly workflow and signing-policy contracts."""
|
||||
import copy
|
||||
from decimal import Decimal
|
||||
import json
|
||||
from pathlib import Path
|
||||
import re
|
||||
@@ -9,6 +10,20 @@ import unittest
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
INSTALLED_POLICY = ROOT / ".github/nightly-signing-policy.json"
|
||||
|
||||
|
||||
def security_bound_problem(maximum):
|
||||
"""None when an accepted security-rating maximum is the reviewed whole A..E rating.
|
||||
|
||||
Decimal, not float: "5.0000000000000001" rounds to 5.0 as a float, so the shared candidate
|
||||
contract would refuse a bound this suite had already accepted.
|
||||
"""
|
||||
value = Decimal(maximum)
|
||||
if int(value) != value:
|
||||
return "the A..E bound is a whole rating"
|
||||
if not 1 <= value <= 5:
|
||||
return "the security bound stays A..E"
|
||||
return None
|
||||
|
||||
APP_NAME = "vectorcraft"
|
||||
PRODUCER_WORKFLOW_NAME = "VectorCraft unsigned nightly"
|
||||
|
||||
@@ -464,10 +479,10 @@ class NightlyInstalledPolicy(unittest.TestCase):
|
||||
"an accepted failure must lie inside the reviewed issue scope")
|
||||
self.assertEqual(condition["comparator"], "GT")
|
||||
self.assertRegex(condition["maximum"], r"^(?:0|[1-9][0-9]*)(?:\.[0-9]+)?$")
|
||||
maximum = float(condition["maximum"])
|
||||
maximum = Decimal(condition["maximum"])
|
||||
if condition["metric"] in ("security_rating", "new_security_rating"):
|
||||
self.assertEqual(int(maximum), maximum, "the A..E bound is a whole rating")
|
||||
self.assertTrue(1 <= maximum <= 5, "the security bound stays A..E")
|
||||
self.assertIsNone(security_bound_problem(condition["maximum"]),
|
||||
"the security bound stays the reviewed whole A..E rating")
|
||||
self.assertEqual(condition["error_threshold"], "1", "the reviewed A threshold stays")
|
||||
else:
|
||||
self.assertLessEqual(maximum, len(sonar["debt"]), "accepted failures exceed the reviewed debt")
|
||||
@@ -475,6 +490,13 @@ class NightlyInstalledPolicy(unittest.TestCase):
|
||||
"accepted conditions and reviewed issue types must cover the same scope")
|
||||
self.assertEqual(set(metrics), gate, "every live gate condition stays gated exactly once")
|
||||
|
||||
def test_security_bound_rejects_a_maximum_float_rounds_to_five(self):
|
||||
"""The shared candidate contract reads the bound as a decimal; float() would hide the widening."""
|
||||
self.assertIsNone(security_bound_problem("5"))
|
||||
self.assertIsNone(security_bound_problem("5.0"))
|
||||
self.assertEqual(security_bound_problem("5.0000000000000001"), "the A..E bound is a whole rating")
|
||||
self.assertEqual(security_bound_problem("6"), "the security bound stays A..E")
|
||||
|
||||
|
||||
SIGNER_BRANCH = "nightly-signer"
|
||||
SHARED = "storytold/craft-common-actions/.github/workflows/"
|
||||
@@ -605,14 +627,15 @@ def workflow_entries(source):
|
||||
entries.append((number, key, _workflow_value(value),
|
||||
is_block or ((value == "" or not is_block) and continues(index, indent))))
|
||||
if "{" in bare and bare != "{}":
|
||||
flow = re.fullmatch(r"\{([^{}\[\]]*)\}", FLOW_QUOTED.sub("''", value.strip()))
|
||||
masked = re.fullmatch(r"\{([^{}\[\]]*)\}", FLOW_QUOTED.sub("''", value.strip()))
|
||||
flow = re.fullmatch(r"\{([^{}\[\]]*)\}", value.strip())
|
||||
if any(set(scalar[1:-1]) & set("#{}[],") for scalar in FLOW_QUOTED.findall(value)):
|
||||
refused.append(f"line {number}: flow mapping quoted scalar with # or flow punctuation")
|
||||
elif flow is None:
|
||||
refused.append(f"line {number}: nested or multi-line flow mapping")
|
||||
elif not re.fullmatch(r"\{([^{}\[\]]*)\}", value.strip()):
|
||||
elif masked is None or flow is None:
|
||||
refused.append(f"line {number}: nested or multi-line flow mapping")
|
||||
else:
|
||||
# The masked text only proves the shape: a quoted key ("uses", 'environment') keeps
|
||||
# its identity, so the entries are read from the original mapping text, never ''.
|
||||
for item in flow.group(1).split(","):
|
||||
entry = WORKFLOW_KEY.match(item.strip())
|
||||
key = _workflow_key(entry.group(1)) if entry else None
|
||||
@@ -709,6 +732,9 @@ class NightlySignerBranchTrustClosure(unittest.TestCase):
|
||||
"a bracket inside a quoted flow scalar": {**tree, "extra.yml": 'jobs:\n x: {name: "[a]", runs-on: ubuntu-latest}\n'},
|
||||
"an unterminated quote": {**tree, "extra.yml": 'jobs:\n x:\n name: "a\n b"\n runs-on: ubuntu-latest\n'},
|
||||
"environment in any flow mapping": {**tree, "extra.yml": "jobs:\n x:\n runs-on: ubuntu-latest\n with: {environment: release}\n"},
|
||||
"a double-quoted environment key in a flow mapping": {**tree, "extra.yml": 'jobs:\n x:\n runs-on: ubuntu-latest\n with: {"environment": release}\n'},
|
||||
"a single-quoted environment key in a flow mapping": {**tree, "extra.yml": "jobs:\n x:\n runs-on: ubuntu-latest\n with: {'environment': release}\n"},
|
||||
"a double-quoted uses key in a flow mapping": {**tree, "extra.yml": 'jobs:\n x: {"uses": ' + SHARED + "nightly-release.yml@" + "a" * 40 + "}\n"},
|
||||
"uses in any flow mapping": {**tree, "extra.yml": "jobs:\n x:\n steps:\n - {uses: actions/checkout@v4}\n"},
|
||||
"another caller of the signer": {**tree, "extra.yml": "jobs:\n x:\n uses: " + SHARED + "nightly-release.yml@" + "a" * 40 + "\n"},
|
||||
"a mutable signer pin": {**tree, "nightly-sign.yml": re.sub(r"nightly-release\.yml@[0-9a-f]{40}", "nightly-release.yml@main", tree["nightly-sign.yml"])},
|
||||
@@ -719,6 +745,14 @@ class NightlySignerBranchTrustClosure(unittest.TestCase):
|
||||
with self.subTest(case=label):
|
||||
self.assertTrue(trust_closure_problems(workflows))
|
||||
|
||||
def test_quoted_keys_in_a_flow_mapping_are_read_not_masked(self):
|
||||
entries, refused = workflow_entries('jobs:\n x: {runs-on: ubuntu-latest, "name": build}\n')
|
||||
self.assertEqual(refused, [])
|
||||
self.assertIn((2, "name", "build", False), entries, "a quoted key keeps its identity")
|
||||
self.assertIn((2, "runs-on", "ubuntu-latest", False), entries)
|
||||
_, refused = workflow_entries("jobs:\n x: {runs-on: ubuntu-latest, 'environment': release}\n")
|
||||
self.assertEqual(refused, ["line 2: environment in a flow mapping (must be block style)"])
|
||||
|
||||
def test_signer_dispatch_guard_and_policy_name_the_same_branch(self):
|
||||
sign = (ROOT / ".github/workflows/nightly-sign.yml").read_text()
|
||||
(_, guard), = job_conditions(sign.split("\njobs:\n", 1)[1])
|
||||
|
||||
Reference in new issue
Block a user