@intentius/chant 0.124.85 → 0.124.87
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundle-check.d.ts +102 -0
- package/dist/bundle-check.d.ts.map +1 -0
- package/dist/bundle-check.js +310 -0
- package/dist/chant-install.d.ts +100 -0
- package/dist/chant-install.d.ts.map +1 -0
- package/dist/chant-install.js +158 -0
- package/dist/ci-commit.d.ts +19 -6
- package/dist/ci-commit.d.ts.map +1 -1
- package/dist/ci-commit.js +23 -4
- package/dist/ci-evidence-jobs.d.ts +78 -0
- package/dist/ci-evidence-jobs.d.ts.map +1 -0
- package/dist/ci-evidence-jobs.js +85 -0
- package/dist/ci-image.d.ts +274 -0
- package/dist/ci-image.d.ts.map +1 -0
- package/dist/ci-image.js +635 -0
- package/dist/ci-login.d.ts +150 -0
- package/dist/ci-login.d.ts.map +1 -0
- package/dist/ci-login.js +240 -0
- package/dist/ci-product.d.ts +16 -0
- package/dist/ci-product.d.ts.map +1 -1
- package/dist/ci-product.js +17 -0
- package/dist/cli/commands/import-index.js +2 -2
- package/dist/cli/handlers/build.d.ts +8 -0
- package/dist/cli/handlers/build.d.ts.map +1 -1
- package/dist/cli/handlers/build.js +22 -4
- package/dist/cli/handlers/ci-check.d.ts.map +1 -1
- package/dist/cli/handlers/ci-check.js +61 -2
- package/dist/cli/handlers/ci-evidence.d.ts +3 -0
- package/dist/cli/handlers/ci-evidence.d.ts.map +1 -0
- package/dist/cli/handlers/ci-evidence.js +174 -0
- package/dist/cli/handlers/components.js +3 -3
- package/dist/cli/handlers/dead-guards.d.ts +3 -0
- package/dist/cli/handlers/dead-guards.d.ts.map +1 -0
- package/dist/cli/handlers/dead-guards.js +35 -0
- package/dist/cli/handlers/graph.js +4 -4
- package/dist/cli/handlers/lifecycle.d.ts +2 -1
- package/dist/cli/handlers/lifecycle.d.ts.map +1 -1
- package/dist/cli/handlers/lifecycle.js +5 -4
- package/dist/cli/handlers/local-chant.d.ts +16 -0
- package/dist/cli/handlers/local-chant.d.ts.map +1 -0
- package/dist/cli/handlers/local-chant.js +109 -0
- package/dist/cli/handlers/operator.js +2 -2
- package/dist/cli/handlers/search.js +5 -5
- package/dist/cli/main.d.ts.map +1 -1
- package/dist/cli/main.js +38 -0
- package/dist/cli/parse-args.d.ts.map +1 -1
- package/dist/cli/parse-args.js +28 -0
- package/dist/cli/registry.d.ts +16 -0
- package/dist/cli/registry.d.ts.map +1 -1
- package/dist/components/check-hooks.d.ts +49 -0
- package/dist/components/check-hooks.d.ts.map +1 -1
- package/dist/components/check-hooks.js +64 -4
- package/dist/components/check-steps.d.ts +17 -0
- package/dist/components/check-steps.d.ts.map +1 -1
- package/dist/components/check-steps.js +37 -5
- package/dist/components/product-pipeline.d.ts +23 -0
- package/dist/components/product-pipeline.d.ts.map +1 -1
- package/dist/components/product-pipeline.js +6 -2
- package/dist/components/product-plan.d.ts +143 -0
- package/dist/components/product-plan.d.ts.map +1 -0
- package/dist/components/product-plan.js +145 -0
- package/dist/components/release-compile.d.ts.map +1 -1
- package/dist/components/release-compile.js +2 -2
- package/dist/config.d.ts +39 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +35 -3
- package/dist/dead-guards.d.ts +82 -0
- package/dist/dead-guards.d.ts.map +1 -0
- package/dist/dead-guards.js +436 -0
- package/dist/discovery/files.d.ts +3 -1
- package/dist/discovery/files.d.ts.map +1 -1
- package/dist/discovery/files.js +5 -3
- package/dist/drift-issue.d.ts +152 -0
- package/dist/drift-issue.d.ts.map +1 -0
- package/dist/drift-issue.js +167 -0
- package/dist/floor-table.d.ts +30 -0
- package/dist/floor-table.d.ts.map +1 -0
- package/dist/floor-table.data.d.ts +3 -0
- package/dist/floor-table.data.d.ts.map +1 -0
- package/dist/floor-table.data.js +179 -0
- package/dist/floor-table.js +56 -0
- package/dist/forge-flags.d.ts +90 -0
- package/dist/forge-flags.d.ts.map +1 -0
- package/dist/forge-flags.js +184 -0
- package/dist/lexicon.d.ts +69 -0
- package/dist/lexicon.d.ts.map +1 -1
- package/dist/lifecycle/gated-op.d.ts +7 -1
- package/dist/lifecycle/gated-op.d.ts.map +1 -1
- package/dist/lifecycle/gated-op.js +7 -4
- package/dist/local-chant.d.ts +98 -0
- package/dist/local-chant.d.ts.map +1 -0
- package/dist/local-chant.js +307 -0
- package/dist/op/activities/predict-behaviour.js +2 -2
- package/dist/op/op-waves-evidence-spec.d.ts +13 -0
- package/dist/op/op-waves-evidence-spec.d.ts.map +1 -0
- package/dist/op/op-waves-evidence-spec.js +21 -0
- package/dist/op/op-waves-evidence.d.ts +40 -0
- package/dist/op/op-waves-evidence.d.ts.map +1 -0
- package/dist/op/op-waves-evidence.js +58 -0
- package/dist/op/op-waves-run.d.ts +4 -0
- package/dist/op/op-waves-run.d.ts.map +1 -1
- package/dist/op/op-waves-run.js +24 -1
- package/dist/op/op-waves.d.ts +17 -1
- package/dist/op/op-waves.d.ts.map +1 -1
- package/dist/op/op-waves.js +23 -0
- package/dist/op/schedule-overdue.d.ts +41 -9
- package/dist/op/schedule-overdue.d.ts.map +1 -1
- package/dist/op/schedule-overdue.js +154 -25
- package/dist/plan-summary.d.ts +25 -0
- package/dist/plan-summary.d.ts.map +1 -1
- package/dist/plan-summary.js +31 -0
- package/dist/pr-plan-note.d.ts +35 -0
- package/dist/pr-plan-note.d.ts.map +1 -1
- package/dist/pr-plan-note.js +10 -0
- package/dist/pr-post.d.ts +23 -0
- package/dist/pr-post.d.ts.map +1 -1
- package/dist/pr-post.js +125 -3
- package/dist/release-floors.d.ts +33 -1
- package/dist/release-floors.d.ts.map +1 -1
- package/dist/release-floors.js +33 -1
- package/dist/state-migration.d.ts +24 -0
- package/dist/state-migration.d.ts.map +1 -1
- package/dist/state-migration.js +100 -5
- package/dist/wave-runtime.mjs +309 -302
- package/dist/workspace/ci-green.d.ts.map +1 -1
- package/dist/workspace/ci-green.js +4 -3
- package/dist/workspace/lexicon-outputs.d.ts.map +1 -1
- package/dist/workspace/lexicon-outputs.js +21 -7
- package/dist/workspace/reason-codes.d.ts +3 -0
- package/dist/workspace/reason-codes.d.ts.map +1 -1
- package/dist/workspace/reason-codes.js +4 -0
- package/dist/workspace/ref-gate.schema.json +85 -0
- package/dist/workspace/search-contract.d.ts +1 -1
- package/dist/workspace/search-contract.d.ts.map +1 -1
- package/dist/workspace/trust/check-evidence-report.d.ts +58 -0
- package/dist/workspace/trust/check-evidence-report.d.ts.map +1 -0
- package/dist/workspace/trust/check-evidence-report.js +109 -0
- package/dist/workspace/trust/check-evidence.d.ts +160 -0
- package/dist/workspace/trust/check-evidence.d.ts.map +1 -0
- package/dist/workspace/trust/check-evidence.js +309 -0
- package/dist/workspace/trust/ci-tag-statement.d.ts +2 -2
- package/dist/workspace/trust/ci-tag-statement.d.ts.map +1 -1
- package/dist/workspace/trust/dsse.d.ts +40 -2
- package/dist/workspace/trust/dsse.d.ts.map +1 -1
- package/dist/workspace/trust/dsse.js +34 -2
- package/dist/workspace/trust/evidence.d.ts +2 -2
- package/dist/workspace/trust/evidence.d.ts.map +1 -1
- package/dist/workspace/trust/keyless-fixture.d.ts +41 -0
- package/dist/workspace/trust/keyless-fixture.d.ts.map +1 -0
- package/dist/workspace/trust/keyless-fixture.js +161 -0
- package/dist/workspace/trust/keyless.d.ts +202 -0
- package/dist/workspace/trust/keyless.d.ts.map +1 -0
- package/dist/workspace/trust/keyless.js +488 -0
- package/dist/workspace/trust/local-evidence.d.ts +123 -0
- package/dist/workspace/trust/local-evidence.d.ts.map +1 -0
- package/dist/workspace/trust/local-evidence.js +259 -0
- package/dist/workspace/trust/op-run-statement.d.ts +2 -2
- package/dist/workspace/trust/op-run-statement.d.ts.map +1 -1
- package/dist/workspace/trust/policy.d.ts +140 -1
- package/dist/workspace/trust/policy.d.ts.map +1 -1
- package/dist/workspace/trust/policy.js +197 -3
- package/dist/workspace/trust/ref-gate-cli.d.ts +33 -0
- package/dist/workspace/trust/ref-gate-cli.d.ts.map +1 -0
- package/dist/workspace/trust/ref-gate-cli.js +234 -0
- package/dist/workspace/trust/ref-gate-fixture.d.ts +38 -0
- package/dist/workspace/trust/ref-gate-fixture.d.ts.map +1 -0
- package/dist/workspace/trust/ref-gate-fixture.js +97 -0
- package/dist/workspace/trust/ref-gate.d.ts +187 -0
- package/dist/workspace/trust/ref-gate.d.ts.map +1 -0
- package/dist/workspace/trust/ref-gate.js +432 -0
- package/dist/workspace/trust/run-statement.d.ts +3 -3
- package/dist/workspace/trust/run-statement.d.ts.map +1 -1
- package/dist/workspace/trust/runner-identity.d.ts +56 -0
- package/dist/workspace/trust/runner-identity.d.ts.map +1 -0
- package/dist/workspace/trust/runner-identity.js +65 -0
- package/dist/workspace/trust/trust-files.d.ts.map +1 -1
- package/dist/workspace/trust/trust-files.js +25 -1
- package/package.json +1 -1
- package/src/bundle-check.test.ts +140 -0
- package/src/bundle-check.ts +352 -0
- package/src/chant-install.test.ts +112 -0
- package/src/chant-install.ts +179 -0
- package/src/ci-commit.test.ts +45 -0
- package/src/ci-commit.ts +38 -4
- package/src/ci-evidence-jobs.ts +105 -0
- package/src/ci-image.test.ts +506 -0
- package/src/ci-image.ts +822 -0
- package/src/ci-login.test.ts +235 -0
- package/src/ci-login.ts +307 -0
- package/src/ci-product.ts +18 -0
- package/src/cli/commands/__fixtures__/source-dir-include/chant.config.json +1 -0
- package/src/cli/commands/__fixtures__/source-dir-include/infra.ts +1 -0
- package/src/cli/commands/__fixtures__/source-dir-include/scripts/run-on-load.ts +3 -0
- package/src/cli/commands/__fixtures__/source-dir-root/chant.config.json +1 -0
- package/src/cli/commands/__fixtures__/source-dir-root/infra.test.ts +1 -0
- package/src/cli/commands/__fixtures__/source-dir-root/infra.ts +1 -0
- package/src/cli/commands/__fixtures__/source-dir-root/scripts/run-on-load.ts +3 -0
- package/src/cli/commands/__fixtures__/source-dir-scoped/app.ts +3 -0
- package/src/cli/commands/__fixtures__/source-dir-scoped/chant.config.json +1 -0
- package/src/cli/commands/__fixtures__/source-dir-scoped/infra/net.ts +1 -0
- package/src/cli/commands/__fixtures__/source-dir-scoped/scripts/run-on-load.ts +3 -0
- package/src/cli/commands/import-index.ts +2 -2
- package/src/cli/handlers/build-source-dir.test.ts +64 -0
- package/src/cli/handlers/build.ts +21 -4
- package/src/cli/handlers/ci-check.ts +60 -3
- package/src/cli/handlers/ci-evidence.ts +167 -0
- package/src/cli/handlers/components.ts +3 -3
- package/src/cli/handlers/dead-guards.ts +37 -0
- package/src/cli/handlers/graph.ts +4 -4
- package/src/cli/handlers/lifecycle.ts +5 -4
- package/src/cli/handlers/local-chant.ts +106 -0
- package/src/cli/handlers/operator.ts +2 -2
- package/src/cli/handlers/search.ts +5 -5
- package/src/cli/main.test.ts +7 -0
- package/src/cli/main.ts +38 -0
- package/src/cli/parse-args.ts +21 -0
- package/src/cli/registry.ts +16 -0
- package/src/components/check-evidence-stage.test.ts +80 -0
- package/src/components/check-hooks.ts +84 -4
- package/src/components/check-local-evidence-stage.test.ts +141 -0
- package/src/components/check-steps.ts +56 -6
- package/src/components/product-pipeline.ts +28 -3
- package/src/components/product-plan.test.ts +87 -0
- package/src/components/product-plan.ts +230 -0
- package/src/components/release-compile.ts +2 -2
- package/src/config.ts +44 -3
- package/src/dead-guards.test.ts +206 -0
- package/src/dead-guards.ts +446 -0
- package/src/discovery/files.ts +5 -3
- package/src/drift-issue-bundle.test.ts +31 -0
- package/src/drift-issue.test.ts +206 -0
- package/src/drift-issue.ts +274 -0
- package/src/fit-note.test.ts +44 -0
- package/src/floor-table.data.ts +181 -0
- package/src/floor-table.ts +77 -0
- package/src/forge-flags.test.ts +110 -0
- package/src/forge-flags.ts +208 -0
- package/src/gate-decision-bundle.test.ts +1 -0
- package/src/lexicon.ts +68 -0
- package/src/lifecycle/gated-op.ts +10 -5
- package/src/local-chant.e2e.test.ts +94 -0
- package/src/local-chant.test.ts +162 -0
- package/src/local-chant.ts +341 -0
- package/src/op/activities/predict-behaviour.ts +2 -2
- package/src/op/op-waves-evidence-spec.ts +24 -0
- package/src/op/op-waves-evidence.test.ts +130 -0
- package/src/op/op-waves-evidence.ts +58 -0
- package/src/op/op-waves-run.ts +25 -1
- package/src/op/op-waves.ts +31 -1
- package/src/op/schedule-overdue.test.ts +85 -0
- package/src/op/schedule-overdue.ts +162 -26
- package/src/plan-summary.ts +40 -0
- package/src/pr-plan-note.ts +34 -0
- package/src/pr-post-plan-note.test.ts +146 -0
- package/src/pr-post.ts +127 -3
- package/src/release-floors.ts +47 -1
- package/src/stage-hooks-bundle.test.ts +1 -0
- package/src/state-migration.test.ts +52 -1
- package/src/state-migration.ts +107 -5
- package/src/workspace/ci-green.ts +4 -3
- package/src/workspace/lexicon-outputs.ts +23 -6
- package/src/workspace/reason-codes.test.ts +3 -0
- package/src/workspace/reason-codes.ts +4 -0
- package/src/workspace/ref-gate.schema.json +85 -0
- package/src/workspace/trust/check-evidence-report.ts +115 -0
- package/src/workspace/trust/check-evidence.test.ts +133 -0
- package/src/workspace/trust/check-evidence.ts +327 -0
- package/src/workspace/trust/ci-tag-statement.ts +2 -2
- package/src/workspace/trust/dsse.ts +48 -4
- package/src/workspace/trust/evidence.ts +2 -2
- package/src/workspace/trust/keyless-fixture.ts +214 -0
- package/src/workspace/trust/keyless.test.ts +220 -0
- package/src/workspace/trust/keyless.ts +557 -0
- package/src/workspace/trust/local-evidence.test.ts +127 -0
- package/src/workspace/trust/local-evidence.ts +268 -0
- package/src/workspace/trust/op-run-statement.ts +2 -2
- package/src/workspace/trust/policy.ts +263 -3
- package/src/workspace/trust/ref-gate-cli.ts +244 -0
- package/src/workspace/trust/ref-gate-fixture.ts +125 -0
- package/src/workspace/trust/ref-gate.e2e.test.ts +76 -0
- package/src/workspace/trust/ref-gate.test.ts +247 -0
- package/src/workspace/trust/ref-gate.ts +539 -0
- package/src/workspace/trust/run-statement.ts +3 -3
- package/src/workspace/trust/runner-identity.ts +92 -0
- package/src/workspace/trust/trust-files.test.ts +22 -0
- package/src/workspace/trust/trust-files.ts +54 -1
|
@@ -23,6 +23,8 @@
|
|
|
23
23
|
import { posix } from "node:path";
|
|
24
24
|
import { z } from "zod";
|
|
25
25
|
import { DEFAULT_SIGNERS_PATH, TRUST_CONFIG_PATH, parseAllowedSigners } from "./trust-files.js";
|
|
26
|
+
import { execFileSync } from "node:child_process";
|
|
27
|
+
import { DEFAULT_FULCIO_URL, DEFAULT_SIGNING_AUDIENCE, DEFAULT_TIMESTAMP_URL, keylessVerifier, parseTrustedRoot } from "./keyless.js";
|
|
26
28
|
export { DEFAULT_SIGNERS_PATH, TRUST_CONFIG_PATH, parseAllowedSigners, renderAllowedSigners, } from "./trust-files.js";
|
|
27
29
|
// ── trust.json ───────────────────────────────────────────────────────────────
|
|
28
30
|
const fullCommit = z.string().regex(/^[0-9a-f]{40}([0-9a-f]{24})?$/, "a full commit id");
|
|
@@ -33,6 +35,24 @@ const repoPath = z
|
|
|
33
35
|
.refine((p) => !p.startsWith("/") && !p.includes("\\") && posix.normalize(p) === p && !p.split("/").includes(".."), {
|
|
34
36
|
message: "a path inside the repository, with / separators and no ..",
|
|
35
37
|
});
|
|
38
|
+
/** An http or https URL (#4869): an OIDC issuer, a certificate or timestamp authority. */
|
|
39
|
+
const httpUrl = z.string().regex(/^https?:\/\/[^\s]+$/, "an http or https URL");
|
|
40
|
+
/** A check name a ref rule requires (#4867): it is also part of an override's subject. */
|
|
41
|
+
export const REF_CHECK_NAME = /^[A-Za-z0-9][A-Za-z0-9._:-]*$/;
|
|
42
|
+
/** A ref pattern (#4867): a full ref name, where `*` matches within one `/` segment and `**` matches across them. */
|
|
43
|
+
export const REF_PATTERN = /^refs\/[^\s\\]+$/;
|
|
44
|
+
/**
|
|
45
|
+
* Checks local evidence never stands in for (#4868): the ones that gate an
|
|
46
|
+
* apply, a release or a gate. A name is refused when it is one of these, or
|
|
47
|
+
* one of these followed by `:` (a wave's `plan:<wave>`).
|
|
48
|
+
*/
|
|
49
|
+
export const LOCAL_EVIDENCE_NEVER = ["plan", "policy", "apply", "drift", "release", "gate", "approval", "confirm"];
|
|
50
|
+
/** Whether local evidence may ever be accepted for `check` (#4868). */
|
|
51
|
+
export function localEvidenceAllowedFor(check) {
|
|
52
|
+
return !LOCAL_EVIDENCE_NEVER.some((n) => check === n || check.startsWith(`${n}:`));
|
|
53
|
+
}
|
|
54
|
+
/** Who signs local evidence (#4868): a person on their machine, or an agent session as itself. */
|
|
55
|
+
export const LOCAL_SIGNER_CLASSES = ["person", "agent"];
|
|
36
56
|
export const trustConfigSchema = z
|
|
37
57
|
.object({
|
|
38
58
|
schema: z.literal(1),
|
|
@@ -63,6 +83,38 @@ export const trustConfigSchema = z
|
|
|
63
83
|
})
|
|
64
84
|
.strict())
|
|
65
85
|
.optional(),
|
|
86
|
+
/**
|
|
87
|
+
* CI identities that sign runner statements keyless (#4869): each an
|
|
88
|
+
* OIDC issuer and a pattern over the subject alternative name of the
|
|
89
|
+
* certificate the job's token was traded for, which names the
|
|
90
|
+
* repository, the workflow and the ref. `trustedRoot` is a file in
|
|
91
|
+
* sigstore's `trusted_root.json` format with the certificate and
|
|
92
|
+
* timestamp authorities. `fulcio`, `timestamp` and `audience` tell a
|
|
93
|
+
* signing job where to trade its token; sigstore's public instances by
|
|
94
|
+
* default. With `since`, a statement over that commit or any commit not
|
|
95
|
+
* a strict ancestor of it counts only when signed keyless; a runner key's
|
|
96
|
+
* statement over an earlier commit still counts.
|
|
97
|
+
*/
|
|
98
|
+
keyless: z
|
|
99
|
+
.object({
|
|
100
|
+
trustedRoot: repoPath,
|
|
101
|
+
identities: z
|
|
102
|
+
.array(z
|
|
103
|
+
.object({
|
|
104
|
+
principal: z.string().min(1),
|
|
105
|
+
class: z.enum(["runner", "service"]),
|
|
106
|
+
issuer: httpUrl,
|
|
107
|
+
subject: z.string().min(1),
|
|
108
|
+
})
|
|
109
|
+
.strict())
|
|
110
|
+
.min(1),
|
|
111
|
+
since: fullCommit.optional(),
|
|
112
|
+
fulcio: httpUrl.optional(),
|
|
113
|
+
timestamp: httpUrl.optional(),
|
|
114
|
+
audience: z.string().min(1).optional(),
|
|
115
|
+
})
|
|
116
|
+
.strict()
|
|
117
|
+
.optional(),
|
|
66
118
|
/**
|
|
67
119
|
* Passkeys that sign gate approvals for people (#4646): a WebAuthn
|
|
68
120
|
* credential's id, its public key as base64url DER SubjectPublicKeyInfo,
|
|
@@ -103,14 +155,102 @@ export const trustConfigSchema = z
|
|
|
103
155
|
})
|
|
104
156
|
.strict())
|
|
105
157
|
.optional(),
|
|
158
|
+
/**
|
|
159
|
+
* The checks a ref update must carry evidence for (#4867). Each entry
|
|
160
|
+
* names a ref pattern and the checks a commit pushed there needs current
|
|
161
|
+
* runner evidence of, each with what to do without it (`block` refuses
|
|
162
|
+
* the update, `warn` admits it and says what was missing) and the command
|
|
163
|
+
* that produces it. `status` is the commit status a forge requires, by
|
|
164
|
+
* default `chant/ref-gate`. `overrides` says how an override is judged:
|
|
165
|
+
* `sealed` when the signers file at base exists, else `ledger`.
|
|
166
|
+
*/
|
|
167
|
+
refs: z
|
|
168
|
+
.array(z
|
|
169
|
+
.object({
|
|
170
|
+
ref: z.string().regex(REF_PATTERN, "a full ref name such as refs/heads/main, where * and ** match"),
|
|
171
|
+
checks: z
|
|
172
|
+
.array(z
|
|
173
|
+
.object({
|
|
174
|
+
check: z.string().regex(REF_CHECK_NAME, "a check name: letters, digits, . _ : -"),
|
|
175
|
+
action: z.enum(["block", "warn"]).optional(),
|
|
176
|
+
command: z.string().min(1),
|
|
177
|
+
})
|
|
178
|
+
.strict())
|
|
179
|
+
.min(1),
|
|
180
|
+
status: z.string().min(1).optional(),
|
|
181
|
+
overrides: z.enum(["ledger", "sealed"]).optional(),
|
|
182
|
+
})
|
|
183
|
+
.strict())
|
|
184
|
+
.optional(),
|
|
185
|
+
/**
|
|
186
|
+
* Local evidence (#4868): keys that sign on a developer's machine, for a
|
|
187
|
+
* person or an agent session, and the checks whose CI run such evidence
|
|
188
|
+
* stands in for. Off for every check not named in `checks`, and never
|
|
189
|
+
* for the checks {@link LOCAL_EVIDENCE_NEVER} names. A local key is
|
|
190
|
+
* never a runner key: local evidence never counts as runner evidence.
|
|
191
|
+
*/
|
|
192
|
+
local: z
|
|
193
|
+
.object({
|
|
194
|
+
keys: z
|
|
195
|
+
.array(z
|
|
196
|
+
.object({
|
|
197
|
+
principal: z.string().min(1),
|
|
198
|
+
class: z.enum(LOCAL_SIGNER_CLASSES),
|
|
199
|
+
key: z.string().regex(/^ssh-ed25519 [A-Za-z0-9+/]+={0,2}$/, "an ssh-ed25519 public key, with no comment"),
|
|
200
|
+
})
|
|
201
|
+
.strict())
|
|
202
|
+
.optional(),
|
|
203
|
+
checks: z
|
|
204
|
+
.array(z
|
|
205
|
+
.object({
|
|
206
|
+
check: z
|
|
207
|
+
.string()
|
|
208
|
+
.regex(REF_CHECK_NAME, "a check name: letters, digits, . _ : -")
|
|
209
|
+
.refine(localEvidenceAllowedFor, { message: `local evidence never stands in for ${LOCAL_EVIDENCE_NEVER.join(", ")} (or <name>:<wave>)` }),
|
|
210
|
+
from: z.array(z.enum(LOCAL_SIGNER_CLASSES)).min(1).optional(),
|
|
211
|
+
})
|
|
212
|
+
.strict())
|
|
213
|
+
.optional(),
|
|
214
|
+
})
|
|
215
|
+
.strict()
|
|
216
|
+
.optional(),
|
|
106
217
|
})
|
|
107
218
|
.strict();
|
|
108
219
|
/** The role whose holders may change the policy. Without any grant of it, every signer may. */
|
|
109
220
|
export const ADMIN_ROLE = "admin";
|
|
110
|
-
/** Paths whose change is a protected write under `policy`: the config, the signers file and its rotation file (#2553). */
|
|
221
|
+
/** Paths whose change is a protected write under `policy`: the config, the signers file and its rotation file (#2553), and the keyless trusted root (#4869). */
|
|
111
222
|
export function protectedPaths(policy) {
|
|
112
223
|
const s = policy.signersPath;
|
|
113
|
-
return [...new Set([TRUST_CONFIG_PATH, s, posix.join(posix.dirname(s), `${posix.basename(s)}.rotation.json`)])].sort();
|
|
224
|
+
return [...new Set([TRUST_CONFIG_PATH, s, posix.join(posix.dirname(s), `${posix.basename(s)}.rotation.json`), ...(policy.keyless ? [policy.keyless.trustedRoot] : [])])].sort();
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* The runners whose statements over `commit` count (#4869): the runner keys
|
|
228
|
+
* and the keyless identities. With `keyless.since`, a runner key counts
|
|
229
|
+
* only for a commit that is a strict ancestor of `since`, the way
|
|
230
|
+
* `ci.green.signedSince` judges tags by position in history; a `since` the
|
|
231
|
+
* clone does not have leaves the keys out. Without `at`, under `since`, only
|
|
232
|
+
* the identities.
|
|
233
|
+
*/
|
|
234
|
+
export function runnersAt(policy, at) {
|
|
235
|
+
const ids = policy.runnerIdentities ?? [];
|
|
236
|
+
const since = policy.keyless?.since;
|
|
237
|
+
if (!since)
|
|
238
|
+
return [...policy.runners, ...ids];
|
|
239
|
+
if (!at || !strictAncestor(at.repo, at.commit, since))
|
|
240
|
+
return ids;
|
|
241
|
+
return [...policy.runners, ...ids];
|
|
242
|
+
}
|
|
243
|
+
function strictAncestor(repo, commit, of) {
|
|
244
|
+
try {
|
|
245
|
+
const full = execFileSync("git", ["rev-parse", "--verify", "--quiet", `${commit}^{commit}`], { cwd: repo, encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] }).trim();
|
|
246
|
+
if (full === of)
|
|
247
|
+
return false;
|
|
248
|
+
execFileSync("git", ["merge-base", "--is-ancestor", full, of], { cwd: repo, stdio: "ignore" });
|
|
249
|
+
return true;
|
|
250
|
+
}
|
|
251
|
+
catch {
|
|
252
|
+
return false;
|
|
253
|
+
}
|
|
114
254
|
}
|
|
115
255
|
/** Principals allowed to change the policy: the admins when any are granted, otherwise every signer. */
|
|
116
256
|
export function policyWriters(policy) {
|
|
@@ -121,7 +261,7 @@ export function policyWriters(policy) {
|
|
|
121
261
|
}
|
|
122
262
|
/** A policy with nothing in it: attestation off. */
|
|
123
263
|
export function emptyPolicy(base, problems = []) {
|
|
124
|
-
return { base, signersPath: DEFAULT_SIGNERS_PATH, active: false, signers: [], excluded: [], roles: {}, adopted: [], runners: [], excludedRunners: [], passkeys: [], admitted: {}, problems };
|
|
264
|
+
return { base, signersPath: DEFAULT_SIGNERS_PATH, active: false, signers: [], excluded: [], roles: {}, adopted: [], runners: [], excludedRunners: [], passkeys: [], admitted: {}, refs: [], local: { keys: [], excluded: [], checks: [] }, problems };
|
|
125
265
|
}
|
|
126
266
|
/**
|
|
127
267
|
* Read the policy through `source`, which must read the base revision.
|
|
@@ -167,6 +307,7 @@ export function readTrustPolicy(source, base) {
|
|
|
167
307
|
runners.push(r);
|
|
168
308
|
}
|
|
169
309
|
}
|
|
310
|
+
const { runnerIdentities, keyless } = keylessOf(config, source, humanNames, excludedRunners);
|
|
170
311
|
return {
|
|
171
312
|
base,
|
|
172
313
|
signersPath,
|
|
@@ -177,11 +318,64 @@ export function readTrustPolicy(source, base) {
|
|
|
177
318
|
adopted: config.adopted ?? [],
|
|
178
319
|
runners,
|
|
179
320
|
excludedRunners,
|
|
321
|
+
...(keyless ? { runnerIdentities, keyless } : {}),
|
|
180
322
|
passkeys: config.passkeys ?? [],
|
|
181
323
|
admitted: admittedOf(config),
|
|
324
|
+
refs: (config.refs ?? []).map((r) => ({ ...r, checks: r.checks.map((c) => ({ ...c, action: c.action ?? "block" })) })),
|
|
325
|
+
local: localOf(config, runners),
|
|
182
326
|
problems: [],
|
|
183
327
|
};
|
|
184
328
|
}
|
|
329
|
+
/** The local evidence policy (#4868): a key a runner entry also holds is left out, so one key never speaks as both. */
|
|
330
|
+
function localOf(config, runners) {
|
|
331
|
+
const runnerKeys = new Set([...runners.map((r) => r.key), ...(config.runners ?? []).map((r) => r.key)]);
|
|
332
|
+
const all = config.local?.keys ?? [];
|
|
333
|
+
const keys = [];
|
|
334
|
+
const excluded = [];
|
|
335
|
+
for (const k of all) {
|
|
336
|
+
if (runnerKeys.has(k.key))
|
|
337
|
+
excluded.push({ principal: k.principal, reason: "a runner entry has this key; local evidence is signed by a person's or an agent's key, never a runner's" });
|
|
338
|
+
else if (all.filter((o) => o.key === k.key || o.principal === k.principal).length > 1)
|
|
339
|
+
excluded.push({ principal: k.principal, reason: "another local key has the same key or principal" });
|
|
340
|
+
else
|
|
341
|
+
keys.push(k);
|
|
342
|
+
}
|
|
343
|
+
return { keys, excluded, checks: (config.local?.checks ?? []).map((c) => ({ check: c.check, from: c.from ?? ["person"] })) };
|
|
344
|
+
}
|
|
345
|
+
/**
|
|
346
|
+
* The keyless identities (#4869), each with the trusted root read through
|
|
347
|
+
* `source`. A trusted root that cannot be read leaves every identity out,
|
|
348
|
+
* with the reason in `excluded`; the runner keys still count.
|
|
349
|
+
*/
|
|
350
|
+
function keylessOf(config, source, humanNames, excluded) {
|
|
351
|
+
const k = config.keyless;
|
|
352
|
+
if (!k)
|
|
353
|
+
return { runnerIdentities: [] };
|
|
354
|
+
// Kept when the root does not read, so `since` still leaves the keys out: fail closed.
|
|
355
|
+
const keyless = { ...(k.since ? { since: k.since } : {}), fulcio: k.fulcio ?? DEFAULT_FULCIO_URL, timestamp: k.timestamp ?? DEFAULT_TIMESTAMP_URL, audience: k.audience ?? DEFAULT_SIGNING_AUDIENCE, trustedRoot: k.trustedRoot };
|
|
356
|
+
let roots;
|
|
357
|
+
try {
|
|
358
|
+
const text = readOptional(source, k.trustedRoot);
|
|
359
|
+
if (text === undefined)
|
|
360
|
+
throw new Error("the file is not there");
|
|
361
|
+
roots = parseTrustedRoot(text);
|
|
362
|
+
}
|
|
363
|
+
catch (err) {
|
|
364
|
+
for (const i of k.identities)
|
|
365
|
+
excluded.push({ principal: i.principal, reason: `the keyless trusted root ${k.trustedRoot} cannot be read: ${err instanceof Error ? err.message : String(err)}` });
|
|
366
|
+
return { runnerIdentities: [], keyless };
|
|
367
|
+
}
|
|
368
|
+
const runnerIdentities = [];
|
|
369
|
+
for (const i of k.identities) {
|
|
370
|
+
if (humanNames.has(i.principal))
|
|
371
|
+
excluded.push({ principal: i.principal, reason: "the signers file lists this principal; a keyless identity is a CI job's, never a signer's" });
|
|
372
|
+
else {
|
|
373
|
+
const verify = keylessVerifier({ ...i, roots });
|
|
374
|
+
runnerIdentities.push({ ...i, roots, verifyKeyless: (message, signature) => verify(message, signature) });
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
return { runnerIdentities, keyless };
|
|
378
|
+
}
|
|
185
379
|
/** The admitted signers, by return id. Two entries for one return add up. */
|
|
186
380
|
function admittedOf(config) {
|
|
187
381
|
const out = {};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `chant workspace ref-gate` (#4867): refuse a ref update that lacks the
|
|
3
|
+
* evidence the policy at base requires. See ./ref-gate.ts.
|
|
4
|
+
*
|
|
5
|
+
* - `pre-receive` and `pre-push` are what the hooks `install` writes run;
|
|
6
|
+
* they read git's hook input on standard input.
|
|
7
|
+
* - `check --ref <ref>` decides one update from a checkout, and records the
|
|
8
|
+
* request for an override of each blocked check, as `pre-push` does.
|
|
9
|
+
* - `status --ref <ref>` decides the update a merge would make and sets the
|
|
10
|
+
* commit status the forge requires, so the forge refuses the merge.
|
|
11
|
+
* - `attach --envelope <file>` attaches runner evidence to a commit.
|
|
12
|
+
* - `install --hook pre-receive|pre-push` writes the hook.
|
|
13
|
+
*
|
|
14
|
+
* With `--json` each prints the `ref-gate.schema.json` document.
|
|
15
|
+
*/
|
|
16
|
+
import type { CommandContext } from "../../cli/registry.js";
|
|
17
|
+
import { type RefDecision } from "./ref-gate.js";
|
|
18
|
+
export declare const REF_GATE_CONTRACT_VERSION = 1;
|
|
19
|
+
export declare const REF_GATE_OUTPUT_SCHEMA_ID = "https://intentius.io/chant/schemas/workspace/ref-gate/v1/ref-gate.schema.json";
|
|
20
|
+
/** The line a hook chant writes carries, so `install` knows it may replace it. */
|
|
21
|
+
export declare const REF_GATE_HOOK_MARK = "# chant ref gate (#4867)";
|
|
22
|
+
export declare function runWorkspaceRefGate(ctx: CommandContext): Promise<number>;
|
|
23
|
+
/** The commit status a forge requires for `d`'s ref: `success` when it is admitted, `failure` naming the missing checks when not. */
|
|
24
|
+
export declare function postRefGateStatus(forge: {
|
|
25
|
+
setStatus(sha: string, status: {
|
|
26
|
+
context: string;
|
|
27
|
+
state: "success" | "failure";
|
|
28
|
+
description: string;
|
|
29
|
+
}): Promise<void>;
|
|
30
|
+
}, d: RefDecision): Promise<void>;
|
|
31
|
+
/** The hook script: it runs `chant` (or `command`) with the hook's arguments and input. */
|
|
32
|
+
export declare function refGateHook(hook: "pre-receive" | "pre-push", command?: string): string;
|
|
33
|
+
//# sourceMappingURL=ref-gate-cli.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ref-gate-cli.d.ts","sourceRoot":"","sources":["../../../src/workspace/trust/ref-gate-cli.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAKH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEzD,OAAO,EAYL,KAAK,WAAW,EAGjB,MAAM,YAAY,CAAC;AAIpB,eAAO,MAAM,yBAAyB,IAAI,CAAC;AAC3C,eAAO,MAAM,yBAAyB,kFAAkF,CAAC;AACzH,kFAAkF;AAClF,eAAO,MAAM,kBAAkB,6BAA6B,CAAC;AAyF7D,wBAAsB,mBAAmB,CAAC,GAAG,EAAE,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC,CAuE9E;AAED,qIAAqI;AACrI,wBAAsB,iBAAiB,CAAC,KAAK,EAAE;IAAE,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,SAAS,GAAG,SAAS,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;CAAE,EAAE,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAUvM;AAED,2FAA2F;AAC3F,wBAAgB,WAAW,CAAC,IAAI,EAAE,aAAa,GAAG,UAAU,EAAE,OAAO,SAAU,GAAG,MAAM,CAEvF"}
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `chant workspace ref-gate` (#4867): refuse a ref update that lacks the
|
|
3
|
+
* evidence the policy at base requires. See ./ref-gate.ts.
|
|
4
|
+
*
|
|
5
|
+
* - `pre-receive` and `pre-push` are what the hooks `install` writes run;
|
|
6
|
+
* they read git's hook input on standard input.
|
|
7
|
+
* - `check --ref <ref>` decides one update from a checkout, and records the
|
|
8
|
+
* request for an override of each blocked check, as `pre-push` does.
|
|
9
|
+
* - `status --ref <ref>` decides the update a merge would make and sets the
|
|
10
|
+
* commit status the forge requires, so the forge refuses the merge.
|
|
11
|
+
* - `attach --envelope <file>` attaches runner evidence to a commit.
|
|
12
|
+
* - `install --hook pre-receive|pre-push` writes the hook.
|
|
13
|
+
*
|
|
14
|
+
* With `--json` each prints the `ref-gate.schema.json` document.
|
|
15
|
+
*/
|
|
16
|
+
import { chmodSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
17
|
+
import { join } from "node:path";
|
|
18
|
+
import { formatError, formatSuccess } from "../../cli/format.js";
|
|
19
|
+
import { readerVersion } from "../declaration.js";
|
|
20
|
+
import { appendRefGateLedger, attachEvidence, commitOf, decideRefUpdate, describeDecision, readRefGateLedger, refGateLedgerPath, RefUpdateInputError, runPrePush, runPreReceive, spentOverrides, } from "./ref-gate.js";
|
|
21
|
+
import { resolveBase } from "./provenance.js";
|
|
22
|
+
import { spawnSync } from "node:child_process";
|
|
23
|
+
export const REF_GATE_CONTRACT_VERSION = 1;
|
|
24
|
+
export const REF_GATE_OUTPUT_SCHEMA_ID = "https://intentius.io/chant/schemas/workspace/ref-gate/v1/ref-gate.schema.json";
|
|
25
|
+
/** The line a hook chant writes carries, so `install` knows it may replace it. */
|
|
26
|
+
export const REF_GATE_HOOK_MARK = "# chant ref gate (#4867)";
|
|
27
|
+
/** How long a recorded request for an override stands. */
|
|
28
|
+
const OVERRIDE_REQUEST_HOURS = 72;
|
|
29
|
+
const USAGE = "chant workspace ref-gate check --ref <ref> [--at <rev>] [--base <rev>] [--dry-run] [--ledger <file>] [--json]\n" +
|
|
30
|
+
" chant workspace ref-gate status --ref <ref> [--at <rev>] [--base <rev>] [--dry-run] [--ledger <file>] [--json]\n" +
|
|
31
|
+
" chant workspace ref-gate pre-receive|pre-push [--ledger <file>] [--dry-run] [--json] (git hook input on stdin)\n" +
|
|
32
|
+
" chant workspace ref-gate attach --envelope <file> [--at <rev>]\n" +
|
|
33
|
+
" chant workspace ref-gate install --hook pre-receive|pre-push [--git-dir <dir>] [--chant <command>]";
|
|
34
|
+
function head() {
|
|
35
|
+
return { $schema: REF_GATE_OUTPUT_SCHEMA_ID, contract: REF_GATE_CONTRACT_VERSION, chant: readerVersion() };
|
|
36
|
+
}
|
|
37
|
+
function fail(json, code, message) {
|
|
38
|
+
if (json)
|
|
39
|
+
console.log(JSON.stringify({ ...head(), error: { code, message } }, null, 2));
|
|
40
|
+
else
|
|
41
|
+
console.error(formatError({ message: `${message} (${code})` }));
|
|
42
|
+
return 1;
|
|
43
|
+
}
|
|
44
|
+
function usage(message) {
|
|
45
|
+
console.error(formatError({ message, hint: USAGE }));
|
|
46
|
+
return 1;
|
|
47
|
+
}
|
|
48
|
+
/** The git directory of the current directory, bare or not, and the work tree root when there is one. */
|
|
49
|
+
function repoHere() {
|
|
50
|
+
const r = spawnSync("git", ["rev-parse", "--is-bare-repository", "--show-toplevel"], { encoding: "utf-8" });
|
|
51
|
+
if (r.status !== 0) {
|
|
52
|
+
const g = spawnSync("git", ["rev-parse", "--absolute-git-dir"], { encoding: "utf-8" });
|
|
53
|
+
return g.status === 0 ? { repo: g.stdout.trim(), bare: true } : null;
|
|
54
|
+
}
|
|
55
|
+
const [bare, top] = r.stdout.trim().split("\n");
|
|
56
|
+
if (bare === "true" || !top) {
|
|
57
|
+
const g = spawnSync("git", ["rev-parse", "--absolute-git-dir"], { encoding: "utf-8" });
|
|
58
|
+
return { repo: g.stdout.trim(), bare: true };
|
|
59
|
+
}
|
|
60
|
+
return { repo: top, bare: false };
|
|
61
|
+
}
|
|
62
|
+
function print(json, decisions, ledger, stream) {
|
|
63
|
+
const ok = decisions.every((d) => d.decision === "admit");
|
|
64
|
+
if (json) {
|
|
65
|
+
console.log(JSON.stringify({ ...head(), ok, ...(ledger ? { ledger } : {}), decisions }, null, 2));
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
for (const d of decisions) {
|
|
69
|
+
if (d.status === null && d.checks.length === 0 && !d.error)
|
|
70
|
+
continue;
|
|
71
|
+
const text = describeDecision(d).join("\n");
|
|
72
|
+
if (stream === "err" || d.decision === "refuse")
|
|
73
|
+
console.error(text);
|
|
74
|
+
else
|
|
75
|
+
console.log(text);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Record the request for an override of each blocked check, unless one
|
|
80
|
+
* stands, so a person can answer it with `chant approve policy-override`.
|
|
81
|
+
* Needs a checkout with `chant/lifecycle`; a failure to record is said and
|
|
82
|
+
* does not change the decision.
|
|
83
|
+
*/
|
|
84
|
+
async function recordRequests(repo, decisions, now) {
|
|
85
|
+
const blocked = decisions.flatMap((d) => d.checks.filter((c) => c.action === "block" && (c.status === "missing" || c.status === "stale")).map((c) => ({ d, c })));
|
|
86
|
+
if (blocked.length === 0)
|
|
87
|
+
return;
|
|
88
|
+
const { readOverrideLedger, recordOverrideDenial } = await import("../../lifecycle/override-ledger.js");
|
|
89
|
+
const { recordedDenials } = await import("../../override-gate.js");
|
|
90
|
+
try {
|
|
91
|
+
const standing = recordedDenials((await readOverrideLedger({ cwd: repo })).pending);
|
|
92
|
+
for (const { d, c } of blocked) {
|
|
93
|
+
const s = standing.find((x) => x.gate === c.subject);
|
|
94
|
+
if (s && Date.parse(s.expiresAt) > Date.parse(now) && s.plan === d.new)
|
|
95
|
+
continue;
|
|
96
|
+
await recordOverrideDenial({
|
|
97
|
+
subject: c.subject,
|
|
98
|
+
planDigest: d.new,
|
|
99
|
+
rules: [c.check],
|
|
100
|
+
timestamp: now,
|
|
101
|
+
expiresAt: new Date(Date.parse(now) + OVERRIDE_REQUEST_HOURS * 3600000).toISOString(),
|
|
102
|
+
description: `update of ${d.ref} to ${d.new.slice(0, 12)}, which has no current evidence for ${c.check}`,
|
|
103
|
+
}, { cwd: repo });
|
|
104
|
+
}
|
|
105
|
+
console.error(`chant ref gate: the request for an override of ${blocked.map((b) => b.c.subject).join(", ")} is recorded on chant/lifecycle; push chant/lifecycle with the override.`);
|
|
106
|
+
}
|
|
107
|
+
catch (err) {
|
|
108
|
+
console.error(`chant ref gate: could not record the request for an override: ${err instanceof Error ? err.message : String(err)}`);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
export async function runWorkspaceRefGate(ctx) {
|
|
112
|
+
const { args } = ctx;
|
|
113
|
+
const sub = args.extraPositional;
|
|
114
|
+
const subs = ["check", "status", "pre-receive", "pre-push", "attach", "install"];
|
|
115
|
+
if (!sub || !subs.includes(sub))
|
|
116
|
+
return usage(sub ? `Unknown ref-gate subcommand: ${sub}` : `chant workspace ref-gate needs one of ${subs.join(", ")}`);
|
|
117
|
+
const here = repoHere();
|
|
118
|
+
if (!here)
|
|
119
|
+
return fail(args.json, "not-a-git-repository", "the ref gate judges git ref updates, and this directory is not in a git repository");
|
|
120
|
+
const now = new Date().toISOString();
|
|
121
|
+
if (sub === "install")
|
|
122
|
+
return install(here.repo, args.hook, args.gitDir, args.ciChant);
|
|
123
|
+
if (sub === "attach") {
|
|
124
|
+
if (!args.envelope)
|
|
125
|
+
return usage("--envelope <file> is required");
|
|
126
|
+
const commit = commitOf(here.repo, args.at ?? "HEAD");
|
|
127
|
+
if (!commit)
|
|
128
|
+
return fail(args.json, "revision-unknown", `--at ${args.at ?? "HEAD"} names no commit`);
|
|
129
|
+
let envelope;
|
|
130
|
+
try {
|
|
131
|
+
envelope = JSON.parse(readFileSync(args.envelope, "utf-8"));
|
|
132
|
+
}
|
|
133
|
+
catch (err) {
|
|
134
|
+
return usage(`--envelope ${args.envelope} could not be read as JSON: ${err instanceof Error ? err.message : String(err)}`);
|
|
135
|
+
}
|
|
136
|
+
attachEvidence(here.repo, commit, envelope);
|
|
137
|
+
console.error(formatSuccess(`attached the evidence to ${commit.slice(0, 8)}; push refs/notes/chant/evidence with the ref`));
|
|
138
|
+
return 0;
|
|
139
|
+
}
|
|
140
|
+
if (sub === "pre-receive" || sub === "pre-push") {
|
|
141
|
+
const stdin = readFileSync(0, "utf-8");
|
|
142
|
+
try {
|
|
143
|
+
if (sub === "pre-receive") {
|
|
144
|
+
const r = runPreReceive(here.repo, stdin, { ...(args.ledger ? { ledger: args.ledger } : {}), now });
|
|
145
|
+
print(args.json, r.decisions, r.ledger, "err");
|
|
146
|
+
return r.ok ? 0 : 1;
|
|
147
|
+
}
|
|
148
|
+
const r = runPrePush(here.repo, stdin, { ...(args.ledger ? { ledger: args.ledger } : {}), now, base: (repo) => resolveBase(repo).commit });
|
|
149
|
+
print(args.json, r.decisions, r.ledger, "err");
|
|
150
|
+
if (!r.ok && !args.dryRun && !here.bare)
|
|
151
|
+
await recordRequests(here.repo, r.decisions, now);
|
|
152
|
+
return r.ok ? 0 : 1;
|
|
153
|
+
}
|
|
154
|
+
catch (err) {
|
|
155
|
+
if (err instanceof RefUpdateInputError)
|
|
156
|
+
return fail(args.json, "ref-update-invalid", err.message);
|
|
157
|
+
throw err;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
// check and status: one update, from a checkout or a CI job.
|
|
161
|
+
if (!args.ref || !args.ref.startsWith("refs/"))
|
|
162
|
+
return usage("--ref <ref> is required, as a full ref name such as refs/heads/main");
|
|
163
|
+
const at = commitOf(here.repo, args.at ?? "HEAD");
|
|
164
|
+
if (!at)
|
|
165
|
+
return fail(args.json, "revision-unknown", `--at ${args.at ?? "HEAD"} names no commit`);
|
|
166
|
+
const resolved = resolveBase(here.repo, args.base);
|
|
167
|
+
if (args.base !== undefined && !resolved.commit)
|
|
168
|
+
return fail(args.json, "revision-unknown", resolved.problem ?? `--base ${args.base} names no commit`);
|
|
169
|
+
const site = sub === "status" ? "status" : "check";
|
|
170
|
+
const ledger = args.ledger ?? refGateLedgerPath(here.repo);
|
|
171
|
+
const spent = spentOverrides(readRefGateLedger(ledger));
|
|
172
|
+
const d = decideRefUpdate({ repo: here.repo, update: { ref: args.ref, old: resolved.commit, new: at }, base: resolved.commit, spent, now });
|
|
173
|
+
if (!args.dryRun)
|
|
174
|
+
appendRefGateLedger(ledger, [{ ...d, version: 1, kind: "ref-update", site, timestamp: now }]);
|
|
175
|
+
print(args.json, [d], args.dryRun ? undefined : ledger, "out");
|
|
176
|
+
if (site === "check" && d.decision === "refuse" && !args.dryRun && !here.bare)
|
|
177
|
+
await recordRequests(here.repo, [d], now);
|
|
178
|
+
if (site === "status" && d.status !== null) {
|
|
179
|
+
if (args.dryRun) {
|
|
180
|
+
console.error(`chant ref gate: would set ${d.status} to ${d.decision === "admit" ? "success" : "failure"} on ${at.slice(0, 8)}`);
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
const { detectForge, forgeFromEnv } = await import("../../pr-forge.js");
|
|
184
|
+
const kind = detectForge();
|
|
185
|
+
if (!kind) {
|
|
186
|
+
console.error(formatError({ message: `no forge detected, so ${d.status} was not set`, hint: "run it in a GitHub, GitLab or Forgejo job, or pass --dry-run" }));
|
|
187
|
+
return 1;
|
|
188
|
+
}
|
|
189
|
+
await postRefGateStatus(forgeFromEnv(kind), d);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
return d.decision === "admit" ? 0 : 1;
|
|
193
|
+
}
|
|
194
|
+
/** The commit status a forge requires for `d`'s ref: `success` when it is admitted, `failure` naming the missing checks when not. */
|
|
195
|
+
export async function postRefGateStatus(forge, d) {
|
|
196
|
+
if (d.status === null || d.new === null)
|
|
197
|
+
return;
|
|
198
|
+
const missing = d.checks.filter((c) => c.action === "block" && (c.status === "missing" || c.status === "stale"));
|
|
199
|
+
const overridden = d.checks.filter((c) => c.status === "overridden").map((c) => c.check);
|
|
200
|
+
const description = d.error
|
|
201
|
+
? `refused: ${d.error.code}`
|
|
202
|
+
: missing.length > 0
|
|
203
|
+
? `missing evidence: ${missing.map((c) => `${c.check} (run ${c.command})`).join(", ")}`
|
|
204
|
+
: `evidence current${overridden.length ? `; overridden: ${overridden.join(", ")}` : ""}`;
|
|
205
|
+
await forge.setStatus(d.new, { context: d.status, state: d.decision === "admit" ? "success" : "failure", description });
|
|
206
|
+
}
|
|
207
|
+
/** The hook script: it runs `chant` (or `command`) with the hook's arguments and input. */
|
|
208
|
+
export function refGateHook(hook, command = "chant") {
|
|
209
|
+
return `#!/bin/sh\n${REF_GATE_HOOK_MARK}\nexec ${command} workspace ref-gate ${hook} "$@"\n`;
|
|
210
|
+
}
|
|
211
|
+
function install(repo, hook, gitDir, command) {
|
|
212
|
+
if (hook !== "pre-receive" && hook !== "pre-push")
|
|
213
|
+
return usage("--hook pre-receive (on the remote) or --hook pre-push (in a checkout) is required");
|
|
214
|
+
let dir = gitDir;
|
|
215
|
+
if (!dir) {
|
|
216
|
+
const r = spawnSync("git", ["rev-parse", "--git-path", "hooks"], { cwd: repo, encoding: "utf-8" });
|
|
217
|
+
dir = r.status === 0 ? join(repo, r.stdout.trim()) : join(repo, "hooks");
|
|
218
|
+
if (r.status === 0 && r.stdout.trim().startsWith("/"))
|
|
219
|
+
dir = r.stdout.trim();
|
|
220
|
+
}
|
|
221
|
+
else {
|
|
222
|
+
dir = join(dir, "hooks");
|
|
223
|
+
}
|
|
224
|
+
const path = join(dir, hook);
|
|
225
|
+
if (existsSync(path) && !readFileSync(path, "utf-8").includes(REF_GATE_HOOK_MARK)) {
|
|
226
|
+
console.error(formatError({ message: `${path} exists and is not chant's ref gate hook; it was left as it is`, hint: `call ${command ?? "chant"} workspace ref-gate ${hook} from it` }));
|
|
227
|
+
return 1;
|
|
228
|
+
}
|
|
229
|
+
mkdirSync(dir, { recursive: true });
|
|
230
|
+
writeFileSync(path, refGateHook(hook, command));
|
|
231
|
+
chmodSync(path, 0o755);
|
|
232
|
+
console.error(formatSuccess(`wrote ${path}`));
|
|
233
|
+
return 0;
|
|
234
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Test support for the ref gate (#4867): a checkout and a bare remote, a
|
|
3
|
+
* runner key, fake runner evidence signed with it, and override lines on
|
|
4
|
+
* `chant/lifecycle`. Isolated from the user's git config. The temporary
|
|
5
|
+
* directories are left in the system's temp directory.
|
|
6
|
+
*/
|
|
7
|
+
export interface RunnerKeyPair {
|
|
8
|
+
pem: string;
|
|
9
|
+
pub: string;
|
|
10
|
+
}
|
|
11
|
+
export declare function runnerKey(): RunnerKeyPair;
|
|
12
|
+
export declare const RUNNER = "ci@example.test";
|
|
13
|
+
export declare class GateRepos {
|
|
14
|
+
readonly root: string;
|
|
15
|
+
readonly work: string;
|
|
16
|
+
readonly origin: string;
|
|
17
|
+
readonly home: string;
|
|
18
|
+
constructor(label: string);
|
|
19
|
+
env(): NodeJS.ProcessEnv;
|
|
20
|
+
run(cwd: string, args: string[], input?: string): string;
|
|
21
|
+
git(args: string[], input?: string): string;
|
|
22
|
+
write(path: string, text: string): void;
|
|
23
|
+
commit(message: string): string;
|
|
24
|
+
/** Push `refspecs` to the bare remote with no hook in the way, and return git's output. */
|
|
25
|
+
push(...refspecs: string[]): string;
|
|
26
|
+
/** Sign evidence for `check` at `at` over `paths`, with `key`, and attach it to `to` (default `at`). */
|
|
27
|
+
sign(key: RunnerKeyPair, check: string, at: string, paths: string[], to?: string): unknown;
|
|
28
|
+
notesTip(): string;
|
|
29
|
+
/** Write `chant/lifecycle` holding a request for an override of `check` on `commit` and `by`'s override of it. */
|
|
30
|
+
override(commit: string, check: string, by: string, reason: string, at?: string): string;
|
|
31
|
+
}
|
|
32
|
+
/** `.chant/trust.json` with one runner and a ref rule for `refs/heads/main` and `refs/heads/release/*`. */
|
|
33
|
+
export declare function trustJson(runner: RunnerKeyPair, checks: Array<{
|
|
34
|
+
check: string;
|
|
35
|
+
action?: "block" | "warn";
|
|
36
|
+
command: string;
|
|
37
|
+
}>, extra?: Record<string, unknown>): string;
|
|
38
|
+
//# sourceMappingURL=ref-gate-fixture.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ref-gate-fixture.d.ts","sourceRoot":"","sources":["../../../src/workspace/trust/ref-gate-fixture.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAYH,MAAM,WAAW,aAAa;IAC5B,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;CACb;AAED,wBAAgB,SAAS,IAAI,aAAa,CAIzC;AAED,eAAO,MAAM,MAAM,oBAAoB,CAAC;AAExC,qBAAa,SAAS;IACpB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB,YAAY,KAAK,EAAE,MAAM,EASxB;IAED,GAAG,IAAI,MAAM,CAAC,UAAU,CAWvB;IAED,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAEvD;IAED,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAE1C;IAED,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAGtC;IAED,MAAM,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAI9B;IAED,2FAA2F;IAC3F,IAAI,CAAC,GAAG,QAAQ,EAAE,MAAM,EAAE,GAAG,MAAM,CAElC;IAED,wGAAwG;IACxG,IAAI,CAAC,GAAG,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,SAAK,GAAG,OAAO,CAMrF;IAED,QAAQ,IAAI,MAAM,CAEjB;IAED,kHAAkH;IAClH,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,SAA6B,GAAG,MAAM,CAW3G;CACF;AAED,2GAA2G;AAC3G,wBAAgB,SAAS,CAAC,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,KAAK,CAAC;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC,EAAE,KAAK,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,GAAG,MAAM,CAW1K"}
|