@intentius/chant 0.124.81 → 0.124.85

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.
@@ -80,16 +80,58 @@ export interface ReleaseWorkflowInput {
80
80
  * `tokenEnv` reads `GITHUB_TOKEN`, so the publish job sets it to the job's
81
81
  * token unless `release.workflow.env` sets it.
82
82
  */
83
- publish?: ReadonlyArray<{
84
- type: string;
85
- forge?: string;
86
- tokenEnv?: string;
87
- }>;
83
+ publish?: ReadonlyArray<ReleaseWorkflowTarget>;
88
84
  }
85
+ /** What the generator reads of a `release.publish` target: enough to know which credentials and tools its job needs. */
86
+ export interface ReleaseWorkflowTarget {
87
+ type: string;
88
+ forge?: string;
89
+ tokenEnv?: string;
90
+ /** An `oci` target's `<registry host>/<name>`. */
91
+ repository?: string;
92
+ usernameEnv?: string;
93
+ passwordEnv?: string;
94
+ /** An `npm` target's registry. */
95
+ registry?: string;
96
+ }
97
+ /** npm trusted publishing needs this npm or later (#4786). */
98
+ export declare const NPM_TRUSTED_PUBLISHING_MIN = "11.5.1";
99
+ /** The npm a publish job installs when the runner's Node bundles one older than {@link NPM_TRUSTED_PUBLISHING_MIN}. */
100
+ export declare const NPM_TRUSTED_PUBLISHING_VERSION = "11.19.0";
101
+ /**
102
+ * The shell line that installs {@link NPM_TRUSTED_PUBLISHING_VERSION} when the
103
+ * runner's npm is older than {@link NPM_TRUSTED_PUBLISHING_MIN}, and prints the
104
+ * npm in use.
105
+ */
106
+ export declare const NPM_TRUSTED_PUBLISHING_SETUP = "have=\"$(npm --version)\"; if [ \"$(printf '%s\\n' \"11.5.1\" \"$have\" | sort -V | head -n1)\" != \"11.5.1\" ]; then npm install -g npm@11.19.0; fi; npm --version";
107
+ /**
108
+ * What a GitHub release workflow needs for its targets, worked out from them
109
+ * (#4786), so no product wires it by hand:
110
+ *
111
+ * - an `oci` target on `ghcr.io` that names no credentials pushes with the
112
+ * job's token: `packages: write`, and `OCI_USERNAME` and `OCI_PASSWORD`
113
+ * from `github.actor` and `github.token`;
114
+ * - an `npm` target on npmjs publishes with trusted publishing, which needs
115
+ * npm {@link NPM_TRUSTED_PUBLISHING_MIN}: the jobs upgrade npm when the
116
+ * runner's is older.
117
+ *
118
+ * `release.workflow` wins: a scope, variable or the same setup line it names
119
+ * is not added again. Other forges, and configs without such targets, get
120
+ * nothing.
121
+ */
122
+ export declare function targetExtras(forge: ReleaseWorkflowForge, targets: ReadonlyArray<ReleaseWorkflowTarget>, p: ReleasePipelineConfig): Pick<ReleasePipelineConfig, "permissions" | "env" | "setup">;
89
123
  /** The flags `chant release publish` gets under the groups. */
90
124
  export declare function publishFlags(groups: ReadonlySet<SecurityGroup>): string[];
91
- /** Where `chant release images` writes the digests the publish job's build reads (#4657). */
125
+ /** Where `chant release images` writes the digests the publish job's build reads (#4657), by default and at a workstation. */
92
126
  export declare const RELEASE_DIGESTS_FILE = ".chant/release-digests.json";
127
+ /**
128
+ * Where a generated publish job writes the digests: the runner's temp
129
+ * directory, outside the checkout, so `chant release publish` finds the tree
130
+ * as the cut left it (#4853). A repository that commits files under `.chant/`
131
+ * can't ignore the directory, and a digests file there made the publish
132
+ * refuse with `release-worktree-dirty`.
133
+ */
134
+ export declare const RELEASE_DIGESTS_PATHS: Record<ReleaseWorkflowForge, string>;
93
135
  /** The workflow file's text, without the generated-by header. */
94
136
  export declare function renderReleaseWorkflow(input: ReleaseWorkflowInput): string;
95
137
  /** The workflow artifact the cut job hands its image archives on in. */
@@ -1 +1 @@
1
- {"version":3,"file":"release-workflow.d.ts","sourceRoot":"","sources":["../../src/workspace/release-workflow.ts"],"names":[],"mappings":"AAgCA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C,eAAO,MAAM,uBAAuB,YAAI,QAAQ,EAAE,SAAS,EAAE,QAAQ,CAAU,CAAC;AAChF,MAAM,MAAM,oBAAoB,GA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AAC,KAAK,EAAE,oBAAoB,GAAG,MAAM,CAkHzE;AAoFD,wEAAwE;AACxE,eAAO,MAAM,uBAAuB,yBAAyB,CAAC;AAuN9D,wFAAwF;AACxF,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAE7D;AAED;;;;GAIG;AACH,wBAAsB,kBAAkB,CAAC,GAAG,EAAE,OAAO,iBAAiB,EAAE,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC,CA8DvG"}
@@ -38,12 +38,59 @@ export const RELEASE_WORKFLOW_FILES = {
38
38
  // GitLab reads one .gitlab-ci.yml, which includes this file: `include: { local: .gitlab/chant-release.yml }`.
39
39
  gitlab: ".gitlab/chant-release.yml",
40
40
  };
41
+ /** npm trusted publishing needs this npm or later (#4786). */
42
+ export const NPM_TRUSTED_PUBLISHING_MIN = "11.5.1";
43
+ /** The npm a publish job installs when the runner's Node bundles one older than {@link NPM_TRUSTED_PUBLISHING_MIN}. */
44
+ export const NPM_TRUSTED_PUBLISHING_VERSION = "11.19.0";
45
+ /**
46
+ * The shell line that installs {@link NPM_TRUSTED_PUBLISHING_VERSION} when the
47
+ * runner's npm is older than {@link NPM_TRUSTED_PUBLISHING_MIN}, and prints the
48
+ * npm in use.
49
+ */
50
+ export const NPM_TRUSTED_PUBLISHING_SETUP = `have="$(npm --version)"; if [ "$(printf '%s\\n' "${NPM_TRUSTED_PUBLISHING_MIN}" "$have" | sort -V | head -n1)" != "${NPM_TRUSTED_PUBLISHING_MIN}" ]; then npm install -g npm@${NPM_TRUSTED_PUBLISHING_VERSION}; fi; npm --version`;
51
+ /**
52
+ * What a GitHub release workflow needs for its targets, worked out from them
53
+ * (#4786), so no product wires it by hand:
54
+ *
55
+ * - an `oci` target on `ghcr.io` that names no credentials pushes with the
56
+ * job's token: `packages: write`, and `OCI_USERNAME` and `OCI_PASSWORD`
57
+ * from `github.actor` and `github.token`;
58
+ * - an `npm` target on npmjs publishes with trusted publishing, which needs
59
+ * npm {@link NPM_TRUSTED_PUBLISHING_MIN}: the jobs upgrade npm when the
60
+ * runner's is older.
61
+ *
62
+ * `release.workflow` wins: a scope, variable or the same setup line it names
63
+ * is not added again. Other forges, and configs without such targets, get
64
+ * nothing.
65
+ */
66
+ export function targetExtras(forge, targets, p) {
67
+ if (forge !== "github")
68
+ return {};
69
+ const ghcr = targets.some((t) => t.type === "oci" && /^ghcr\.io\//.test(t.repository ?? "") && !t.usernameEnv && !t.passwordEnv);
70
+ const npm = targets.some((t) => t.type === "npm" && (t.registry === undefined || /^https:\/\/registry\.npmjs\.org\/?$/.test(t.registry)));
71
+ const permissions = ghcr && p.permissions?.packages === undefined ? { packages: "write" } : undefined;
72
+ const env = ghcr ? Object.fromEntries(["OCI_USERNAME", "OCI_PASSWORD"].filter((k) => p.env?.[k] === undefined).map((k) => [k, k === "OCI_USERNAME" ? "${{ github.actor }}" : "${{ github.token }}"])) : {};
73
+ const setup = npm && !(p.setup ?? []).some((s) => !("uses" in s) && s.run === NPM_TRUSTED_PUBLISHING_SETUP) ? [{ run: NPM_TRUSTED_PUBLISHING_SETUP }] : [];
74
+ return { ...(permissions ? { permissions } : {}), ...(Object.keys(env).length > 0 ? { env } : {}), ...(setup.length > 0 ? { setup } : {}) };
75
+ }
41
76
  /** The flags `chant release publish` gets under the groups. */
42
77
  export function publishFlags(groups) {
43
78
  return [...(groups.has("supply-chain") ? ["--require-provenance"] : []), "--yes"];
44
79
  }
45
- /** Where `chant release images` writes the digests the publish job's build reads (#4657). */
80
+ /** Where `chant release images` writes the digests the publish job's build reads (#4657), by default and at a workstation. */
46
81
  export const RELEASE_DIGESTS_FILE = ".chant/release-digests.json";
82
+ /**
83
+ * Where a generated publish job writes the digests: the runner's temp
84
+ * directory, outside the checkout, so `chant release publish` finds the tree
85
+ * as the cut left it (#4853). A repository that commits files under `.chant/`
86
+ * can't ignore the directory, and a digests file there made the publish
87
+ * refuse with `release-worktree-dirty`.
88
+ */
89
+ export const RELEASE_DIGESTS_PATHS = {
90
+ github: "$RUNNER_TEMP/chant-release-digests.json",
91
+ forgejo: "$RUNNER_TEMP/chant-release-digests.json",
92
+ gitlab: "/tmp/chant-release-digests.json",
93
+ };
47
94
  /** A string as a single-quoted shell word. */
48
95
  function sq(s) {
49
96
  return `'${s.replaceAll("'", "'\\''")}'`;
@@ -60,7 +107,14 @@ export function renderReleaseWorkflow(input) {
60
107
  const after = p.after ?? [];
61
108
  const images = input.images === true;
62
109
  const version = input.version === true;
63
- const extra = jobExtras(p, input.forge);
110
+ // #4786: the targets' own needs first, then the config's, so a config that set them by hand renders the same file without them.
111
+ const derived = targetExtras(input.forge, input.publish ?? [], p);
112
+ const extra = jobExtras({
113
+ ...p,
114
+ ...(derived.permissions ? { permissions: { ...p.permissions, ...derived.permissions } } : {}),
115
+ ...(derived.env ? { env: { ...p.env, ...derived.env } } : {}),
116
+ ...(derived.setup ? { setup: [...(p.setup ?? []), ...derived.setup] } : {}),
117
+ }, input.forge);
64
118
  // #4767: Forgejo's job token is not a GitHub token, and GitLab has no such expression.
65
119
  const forgeToken = input.forge === "github" && p.env?.GITHUB_TOKEN === undefined && (input.publish ?? []).some((t) => t.type === "forge" && t.forge === "github" && !t.tokenEnv)
66
120
  ? [" GITHUB_TOKEN: ${{ github.token }}"]
@@ -71,7 +125,8 @@ export function renderReleaseWorkflow(input) {
71
125
  return input.forge === "gitlab" ? renderGitlabDispatch(o) : renderGithubDispatch(o);
72
126
  }
73
127
  // #4657: the images are built from the release, so chant/lifecycle is fetched before them and the build after.
74
- const imageLines = (label, env) => [`${chant} release images ${label} -o ${RELEASE_DIGESTS_FILE}`, env];
128
+ const digests = RELEASE_DIGESTS_PATHS[input.forge];
129
+ const imageLines = (label, env) => [`${chant} release images ${label} -o "${digests}"`, env];
75
130
  if (input.forge === "gitlab") {
76
131
  const label = '"${CI_COMMIT_TAG#release/}"';
77
132
  const fetches = [" - git fetch origin 'refs/tags/ci/*:refs/tags/ci/*'", " - git fetch origin chant/lifecycle:chant/lifecycle"];
@@ -88,7 +143,7 @@ export function renderReleaseWorkflow(input) {
88
143
  ` - ${install}`,
89
144
  ...extra.gitlabScript.map((l) => ` - ${l}`),
90
145
  ...(version ? [` - ${chant} release stamp ${label}`] : []),
91
- ...(images ? [...fetches, ...imageLines(label, `export CHANT_RELEASE_DIGESTS="$PWD/${RELEASE_DIGESTS_FILE}"`).map((l) => ` - ${l}`)] : []),
146
+ ...(images ? [...fetches, ...imageLines(label, `export CHANT_RELEASE_DIGESTS="${digests}"`).map((l) => ` - ${l}`)] : []),
92
147
  ...(build ? [` - ${build}`] : []),
93
148
  ...(images ? [] : fetches),
94
149
  ...(verify ? [` - ${chant} release verify ${label}`] : []),
@@ -120,7 +175,7 @@ export function renderReleaseWorkflow(input) {
120
175
  ` - run: ${install}`,
121
176
  ...extra.githubSteps,
122
177
  ...(version ? [` - run: ${chant} release stamp ${label}`] : []),
123
- ...(images ? [...fetches, ...imageLines(label, `echo "CHANT_RELEASE_DIGESTS=$PWD/${RELEASE_DIGESTS_FILE}" >> "$GITHUB_ENV"`).map((l) => ` - run: ${l}`)] : []),
178
+ ...(images ? [...fetches, ...imageLines(label, `echo "CHANT_RELEASE_DIGESTS=${digests}" >> "$GITHUB_ENV"`).map((l) => ` - run: ${l}`)] : []),
124
179
  ...(build ? [` - run: ${build}`] : []),
125
180
  ...(images ? [] : fetches),
126
181
  ...(verify ? [` - run: ${chant} release verify ${label}`] : []),
@@ -199,7 +254,7 @@ function commonDir(paths) {
199
254
  }
200
255
  /** The `release images` line of a publish job: checking the archives handed on, or building them again. */
201
256
  function imagesLine(o) {
202
- return `${o.chant} release images "$CHANT_RELEASE_LABEL"${o.archives.length > 0 ? " --no-build" : ""} -o ${RELEASE_DIGESTS_FILE}`;
257
+ return `${o.chant} release images "$CHANT_RELEASE_LABEL"${o.archives.length > 0 ? " --no-build" : ""} -o "${RELEASE_DIGESTS_PATHS[o.forge]}"`;
203
258
  }
204
259
  /** The publish job's `release stamp` line (#4840). */
205
260
  function stampLine(o) {
@@ -207,12 +262,30 @@ function stampLine(o) {
207
262
  }
208
263
  /** The node one-liner that prints a JSON document's field from stdin, or from the file its argument names. */
209
264
  const field = (path) => `node -e 'const f=process.argv[1];const t=f?require("fs").readFileSync(f,"utf8"):require("fs").readFileSync(0,"utf8");const d=JSON.parse(t);process.stdout.write(String(${path}??""))'`;
265
+ /**
266
+ * GitHub refuses the job's token a ref on a commit whose workflow files differ
267
+ * from the default branch's (#4852). The gate checks before the cut builds
268
+ * anything: when the green commit's `.github/workflows` differs from the
269
+ * dispatched commit's, it stops and names the newest commit that changed
270
+ * them, the one to wait for.
271
+ */
272
+ function workflowFilesCheck(dispatched) {
273
+ const files = '":(top).github/workflows"';
274
+ return [
275
+ `if ! git diff --quiet "$commit" "${dispatched}" -- ${files}; then`,
276
+ ` changed="$(git log -1 --format=%H "$commit..${dispatched}" -- ${files})"`,
277
+ ` echo "the newest green commit, $commit, has other workflow files than ${dispatched}, and GitHub refuses this job's token a tag on it, so no release is cut. Dispatch again once \${changed:-${dispatched}}, which changed .github/workflows, or a commit after it is green." >&2`,
278
+ " exit 1",
279
+ "fi",
280
+ ];
281
+ }
210
282
  /** The gate's shell: the commit to cut, from `ci last-green`, refused when there is none or, under `head`, when it is not the dispatched one. */
211
283
  function gateScript(o, dispatched) {
212
284
  return [
213
285
  `commit="$(${o.chant} ci last-green --from "${dispatched}"${o.lane ? ` --lane ${o.lane}` : ""} --json | ${field("d.commit?.sha")})"`,
214
286
  `if [ -z "$commit" ]; then echo "no green commit at or below ${dispatched}, so no release is cut" >&2; exit 1; fi`,
215
287
  ...(o.gate === "head" ? [`if [ "$commit" != "${dispatched}" ]; then echo "${dispatched} is not green (the newest green commit below it is $commit), so no release is cut" >&2; exit 1; fi`] : []),
288
+ ...(o.forge === "github" && o.gate !== "head" ? workflowFilesCheck(dispatched) : []),
216
289
  ];
217
290
  }
218
291
  /** The cut's shell: cut the label at the gate's commit, then push the tag the cut made. */
@@ -306,7 +379,7 @@ function renderGithubDispatch(o) {
306
379
  ? [` - uses: ${usesRef(o.forge === "forgejo" ? ACTION_PINS.downloadArtifact3 : ACTION_PINS.downloadArtifact4)}`, " with:", ` name: ${RELEASE_IMAGES_ARTIFACT}`, ` path: ${commonDir(o.archives)}`]
307
380
  : []),
308
381
  ...(o.version ? [` - run: ${stampLine(o)}`] : []),
309
- ...(o.images ? [` - run: ${imagesLine(o)}`, ` - run: echo "CHANT_RELEASE_DIGESTS=$PWD/${RELEASE_DIGESTS_FILE}" >> "$GITHUB_ENV"`] : []),
382
+ ...(o.images ? [` - run: ${imagesLine(o)}`, ` - run: echo "CHANT_RELEASE_DIGESTS=${RELEASE_DIGESTS_PATHS[o.forge]}" >> "$GITHUB_ENV"`] : []),
310
383
  ...(o.build ? [` - run: ${o.build}`] : []),
311
384
  ...(o.verify ? [` - run: ${o.chant} release verify "$CHANT_RELEASE_LABEL"`] : []),
312
385
  ` - run: ${o.chant} release publish "$CHANT_RELEASE_LABEL" ${o.flags}`,
@@ -357,7 +430,7 @@ function renderGitlabDispatch(o) {
357
430
  ...fetches,
358
431
  ...auth,
359
432
  ...(o.version ? [stampLine(o)] : []),
360
- ...(o.images ? [imagesLine(o), `export CHANT_RELEASE_DIGESTS="$PWD/${RELEASE_DIGESTS_FILE}"`] : []),
433
+ ...(o.images ? [imagesLine(o), `export CHANT_RELEASE_DIGESTS="${RELEASE_DIGESTS_PATHS.gitlab}"`] : []),
361
434
  ...(o.build ? [o.build] : []),
362
435
  ...(o.verify ? [`${o.chant} release verify "$CHANT_RELEASE_LABEL"`] : []),
363
436
  `${o.chant} release publish "$CHANT_RELEASE_LABEL" ${o.flags}`,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intentius/chant",
3
- "version": "0.124.81",
3
+ "version": "0.124.85",
4
4
  "description": "Declarative infrastructure-as-code toolkit — TypeScript on Node.js",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://intentius.io/chant",
@@ -1,4 +1,4 @@
1
- import { describe, test, expect } from "vitest";
1
+ import { beforeAll, describe, test, expect } from "vitest";
2
2
  import { auditFiles, CROSS_FILE, type AuditInput } from "./core";
3
3
  import type { PostSynthCheck } from "../lint/post-synth";
4
4
 
@@ -70,6 +70,13 @@ jobs:
70
70
  `;
71
71
 
72
72
  describe("auditFiles", () => {
73
+ // The first audit of a lexicon loads its plugin and checks; on a CI runner that
74
+ // took the first test past the 5s unit budget (#2817). Load them once here.
75
+ // A lexicon that can't load is left for the test that needs it to report.
76
+ beforeAll(async () => {
77
+ for (const lexicon of ["github", "gitlab", "forgejo", "terraform", "k8s"]) await auditFiles([{ path: `warm.${lexicon}`, content: "", lexicon }]).catch(() => undefined);
78
+ }, 60_000);
79
+
73
80
  test("flags unpinned action and write-all permissions in a github workflow", async () => {
74
81
  const inputs: AuditInput[] = [
75
82
  { path: ".github/workflows/ci.yml", content: DIRTY_GH, lexicon: "github" },
@@ -109,7 +109,7 @@ export function checkoutRelayDeps(cwd: string, principal: string): RelayDeps {
109
109
  await fetchDefaultBranch(cwd);
110
110
  const { scopeSource } = await import("../../workspace/write-scope");
111
111
  const policy = scopeSource(cwd).policy;
112
- return { signers: policy.signers, path: policy.signersPath };
112
+ return { signers: policy.signers, path: policy.signersPath, problems: policy.problems };
113
113
  }),
114
114
  pending: (digest) =>
115
115
  one(async () => {
@@ -26,12 +26,27 @@ export interface FakeRegistry {
26
26
  close(): Promise<void>;
27
27
  }
28
28
 
29
+ /** GHCR's answer to a blob PUT it refuses intermittently (#4877). */
30
+ export const GHCR_DENIED = JSON.stringify({ errors: [{ code: "DENIED", message: "permission_denied: write_package" }] });
31
+
32
+ /**
33
+ * Faults the registry fake can inject (#4877): `denyPuts` refuses that many
34
+ * blob PUTs with GHCR's 403 body before it accepts one; `expireTokenAfter`
35
+ * makes the token it handed out expire after that many accepted blob PUTs,
36
+ * so the next request is answered 401 with the challenge again, and a new
37
+ * token is issued.
38
+ */
39
+ export interface FakeRegistryFaults {
40
+ denyPuts?: number;
41
+ expireTokenAfter?: number;
42
+ }
43
+
29
44
  /** A registry fake with a Bearer token service that accepts `username` and `password`. */
30
- export async function startFakeRegistry(creds: { username: string; password: string; token: string }): Promise<FakeRegistry> {
45
+ export async function startFakeRegistry(creds: { username: string; password: string; token: string }, faults: FakeRegistryFaults = {}): Promise<FakeRegistry> {
31
46
  const blobs = new Map<string, Buffer>();
32
47
  const manifests = new Map<string, { name: string; type: string; bytes: Buffer }>();
33
48
  const requests: FakeRegistry["requests"] = [];
34
- const state = { uploads: 0, port: 0 };
49
+ const state = { uploads: 0, port: 0, denied: 0, token: creds.token, tokens: 0 };
35
50
  const read = (req: IncomingMessage) =>
36
51
  new Promise<Buffer>((res) => {
37
52
  const parts: Buffer[] = [];
@@ -49,18 +64,25 @@ export async function startFakeRegistry(creds: { username: string; password: str
49
64
  if (url.pathname === "/token") {
50
65
  const basic = `Basic ${Buffer.from(`${creds.username}:${creds.password}`).toString("base64")}`;
51
66
  if (req.headers.authorization !== basic) return send(401, {}, "bad credentials");
52
- return send(200, { "content-type": "application/json" }, JSON.stringify({ token: creds.token }));
67
+ state.token = state.tokens === 0 ? creds.token : `${creds.token}-${state.tokens}`;
68
+ state.tokens++;
69
+ return send(200, { "content-type": "application/json" }, JSON.stringify({ token: state.token }));
53
70
  }
54
- if (req.headers.authorization !== `Bearer ${creds.token}`) {
71
+ if (req.headers.authorization !== `Bearer ${state.token}`) {
55
72
  return send(401, { "www-authenticate": `Bearer realm="http://127.0.0.1:${state.port}/token",service="fake-registry"` }, "unauthorized");
56
73
  }
57
74
  let m = url.pathname.match(/^\/v2\/(.+)\/blobs\/uploads\/(.*)$/);
58
75
  if (m) {
59
76
  if (req.method === "POST") return send(202, { location: `/v2/${m[1]}/blobs/uploads/u${requests.length}?_state=s` });
60
77
  const digest = url.searchParams.get("digest") ?? "";
78
+ if (req.method === "PUT" && state.denied < (faults.denyPuts ?? 0)) {
79
+ state.denied++;
80
+ return send(403, { "content-type": "application/json" }, GHCR_DENIED);
81
+ }
61
82
  if (req.method === "PUT" && sha(body) === digest && url.searchParams.get("_state") === "s") {
62
83
  blobs.set(digest, body);
63
84
  state.uploads++;
85
+ if (faults.expireTokenAfter !== undefined && state.uploads === faults.expireTokenAfter) state.token = "expired";
64
86
  return send(201, { "docker-content-digest": digest });
65
87
  }
66
88
  return send(400, {}, "digest invalid");
@@ -175,7 +175,37 @@ function ociCredential(decl: OciPublishDeclaration, repo: OciRepository, ctx: Pu
175
175
  return null;
176
176
  }
177
177
 
178
- /** A registry client that answers the registry's auth challenge once and keeps the token. */
178
+ /** How many times an upload or a manifest is tried before the target fails (#4877). */
179
+ export const OCI_PUSH_ATTEMPTS = 4;
180
+ /** The wait before the second try, doubled for each try after it. */
181
+ export const OCI_PUSH_RETRY_MS = 2000;
182
+
183
+ /**
184
+ * Whether a registry's answer to an upload or a manifest is worth trying
185
+ * again (#4877): GHCR intermittently refuses a blob PUT with 403 `DENIED`
186
+ * (`permission_denied: write_package`) under a token that pushed the blob
187
+ * before it, and any registry can time out, throttle or fail.
188
+ */
189
+ function retryable(status: number, body: string): boolean {
190
+ return status === 408 || status === 429 || status >= 500 || (status === 403 && /"DENIED"/.test(body));
191
+ }
192
+
193
+ /** A registry's answer the target gave up on: what was asked, the status and the body. */
194
+ class RegistryAnswer extends Error {
195
+ constructor(
196
+ readonly what: string,
197
+ readonly status: number,
198
+ readonly body: string,
199
+ ) {
200
+ super(`${what} answered ${status}`);
201
+ }
202
+ }
203
+
204
+ /**
205
+ * A registry client that answers the registry's auth challenge and keeps the
206
+ * token. A 401 under a token it already holds, as when the registry's token
207
+ * expires during a long push, is answered once more (#4877).
208
+ */
179
209
  class Registry {
180
210
  private auth: string | null = null;
181
211
  constructor(
@@ -183,6 +213,7 @@ class Registry {
183
213
  private readonly fetch: PublishFetch,
184
214
  private readonly cred: { username: string; password: Credential } | null,
185
215
  private readonly ctx: PublishContext,
216
+ private readonly sleep: (ms: number) => Promise<void> = (ms) => new Promise<void>((r) => setTimeout(r, ms)),
186
217
  ) {}
187
218
 
188
219
  private fail(what: string, status: number, body: string): never {
@@ -193,8 +224,14 @@ class Registry {
193
224
  const url = /^https?:\/\//.test(path) ? path : `${this.repo.base}${path}`;
194
225
  const send = () => this.fetch(url, { method, headers: { ...headers, ...(this.auth ? { authorization: this.auth } : {}) }, ...(body ? { body } : {}) });
195
226
  let res = await send();
196
- if (res.status === 401 && this.auth === null) {
197
- await this.answerChallenge(res.headers.get("www-authenticate") ?? "");
227
+ if (res.status === 401) {
228
+ const challenge = res.headers.get("www-authenticate") ?? "";
229
+ if (this.auth !== null) {
230
+ if (!challenge) return res;
231
+ this.ctx.log(`${this.repo.base} asked for credentials again; answering its challenge once more`);
232
+ }
233
+ this.auth = null;
234
+ await this.answerChallenge(challenge);
198
235
  res = await send();
199
236
  }
200
237
  return res;
@@ -224,19 +261,52 @@ class Registry {
224
261
  this.auth = `Bearer ${token}`;
225
262
  }
226
263
 
264
+ /**
265
+ * Run `attempt` up to {@link OCI_PUSH_ATTEMPTS} times while it fails with a
266
+ * {@link retryable} answer or a dropped connection, waiting longer before
267
+ * each try (#4877). Any other answer fails the target at once.
268
+ */
269
+ private async tries<T>(what: string, attempt: () => Promise<T>): Promise<T> {
270
+ for (let n = 1; ; n++) {
271
+ try {
272
+ return await attempt();
273
+ } catch (err) {
274
+ const answer = err instanceof RegistryAnswer ? err : null;
275
+ const dropped = !answer && !(err instanceof PublishTargetError);
276
+ const again = n < OCI_PUSH_ATTEMPTS && (dropped || (answer !== null && retryable(answer.status, answer.body)));
277
+ if (!again) {
278
+ if (answer) this.fail(answer.what, answer.status, answer.body);
279
+ throw err;
280
+ }
281
+ const why = answer ? `answered ${answer.status}${answer.body ? `: ${this.ctx.redactor.redact(answer.body.slice(0, 200))}` : ""}` : `failed: ${this.ctx.redactor.redact(err instanceof Error ? err.message : String(err))}`;
282
+ const wait = OCI_PUSH_RETRY_MS * 2 ** (n - 1);
283
+ this.ctx.log(`${what} at ${this.repo.base} ${why}; trying again in ${wait / 1000}s (${n + 1} of ${OCI_PUSH_ATTEMPTS})`);
284
+ await this.sleep(wait);
285
+ }
286
+ }
287
+ }
288
+
227
289
  /** Upload a blob unless the registry holds it. True when it was uploaded. */
228
290
  async pushBlob(digest: string, bytes: () => Uint8Array): Promise<boolean> {
229
291
  const head = await this.request("HEAD", `/v2/${this.repo.name}/blobs/${digest}`);
230
292
  if (head.status === 200) return false;
231
- const start = await this.request("POST", `/v2/${this.repo.name}/blobs/uploads/`, { "content-length": "0" });
232
- if (start.status !== 202) this.fail(`starting an upload of ${digest}`, start.status, await start.text());
233
- const location = start.headers.get("location");
234
- if (!location) this.fail(`starting an upload of ${digest}`, start.status, "with no Location");
235
- const abs = /^https?:\/\//.test(location) ? location : `${this.repo.base}${location.startsWith("/") ? "" : "/"}${location}`;
236
- const put = `${abs}${abs.includes("?") ? "&" : "?"}digest=${encodeURIComponent(digest)}`;
237
- const data = bytes();
238
- const done = await this.request("PUT", put, { "content-type": "application/octet-stream", "content-length": String(data.byteLength) }, data);
239
- if (done.status !== 201) this.fail(`uploading ${digest}`, done.status, await done.text());
293
+ await this.tries(`uploading ${digest}`, async () => {
294
+ // A fresh upload session each try: a refused PUT may have ended the last one.
295
+ const start = await this.request("POST", `/v2/${this.repo.name}/blobs/uploads/`, { "content-length": "0" });
296
+ if (start.status !== 202) {
297
+ const text = await start.text();
298
+ // A refused POST means the credentials can't push here; that is not tried again.
299
+ if (start.status === 401 || start.status === 403) this.fail(`starting an upload of ${digest}`, start.status, text);
300
+ throw new RegistryAnswer(`starting an upload of ${digest}`, start.status, text);
301
+ }
302
+ const location = start.headers.get("location");
303
+ if (!location) this.fail(`starting an upload of ${digest}`, start.status, "with no Location");
304
+ const abs = /^https?:\/\//.test(location) ? location : `${this.repo.base}${location.startsWith("/") ? "" : "/"}${location}`;
305
+ const put = `${abs}${abs.includes("?") ? "&" : "?"}digest=${encodeURIComponent(digest)}`;
306
+ const data = bytes();
307
+ const done = await this.request("PUT", put, { "content-type": "application/octet-stream", "content-length": String(data.byteLength) }, data);
308
+ if (done.status !== 201) throw new RegistryAnswer(`uploading ${digest}`, done.status, await done.text());
309
+ });
240
310
  return true;
241
311
  }
242
312
 
@@ -247,8 +317,10 @@ class Registry {
247
317
  }
248
318
 
249
319
  async putManifest(ref: string, mediaType: string, bytes: Uint8Array): Promise<void> {
250
- const res = await this.request("PUT", `/v2/${this.repo.name}/manifests/${ref}`, { "content-type": mediaType }, bytes);
251
- if (res.status !== 201) this.fail(`putting manifest ${ref}`, res.status, await res.text());
320
+ await this.tries(`putting manifest ${ref}`, async () => {
321
+ const res = await this.request("PUT", `/v2/${this.repo.name}/manifests/${ref}`, { "content-type": mediaType }, bytes);
322
+ if (res.status !== 201) throw new RegistryAnswer(`putting manifest ${ref}`, res.status, await res.text());
323
+ });
252
324
  }
253
325
  }
254
326
 
@@ -336,7 +408,7 @@ export function ociTarget(decl: OciPublishDeclaration, deps: PublishDeps): Publi
336
408
  const referrerItem = (r: Referrer): PublishItem => ({ name: r.attachment.name, destination: `${decl.repository}@${r.digest}, a referrer of the image`, digest: r.digest, attachment: r.attachment.kind });
337
409
  const connect = (ctx: PublishContext) => {
338
410
  const cred = ociCredential(decl, repo, ctx);
339
- return { cred, registry: new Registry(repo, fetchImpl, cred, ctx) };
411
+ return { cred, registry: new Registry(repo, fetchImpl, cred, ctx, deps.sleep) };
340
412
  };
341
413
  return {
342
414
  kind: "oci",
@@ -18,10 +18,10 @@ import { createRedactor, REDACTED } from "./publish-credentials";
18
18
  import { PublishDeclarationSchema } from "./publish-declaration";
19
19
  import { createPublishTargets } from "./publish-targets";
20
20
  import { memberSbom } from "./publish-attachments";
21
- import { parseRepository } from "./publish-oci";
21
+ import { OCI_PUSH_ATTEMPTS, parseRepository } from "./publish-oci";
22
22
  import { PublishTargetError, type PublishContext, type PublishTarget, type PublishedTarget } from "./release-publish";
23
23
  import { makeRelease, type ReleaseArtifact } from "./release-store";
24
- import { readFakeNpmRegistry, seedFakeNpmRegistry, startFakeForge, startFakeRegistry, writeFakeNpm, writeLockfile, writeOciLayout, writePackage } from "./__fixtures__/publish-fakes";
24
+ import { GHCR_DENIED, readFakeNpmRegistry, seedFakeNpmRegistry, startFakeForge, startFakeRegistry, writeFakeNpm, writeLockfile, writeOciLayout, writePackage } from "./__fixtures__/publish-fakes";
25
25
 
26
26
  const dirs: string[] = [];
27
27
  afterAll(() => {
@@ -297,6 +297,63 @@ describe("oci", () => {
297
297
  }
298
298
  });
299
299
 
300
+ describe("a registry that refuses or drops an upload (#4877)", () => {
301
+ const env = { OCI_USERNAME: "robot", OCI_PASSWORD: "oci-pass-9876" };
302
+ async function push(faults: Parameters<typeof startFakeRegistry>[1]) {
303
+ const reg = await startFakeRegistry({ username: "robot", password: "oci-pass-9876", token: "registry-token-abcdef" }, faults);
304
+ const waits: number[] = [];
305
+ const dir = temp();
306
+ writeLockfile(dir);
307
+ const { digest, configDigest } = writeOciLayout(join(dir, "dist", "api.oci"));
308
+ const [target] = await createPublishTargets([decl({ type: "oci", image: "dist/api.oci", repository: `${reg.host}/acme/api`, sbom: false })], { sleep: async (ms) => void waits.push(ms) });
309
+ const ctx = context(dir, { env, artifacts: [{ component: "api", kind: "image", path: "dist/api.oci", digest: configDigest }] });
310
+ return { reg, waits, digest, ctx, stage: () => target!.stage(ctx) };
311
+ }
312
+
313
+ test("GHCR's intermittent 403 on a blob PUT: a fresh upload is tried again, and the image is staged", async () => {
314
+ const { reg, waits, digest, ctx, stage } = await push({ denyPuts: 2 });
315
+ try {
316
+ await stage();
317
+ expect(reg.manifests.has(digest)).toBe(true);
318
+ expect(waits).toEqual([2000, 4000]);
319
+ const posts = reg.requests.filter((r) => r.method === "POST" && r.path.includes("/blobs/uploads/")).length;
320
+ expect(posts).toBe(reg.uploads + 2);
321
+ const out = ctx.lines.join("\n");
322
+ expect(out).toMatch(/uploading sha256:[0-9a-f]{64} at http:\/\/127\.0\.0\.1:\d+ answered 403: .*permission_denied: write_package.*; trying again in 2s \(2 of 4\)/);
323
+ expect(out).not.toContain("oci-pass-9876");
324
+ } finally {
325
+ await reg.close();
326
+ }
327
+ });
328
+
329
+ test("a registry that refuses every PUT fails the target with its last answer after the last try", async () => {
330
+ const { reg, waits, stage } = await push({ denyPuts: 100 });
331
+ try {
332
+ const err = await refused(stage());
333
+ expect(err.code).toBe("publish-oci-failed");
334
+ expect(err.message).toMatch(/uploading sha256:[0-9a-f]{64} at http:\/\/127\.0\.0\.1:\d+ answered 403: /);
335
+ expect(err.message).toContain(GHCR_DENIED.slice(0, 40));
336
+ expect(waits).toHaveLength(OCI_PUSH_ATTEMPTS - 1);
337
+ expect(reg.manifests.size).toBe(0);
338
+ } finally {
339
+ await reg.close();
340
+ }
341
+ });
342
+
343
+ test("a token that expires during the push is answered again, not given up on", async () => {
344
+ const { reg, waits, digest, ctx, stage } = await push({ expireTokenAfter: 1 });
345
+ try {
346
+ await stage();
347
+ expect(reg.manifests.has(digest)).toBe(true);
348
+ expect(waits).toEqual([]);
349
+ expect(reg.requests.filter((r) => r.path === "/token")).toHaveLength(2);
350
+ expect(ctx.lines.join("\n")).toContain("asked for credentials again; answering its challenge once more");
351
+ } finally {
352
+ await reg.close();
353
+ }
354
+ });
355
+ });
356
+
300
357
  test("pushes a docker save style tar with docker config credentials; refuses bad credentials, a layout the release did not build, and a missing one", async () => {
301
358
  const reg = await startFakeRegistry({ username: "dh", password: "dockerhub-pat-555", token: "tok-777777" });
302
359
  try {
@@ -18,6 +18,8 @@ import { relayToken } from "./notify";
18
18
  import { decideRelayClick } from "./notify-relay";
19
19
  import { checkRelayToken, prepareRelayCheckout, relayGitAuthEnv, relayRepo, type RelayRepo } from "./notify-relay-repo";
20
20
  import { cleanScratch, git, scratchDir, writeFiles } from "./workspace/__fixtures__/contract-repo";
21
+ import { ROTATION_NAMESPACE, rotationStatement, signersDigest } from "./workspace/trust/rotation";
22
+ import { TestRepo } from "./workspace/trust/test-repo";
21
23
 
22
24
  afterAll(cleanScratch);
23
25
 
@@ -193,7 +195,11 @@ describe("the relay's flags (#4759)", () => {
193
195
  });
194
196
 
195
197
  describe("the relay's own checkout (#4759)", () => {
196
- const SIGNERS = `alice@acme.com,slack:T1/U1 ssh-ed25519 ${KEY}\nbob@acme.com ssh-ed25519 ${KEY}\n`;
198
+ // alice holds a real key, so a rotation that adds a signer can be signed by the set before it (#4803).
199
+ const keys = new TestRepo("relay-keys");
200
+ afterAll(() => keys.cleanup());
201
+ const alice = keys.key("alice");
202
+ const SIGNERS = `alice@acme.com,slack:T1/U1 ${alice.pub}\nbob@acme.com ssh-ed25519 ${KEY}\n`;
197
203
  const T = (h: number): string => new Date(Date.now() - 3600_000 + h * 3600_000).toISOString();
198
204
  const pending = { version: 1, kind: "pending", op: "tf-apply", gate: "wave-1", timestamp: T(1), expiresAt: T(49), planDigest: D };
199
205
 
@@ -244,9 +250,16 @@ describe("the relay's own checkout (#4759)", () => {
244
250
  expect(readFileSync(join(made.dir, ".git", "config"), "utf-8")).not.toContain(Buffer.from(`x-access-token:${TOKEN}`).toString("base64"));
245
251
  expect(git(made.dir, "remote", "get-url", "origin")).toBe(`${f.url}/acme/infra.git`);
246
252
 
247
- // A signer added on main after the clone.
248
- writeFiles(work, { ".chant/allowed_signers": `${SIGNERS}carol@acme.com,slack:T1/U3 ssh-ed25519 ${KEY}\n` });
249
- git(work, "commit", "-qam", "add carol");
253
+ // A signer added on main after the clone, by a rotation alice signs.
254
+ const next = `${SIGNERS}carol@acme.com,slack:T1/U3 ssh-ed25519 ${KEY}\n`;
255
+ const rotation = { version: 2, previous: signersDigest(SIGNERS), threshold: 1 };
256
+ const signature = keys.sshSign(alice, rotationStatement(rotation, signersDigest(next)), ROTATION_NAMESPACE);
257
+ writeFiles(work, {
258
+ ".chant/allowed_signers": next,
259
+ ".chant/allowed_signers.rotation.json": JSON.stringify({ schema: 1, ...rotation, signatures: [{ principal: "alice@acme.com", signature }] }, null, 2),
260
+ });
261
+ git(work, "add", "-A");
262
+ git(work, "commit", "-qm", "add carol");
250
263
  git(work, "push", "-q", bare, "main");
251
264
 
252
265
  const prev = { env: { ...process.env }, cwd: process.cwd() };