@caelo-cms/provisioning 0.11.21 → 0.12.1
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/adapter.d.ts +6 -1
- package/dist/adapter.d.ts.map +1 -1
- package/dist/agent-db.js +133 -8
- package/dist/bootstrap-token.d.ts +4 -3
- package/dist/bootstrap-token.d.ts.map +1 -1
- package/dist/bootstrap-token.js.map +1 -1
- package/dist/cli-routing.d.ts.map +1 -1
- package/dist/cli-routing.js +5 -0
- package/dist/cli-routing.js.map +1 -1
- package/dist/cli.js +4 -0
- package/dist/cli.js.map +1 -1
- package/dist/converge-job-gcp.d.ts +1 -16
- package/dist/converge-job-gcp.d.ts.map +1 -1
- package/dist/converge-job-gcp.js +10 -97
- package/dist/converge-job-gcp.js.map +1 -1
- package/dist/converge-job.d.ts +7 -46
- package/dist/converge-job.d.ts.map +1 -1
- package/dist/converge-job.js +22 -57
- package/dist/converge-job.js.map +1 -1
- package/dist/gateway-armor.d.ts.map +1 -1
- package/dist/gateway-armor.js +11 -3
- package/dist/gateway-armor.js.map +1 -1
- package/dist/gcp-names.d.ts +2 -0
- package/dist/gcp-names.d.ts.map +1 -1
- package/dist/gcp-names.js +4 -0
- package/dist/gcp-names.js.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/infra-contract.d.ts +1 -1
- package/dist/infra-contract.d.ts.map +1 -1
- package/dist/infra-contract.js +14 -1
- package/dist/infra-contract.js.map +1 -1
- package/dist/job-handover-gcp.d.ts +40 -0
- package/dist/job-handover-gcp.d.ts.map +1 -0
- package/dist/job-handover-gcp.js +108 -0
- package/dist/job-handover-gcp.js.map +1 -0
- package/dist/job-handover.d.ts +141 -0
- package/dist/job-handover.d.ts.map +1 -0
- package/dist/job-handover.js +141 -0
- package/dist/job-handover.js.map +1 -0
- package/dist/owner-setup-token.d.ts +52 -0
- package/dist/owner-setup-token.d.ts.map +1 -0
- package/dist/owner-setup-token.js +111 -0
- package/dist/owner-setup-token.js.map +1 -0
- package/dist/project-status.d.ts +33 -0
- package/dist/project-status.d.ts.map +1 -1
- package/dist/project-status.js +116 -26
- package/dist/project-status.js.map +1 -1
- package/dist/stack-converge.d.ts.map +1 -1
- package/dist/stack-converge.js +9 -5
- package/dist/stack-converge.js.map +1 -1
- package/dist/static-security-headers.d.ts +6 -0
- package/dist/static-security-headers.d.ts.map +1 -1
- package/dist/static-security-headers.js +11 -1
- package/dist/static-security-headers.js.map +1 -1
- package/dist/upgrader-assess.d.ts +30 -3
- package/dist/upgrader-assess.d.ts.map +1 -1
- package/dist/upgrader-assess.js +77 -24
- package/dist/upgrader-assess.js.map +1 -1
- package/dist/upgrader-gcp.d.ts +4 -2
- package/dist/upgrader-gcp.d.ts.map +1 -1
- package/dist/upgrader-gcp.js +16 -3
- package/dist/upgrader-gcp.js.map +1 -1
- package/dist/upgrader-iam-preflight.d.ts +14 -3
- package/dist/upgrader-iam-preflight.d.ts.map +1 -1
- package/dist/upgrader-iam-preflight.js +40 -6
- package/dist/upgrader-iam-preflight.js.map +1 -1
- package/dist/upgrader-job.d.ts +51 -9
- package/dist/upgrader-job.d.ts.map +1 -1
- package/dist/upgrader-job.js +92 -37
- package/dist/upgrader-job.js.map +1 -1
- package/dist/upgrader-setup.d.ts +1 -1
- package/dist/upgrader-setup.d.ts.map +1 -1
- package/dist/upgrader-setup.js +5 -2
- package/dist/upgrader-setup.js.map +1 -1
- package/dist/wizards/gcp-install-job.d.ts.map +1 -1
- package/dist/wizards/gcp-install-job.js +11 -1
- package/dist/wizards/gcp-install-job.js.map +1 -1
- package/dist/wizards/gcp-pulumi.d.ts +0 -13
- package/dist/wizards/gcp-pulumi.d.ts.map +1 -1
- package/dist/wizards/gcp-pulumi.js +0 -12
- package/dist/wizards/gcp-pulumi.js.map +1 -1
- package/dist/wizards/gcp.d.ts.map +1 -1
- package/dist/wizards/gcp.js +21 -50
- package/dist/wizards/gcp.js.map +1 -1
- package/package.json +2 -2
- package/src/adapter.ts +6 -1
- package/src/bootstrap-token.ts +4 -3
- package/src/caddy-redirects.docker.test.ts +5 -0
- package/src/cli-routing.test.ts +1 -1
- package/src/cli-routing.ts +6 -0
- package/src/cli.ts +4 -0
- package/src/converge-job-gcp.test.ts +1 -40
- package/src/converge-job-gcp.ts +10 -100
- package/src/converge-job.test.ts +9 -3
- package/src/converge-job.ts +33 -115
- package/src/gateway-armor.ts +14 -3
- package/src/gateway-edge.test.ts +16 -1
- package/src/gcp-names.ts +4 -0
- package/src/gcp-url-map.test.ts +2 -0
- package/src/index.ts +3 -0
- package/src/infra-contract.test.ts +4 -3
- package/src/infra-contract.ts +14 -1
- package/src/job-handover-gcp.test.ts +129 -0
- package/src/job-handover-gcp.ts +135 -0
- package/src/job-handover.ts +259 -0
- package/src/owner-setup-token.test.ts +195 -0
- package/src/owner-setup-token.ts +138 -0
- package/src/project-status.test.ts +112 -3
- package/src/project-status.ts +141 -17
- package/src/stack-converge.ts +12 -5
- package/src/static-security-headers.test.ts +16 -0
- package/src/static-security-headers.ts +12 -1
- package/src/upgrader-assess.test.ts +75 -1
- package/src/upgrader-assess.ts +121 -57
- package/src/upgrader-gcp.ts +19 -5
- package/src/upgrader-iam-preflight.test.ts +28 -1
- package/src/upgrader-iam-preflight.ts +46 -6
- package/src/upgrader-job.test.ts +365 -31
- package/src/upgrader-job.ts +177 -53
- package/src/upgrader-setup.test.ts +17 -0
- package/src/upgrader-setup.ts +5 -2
- package/src/url-map-redirects-access.test.ts +1 -1
- package/src/wizards/gcp-install-job.ts +10 -1
- package/src/wizards/gcp-pulumi.ts +0 -18
- package/src/wizards/gcp.ts +24 -61
- package/stacks/aws/README.md +4 -2
- package/stacks/aws/index.ts +4 -8
- package/stacks/azure/README.md +4 -2
- package/stacks/azure/index.ts +4 -8
- package/stacks/gcp/README.md +6 -3
- package/stacks/gcp/index.ts +7 -8
- package/stacks/gcp-firebase/index.ts +4 -6
package/src/project-status.ts
CHANGED
|
@@ -6,14 +6,19 @@
|
|
|
6
6
|
* gone, and a reset Cloud Shell has no `~/.caelo-*` left, so this command
|
|
7
7
|
* needs nothing but a signed-in gcloud identity: it reads the project
|
|
8
8
|
* (install.json, install-job.json and progress.json in the ops bucket, the
|
|
9
|
-
* Owner setup link in Secret Manager) and writes nothing, here or
|
|
9
|
+
* Owner setup link and token in Secret Manager) and writes nothing, here or
|
|
10
|
+
* there.
|
|
10
11
|
*
|
|
11
12
|
* The setup link is a secret (#656). It goes to a terminal only: with stdout
|
|
12
13
|
* piped or redirected it stays unprinted, so it can't land in a CI log or a
|
|
13
14
|
* file. Once Owner setup is done the command says so instead of showing a
|
|
14
|
-
* used link.
|
|
15
|
+
* used link; a link past its 24 hours (#1476) is not shown either.
|
|
16
|
+
*
|
|
17
|
+
* `setup-link --project <id>` is the one command here that writes: what a
|
|
18
|
+
* late Owner runs for a new link ({@link setupLinkCommand}).
|
|
15
19
|
*/
|
|
16
20
|
|
|
21
|
+
import type { OwnerBootstrapToken } from "@caelo-cms/shared";
|
|
17
22
|
import { log } from "@clack/prompts";
|
|
18
23
|
import { bold, cyan, dim, green, red, yellow } from "kleur/colors";
|
|
19
24
|
import { z } from "zod";
|
|
@@ -35,6 +40,12 @@ import {
|
|
|
35
40
|
readSetupLink,
|
|
36
41
|
recordedDnsRecords,
|
|
37
42
|
} from "./install-job.js";
|
|
43
|
+
import {
|
|
44
|
+
issueOwnerSetup,
|
|
45
|
+
type OwnerSetupIssued,
|
|
46
|
+
readOwnerBootstrapToken,
|
|
47
|
+
} from "./owner-setup-token.js";
|
|
48
|
+
import { selfCommand } from "./self-command.js";
|
|
38
49
|
import { readProjectInstall } from "./state-attach.js";
|
|
39
50
|
import { realSyncGcloud, type SyncGcloud } from "./state-store.js";
|
|
40
51
|
import {
|
|
@@ -68,9 +79,21 @@ export type OwnerSetup =
|
|
|
68
79
|
/** An Owner exists; the link is used. */
|
|
69
80
|
| { readonly kind: "done" }
|
|
70
81
|
/** Setup is open, or could not be checked ({@link unverified} says why). */
|
|
71
|
-
| {
|
|
82
|
+
| {
|
|
83
|
+
readonly kind: "link";
|
|
84
|
+
readonly link: string;
|
|
85
|
+
readonly expiresAt: string;
|
|
86
|
+
readonly unverified: string | null;
|
|
87
|
+
}
|
|
72
88
|
/** A link exists, but stdout is not a terminal. */
|
|
73
|
-
| { readonly kind: "withheld" }
|
|
89
|
+
| { readonly kind: "withheld"; readonly expiresAt: string }
|
|
90
|
+
/**
|
|
91
|
+
* A link exists but cannot work: its token expired on {@link expiresAt}, or
|
|
92
|
+
* (null) it does not carry the stored token. That is an install that finished
|
|
93
|
+
* before #1476, whose admin refuses `/setup` until it has a token, or a new
|
|
94
|
+
* token stored without its link by an interrupted run.
|
|
95
|
+
*/
|
|
96
|
+
| { readonly kind: "stale"; readonly expiresAt: string | null }
|
|
74
97
|
/** No link in Secret Manager. */
|
|
75
98
|
| { readonly kind: "no-link" }
|
|
76
99
|
/** Reading the link failed; the message says what the account needs. */
|
|
@@ -99,6 +122,8 @@ export interface ProjectStatusDeps {
|
|
|
99
122
|
) => Promise<AdminInternalResult<"open" | "done">>;
|
|
100
123
|
/** Whether stdout is a terminal: the only place the setup link may go. */
|
|
101
124
|
readonly isTerminal: boolean;
|
|
125
|
+
/** The current time in ms. */
|
|
126
|
+
readonly now: () => number;
|
|
102
127
|
}
|
|
103
128
|
|
|
104
129
|
/** The admin's origin from the stack's outputs; null before the stack ran. */
|
|
@@ -163,8 +188,29 @@ async function readOwnerSetup(
|
|
|
163
188
|
? await deps.ownerSetupState(target)
|
|
164
189
|
: { ok: false, error: "install.json records no region" };
|
|
165
190
|
if (state.ok && state.value === "done") return { kind: "done" };
|
|
166
|
-
|
|
167
|
-
|
|
191
|
+
// Only now: an install with an Owner has no use for the token, so nothing
|
|
192
|
+
// about that secret may change what it reports.
|
|
193
|
+
let token: OwnerBootstrapToken | null;
|
|
194
|
+
try {
|
|
195
|
+
token = await readOwnerBootstrapToken(deps.run, args.install.projectId);
|
|
196
|
+
} catch (e) {
|
|
197
|
+
return { kind: "error", message: e instanceof Error ? e.message : String(e) };
|
|
198
|
+
}
|
|
199
|
+
// A run of `setup-link` stopped between the two secrets leaves a new token
|
|
200
|
+
// beside the old link: that link is not the one the admin accepts.
|
|
201
|
+
if (token === null || !link.endsWith(`token=${token.token}`)) {
|
|
202
|
+
return { kind: "stale", expiresAt: null };
|
|
203
|
+
}
|
|
204
|
+
if (Date.parse(token.expiresAt) <= deps.now()) {
|
|
205
|
+
return { kind: "stale", expiresAt: token.expiresAt };
|
|
206
|
+
}
|
|
207
|
+
if (!deps.isTerminal) return { kind: "withheld", expiresAt: token.expiresAt };
|
|
208
|
+
return {
|
|
209
|
+
kind: "link",
|
|
210
|
+
link,
|
|
211
|
+
expiresAt: token.expiresAt,
|
|
212
|
+
unverified: state.ok ? null : state.error,
|
|
213
|
+
};
|
|
168
214
|
}
|
|
169
215
|
|
|
170
216
|
/**
|
|
@@ -227,7 +273,7 @@ function dnsLines(s: ProjectStatus): string[] {
|
|
|
227
273
|
|
|
228
274
|
function ownerLines(s: ProjectStatus): string[] {
|
|
229
275
|
const { owner, install, adminUrl } = s;
|
|
230
|
-
const
|
|
276
|
+
const newLink = selfCommand("setup-link", "--project", install.projectId);
|
|
231
277
|
switch (owner.kind) {
|
|
232
278
|
case "not-yet":
|
|
233
279
|
return ["Owner setup: the link appears here when the install has finished."];
|
|
@@ -235,18 +281,22 @@ function ownerLines(s: ProjectStatus): string[] {
|
|
|
235
281
|
return [`Owner setup: ${green("done.")} Sign in at ${cyan(adminUrl ?? "")}`];
|
|
236
282
|
case "withheld":
|
|
237
283
|
return [
|
|
238
|
-
`Owner setup: ${yellow(
|
|
284
|
+
`Owner setup: ${yellow(`a link is stored, valid until ${owner.expiresAt}, but it is a secret and only goes to a terminal.`)} Run this command in your own terminal, without a pipe or redirect.`,
|
|
285
|
+
];
|
|
286
|
+
case "stale":
|
|
287
|
+
return [
|
|
288
|
+
`Owner setup: ${yellow(owner.expiresAt ? `the stored link expired on ${owner.expiresAt}.` : "the stored link has no token the admin can use.")} Nobody can use it. Get a new one: ${newLink}`,
|
|
239
289
|
];
|
|
240
290
|
case "no-link":
|
|
241
291
|
return [
|
|
242
292
|
`Owner setup: no link is stored in this project (${INSTALL_SETUP_LINK_SECRET}). If Owner setup is done, sign in at ${cyan(adminUrl ?? "")}`,
|
|
243
|
-
` If it is not, this
|
|
293
|
+
` If it is not, this stores a link and prints it: ${newLink}`,
|
|
244
294
|
];
|
|
245
295
|
case "error":
|
|
246
296
|
return [`Owner setup: ${red(owner.message)}`];
|
|
247
297
|
case "link":
|
|
248
298
|
return [
|
|
249
|
-
`Owner setup: open this link in your browser, signed in as ${install.ownerEmail}. Do not share it
|
|
299
|
+
`Owner setup: open this link in your browser, signed in as ${install.ownerEmail}. Do not share it. It works until ${owner.expiresAt}, then: ${newLink}`,
|
|
250
300
|
` ${bold(cyan(owner.link))}`,
|
|
251
301
|
...(owner.unverified === null
|
|
252
302
|
? []
|
|
@@ -280,6 +330,86 @@ export function projectStatusFailure(e: unknown): string {
|
|
|
280
330
|
return e instanceof Error ? e.message : String(e);
|
|
281
331
|
}
|
|
282
332
|
|
|
333
|
+
/** The real {@link ProjectStatusDeps}: the operator's gcloud, public DNS, this process. */
|
|
334
|
+
function realProjectStatusDeps(): ProjectStatusDeps {
|
|
335
|
+
return {
|
|
336
|
+
run: gcloud,
|
|
337
|
+
syncRun: realSyncGcloud,
|
|
338
|
+
resolves: checkRecord,
|
|
339
|
+
ownerSetupState: (target) => readOwnerSetupState(target),
|
|
340
|
+
isTerminal: process.stdout.isTTY === true,
|
|
341
|
+
now: Date.now,
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* What `setup-link` does for an install in `status`: a line to print and stop
|
|
347
|
+
* on, or null to go on and issue a link. There is nothing to issue before the
|
|
348
|
+
* install finished or after an Owner exists, and a refused read must not
|
|
349
|
+
* read as "no link".
|
|
350
|
+
*/
|
|
351
|
+
export function setupLinkRefusal(status: ProjectStatus): string | null {
|
|
352
|
+
switch (status.owner.kind) {
|
|
353
|
+
case "not-yet":
|
|
354
|
+
return "The install has not finished. Its last step stores the Owner setup link.";
|
|
355
|
+
case "done":
|
|
356
|
+
return `Owner setup is done; no link is needed. Sign in at ${status.adminUrl ?? "the admin"}.`;
|
|
357
|
+
case "error":
|
|
358
|
+
return status.owner.message;
|
|
359
|
+
default:
|
|
360
|
+
return null;
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
/**
|
|
365
|
+
* Lines of `setup-link`'s result. Holds the link only on a terminal, like
|
|
366
|
+
* {@link projectStatusLines}.
|
|
367
|
+
*/
|
|
368
|
+
export function setupLinkLines(issued: OwnerSetupIssued, isTerminal: boolean): string[] {
|
|
369
|
+
const state = issued.minted ? "A new link is stored" : "The current link still works";
|
|
370
|
+
return isTerminal
|
|
371
|
+
? [
|
|
372
|
+
`${state}, until ${issued.expiresAt}. Open it in your browser. Do not share it.`,
|
|
373
|
+
` ${bold(cyan(issued.link))}`,
|
|
374
|
+
]
|
|
375
|
+
: [`${state}, until ${issued.expiresAt}. It is a secret and only goes to a terminal.`];
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
/**
|
|
379
|
+
* `setup-link --project <id>` (#1476): a working Owner setup link for an
|
|
380
|
+
* install without an Owner, from any signed-in terminal. Exit 1 when none
|
|
381
|
+
* could be given.
|
|
382
|
+
*/
|
|
383
|
+
export async function setupLinkCommand(argv: readonly string[]): Promise<void> {
|
|
384
|
+
const projectId = argv[argv.indexOf("--project") + 1] ?? "";
|
|
385
|
+
if (!argv.includes("--project") || !isGcpProjectId(projectId)) {
|
|
386
|
+
console.error("Usage: cms-provision setup-link --project <gcp-project-id>");
|
|
387
|
+
process.exit(2);
|
|
388
|
+
}
|
|
389
|
+
try {
|
|
390
|
+
const auth = await checkGcloudAuth();
|
|
391
|
+
if (!auth.ok) throw new Error(auth.error);
|
|
392
|
+
const deps = realProjectStatusDeps();
|
|
393
|
+
const status = await readProjectStatus(projectId, deps);
|
|
394
|
+
const refusal = setupLinkRefusal(status);
|
|
395
|
+
if (refusal !== null) {
|
|
396
|
+
console.log(refusal);
|
|
397
|
+
if (status.owner.kind !== "done") process.exitCode = 1;
|
|
398
|
+
return;
|
|
399
|
+
}
|
|
400
|
+
const { region } = status.install;
|
|
401
|
+
if (region === null || status.adminUrl === null) {
|
|
402
|
+
throw new Error(`install.json of ${projectId} records no region or admin URL.`);
|
|
403
|
+
}
|
|
404
|
+
const issued = await issueOwnerSetup(deps.run, { projectId, region }, status.adminUrl);
|
|
405
|
+
if (!issued.ok) throw new Error(issued.error);
|
|
406
|
+
for (const line of setupLinkLines(issued, deps.isTerminal)) console.log(line);
|
|
407
|
+
} catch (e) {
|
|
408
|
+
log.error(red(projectStatusFailure(e)));
|
|
409
|
+
process.exit(1);
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
|
|
283
413
|
/** `status --project <id>`: print where the install stands; exit 1 when part of it can't be read. */
|
|
284
414
|
export async function projectStatusCommand(argv: readonly string[]): Promise<void> {
|
|
285
415
|
const projectId = argv[argv.indexOf("--project") + 1] ?? "";
|
|
@@ -290,13 +420,7 @@ export async function projectStatusCommand(argv: readonly string[]): Promise<voi
|
|
|
290
420
|
try {
|
|
291
421
|
const auth = await checkGcloudAuth();
|
|
292
422
|
if (!auth.ok) throw new Error(auth.error);
|
|
293
|
-
const status = await readProjectStatus(projectId,
|
|
294
|
-
run: gcloud,
|
|
295
|
-
syncRun: realSyncGcloud,
|
|
296
|
-
resolves: checkRecord,
|
|
297
|
-
ownerSetupState: (target) => readOwnerSetupState(target),
|
|
298
|
-
isTerminal: process.stdout.isTTY === true,
|
|
299
|
-
});
|
|
423
|
+
const status = await readProjectStatus(projectId, realProjectStatusDeps());
|
|
300
424
|
for (const line of projectStatusLines(status)) console.log(line);
|
|
301
425
|
if (status.owner.kind === "error") process.exitCode = 1;
|
|
302
426
|
} catch (e) {
|
package/src/stack-converge.ts
CHANGED
|
@@ -68,7 +68,10 @@ import {
|
|
|
68
68
|
stagingGatewayEnvContract,
|
|
69
69
|
staticBackendBucketPrefix,
|
|
70
70
|
} from "./stack-contract.js";
|
|
71
|
-
import {
|
|
71
|
+
import {
|
|
72
|
+
GCP_STATIC_RESPONSE_HEADERS,
|
|
73
|
+
withStaticResponseHeaders,
|
|
74
|
+
} from "./static-security-headers.js";
|
|
72
75
|
import { ensureSvgDownloads } from "./static-svg-gcp.js";
|
|
73
76
|
|
|
74
77
|
// ===========================================================================
|
|
@@ -590,19 +593,22 @@ async function ensureCdnPolicy(
|
|
|
590
593
|
project,
|
|
591
594
|
"--format=json",
|
|
592
595
|
]);
|
|
596
|
+
let liveHeaders: readonly string[] = [];
|
|
593
597
|
if (describe.ok) {
|
|
594
598
|
const live = JSON.parse(describe.stdout) as {
|
|
595
599
|
cdnPolicy?: Record<string, unknown>;
|
|
596
600
|
customResponseHeaders?: unknown;
|
|
597
601
|
};
|
|
598
602
|
const cdn = live.cdnPolicy;
|
|
603
|
+
if (Array.isArray(live.customResponseHeaders)) {
|
|
604
|
+
liveHeaders = live.customResponseHeaders.map(String);
|
|
605
|
+
}
|
|
599
606
|
const inShape =
|
|
600
607
|
cdn !== undefined &&
|
|
601
608
|
(Object.keys(STATIC_CDN_POLICY) as (keyof typeof STATIC_CDN_POLICY)[]).every(
|
|
602
609
|
(k) => String(cdn[k]) === String(STATIC_CDN_POLICY[k]),
|
|
603
610
|
) &&
|
|
604
|
-
|
|
605
|
-
JSON.stringify(GCP_STATIC_RESPONSE_HEADERS);
|
|
611
|
+
GCP_STATIC_RESPONSE_HEADERS.every((h) => liveHeaders.includes(h));
|
|
606
612
|
if (inShape) return { ...base, status: "present" };
|
|
607
613
|
}
|
|
608
614
|
const update = await run([
|
|
@@ -615,8 +621,9 @@ async function ensureCdnPolicy(
|
|
|
615
621
|
`--default-ttl=${STATIC_CDN_POLICY.defaultTtl}`,
|
|
616
622
|
`--max-ttl=${STATIC_CDN_POLICY.maxTtl}`,
|
|
617
623
|
`--client-ttl=${STATIC_CDN_POLICY.clientTtl}`,
|
|
618
|
-
// Replaces the bucket's list, so this is the complete set
|
|
619
|
-
|
|
624
|
+
// Replaces the bucket's list, so this is the complete set: the stack's
|
|
625
|
+
// own headers and those of the live build (#1454, Publish live writes them).
|
|
626
|
+
...withStaticResponseHeaders(liveHeaders).map((h) => `--custom-response-header=${h}`),
|
|
620
627
|
"--quiet",
|
|
621
628
|
]);
|
|
622
629
|
return update.ok
|
|
@@ -19,11 +19,27 @@ import {
|
|
|
19
19
|
FRONT_DOOR_SECURITY_RULE_SET,
|
|
20
20
|
frontDoorSecurityRules,
|
|
21
21
|
GCP_STATIC_RESPONSE_HEADERS,
|
|
22
|
+
withStaticResponseHeaders,
|
|
22
23
|
} from "./static-security-headers.js";
|
|
23
24
|
|
|
24
25
|
const stack = (provider: string): string =>
|
|
25
26
|
readFileSync(resolve(import.meta.dir, "..", "stacks", provider, "index.ts"), "utf8");
|
|
26
27
|
|
|
28
|
+
describe("GCP backend bucket (#1454)", () => {
|
|
29
|
+
it("a converge keeps the live build's page headers beside the stack's own", () => {
|
|
30
|
+
const live = ["Referrer-Policy: no-referrer", ...GCP_STATIC_RESPONSE_HEADERS];
|
|
31
|
+
expect(withStaticResponseHeaders(live)).toEqual([
|
|
32
|
+
...GCP_STATIC_RESPONSE_HEADERS,
|
|
33
|
+
"Referrer-Policy: no-referrer",
|
|
34
|
+
]);
|
|
35
|
+
expect(withStaticResponseHeaders([])).toEqual([...GCP_STATIC_RESPONSE_HEADERS]);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it("the stack does not reset what Publish live wrote", () => {
|
|
39
|
+
expect(stack("gcp")).toContain('ignoreChanges: ["customResponseHeaders"]');
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
|
|
27
43
|
describe("AWS CloudFront response headers policies", () => {
|
|
28
44
|
it("site: nosniff only (a CSP with sandbox would break every page)", () => {
|
|
29
45
|
const p = cloudFrontHeadersPolicy("site");
|
|
@@ -22,7 +22,8 @@
|
|
|
22
22
|
* - Firebase Hosting: version-config headers the publisher writes
|
|
23
23
|
* (admin-core static-publisher-firebase.ts).
|
|
24
24
|
* - GCP (`gcp` stack): the static backend bucket's custom response header
|
|
25
|
-
* carries nosniff
|
|
25
|
+
* carries nosniff (and, written by Publish live, the live build's page
|
|
26
|
+
* headers, #1454); the CSP cannot be attached per file on that load
|
|
26
27
|
* balancer (see `gcsObjectMetadata` in admin-core for why), so SVG
|
|
27
28
|
* objects are stored `Content-Disposition: attachment` instead and the
|
|
28
29
|
* converge backfills them (static-svg-gcp.ts).
|
|
@@ -44,6 +45,16 @@ export const GCP_STATIC_RESPONSE_HEADERS: readonly string[] = [
|
|
|
44
45
|
`X-Content-Type-Options: ${NOSNIFF}`,
|
|
45
46
|
];
|
|
46
47
|
|
|
48
|
+
/**
|
|
49
|
+
* The list a converge writes: the stack's headers first, then whatever the
|
|
50
|
+
* bucket carries beside them. Those are the live build's page headers
|
|
51
|
+
* (#1454), which Publish live writes; the stack does not own them.
|
|
52
|
+
*/
|
|
53
|
+
export function withStaticResponseHeaders(live: readonly string[]): string[] {
|
|
54
|
+
const own = new Set(GCP_STATIC_RESPONSE_HEADERS);
|
|
55
|
+
return [...GCP_STATIC_RESPONSE_HEADERS, ...live.filter((h) => !own.has(h))];
|
|
56
|
+
}
|
|
57
|
+
|
|
47
58
|
// ===========================================================================
|
|
48
59
|
// AWS — CloudFront
|
|
49
60
|
// ===========================================================================
|
|
@@ -9,7 +9,12 @@
|
|
|
9
9
|
import { describe, expect, it } from "bun:test";
|
|
10
10
|
import type { StoredUpdatePolicy } from "@caelo-cms/shared";
|
|
11
11
|
import type { ReleaseManifest, ReleaseManifestResult } from "./release-manifest.js";
|
|
12
|
-
import {
|
|
12
|
+
import {
|
|
13
|
+
type AssessmentInput,
|
|
14
|
+
assessHandover,
|
|
15
|
+
assessUpgradeRequest,
|
|
16
|
+
type InstalledState,
|
|
17
|
+
} from "./upgrader-assess.js";
|
|
13
18
|
|
|
14
19
|
const D = (c: string) => `sha256:${c.repeat(64)}`;
|
|
15
20
|
|
|
@@ -416,3 +421,72 @@ describe("assessUpgradeRequest — the converge route (#819)", () => {
|
|
|
416
421
|
expect(d.kind === "stop" ? d.reason : "").toContain("converge job");
|
|
417
422
|
});
|
|
418
423
|
});
|
|
424
|
+
|
|
425
|
+
describe("assessHandover (#1029: stage 1, only what must hold before the target's code runs)", () => {
|
|
426
|
+
const input = (over: Partial<AssessmentInput> = {}): AssessmentInput => ({
|
|
427
|
+
request: { targetVersion: "0.11.0", trigger: "manual" },
|
|
428
|
+
manifest: { ok: true, manifest: MANIFEST },
|
|
429
|
+
installed: { version: "0.10.50", infraContractVersion: 2 },
|
|
430
|
+
policy: POLICY,
|
|
431
|
+
now: new Date("2026-10-13T12:00:00Z"),
|
|
432
|
+
...over,
|
|
433
|
+
});
|
|
434
|
+
|
|
435
|
+
it("proceeds with the verified manifest", () => {
|
|
436
|
+
const d = assessHandover(input());
|
|
437
|
+
expect(d).toEqual({ kind: "proceed", manifest: MANIFEST, warnings: [] });
|
|
438
|
+
});
|
|
439
|
+
|
|
440
|
+
it("leaves everything else to the target's code", () => {
|
|
441
|
+
const tooFar = { ...MANIFEST, minFromVersion: "0.10.99" };
|
|
442
|
+
expect(assessHandover(input({ manifest: { ok: true, manifest: tooFar } })).kind).toBe(
|
|
443
|
+
"proceed",
|
|
444
|
+
);
|
|
445
|
+
const destructive = {
|
|
446
|
+
...MANIFEST,
|
|
447
|
+
migrations: { ...MANIFEST.migrations, contract: true },
|
|
448
|
+
};
|
|
449
|
+
expect(assessHandover(input({ manifest: { ok: true, manifest: destructive } })).kind).toBe(
|
|
450
|
+
"proceed",
|
|
451
|
+
);
|
|
452
|
+
});
|
|
453
|
+
|
|
454
|
+
it("the same release passes: install.json may be the stale side", () => {
|
|
455
|
+
expect(
|
|
456
|
+
assessHandover(input({ installed: { version: "0.11.0", infraContractVersion: 2 } })).kind,
|
|
457
|
+
).toBe("proceed");
|
|
458
|
+
});
|
|
459
|
+
|
|
460
|
+
it("refuses a release older than install.json's, for any trigger", () => {
|
|
461
|
+
const d = assessHandover(input({ installed: { version: "0.11.1", infraContractVersion: 2 } }));
|
|
462
|
+
expect(d).toMatchObject({ kind: "stop", status: "refused", codes: ["not-newer"] });
|
|
463
|
+
});
|
|
464
|
+
|
|
465
|
+
it("refuses what the manifest does not vouch for", () => {
|
|
466
|
+
const bad = (code: "signature" | "schema") =>
|
|
467
|
+
assessHandover(input({ manifest: { ok: false, error: { code, message: "x" } } }));
|
|
468
|
+
expect(bad("signature")).toMatchObject({ status: "refused", codes: ["signature"] });
|
|
469
|
+
expect(bad("schema")).toMatchObject({
|
|
470
|
+
status: "needs_cloud_shell",
|
|
471
|
+
codes: ["manifest-unreadable"],
|
|
472
|
+
});
|
|
473
|
+
});
|
|
474
|
+
|
|
475
|
+
it("stops when the install does not know what it runs", () => {
|
|
476
|
+
const d = assessHandover(input({ installed: { version: null, infraContractVersion: 2 } }));
|
|
477
|
+
expect(d).toMatchObject({ codes: ["install-version-unknown"] });
|
|
478
|
+
});
|
|
479
|
+
|
|
480
|
+
it("an infrastructure change is not this job's", () => {
|
|
481
|
+
const d = assessHandover(input({ installed: { version: "0.10.50", infraContractVersion: 1 } }));
|
|
482
|
+
expect(d).toMatchObject({ status: "needs_cloud_shell", codes: ["infra-contract"] });
|
|
483
|
+
});
|
|
484
|
+
|
|
485
|
+
it("an automatic request is judged in full: nobody asked for it", () => {
|
|
486
|
+
const auto = input({
|
|
487
|
+
request: { targetVersion: "0.11.0", trigger: "auto" },
|
|
488
|
+
policy: { ...POLICY, mode: "notify" },
|
|
489
|
+
});
|
|
490
|
+
expect(assessHandover(auto)).toMatchObject({ kind: "stop", codes: ["policy"] });
|
|
491
|
+
});
|
|
492
|
+
});
|
package/src/upgrader-assess.ts
CHANGED
|
@@ -47,6 +47,11 @@
|
|
|
47
47
|
* converge route needs the Owner's `autoConverge` (#864) on top of
|
|
48
48
|
* everything an automatic install needs; the scheduler queues one only
|
|
49
49
|
* then, and the job re-checks it here against the policy it claimed.
|
|
50
|
+
*
|
|
51
|
+
* Stage 1 of the upgrader job (#1029) asks {@link assessHandover}, not this:
|
|
52
|
+
* it only decides whether the job may move onto the target's ops image.
|
|
53
|
+
* This full assessment then runs in the TARGET's code, so a fix to it reaches
|
|
54
|
+
* the installs that need it.
|
|
50
55
|
*/
|
|
51
56
|
|
|
52
57
|
import {
|
|
@@ -130,8 +135,8 @@ const stop = (
|
|
|
130
135
|
...(manifest ? { manifest } : {}),
|
|
131
136
|
});
|
|
132
137
|
|
|
133
|
-
/**
|
|
134
|
-
export
|
|
138
|
+
/** What {@link assessUpgradeRequest} decides from. */
|
|
139
|
+
export interface AssessmentInput {
|
|
135
140
|
readonly request: {
|
|
136
141
|
readonly targetVersion: string;
|
|
137
142
|
readonly trigger: PlatformUpdateTrigger;
|
|
@@ -149,52 +154,123 @@ export function assessUpgradeRequest(input: {
|
|
|
149
154
|
* contract bump is installed, not handed to Cloud Shell. Default `app_roll`.
|
|
150
155
|
*/
|
|
151
156
|
readonly route?: "app_roll" | "converge";
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
"registry",
|
|
167
|
-
`Could not reach the Caelo release registry to verify v${target} (${e.message}). Nothing was changed; try again later.`,
|
|
168
|
-
);
|
|
169
|
-
}
|
|
170
|
-
return stop(
|
|
171
|
-
"refused",
|
|
172
|
-
"manifest-missing",
|
|
173
|
-
`v${target} has no signed release manifest in the Caelo release registry, so it cannot be verified and will not be installed. Nothing was changed; retrying will not help. (${e.message})`,
|
|
174
|
-
);
|
|
175
|
-
case "schema":
|
|
176
|
-
return stop(
|
|
177
|
-
"needs_cloud_shell",
|
|
178
|
-
"manifest-unreadable",
|
|
179
|
-
`This upgrader is too old to read the release information of v${target}. Install it once ${by}; afterwards the admin can install updates again. (${e.message})`,
|
|
180
|
-
);
|
|
181
|
-
default:
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/** Why the manifest cannot be used, as a stop; the first rows of the matrix. */
|
|
160
|
+
function manifestStop(
|
|
161
|
+
e: Extract<ReleaseManifestResult, { ok: false }>["error"],
|
|
162
|
+
target: string,
|
|
163
|
+
by: string,
|
|
164
|
+
): RequestDecision {
|
|
165
|
+
switch (e.code) {
|
|
166
|
+
case "registry":
|
|
167
|
+
// Only an outage is worth retrying: a manifest the registry says
|
|
168
|
+
// does not exist (404 / other 4xx) never appears, so retrying would
|
|
169
|
+
// loop on "try again later" forever.
|
|
170
|
+
if (e.transient) {
|
|
182
171
|
return stop(
|
|
183
|
-
"
|
|
184
|
-
"
|
|
185
|
-
`
|
|
172
|
+
"failed",
|
|
173
|
+
"registry",
|
|
174
|
+
`Could not reach the Caelo release registry to verify v${target} (${e.message}). Nothing was changed; try again later.`,
|
|
186
175
|
);
|
|
187
|
-
|
|
176
|
+
}
|
|
177
|
+
return stop(
|
|
178
|
+
"refused",
|
|
179
|
+
"manifest-missing",
|
|
180
|
+
`v${target} has no signed release manifest in the Caelo release registry, so it cannot be verified and will not be installed. Nothing was changed; retrying will not help. (${e.message})`,
|
|
181
|
+
);
|
|
182
|
+
case "schema":
|
|
183
|
+
return stop(
|
|
184
|
+
"needs_cloud_shell",
|
|
185
|
+
"manifest-unreadable",
|
|
186
|
+
`This upgrader is too old to read the release information of v${target}. Install it once ${by}; afterwards the admin can install updates again. (${e.message})`,
|
|
187
|
+
);
|
|
188
|
+
default:
|
|
189
|
+
return stop(
|
|
190
|
+
"refused",
|
|
191
|
+
"signature",
|
|
192
|
+
`The release information of v${target} is not signed by Caelo's release workflow, so it was not installed. Nothing was changed. (${e.message})`,
|
|
193
|
+
);
|
|
188
194
|
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
function versionUnknownStop(by: string, manifest: ReleaseManifest): RequestDecision {
|
|
198
|
+
return stop(
|
|
199
|
+
"needs_cloud_shell",
|
|
200
|
+
"install-version-unknown",
|
|
201
|
+
`This install has not recorded which Caelo release it runs yet. Upgrade it once ${by}; that records it, and the admin can install updates from then on.`,
|
|
202
|
+
manifest,
|
|
203
|
+
);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
function olderStop(target: string, installed: string, manifest: ReleaseManifest): RequestDecision {
|
|
207
|
+
return stop(
|
|
208
|
+
"refused",
|
|
209
|
+
"not-newer",
|
|
210
|
+
`v${target} is not newer than the installed v${installed}; Caelo never installs an older release over a newer one.`,
|
|
211
|
+
manifest,
|
|
212
|
+
);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
function infraChangeStop(
|
|
216
|
+
target: string,
|
|
217
|
+
installed: number,
|
|
218
|
+
required: number,
|
|
219
|
+
manifest: ReleaseManifest,
|
|
220
|
+
): RequestDecision {
|
|
221
|
+
return stop(
|
|
222
|
+
"needs_cloud_shell",
|
|
223
|
+
"infra-contract",
|
|
224
|
+
`v${target} changes this install's cloud setup (infrastructure contract ${installed} → ${required}: ${infraStepsText(installed, required)}). The upgrader may not change cloud permissions, so Caelo installs this release with its converge job: start it again from Settings → Updates. On an install without the converge job, install it once with your own Google account in Cloud Shell.`,
|
|
225
|
+
manifest,
|
|
226
|
+
);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Stage 1 of the upgrader job (#1029): may this job move onto the target's
|
|
231
|
+
* ops image? Moving changes nothing on the site, so this is deliberately
|
|
232
|
+
* only what must hold before ANY of the target's code runs as the job's
|
|
233
|
+
* account, and everything else waits for {@link assessUpgradeRequest} in
|
|
234
|
+
* the target's code. Whatever this checks cannot be fixed forward.
|
|
235
|
+
*
|
|
236
|
+
* - The manifest verified, so the digest comes from Caelo's signature.
|
|
237
|
+
* - The target is not older than install.json's release. This is the
|
|
238
|
+
* line that keeps a compromised admin from pointing the job at an
|
|
239
|
+
* older signed release; the request row is untrusted. The same release
|
|
240
|
+
* passes: install.json may be stale, and the target's code sorts it out.
|
|
241
|
+
* - No infrastructure change: the upgrader job cannot install it.
|
|
242
|
+
* - An automatic request is judged in full. Nobody asked for it, so the
|
|
243
|
+
* job does not move unless the policy allows the install; a bug here
|
|
244
|
+
* costs an automatic run, and the Owner's click still gets through.
|
|
245
|
+
*
|
|
246
|
+
* @returns `proceed` when stage 1 may hand over, with the verified manifest
|
|
247
|
+
*/
|
|
248
|
+
export function assessHandover(input: AssessmentInput): RequestDecision {
|
|
249
|
+
const { request, installed } = input;
|
|
250
|
+
const by = manualRun(input.manualPath ?? "cloud-shell");
|
|
251
|
+
const target = request.targetVersion;
|
|
252
|
+
if (!input.manifest.ok) return manifestStop(input.manifest.error, target, by);
|
|
189
253
|
const manifest = input.manifest.manifest;
|
|
190
|
-
if (installed.version === null)
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
"install-version-unknown",
|
|
194
|
-
`This install has not recorded which Caelo release it runs yet. Upgrade it once ${by}; that records it, and the admin can install updates from then on.`,
|
|
195
|
-
manifest,
|
|
196
|
-
);
|
|
254
|
+
if (installed.version === null) return versionUnknownStop(by, manifest);
|
|
255
|
+
if (compareSemver(target, installed.version) < 0) {
|
|
256
|
+
return olderStop(target, installed.version, manifest);
|
|
197
257
|
}
|
|
258
|
+
const contract = installed.infraContractVersion ?? manifest.infraContractVersion;
|
|
259
|
+
if (needsConverge({ infraContractVersion: contract }, manifest.infraContractVersion)) {
|
|
260
|
+
return infraChangeStop(target, contract, manifest.infraContractVersion, manifest);
|
|
261
|
+
}
|
|
262
|
+
if (request.trigger === "auto") return assessUpgradeRequest(input);
|
|
263
|
+
return { kind: "proceed", manifest, warnings: [] };
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/** Decide what the job does with a request. See the file comment for the matrix. */
|
|
267
|
+
export function assessUpgradeRequest(input: AssessmentInput): RequestDecision {
|
|
268
|
+
const { request, installed } = input;
|
|
269
|
+
const by = manualRun(input.manualPath ?? "cloud-shell");
|
|
270
|
+
const target = request.targetVersion;
|
|
271
|
+
if (!input.manifest.ok) return manifestStop(input.manifest.error, target, by);
|
|
272
|
+
const manifest = input.manifest.manifest;
|
|
273
|
+
if (installed.version === null) return versionUnknownStop(by, manifest);
|
|
198
274
|
const order = compareSemver(target, installed.version);
|
|
199
275
|
if (order === 0) {
|
|
200
276
|
// Reached after a run that rolled but could not record it (#860): the
|
|
@@ -206,14 +282,7 @@ export function assessUpgradeRequest(input: {
|
|
|
206
282
|
manifest,
|
|
207
283
|
);
|
|
208
284
|
}
|
|
209
|
-
if (order < 0)
|
|
210
|
-
return stop(
|
|
211
|
-
"refused",
|
|
212
|
-
"not-newer",
|
|
213
|
-
`v${target} is not newer than the installed v${installed.version}; Caelo never installs an older release over a newer one.`,
|
|
214
|
-
manifest,
|
|
215
|
-
);
|
|
216
|
-
}
|
|
285
|
+
if (order < 0) return olderStop(target, installed.version, manifest);
|
|
217
286
|
if (compareSemver(installed.version, manifest.minFromVersion) < 0) {
|
|
218
287
|
return stop(
|
|
219
288
|
"refused",
|
|
@@ -229,12 +298,7 @@ export function assessUpgradeRequest(input: {
|
|
|
229
298
|
installed.infraContractVersion !== null &&
|
|
230
299
|
needsConverge({ infraContractVersion }, manifest.infraContractVersion);
|
|
231
300
|
if (infraChange && !converge) {
|
|
232
|
-
return
|
|
233
|
-
"needs_cloud_shell",
|
|
234
|
-
"infra-contract",
|
|
235
|
-
`v${target} changes this install's cloud setup (infrastructure contract ${infraContractVersion} → ${manifest.infraContractVersion}: ${infraStepsText(infraContractVersion, manifest.infraContractVersion)}). The upgrader may not change cloud permissions, so Caelo installs this release with its converge job: start it again from Settings → Updates. On an install without the converge job, install it once with your own Google account in Cloud Shell.`,
|
|
236
|
-
manifest,
|
|
237
|
-
);
|
|
301
|
+
return infraChangeStop(target, infraContractVersion, manifest.infraContractVersion, manifest);
|
|
238
302
|
}
|
|
239
303
|
if (converge && request.trigger === "auto" && !input.policy.autoConverge) {
|
|
240
304
|
return stop(
|