@caelo-cms/provisioning 0.11.20 → 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/admin-internal-google.d.ts +13 -1
- package/dist/admin-internal-google.d.ts.map +1 -1
- package/dist/admin-internal-google.js +47 -0
- package/dist/admin-internal-google.js.map +1 -1
- package/dist/agent/command.d.ts +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 +7 -2
- package/dist/cli-routing.js.map +1 -1
- package/dist/cli.js +9 -0
- package/dist/cli.js.map +1 -1
- package/dist/converge-checkpoint.d.ts +6 -0
- package/dist/converge-checkpoint.d.ts.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/dns/manual.d.ts +5 -1
- package/dist/dns/manual.d.ts.map +1 -1
- package/dist/dns/manual.js +2 -1
- package/dist/dns/manual.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/install-job-runner.d.ts.map +1 -1
- package/dist/install-job-runner.js +4 -3
- package/dist/install-job-runner.js.map +1 -1
- package/dist/install-job.d.ts +25 -1
- package/dist/install-job.d.ts.map +1 -1
- package/dist/install-job.js +72 -3
- package/dist/install-job.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/operator-access.d.ts +7 -2
- package/dist/operator-access.d.ts.map +1 -1
- package/dist/operator-access.js +37 -6
- package/dist/operator-access.js.map +1 -1
- 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 +128 -0
- package/dist/project-status.d.ts.map +1 -0
- package/dist/project-status.js +303 -0
- package/dist/project-status.js.map +1 -0
- 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/state-attach.d.ts +17 -0
- package/dist/state-attach.d.ts.map +1 -1
- package/dist/state-attach.js +27 -9
- package/dist/state-attach.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 +27 -4
- package/dist/wizards/gcp-install-job.d.ts.map +1 -1
- package/dist/wizards/gcp-install-job.js +73 -33
- 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 +3 -0
- package/dist/wizards/gcp.d.ts.map +1 -1
- package/dist/wizards/gcp.js +30 -53
- package/dist/wizards/gcp.js.map +1 -1
- package/package.json +2 -2
- package/src/adapter.ts +6 -1
- package/src/admin-internal-google.ts +48 -0
- 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 +9 -2
- package/src/cli.ts +9 -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/dns/manual.ts +4 -1
- 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/install-job-runner.ts +4 -2
- package/src/install-job.ts +86 -4
- 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/operator-access.test.ts +43 -0
- package/src/operator-access.ts +38 -6
- package/src/owner-setup-token.test.ts +195 -0
- package/src/owner-setup-token.ts +138 -0
- package/src/project-status.test.ts +571 -0
- package/src/project-status.ts +430 -0
- package/src/stack-converge.ts +12 -5
- package/src/state-attach.ts +46 -16
- 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 +101 -47
- package/src/wizards/gcp-pulumi.ts +0 -18
- package/src/wizards/gcp.ts +37 -67
- 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
|
@@ -20,8 +20,9 @@ describe("infrastructure contract steps", () => {
|
|
|
20
20
|
);
|
|
21
21
|
});
|
|
22
22
|
|
|
23
|
-
it("is at
|
|
24
|
-
expect(INFRA_CONTRACT_VERSION).toBe(
|
|
23
|
+
it("is at 23: public_role revoke (3), URL-map redirects role (4), no gateway cms_admin login (5), ops-bucket list (6), gateway proxy hops (7), quality-audit job (8), converge job (9), remote MCP (10), Google sign-in (11), project-level sign-in client (12), edge security headers (13), capture job (14), database verify-full TLS (15), MCP-Auth-Proxy (16), staging database (17), scheduler tick (18), scheduler tick as JSON (19), staging gateway (20), gateway budget and plain-gcp repairs (21), per-path Cloud Armor rules (22), site security headers on the backend bucket (23)", () => {
|
|
24
|
+
expect(INFRA_CONTRACT_VERSION).toBe(23);
|
|
25
|
+
expect(INFRA_CONTRACT_STEPS[23]).toContain("#1454");
|
|
25
26
|
expect(INFRA_CONTRACT_STEPS[3]).toContain("#633");
|
|
26
27
|
expect(INFRA_CONTRACT_STEPS[4]).toContain("#587");
|
|
27
28
|
expect(INFRA_CONTRACT_STEPS[5]).toContain("#635");
|
|
@@ -52,6 +53,6 @@ describe("infrastructure contract steps", () => {
|
|
|
52
53
|
});
|
|
53
54
|
|
|
54
55
|
it("names a version a newer release added by number", () => {
|
|
55
|
-
expect(infraStepsText(
|
|
56
|
+
expect(infraStepsText(23, 24)).toBe("infrastructure step 24 (see that release's notes)");
|
|
56
57
|
});
|
|
57
58
|
});
|
package/src/infra-contract.ts
CHANGED
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
* whose app-roll references infrastructure an install does not have yet fails
|
|
23
23
|
* at roll time, after migrations ran.
|
|
24
24
|
*/
|
|
25
|
-
export const INFRA_CONTRACT_VERSION =
|
|
25
|
+
export const INFRA_CONTRACT_VERSION = 23;
|
|
26
26
|
|
|
27
27
|
// History (why each bump happened — an install below a number needs the
|
|
28
28
|
// converge that introduced it):
|
|
@@ -187,6 +187,18 @@ export const INFRA_CONTRACT_VERSION = 22;
|
|
|
187
187
|
// writes the in-cloud upgrader holds no compute rights for, so the
|
|
188
188
|
// converge applies them (gateway-armor.ts). Other providers have
|
|
189
189
|
// nothing to converge for it.
|
|
190
|
+
// 23 — #1454: on `gcp` the admin writes a build's page headers (CSP and the
|
|
191
|
+
// rest) to the static backend bucket at Publish live, so its
|
|
192
|
+
// `caeloUrlMapRedirects` role gains `compute.backendBuckets.get` and
|
|
193
|
+
// `.update`, a custom-role change the in-cloud upgrader may not make.
|
|
194
|
+
// Other providers have nothing to converge for it.
|
|
195
|
+
//
|
|
196
|
+
// #1029 is deliberately NOT a bump. The upgrader job's stage 1 moves the job
|
|
197
|
+
// onto the target's ops image with rights it has held on itself since
|
|
198
|
+
// contract 9 (`run.jobs.update`, `run.jobs.run`, `actAs` on its own account),
|
|
199
|
+
// so no install needs a converge for it. It also ends the first reason of
|
|
200
|
+
// bump 21: once an install's job carries #1029, an app-roll runs the target
|
|
201
|
+
// release's code, and "the upgrader rolls with old code" is no reason to bump.
|
|
190
202
|
|
|
191
203
|
/**
|
|
192
204
|
* What each contract version adds, in operator terms — the upgrader's
|
|
@@ -216,6 +228,7 @@ export const INFRA_CONTRACT_STEPS: Readonly<Record<number, string>> = {
|
|
|
216
228
|
20: "the staging gateway that serves the staged site behind the staging gate on every address: its service, service account and grants, the private staging bucket, and the staging host's own route (a second Firebase Hosting site, or a host rule and certificate on the load balancer); the live gateway no longer holds the staging gate key (#1330, #1331)",
|
|
217
229
|
21: "the gateways' scale-out and connection pool kept inside the database connection budget, and on Google Cloud load-balancer installs the gateway open to visitors and the sign-in and staging routes repaired (#1463)",
|
|
218
230
|
22: "per-path Cloud Armor rules for the visitor and staging gateways on Google Cloud load-balancer installs: a tighter ban on sign-up, login and password reset, a captcha throttle, the general ban only on the visitor API, and fewer false positives from the OWASP rules (#1339)",
|
|
231
|
+
23: "the admin's permission on Google Cloud load-balancer installs to set the site's security headers on the static backend bucket at Publish live (#1454)",
|
|
219
232
|
};
|
|
220
233
|
|
|
221
234
|
/**
|
|
@@ -20,6 +20,7 @@ import { CAELO_VERSION } from "@caelo-cms/shared";
|
|
|
20
20
|
import { assertNoSecrets } from "./checkpoint-secrets.js";
|
|
21
21
|
import {
|
|
22
22
|
type InstallJobStatus,
|
|
23
|
+
isGcpProjectId,
|
|
23
24
|
readInstallJobStatus,
|
|
24
25
|
writeInstallJobStatus,
|
|
25
26
|
} from "./install-job.js";
|
|
@@ -28,14 +29,13 @@ import { attachInstall } from "./state-attach.js";
|
|
|
28
29
|
import { hasLocalPulumiState, opsBucketName, resolveBackend } from "./state-backend.js";
|
|
29
30
|
import { realSyncGcloud, type SyncGcloud } from "./state-store.js";
|
|
30
31
|
|
|
31
|
-
const PROJECT_ID = /^[a-z][a-z0-9-]{4,28}[a-z0-9]$/;
|
|
32
32
|
const ANSI = new RegExp(`${String.fromCharCode(27)}\\[[0-9;?]*[A-Za-z]`, "g");
|
|
33
33
|
|
|
34
34
|
/** The `--project` value of `argv`, validated. */
|
|
35
35
|
export function installJobProject(argv: readonly string[]): string {
|
|
36
36
|
const i = argv.indexOf("--project");
|
|
37
37
|
const value = i === -1 ? undefined : argv[i + 1];
|
|
38
|
-
if (!value || !
|
|
38
|
+
if (!value || !isGcpProjectId(value)) {
|
|
39
39
|
throw new Error("install-job needs --project <gcp-project-id>");
|
|
40
40
|
}
|
|
41
41
|
return value;
|
|
@@ -117,6 +117,7 @@ export async function installJobCommand(
|
|
|
117
117
|
execution,
|
|
118
118
|
state: "running",
|
|
119
119
|
phase: "Starting",
|
|
120
|
+
...(previous?.dnsRecords ? { dnsRecords: previous.dnsRecords } : {}),
|
|
120
121
|
caeloVersion: CAELO_VERSION,
|
|
121
122
|
startedAt: previous?.execution === execution ? previous.startedAt : now,
|
|
122
123
|
updatedAt: now,
|
|
@@ -161,6 +162,7 @@ export async function installJobCommand(
|
|
|
161
162
|
nonInteractive: true,
|
|
162
163
|
setupLink: "secret",
|
|
163
164
|
onPhase: (phase, detail) => record({ phase, detail }),
|
|
165
|
+
onDnsRecords: (dnsRecords) => record({ dnsRecords, detail: status.detail }),
|
|
164
166
|
});
|
|
165
167
|
record({ state: "succeeded", phase: "Done" });
|
|
166
168
|
}
|
package/src/install-job.ts
CHANGED
|
@@ -28,15 +28,20 @@
|
|
|
28
28
|
* The Owner setup link is a secret (#656): it never reaches the bucket or
|
|
29
29
|
* the job's logs. The job stores it in Secret Manager
|
|
30
30
|
* ({@link INSTALL_SETUP_LINK_SECRET}); the operator's terminal reads it there.
|
|
31
|
+
*
|
|
32
|
+
* All of this is readable from the project alone, so `status --project`
|
|
33
|
+
* (project-status.ts, #822) shows the install on any machine signed in to
|
|
34
|
+
* gcloud, after the terminal that started it is gone.
|
|
31
35
|
*/
|
|
32
36
|
|
|
33
37
|
import { z } from "zod";
|
|
34
38
|
import { assertNoSecrets } from "./checkpoint-secrets.js";
|
|
39
|
+
import type { InstallDnsRecord } from "./dns/groups.js";
|
|
35
40
|
import type { GcloudRunner } from "./gcloud-retry.js";
|
|
36
41
|
import { GCP_STACK_ENV } from "./gcp-names.js";
|
|
37
42
|
import { createInstallSecret } from "./runtime-secrets.js";
|
|
38
|
-
import { OPS_INSTALL_PREFIX } from "./state-backend.js";
|
|
39
|
-
import type
|
|
43
|
+
import { OPS_INSTALL_PREFIX, opsBucketName } from "./state-backend.js";
|
|
44
|
+
import { GcsStateStore, type SyncGcloud } from "./state-store.js";
|
|
40
45
|
import { IMAGE_DIGEST } from "./upgrade/release-images.js";
|
|
41
46
|
|
|
42
47
|
/** Name of the Cloud Run job that runs the install. */
|
|
@@ -99,6 +104,20 @@ export function opsImageRef(digest: string): string {
|
|
|
99
104
|
return `${OPS_IMAGE_REPOSITORY}@${digest}`;
|
|
100
105
|
}
|
|
101
106
|
|
|
107
|
+
const GCP_PROJECT_ID = /^[a-z][a-z0-9-]{4,28}[a-z0-9]$/;
|
|
108
|
+
|
|
109
|
+
/** Whether `value` has the shape of a Google Cloud project id. */
|
|
110
|
+
export function isGcpProjectId(value: string): boolean {
|
|
111
|
+
return GCP_PROJECT_ID.test(value);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const DnsRecordSchema = z.object({
|
|
115
|
+
hostname: z.string().min(1),
|
|
116
|
+
type: z.string().min(1),
|
|
117
|
+
value: z.string().min(1),
|
|
118
|
+
purpose: z.string().optional(),
|
|
119
|
+
});
|
|
120
|
+
|
|
102
121
|
/** What `install/install-job.json` records. */
|
|
103
122
|
export const InstallJobStatusSchema = z.object({
|
|
104
123
|
statusVersion: z.literal(1),
|
|
@@ -110,6 +129,12 @@ export const InstallJobStatusSchema = z.object({
|
|
|
110
129
|
phase: z.string(),
|
|
111
130
|
/** Extra context for the phase (the DNS records to set, a failure reason). */
|
|
112
131
|
detail: z.string().optional(),
|
|
132
|
+
/**
|
|
133
|
+
* DNS records the job found out about that are not in the stack's outputs
|
|
134
|
+
* (the staging host's, #822), so `status --project` lists them on any
|
|
135
|
+
* machine. Not secret: anyone can read them from public DNS once set.
|
|
136
|
+
*/
|
|
137
|
+
dnsRecords: z.array(DnsRecordSchema).optional(),
|
|
113
138
|
/** Caelo release the job's image belongs to. */
|
|
114
139
|
caeloVersion: z.string(),
|
|
115
140
|
startedAt: z.string(),
|
|
@@ -134,7 +159,9 @@ export function readJobStatusDoc<T>(url: string, schema: z.ZodType<T>, run: Sync
|
|
|
134
159
|
const r = run(["storage", "cat", url]);
|
|
135
160
|
if (!r.ok) {
|
|
136
161
|
if (NOT_FOUND.test(r.stderr)) return null;
|
|
137
|
-
throw new Error(
|
|
162
|
+
throw new Error(
|
|
163
|
+
`Could not read ${url}: ${r.stderr.trim() || `gcloud exited ${r.exitCode}`}. Check that you are signed in (gcloud auth login) as an account with access to the install's ops bucket.`,
|
|
164
|
+
);
|
|
138
165
|
}
|
|
139
166
|
let json: unknown;
|
|
140
167
|
try {
|
|
@@ -285,7 +312,7 @@ export async function describeExecution(
|
|
|
285
312
|
if (!r.ok) {
|
|
286
313
|
if (NOT_FOUND.test(r.stderr)) return "missing";
|
|
287
314
|
throw new Error(
|
|
288
|
-
`Could not read execution ${target.execution}: ${r.stderr.trim() || `gcloud exited ${r.exitCode}`}
|
|
315
|
+
`Could not read execution ${target.execution}: ${r.stderr.trim() || `gcloud exited ${r.exitCode}`}. Your gcloud account needs run.executions.get on ${target.projectId} (e.g. roles/run.viewer or project Owner).`,
|
|
289
316
|
);
|
|
290
317
|
}
|
|
291
318
|
const d = JSON.parse(r.stdout || "{}") as ExecutionDescription;
|
|
@@ -296,6 +323,61 @@ export async function describeExecution(
|
|
|
296
323
|
: "failed";
|
|
297
324
|
}
|
|
298
325
|
|
|
326
|
+
const RecordedProgressSchema = z.object({ steps: z.record(z.string(), z.unknown()) });
|
|
327
|
+
const RecordedStepSchema = z.object({ outputs: z.record(z.string(), z.unknown()).optional() });
|
|
328
|
+
|
|
329
|
+
/**
|
|
330
|
+
* The stack's outputs as the `pulumi-up` step recorded them in the ops
|
|
331
|
+
* bucket's progress.json — current, never cached (the job writes it), and
|
|
332
|
+
* without touching this machine's install directory. Empty before that step
|
|
333
|
+
* finished.
|
|
334
|
+
*
|
|
335
|
+
* @throws when the bucket can't be read or progress.json is malformed
|
|
336
|
+
*/
|
|
337
|
+
export function readRecordedStackOutputs(
|
|
338
|
+
projectId: string,
|
|
339
|
+
run: SyncGcloud,
|
|
340
|
+
): Record<string, unknown> {
|
|
341
|
+
const bucket = opsBucketName(projectId);
|
|
342
|
+
const text = new GcsStateStore(bucket, "/nonexistent", run).peek("progress.json");
|
|
343
|
+
if (text === null) return {};
|
|
344
|
+
const url = `gs://${bucket}/${OPS_INSTALL_PREFIX}/progress.json`;
|
|
345
|
+
let json: unknown;
|
|
346
|
+
try {
|
|
347
|
+
json = JSON.parse(text);
|
|
348
|
+
} catch {
|
|
349
|
+
throw new Error(`${url} is not valid JSON. Re-run the installer to write it again.`);
|
|
350
|
+
}
|
|
351
|
+
const progress = RecordedProgressSchema.safeParse(json);
|
|
352
|
+
if (!progress.success) {
|
|
353
|
+
throw new Error(
|
|
354
|
+
`${url} is not a checkpoint this CLI understands (${progress.error.message}). Re-run the installer to write it again.`,
|
|
355
|
+
);
|
|
356
|
+
}
|
|
357
|
+
const raw = progress.data.steps[`pulumi-up-${projectId}`];
|
|
358
|
+
if (raw === undefined) return {};
|
|
359
|
+
const step = RecordedStepSchema.safeParse(raw);
|
|
360
|
+
if (!step.success) {
|
|
361
|
+
throw new Error(
|
|
362
|
+
`${url} records the pulumi-up step in a shape this CLI does not understand (${step.error.message}). Re-run the installer to write it again.`,
|
|
363
|
+
);
|
|
364
|
+
}
|
|
365
|
+
return step.data.outputs ?? {};
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
/** The stack's `dnsRecordsRequiredOut` from {@link readRecordedStackOutputs}. */
|
|
369
|
+
export function recordedDnsRecords(outputs: Record<string, unknown>): InstallDnsRecord[] {
|
|
370
|
+
const raw = outputs.dnsRecordsRequiredOut;
|
|
371
|
+
if (raw === undefined) return [];
|
|
372
|
+
const records = z.array(DnsRecordSchema).safeParse(raw);
|
|
373
|
+
if (!records.success) {
|
|
374
|
+
throw new Error(
|
|
375
|
+
`The recorded stack output dnsRecordsRequiredOut is malformed (${records.error.message}). Re-run the installer to refresh it.`,
|
|
376
|
+
);
|
|
377
|
+
}
|
|
378
|
+
return records.data;
|
|
379
|
+
}
|
|
380
|
+
|
|
299
381
|
/** What the launcher does with an install that may already have a job. */
|
|
300
382
|
export type InstallJobDecision =
|
|
301
383
|
| { readonly kind: "start"; readonly previous: InstallJobStatus | null; readonly why: string }
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MPL-2.0
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* What an update job does to itself (#819, #1029). The trust boundary
|
|
5
|
+
* rests on these argv: the image moves by digest and nothing else moves, and
|
|
6
|
+
* the new execution carries no override of args or env (no principal but
|
|
7
|
+
* the provisioner may run a job with overrides, CLAUDE.md §11.C).
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { describe, expect, it } from "bun:test";
|
|
11
|
+
import type { GcloudRunner } from "./gcloud-retry.js";
|
|
12
|
+
import {
|
|
13
|
+
executionImageDigest,
|
|
14
|
+
jobExecutionNameError,
|
|
15
|
+
selfHandoverDeps,
|
|
16
|
+
startedExecutionName,
|
|
17
|
+
} from "./job-handover-gcp.js";
|
|
18
|
+
|
|
19
|
+
const D = `sha256:${"c".repeat(64)}`;
|
|
20
|
+
const OPS = `europe-west1-docker.pkg.dev/caelo-website/caelo-cms-images/ops@${D}`;
|
|
21
|
+
const JOB = "caelo-production-upgrader";
|
|
22
|
+
|
|
23
|
+
function fake(stdout = "caelo-production-upgrader-abc12\n") {
|
|
24
|
+
const calls: string[][] = [];
|
|
25
|
+
const run: GcloudRunner = async (args) => {
|
|
26
|
+
calls.push(args);
|
|
27
|
+
return { ok: true, stdout, stderr: "", exitCode: 0 };
|
|
28
|
+
};
|
|
29
|
+
const deps = selfHandoverDeps(run, {
|
|
30
|
+
job: JOB,
|
|
31
|
+
projectId: "acme",
|
|
32
|
+
region: "europe-west1",
|
|
33
|
+
execution: `${JOB}-x1`,
|
|
34
|
+
});
|
|
35
|
+
return { calls, deps };
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
describe("selfHandoverDeps", () => {
|
|
39
|
+
it("points the job at the digest and changes nothing else", async () => {
|
|
40
|
+
const { calls, deps } = fake();
|
|
41
|
+
await deps.pointJobAt(D);
|
|
42
|
+
expect(calls).toEqual([
|
|
43
|
+
[
|
|
44
|
+
"run",
|
|
45
|
+
"jobs",
|
|
46
|
+
"update",
|
|
47
|
+
JOB,
|
|
48
|
+
`--image=${OPS}`,
|
|
49
|
+
"--region=europe-west1",
|
|
50
|
+
"--project=acme",
|
|
51
|
+
"--quiet",
|
|
52
|
+
],
|
|
53
|
+
]);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it("starts the job with no override of its args, env or task", async () => {
|
|
57
|
+
const { calls, deps } = fake();
|
|
58
|
+
expect(await deps.startJob()).toEqual({
|
|
59
|
+
ok: true,
|
|
60
|
+
execution: "caelo-production-upgrader-abc12",
|
|
61
|
+
});
|
|
62
|
+
expect(calls).toEqual([
|
|
63
|
+
[
|
|
64
|
+
"run",
|
|
65
|
+
"jobs",
|
|
66
|
+
"execute",
|
|
67
|
+
JOB,
|
|
68
|
+
"--region=europe-west1",
|
|
69
|
+
"--project=acme",
|
|
70
|
+
"--async",
|
|
71
|
+
"--format=value(metadata.name)",
|
|
72
|
+
],
|
|
73
|
+
]);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it("reads this execution's image, and nothing outside Cloud Run", async () => {
|
|
77
|
+
const { calls, deps } = fake(
|
|
78
|
+
JSON.stringify({ spec: { template: { spec: { containers: [{ image: OPS }] } } } }),
|
|
79
|
+
);
|
|
80
|
+
expect(await deps.ownImageDigest()).toBe(D);
|
|
81
|
+
expect(calls[0]?.slice(0, 5)).toEqual(["run", "jobs", "executions", "describe", `${JOB}-x1`]);
|
|
82
|
+
const outside = selfHandoverDeps(
|
|
83
|
+
async () => ({ ok: false, stdout: "", stderr: "", exitCode: 1 }),
|
|
84
|
+
{
|
|
85
|
+
job: JOB,
|
|
86
|
+
projectId: "acme",
|
|
87
|
+
region: "europe-west1",
|
|
88
|
+
execution: null,
|
|
89
|
+
},
|
|
90
|
+
);
|
|
91
|
+
expect(await outside.ownImageDigest()).toBeNull();
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
describe("jobExecutionNameError", () => {
|
|
96
|
+
it("accepts a run of the job and no other name", () => {
|
|
97
|
+
expect(jobExecutionNameError(JOB, null)).toBeNull();
|
|
98
|
+
expect(jobExecutionNameError(JOB, `${JOB}-abc12`)).toBeNull();
|
|
99
|
+
expect(jobExecutionNameError(JOB, "caelo-production-converge-abc12")).toContain("not a run of");
|
|
100
|
+
expect(jobExecutionNameError(JOB, `${JOB}-ABC`)).toContain("not a run of");
|
|
101
|
+
expect(jobExecutionNameError(JOB, JOB)).toContain("not a run of");
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
describe("executionImageDigest", () => {
|
|
106
|
+
it("reads both shapes gcloud can print", () => {
|
|
107
|
+
const v1 = { spec: { template: { spec: { containers: [{ image: OPS }] } } } };
|
|
108
|
+
expect(executionImageDigest(JSON.stringify(v1))).toBe(D);
|
|
109
|
+
expect(
|
|
110
|
+
executionImageDigest(JSON.stringify({ template: { containers: [{ image: OPS }] } })),
|
|
111
|
+
).toBe(D);
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it("is null for a tag, an empty description or bad JSON: never a guess", () => {
|
|
115
|
+
const tag = { template: { containers: [{ image: "x/ops:0.11.0" }] } };
|
|
116
|
+
expect(executionImageDigest(JSON.stringify(tag))).toBeNull();
|
|
117
|
+
expect(executionImageDigest("{}")).toBeNull();
|
|
118
|
+
expect(executionImageDigest("not json")).toBeNull();
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
describe("startedExecutionName", () => {
|
|
123
|
+
it("reads --format output, or gcloud's stderr line", () => {
|
|
124
|
+
expect(startedExecutionName("job-abc12\n", "")).toBe("job-abc12");
|
|
125
|
+
expect(startedExecutionName("", "Execution [job-abc12] has started")).toBe("job-abc12");
|
|
126
|
+
expect(startedExecutionName("", "")).toBeNull();
|
|
127
|
+
expect(startedExecutionName("Bad Name; rm -rf", "")).toBeNull();
|
|
128
|
+
});
|
|
129
|
+
});
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MPL-2.0
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The Cloud Run side of an update job's hand-over (job-handover.ts): what
|
|
5
|
+
* the converge job (#819) and the upgrader job (#1029) do to themselves, as
|
|
6
|
+
* their own service accounts. Each holds exactly this on its own job:
|
|
7
|
+
* `run.jobs.update` and `run.jobs.run`, without `run.jobs.runWithOverrides`,
|
|
8
|
+
* and `actAs` on its own account.
|
|
9
|
+
*
|
|
10
|
+
* Two gcloud calls change anything, and tests pin both: `jobs update` with
|
|
11
|
+
* `--image` by digest and no other setting, and `jobs execute` with no flag
|
|
12
|
+
* that overrides the job's args or env.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import type { GcloudRunner } from "./gcloud-retry.js";
|
|
16
|
+
import { describeExecution } from "./install-job.js";
|
|
17
|
+
import type { SelfHandoverDeps } from "./job-handover.js";
|
|
18
|
+
import { releaseImageRef, verifyCosignAll } from "./upgrade/release-images.js";
|
|
19
|
+
|
|
20
|
+
const DIGEST = /@(sha256:[0-9a-f]{64})/;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* The image digest an execution of an update job runs, from its Cloud Run
|
|
24
|
+
* description (the execution's task template names the image it was
|
|
25
|
+
* started with). Null when it cannot be read or names no digest.
|
|
26
|
+
*/
|
|
27
|
+
export function executionImageDigest(describeJson: string): string | null {
|
|
28
|
+
let parsed: unknown;
|
|
29
|
+
try {
|
|
30
|
+
parsed = JSON.parse(describeJson);
|
|
31
|
+
} catch {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
// gcloud prints the v1 resource (spec.template.spec.containers); the v2
|
|
35
|
+
// shape (template.containers) is accepted too. The first container is it.
|
|
36
|
+
const p = parsed as {
|
|
37
|
+
spec?: { template?: { spec?: { containers?: { image?: string }[] } } };
|
|
38
|
+
template?: { containers?: { image?: string }[] };
|
|
39
|
+
};
|
|
40
|
+
const image =
|
|
41
|
+
p.spec?.template?.spec?.containers?.[0]?.image ?? p.template?.containers?.[0]?.image ?? "";
|
|
42
|
+
return DIGEST.exec(image)?.[1] ?? null;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Why `CLOUD_RUN_EXECUTION` cannot name a run of `job`, or null when it
|
|
47
|
+
* can. The name keys the state lock's holder and the hand-over between the
|
|
48
|
+
* job's two stages, so a value that names another job's run (or is not a
|
|
49
|
+
* Cloud Run name at all) stops the job before it acts (#883 review). Cloud
|
|
50
|
+
* Run sets it and rejects user values for it; this is the second line.
|
|
51
|
+
*/
|
|
52
|
+
export function jobExecutionNameError(job: string, execution: string | null): string | null {
|
|
53
|
+
if (execution === null) return null;
|
|
54
|
+
if (!/^[a-z0-9-]{1,63}$/.test(execution) || !execution.startsWith(`${job}-`)) {
|
|
55
|
+
return `CLOUD_RUN_EXECUTION is "${execution.slice(0, 80)}", not a run of ${job}`;
|
|
56
|
+
}
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** The new execution's name from `gcloud run jobs execute --async`. */
|
|
61
|
+
export function startedExecutionName(stdout: string, stderr: string): string | null {
|
|
62
|
+
const name = stdout.trim().split(/\s+/)[0] || /Execution \[([^\]]+)\]/.exec(stderr)?.[1] || "";
|
|
63
|
+
return /^[a-z0-9-]+$/.test(name) ? name : null;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* The real {@link SelfHandoverDeps} of update job `job`, except its version
|
|
68
|
+
* (the caller's image knows it).
|
|
69
|
+
*/
|
|
70
|
+
export function selfHandoverDeps(
|
|
71
|
+
run: GcloudRunner,
|
|
72
|
+
target: {
|
|
73
|
+
readonly job: string;
|
|
74
|
+
readonly projectId: string;
|
|
75
|
+
readonly region: string;
|
|
76
|
+
readonly execution: string | null;
|
|
77
|
+
},
|
|
78
|
+
): Omit<SelfHandoverDeps, "ownVersion"> {
|
|
79
|
+
const { job, projectId, region, execution } = target;
|
|
80
|
+
const location = [`--region=${region}`, `--project=${projectId}`];
|
|
81
|
+
return {
|
|
82
|
+
execution,
|
|
83
|
+
verifyImage: (slug, digest) => verifyCosignAll([{ slug, digest }]),
|
|
84
|
+
ownImageDigest: async () => {
|
|
85
|
+
if (!execution) return null;
|
|
86
|
+
const r = await run([
|
|
87
|
+
"run",
|
|
88
|
+
"jobs",
|
|
89
|
+
"executions",
|
|
90
|
+
"describe",
|
|
91
|
+
execution,
|
|
92
|
+
...location,
|
|
93
|
+
"--format=json",
|
|
94
|
+
]);
|
|
95
|
+
return r.ok ? executionImageDigest(r.stdout) : null;
|
|
96
|
+
},
|
|
97
|
+
pointJobAt: async (digest) => {
|
|
98
|
+
// Only the image changes: the identity, command and args stay what
|
|
99
|
+
// the job's setup deployed.
|
|
100
|
+
const update = await run([
|
|
101
|
+
"run",
|
|
102
|
+
"jobs",
|
|
103
|
+
"update",
|
|
104
|
+
job,
|
|
105
|
+
`--image=${releaseImageRef("ops", digest)}`,
|
|
106
|
+
...location,
|
|
107
|
+
"--quiet",
|
|
108
|
+
]);
|
|
109
|
+
return update.ok
|
|
110
|
+
? { ok: true }
|
|
111
|
+
: { ok: false, error: `update ${job}: ${update.stderr.trim()}` };
|
|
112
|
+
},
|
|
113
|
+
startJob: async () => {
|
|
114
|
+
const exec = await run([
|
|
115
|
+
"run",
|
|
116
|
+
"jobs",
|
|
117
|
+
"execute",
|
|
118
|
+
job,
|
|
119
|
+
...location,
|
|
120
|
+
"--async",
|
|
121
|
+
"--format=value(metadata.name)",
|
|
122
|
+
]);
|
|
123
|
+
if (!exec.ok) return { ok: false, error: `start ${job}: ${exec.stderr.trim()}` };
|
|
124
|
+
const started = startedExecutionName(exec.stdout, exec.stderr);
|
|
125
|
+
if (!started) {
|
|
126
|
+
return {
|
|
127
|
+
ok: false,
|
|
128
|
+
error: `${job} started but gcloud did not name the execution (${exec.stderr.trim()})`,
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
return { ok: true, execution: started };
|
|
132
|
+
},
|
|
133
|
+
executionState: (name) => describeExecution(run, { projectId, region, execution: name }),
|
|
134
|
+
};
|
|
135
|
+
}
|