@caelo-cms/provisioning 0.12.16 → 0.12.18
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/adopt-existing.d.ts +18 -0
- package/dist/adopt-existing.d.ts.map +1 -1
- package/dist/adopt-existing.js +46 -1
- package/dist/adopt-existing.js.map +1 -1
- package/dist/agent-db.js +1522 -101
- package/dist/audit-job-setup.d.ts +0 -9
- package/dist/audit-job-setup.d.ts.map +1 -1
- package/dist/audit-job-setup.js +17 -27
- package/dist/audit-job-setup.js.map +1 -1
- package/dist/converge-job-gcp.d.ts +0 -7
- package/dist/converge-job-gcp.d.ts.map +1 -1
- package/dist/converge-job-gcp.js +1 -36
- package/dist/converge-job-gcp.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 +11 -1
- package/dist/infra-contract.js.map +1 -1
- package/dist/operator-access.d.ts +23 -0
- package/dist/operator-access.d.ts.map +1 -1
- package/dist/operator-access.js +62 -2
- package/dist/operator-access.js.map +1 -1
- package/dist/owner-email.d.ts +79 -0
- package/dist/owner-email.d.ts.map +1 -0
- package/dist/owner-email.js +170 -0
- package/dist/owner-email.js.map +1 -0
- package/dist/reporting-job-catalog.d.ts.map +1 -1
- package/dist/reporting-job-catalog.js +3 -2
- package/dist/reporting-job-catalog.js.map +1 -1
- package/dist/stack-contract.d.ts +12 -7
- package/dist/stack-contract.d.ts.map +1 -1
- package/dist/stack-contract.js +24 -6
- package/dist/stack-contract.js.map +1 -1
- package/dist/wizard.d.ts.map +1 -1
- package/dist/wizard.js +30 -12
- package/dist/wizard.js.map +1 -1
- package/dist/wizards/gcp-cost.d.ts.map +1 -1
- package/dist/wizards/gcp-cost.js +7 -2
- package/dist/wizards/gcp-cost.js.map +1 -1
- package/dist/wizards/gcp-install-job.d.ts +24 -0
- package/dist/wizards/gcp-install-job.d.ts.map +1 -1
- package/dist/wizards/gcp-install-job.js +119 -13
- package/dist/wizards/gcp-install-job.js.map +1 -1
- package/dist/wizards/gcp-pulumi.d.ts +0 -6
- package/dist/wizards/gcp-pulumi.d.ts.map +1 -1
- package/dist/wizards/gcp-pulumi.js +0 -7
- package/dist/wizards/gcp-pulumi.js.map +1 -1
- package/dist/wizards/gcp.js +0 -1
- package/dist/wizards/gcp.js.map +1 -1
- package/package.json +2 -2
- package/src/admin-memory.test.ts +49 -11
- package/src/adopt-existing.test.ts +190 -0
- package/src/adopt-existing.ts +56 -1
- package/src/audit-job-setup.test.ts +14 -39
- package/src/audit-job-setup.ts +17 -35
- package/src/converge-job-gcp.test.ts +2 -5
- package/src/converge-job-gcp.ts +1 -46
- package/src/infra-contract.test.ts +4 -3
- package/src/infra-contract.ts +11 -1
- package/src/operator-access.ts +81 -2
- package/src/owner-email.test.ts +302 -0
- package/src/owner-email.ts +214 -0
- package/src/reporting-job-catalog.ts +3 -2
- package/src/reporting-job-setup.test.ts +1 -1
- package/src/stack-contract.ts +25 -7
- package/src/stack-converge.test.ts +43 -2
- package/src/wizard.ts +30 -10
- package/src/wizards/gcp-cost.ts +8 -2
- package/src/wizards/gcp-install-job.test.ts +180 -0
- package/src/wizards/gcp-install-job.ts +130 -12
- package/src/wizards/gcp-pulumi.ts +0 -7
- package/src/wizards/gcp.ts +0 -1
- package/stacks/azure/index.ts +4 -0
- package/stacks/gcp/index.ts +11 -0
- package/stacks/gcp-firebase/index.ts +11 -0
|
@@ -507,3 +507,193 @@ describe("existingCandidates — every gcloud wording for a missing resource", (
|
|
|
507
507
|
expect(existing).toEqual([]);
|
|
508
508
|
});
|
|
509
509
|
});
|
|
510
|
+
|
|
511
|
+
/**
|
|
512
|
+
* A resumed install whose first run stopped before its Cloud SQL instance
|
|
513
|
+
* existed. The stack below is what the gcp and gcp-firebase stacks declare
|
|
514
|
+
* around the database, in dependency order. `pulumiUpGcp` previews and
|
|
515
|
+
* adopts only when the stack's state holds resources: the first run `up`s an
|
|
516
|
+
* empty stack and stops at the instance (a failed peering or instance
|
|
517
|
+
* create, a killed run); the second previews what is left, adopts, and `up`s.
|
|
518
|
+
*/
|
|
519
|
+
describe("a resumed install whose first run stopped before the Cloud SQL instance existed", () => {
|
|
520
|
+
const INSTANCE = "caelo-production-pg-5e1f0a2";
|
|
521
|
+
const INSTANCE_TYPE = "gcp:sql/databaseInstance:DatabaseInstance";
|
|
522
|
+
const DATABASE = "gcp:sql/database:Database";
|
|
523
|
+
const USER = "gcp:sql/user:User";
|
|
524
|
+
const declared: readonly PlannedStep[] = [
|
|
525
|
+
step({ type: SA, name: "caelo-production-gateway-sa", inputs: { accountId: "caelo-gw" } }),
|
|
526
|
+
step({ type: "gcp:compute/network:Network", name: "caelo-production-vpc", inputs: {} }),
|
|
527
|
+
// Auto-named: the preview carries the name the create will use.
|
|
528
|
+
step({ type: INSTANCE_TYPE, name: "caelo-production-pg", inputs: { name: INSTANCE } }),
|
|
529
|
+
step({
|
|
530
|
+
type: DATABASE,
|
|
531
|
+
name: "caelo-production-cms-admin",
|
|
532
|
+
inputs: { instance: INSTANCE, name: "cms_admin" },
|
|
533
|
+
}),
|
|
534
|
+
step({
|
|
535
|
+
type: DATABASE,
|
|
536
|
+
name: "caelo-production-cms-public-staging",
|
|
537
|
+
inputs: { instance: INSTANCE, name: "cms_public_staging" },
|
|
538
|
+
}),
|
|
539
|
+
step({
|
|
540
|
+
type: USER,
|
|
541
|
+
name: "caelo-production-public-staging-user",
|
|
542
|
+
inputs: { instance: INSTANCE, name: "public_staging_role", password: "[secret]" },
|
|
543
|
+
}),
|
|
544
|
+
];
|
|
545
|
+
const input = (s: PlannedStep, key: string) => String(s.inputs?.[key]);
|
|
546
|
+
|
|
547
|
+
/** The project as Google Cloud answers about it; every call recorded. */
|
|
548
|
+
function fakeProject() {
|
|
549
|
+
const accounts = new Set<string>();
|
|
550
|
+
/** Instance name → its `databases:<name>` and `users:<name>`. */
|
|
551
|
+
const instances = new Map<string, Set<string>>();
|
|
552
|
+
const calls: string[][] = [];
|
|
553
|
+
const run: GcloudRunner = async (args) => {
|
|
554
|
+
calls.push(args);
|
|
555
|
+
const verb = args.slice(0, 3).join(" ");
|
|
556
|
+
if (verb === "iam service-accounts describe") {
|
|
557
|
+
return accounts.has(args[3] ?? "")
|
|
558
|
+
? ok(args[3])
|
|
559
|
+
: fail(
|
|
560
|
+
"ERROR: (gcloud.iam.service-accounts.describe) NOT_FOUND: Unknown service account.",
|
|
561
|
+
);
|
|
562
|
+
}
|
|
563
|
+
if (verb === "sql instances list") return ok([...instances.keys()].join("\n"));
|
|
564
|
+
if (verb === "sql databases describe" || verb === "sql users describe") {
|
|
565
|
+
const on = instances.get(args.find((a) => a.startsWith("--instance="))?.slice(11) ?? "");
|
|
566
|
+
// What the Cloud SQL Admin API answers for anything on an instance
|
|
567
|
+
// that does not exist: 403, not 404.
|
|
568
|
+
if (!on) {
|
|
569
|
+
return fail(
|
|
570
|
+
`ERROR: (gcloud.sql.${args[1]}.describe) HTTPError 403: The client is not authorized to make this request.`,
|
|
571
|
+
);
|
|
572
|
+
}
|
|
573
|
+
return on.has(`${args[1]}:${args[3]}`)
|
|
574
|
+
? ok(args[3])
|
|
575
|
+
: fail(`ERROR: (gcloud.sql.${args[1]}.describe) HTTPError 404: Not Found`);
|
|
576
|
+
}
|
|
577
|
+
return fail(`unexpected gcloud ${args.join(" ")}`);
|
|
578
|
+
};
|
|
579
|
+
return { run, calls, accounts, instances };
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
/** The stack: its state, a preview of what is left, and an `up` that can stop at a resource. */
|
|
583
|
+
function fakeStack(project: ReturnType<typeof fakeProject>) {
|
|
584
|
+
const state = new Set<string>();
|
|
585
|
+
const created: string[] = [];
|
|
586
|
+
const preview = async (): Promise<readonly PlannedStep[]> =>
|
|
587
|
+
declared.filter((s) => !state.has(s.urn));
|
|
588
|
+
const up = (stopAt?: string) => {
|
|
589
|
+
for (const s of declared) {
|
|
590
|
+
if (state.has(s.urn)) continue;
|
|
591
|
+
if (s.name === stopAt) throw new Error(`creating ${s.name} failed`);
|
|
592
|
+
if (s.type === SA) {
|
|
593
|
+
project.accounts.add(`${input(s, "accountId")}@${PROJECT}.iam.gserviceaccount.com`);
|
|
594
|
+
} else if (s.type === INSTANCE_TYPE) {
|
|
595
|
+
project.instances.set(input(s, "name"), new Set());
|
|
596
|
+
} else if (s.type === DATABASE || s.type === USER) {
|
|
597
|
+
const on = project.instances.get(input(s, "instance"));
|
|
598
|
+
if (!on) throw new Error(`${s.name}: its instance does not exist`);
|
|
599
|
+
on.add(`${s.type === DATABASE ? "databases" : "users"}:${input(s, "name")}`);
|
|
600
|
+
}
|
|
601
|
+
state.add(s.urn);
|
|
602
|
+
created.push(s.name);
|
|
603
|
+
}
|
|
604
|
+
};
|
|
605
|
+
const importResources = async (cs: readonly AdoptionCandidate[]) => {
|
|
606
|
+
for (const c of cs) state.add(c.step.urn);
|
|
607
|
+
};
|
|
608
|
+
return { state, created, preview, up, importResources };
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
/** One installer pass in pulumiUpGcp's order. */
|
|
612
|
+
async function installerPass(
|
|
613
|
+
project: ReturnType<typeof fakeProject>,
|
|
614
|
+
stack: ReturnType<typeof fakeStack>,
|
|
615
|
+
stopAt?: string,
|
|
616
|
+
) {
|
|
617
|
+
const adopted =
|
|
618
|
+
stack.state.size > 0
|
|
619
|
+
? (
|
|
620
|
+
await adoptExistingResources(await stack.preview(), {
|
|
621
|
+
projectId: PROJECT,
|
|
622
|
+
gcloud: project.run,
|
|
623
|
+
preview: stack.preview,
|
|
624
|
+
importResources: stack.importResources,
|
|
625
|
+
})
|
|
626
|
+
).adopted
|
|
627
|
+
: [];
|
|
628
|
+
stack.up(stopAt);
|
|
629
|
+
return adopted;
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
it("the second run creates the instance and everything on it instead of stopping at Cloud SQL's 403", async () => {
|
|
633
|
+
const project = fakeProject();
|
|
634
|
+
const stack = fakeStack(project);
|
|
635
|
+
await expect(installerPass(project, stack, "caelo-production-pg")).rejects.toThrow(
|
|
636
|
+
"creating caelo-production-pg failed",
|
|
637
|
+
);
|
|
638
|
+
expect(project.instances.size).toBe(0);
|
|
639
|
+
expect(stack.created).toEqual(["caelo-production-gateway-sa", "caelo-production-vpc"]);
|
|
640
|
+
|
|
641
|
+
const adopted = await installerPass(project, stack);
|
|
642
|
+
expect(adopted).toEqual([]);
|
|
643
|
+
expect([...(project.instances.get(INSTANCE) ?? [])].sort()).toEqual([
|
|
644
|
+
"databases:cms_admin",
|
|
645
|
+
"databases:cms_public_staging",
|
|
646
|
+
"users:public_staging_role",
|
|
647
|
+
]);
|
|
648
|
+
// Nothing on the missing instance was asked about: the instances were
|
|
649
|
+
// listed once, and none of them was it.
|
|
650
|
+
const sql = project.calls.filter((a) => a[0] === "sql").map((a) => a.slice(0, 3).join(" "));
|
|
651
|
+
expect(sql).toEqual(["sql instances list"]);
|
|
652
|
+
});
|
|
653
|
+
|
|
654
|
+
it("the staging database and login a converge made on an existing instance are still adopted (#1329)", async () => {
|
|
655
|
+
const project = fakeProject();
|
|
656
|
+
const stack = fakeStack(project);
|
|
657
|
+
await expect(
|
|
658
|
+
installerPass(project, stack, "caelo-production-cms-public-staging"),
|
|
659
|
+
).rejects.toThrow("failed");
|
|
660
|
+
// Made since by `upgrade` through gcloud (staging-database.ts).
|
|
661
|
+
project.instances.get(INSTANCE)?.add("databases:cms_public_staging");
|
|
662
|
+
project.instances.get(INSTANCE)?.add("users:public_staging_role");
|
|
663
|
+
|
|
664
|
+
const adopted = await installerPass(project, stack);
|
|
665
|
+
expect(adopted.map((c) => c.display)).toEqual([
|
|
666
|
+
`cms_public_staging (${INSTANCE})`,
|
|
667
|
+
`public_staging_role (${INSTANCE})`,
|
|
668
|
+
]);
|
|
669
|
+
expect(stack.created).not.toContain("caelo-production-cms-public-staging");
|
|
670
|
+
});
|
|
671
|
+
|
|
672
|
+
it("a permission 403 on listing the instances stays loud, with the next step", async () => {
|
|
673
|
+
const candidates = adoptionCandidates(declared, PROJECT);
|
|
674
|
+
const run: GcloudRunner = async (args) =>
|
|
675
|
+
args.slice(0, 3).join(" ") === "sql instances list"
|
|
676
|
+
? fail(
|
|
677
|
+
"ERROR: (gcloud.sql.instances.list) HTTPError 403: The client is not authorized to make this request.",
|
|
678
|
+
)
|
|
679
|
+
: fail("ERROR: NOT_FOUND");
|
|
680
|
+
const probe = existingCandidates(candidates, run);
|
|
681
|
+
await expect(probe).rejects.toBeInstanceOf(AdoptionError);
|
|
682
|
+
await expect(probe).rejects.toThrow(
|
|
683
|
+
`could not list the Cloud SQL instances of ${PROJECT} (gcloud: ERROR: (gcloud.sql.instances.list) HTTPError 403`,
|
|
684
|
+
);
|
|
685
|
+
await expect(probe).rejects.toThrow("needs cloudsql.instances.list on the project");
|
|
686
|
+
});
|
|
687
|
+
|
|
688
|
+
it("a 403 about a database on an instance that exists stays loud", async () => {
|
|
689
|
+
const project = fakeProject();
|
|
690
|
+
project.instances.set(INSTANCE, new Set());
|
|
691
|
+
const run: GcloudRunner = async (args) =>
|
|
692
|
+
args[0] === "sql" && args[2] === "describe"
|
|
693
|
+
? fail("ERROR: (gcloud.sql.databases.describe) HTTPError 403: PERMISSION_DENIED")
|
|
694
|
+
: project.run(args);
|
|
695
|
+
await expect(existingCandidates(adoptionCandidates(declared, PROJECT), run)).rejects.toThrow(
|
|
696
|
+
`could not tell whether the Cloud SQL database cms_public_staging (${INSTANCE}) exists`,
|
|
697
|
+
);
|
|
698
|
+
});
|
|
699
|
+
});
|
package/src/adopt-existing.ts
CHANGED
|
@@ -18,7 +18,9 @@
|
|
|
18
18
|
* ever adopted; every other kind is left to Pulumi.
|
|
19
19
|
* 2. {@link existingCandidates}: a gcloud describe per candidate. Exists →
|
|
20
20
|
* adopt; NOT_FOUND → a plain create; anything else stops the run (we
|
|
21
|
-
* can't tell, and guessing either way is wrong).
|
|
21
|
+
* can't tell, and guessing either way is wrong). A Cloud SQL database or
|
|
22
|
+
* user on an instance the project does not list yet is a plain create
|
|
23
|
+
* without a describe: Cloud SQL answers that one with 403.
|
|
22
24
|
* 3. `pulumi import` of the existing ones into the stack, under the
|
|
23
25
|
* stack's explicit GCP provider (wizards/gcp-pulumi.ts). State only: the
|
|
24
26
|
* cloud resources are not touched.
|
|
@@ -70,6 +72,12 @@ export interface AdoptionTarget {
|
|
|
70
72
|
readonly describeArgs: readonly string[];
|
|
71
73
|
/** The id `pulumi import` takes for the kind. */
|
|
72
74
|
readonly importId: string;
|
|
75
|
+
/**
|
|
76
|
+
* The Cloud SQL instance a database or user lives on. It can only exist
|
|
77
|
+
* once the instance does, so it is described only when the project lists
|
|
78
|
+
* that instance ({@link existingCandidates}).
|
|
79
|
+
*/
|
|
80
|
+
readonly sqlInstance?: { readonly projectId: string; readonly name: string };
|
|
73
81
|
}
|
|
74
82
|
|
|
75
83
|
/** A resource kind the installer adopts when it exists already. */
|
|
@@ -215,6 +223,7 @@ export const ADOPTABLE_KINDS: Readonly<Record<string, AdoptableKind>> = {
|
|
|
215
223
|
"--format=value(name)",
|
|
216
224
|
],
|
|
217
225
|
importId: `projects/${projectId}/instances/${instance}/databases/${name}`,
|
|
226
|
+
sqlInstance: { projectId, name: instance },
|
|
218
227
|
};
|
|
219
228
|
},
|
|
220
229
|
},
|
|
@@ -238,6 +247,7 @@ export const ADOPTABLE_KINDS: Readonly<Record<string, AdoptableKind>> = {
|
|
|
238
247
|
],
|
|
239
248
|
// The provider's import id for a Postgres built-in user.
|
|
240
249
|
importId: `${projectId}/${instance}/${name}`,
|
|
250
|
+
sqlInstance: { projectId, name: instance },
|
|
241
251
|
};
|
|
242
252
|
},
|
|
243
253
|
},
|
|
@@ -270,9 +280,44 @@ export function adoptionCandidates(
|
|
|
270
280
|
return out;
|
|
271
281
|
}
|
|
272
282
|
|
|
283
|
+
/**
|
|
284
|
+
* The names of the project's Cloud SQL instances.
|
|
285
|
+
*
|
|
286
|
+
* @throws AdoptionError when they cannot be listed
|
|
287
|
+
*/
|
|
288
|
+
async function listSqlInstances(run: GcloudRunner, projectId: string): Promise<Set<string>> {
|
|
289
|
+
const r = await run([
|
|
290
|
+
"sql",
|
|
291
|
+
"instances",
|
|
292
|
+
"list",
|
|
293
|
+
`--project=${projectId}`,
|
|
294
|
+
"--format=value(name)",
|
|
295
|
+
]);
|
|
296
|
+
if (!r.ok) {
|
|
297
|
+
throw new AdoptionError(
|
|
298
|
+
`could not list the Cloud SQL instances of ${projectId} (gcloud: ${r.stderr.trim()}), so it is unclear whether the databases and users the stack declares exist already. Nothing was imported or applied. The account running the installer needs cloudsql.instances.list on the project (project Owner in your terminal; the install job's caelo-provisioner holds roles/cloudsql.admin). Fix that and re-run the installer.`,
|
|
299
|
+
);
|
|
300
|
+
}
|
|
301
|
+
return new Set(
|
|
302
|
+
r.stdout
|
|
303
|
+
.split("\n")
|
|
304
|
+
.map((l) => l.trim())
|
|
305
|
+
.filter(Boolean),
|
|
306
|
+
);
|
|
307
|
+
}
|
|
308
|
+
|
|
273
309
|
/**
|
|
274
310
|
* The candidates that exist in the project.
|
|
275
311
|
*
|
|
312
|
+
* A Cloud SQL database or user is described only when the project lists its
|
|
313
|
+
* instance. On a first run — or one resumed after a run that stopped before
|
|
314
|
+
* `pulumi up` created the instance — the plan creates the instance together
|
|
315
|
+
* with everything on it, so nothing on it can exist yet; and the Cloud SQL
|
|
316
|
+
* Admin API answers a describe on a missing instance with 403 "not
|
|
317
|
+
* authorized", not 404, which would stop every re-run as if access were
|
|
318
|
+
* missing. The instance list is asked once and tells absent from forbidden;
|
|
319
|
+
* a describe on an instance that is listed keeps every error loud.
|
|
320
|
+
*
|
|
276
321
|
* @throws AdoptionError when a describe fails for another reason than NOT_FOUND
|
|
277
322
|
*/
|
|
278
323
|
export async function existingCandidates(
|
|
@@ -280,7 +325,17 @@ export async function existingCandidates(
|
|
|
280
325
|
run: GcloudRunner,
|
|
281
326
|
): Promise<AdoptionCandidate[]> {
|
|
282
327
|
const existing: AdoptionCandidate[] = [];
|
|
328
|
+
const instancesOf = new Map<string, Set<string>>();
|
|
283
329
|
for (const c of candidates) {
|
|
330
|
+
if (c.sqlInstance) {
|
|
331
|
+
const { projectId, name } = c.sqlInstance;
|
|
332
|
+
let instances = instancesOf.get(projectId);
|
|
333
|
+
if (!instances) {
|
|
334
|
+
instances = await listSqlInstances(run, projectId);
|
|
335
|
+
instancesOf.set(projectId, instances);
|
|
336
|
+
}
|
|
337
|
+
if (!instances.has(name)) continue;
|
|
338
|
+
}
|
|
284
339
|
const r = await run([...c.describeArgs]);
|
|
285
340
|
if (r.ok) existing.push(c);
|
|
286
341
|
else if (!isGcloudNotFound(r.stderr)) {
|
|
@@ -14,7 +14,6 @@ import { existsSync } from "node:fs";
|
|
|
14
14
|
import { join } from "node:path";
|
|
15
15
|
import {
|
|
16
16
|
AUDIT_FORBIDDEN_ROLES,
|
|
17
|
-
AUDIT_PARALLELISM_DEFAULT,
|
|
18
17
|
AUDIT_TASK_SCRIPT,
|
|
19
18
|
type AuditJobTarget,
|
|
20
19
|
ensureAuditJob,
|
|
@@ -35,7 +34,6 @@ const TARGET: AuditJobTarget = {
|
|
|
35
34
|
region: "europe-west1",
|
|
36
35
|
env: "production",
|
|
37
36
|
adminImageRef: ADMIN_IMAGE,
|
|
38
|
-
parallelism: 15,
|
|
39
37
|
};
|
|
40
38
|
|
|
41
39
|
function fakeGcloud(overrides: [RegExp, GcloudResult][] = []) {
|
|
@@ -145,7 +143,7 @@ describe("ensureAuditJob", () => {
|
|
|
145
143
|
);
|
|
146
144
|
expect(flag(deploy, "args")).toBe(`--bun,${AUDIT_TASK_SCRIPT}`);
|
|
147
145
|
expect(flag(deploy, "max-retries")).toBe("0");
|
|
148
|
-
expect(flag(deploy, "parallelism")).toBe("
|
|
146
|
+
expect(flag(deploy, "parallelism")).toBe("0");
|
|
149
147
|
expect(flag(deploy, "set-env-vars")).toBe(
|
|
150
148
|
`CAELO_PROVIDER=gcp,CAELO_AUDIT_RESULTS_BUCKET=${RESULTS},CAELO_STAGING_BUCKET=acme-caelo-production-staging`,
|
|
151
149
|
);
|
|
@@ -167,39 +165,22 @@ describe("ensureAuditJob", () => {
|
|
|
167
165
|
expect(calls.some((c) => c.join(" ").includes("--lifecycle-file="))).toBe(true);
|
|
168
166
|
});
|
|
169
167
|
|
|
170
|
-
it("keeps an existing bucket
|
|
171
|
-
const { run, calls } = fakeGcloud([
|
|
172
|
-
|
|
173
|
-
[/^run jobs describe caelo-production-audit /, ok(`${ADMIN_IMAGE}\n`)],
|
|
174
|
-
]);
|
|
175
|
-
const { parallelism: _, ...converge } = TARGET;
|
|
176
|
-
expect((await ensureAuditJob(converge, { run, sleep: async () => {} })).ok).toBe(true);
|
|
168
|
+
it("keeps an existing bucket on converge", async () => {
|
|
169
|
+
const { run, calls } = fakeGcloud([[/^storage buckets list/, ok(`gs://${RESULTS}/\n`)]]);
|
|
170
|
+
expect((await ensureAuditJob(TARGET, { run, sleep: async () => {} })).ok).toBe(true);
|
|
177
171
|
expect(calls.some((c) => c.slice(0, 3).join(" ") === "storage buckets create")).toBe(false);
|
|
178
|
-
expect(flag(deployOf(calls), "parallelism")).toBeUndefined();
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
it("gives a job the converge creates the default parallelism, as a fresh install's", async () => {
|
|
182
|
-
// gcloud's verbatim stderr for a missing job: no NOT_FOUND code (regression:
|
|
183
|
-
// the converge failed with "read job caelo-production-audit" on every
|
|
184
|
-
// install that had no audit job yet).
|
|
185
|
-
const { run, calls } = fakeGcloud([
|
|
186
|
-
[
|
|
187
|
-
/^run jobs describe/,
|
|
188
|
-
fail("ERROR: (gcloud.run.jobs.describe) Cannot find job [caelo-production-audit]."),
|
|
189
|
-
],
|
|
190
|
-
]);
|
|
191
|
-
const { parallelism: _, ...converge } = TARGET;
|
|
192
|
-
const r = await ensureAuditJob(converge, { run, sleep: async () => {} });
|
|
193
|
-
expect(r.ok).toBe(true);
|
|
194
|
-
expect(flag(deployOf(calls), "parallelism")).toBe(String(AUDIT_PARALLELISM_DEFAULT));
|
|
195
172
|
});
|
|
196
173
|
|
|
197
|
-
it("
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
expect(
|
|
174
|
+
it("#1764 — sets no fixed parallelism, and unsets an older job's, so a 20-vCPU project can create it", async () => {
|
|
175
|
+
// Cloud Run refuses a job whose parallelism times its CPU exceeds the
|
|
176
|
+
// project's quota (15 x 2 vCPU on a new project's 20 stopped installs);
|
|
177
|
+
// the audit runner sizes every execution from the quota instead.
|
|
178
|
+
const { run, calls } = fakeGcloud();
|
|
179
|
+
expect((await ensureAuditJob(TARGET, { run, sleep: async () => {} })).ok).toBe(true);
|
|
180
|
+
expect(flag(deployOf(calls), "parallelism")).toBe("0");
|
|
181
|
+
expect(flag(deployOf(calls), "cpu")).toBe("2");
|
|
182
|
+
// No read of the job before: nothing is kept from it.
|
|
183
|
+
expect(calls.some((c) => c.slice(0, 3).join(" ") === "run jobs describe")).toBe(false);
|
|
203
184
|
});
|
|
204
185
|
|
|
205
186
|
it("#1330 — on gcp-firebase reads the staging bucket too: no preview channel any more", async () => {
|
|
@@ -226,12 +207,6 @@ describe("ensureAuditJob", () => {
|
|
|
226
207
|
expect(calls).toEqual([]);
|
|
227
208
|
});
|
|
228
209
|
|
|
229
|
-
it("refuses a parallelism outside 1-15", async () => {
|
|
230
|
-
const { run } = fakeGcloud();
|
|
231
|
-
const r = await ensureAuditJob({ ...TARGET, parallelism: 16 }, { run });
|
|
232
|
-
expect(r).toMatchObject({ ok: false, error: expect.stringContaining("1 to 15") });
|
|
233
|
-
});
|
|
234
|
-
|
|
235
210
|
it("stops at the first failed grant and names it", async () => {
|
|
236
211
|
const { run, calls } = fakeGcloud([
|
|
237
212
|
[
|
package/src/audit-job-setup.ts
CHANGED
|
@@ -10,8 +10,16 @@
|
|
|
10
10
|
* Why a separate job at all (CLAUDE.md §11.B Tier 5 exception): Lighthouse
|
|
11
11
|
* is CPU-bound and simulates the CPU slowdown from observed task durations,
|
|
12
12
|
* so a run that shares a CPU with another run or with the editor's chat
|
|
13
|
-
* measures that interference too.
|
|
14
|
-
*
|
|
13
|
+
* measures that interference too. A task of its own measures the page
|
|
14
|
+
* alone; as many run at once as the project's Cloud Run CPU quota allows.
|
|
15
|
+
*
|
|
16
|
+
* The job has no fixed `parallelism` (#1764). Cloud Run refuses to create a
|
|
17
|
+
* job whose parallelism times its CPU exceeds the project's regional CPU
|
|
18
|
+
* quota, and a new project has 20 vCPU: a fixed 15 runs of 2 vCPU stopped
|
|
19
|
+
* every fresh install here. The audit runner asks for as many tasks per
|
|
20
|
+
* execution as the quota leaves (admin-core reporting-jobs/run-capacity.ts)
|
|
21
|
+
* and each task runs its share one after another, so a raised quota counts
|
|
22
|
+
* from the next Stage on, without touching the job.
|
|
15
23
|
*
|
|
16
24
|
* Why the CLI owns it and not the stacks: `upgrade` never runs Pulumi, so
|
|
17
25
|
* existing installs get the job only from here, and a bucket or job both
|
|
@@ -58,18 +66,15 @@ import {
|
|
|
58
66
|
} from "./gcp-names.js";
|
|
59
67
|
import { readAdminConfig } from "./migration-runner.js";
|
|
60
68
|
import type { GcpProvider } from "./stack-contract.js";
|
|
61
|
-
import { describeJobImage } from "./upgrade/admin-image-jobs.js";
|
|
62
69
|
|
|
63
70
|
/** Where the admin image ships the task's entry point. */
|
|
64
71
|
export const AUDIT_TASK_SCRIPT = "/app/packages/admin-core/src/quality/audit-task.ts";
|
|
65
72
|
|
|
66
|
-
/** How many audit tasks run at once by default: 5 pages x 3 runs. */
|
|
67
|
-
export const AUDIT_PARALLELISM_DEFAULT = 15;
|
|
68
|
-
|
|
69
73
|
/**
|
|
70
74
|
* Per task: container start, browser start, CPU benchmark and one
|
|
71
|
-
* Lighthouse run. Matches admin-core `parallelAuditTimeoutMs
|
|
72
|
-
*
|
|
75
|
+
* Lighthouse run. Matches admin-core `parallelAuditTimeoutMs(1)`; the
|
|
76
|
+
* audit runner passes each execution's own timeout, longer for a task
|
|
77
|
+
* that runs several runs one after another.
|
|
73
78
|
*/
|
|
74
79
|
const TASK_TIMEOUT = "5m";
|
|
75
80
|
|
|
@@ -104,13 +109,6 @@ export interface AuditJobTarget {
|
|
|
104
109
|
readonly env: string;
|
|
105
110
|
/** The admin image the job runs, digest-pinned (`…/admin@sha256:…`). */
|
|
106
111
|
readonly adminImageRef: string;
|
|
107
|
-
/**
|
|
108
|
-
* Tasks at once (`auditParallelism`, 1–15). Absent on converge: an
|
|
109
|
-
* existing job keeps the value it has, so an operator's choice survives
|
|
110
|
-
* `upgrade`; a job the converge creates gets
|
|
111
|
-
* {@link AUDIT_PARALLELISM_DEFAULT}, as a fresh install's does.
|
|
112
|
-
*/
|
|
113
|
-
readonly parallelism?: number;
|
|
114
112
|
}
|
|
115
113
|
|
|
116
114
|
export type AuditJobResult =
|
|
@@ -147,16 +145,6 @@ export async function ensureAuditJob(
|
|
|
147
145
|
error: `the audit job's image must be pinned by digest, got ${target.adminImageRef}`,
|
|
148
146
|
};
|
|
149
147
|
}
|
|
150
|
-
if (
|
|
151
|
-
target.parallelism !== undefined &&
|
|
152
|
-
(!Number.isInteger(target.parallelism) || target.parallelism < 1 || target.parallelism > 15)
|
|
153
|
-
) {
|
|
154
|
-
return {
|
|
155
|
-
ok: false,
|
|
156
|
-
done,
|
|
157
|
-
error: `auditParallelism must be a whole number from 1 to 15, got ${target.parallelism}`,
|
|
158
|
-
};
|
|
159
|
-
}
|
|
160
148
|
|
|
161
149
|
// 1. The job's own service account.
|
|
162
150
|
const describe = await run([
|
|
@@ -283,15 +271,9 @@ export async function ensureAuditJob(
|
|
|
283
271
|
if (!logs.ok) return fail("grant the audit job roles/logging.logWriter", logs);
|
|
284
272
|
done.push("audit job: roles/logging.logWriter on the project");
|
|
285
273
|
|
|
286
|
-
// 5. The job: the admin image, its own SA, no secrets, no VPC
|
|
287
|
-
//
|
|
288
|
-
//
|
|
289
|
-
let parallelism = target.parallelism;
|
|
290
|
-
if (parallelism === undefined) {
|
|
291
|
-
const existing = await describeJobImage(run, { projectId, region, env }, job);
|
|
292
|
-
if (!existing.ok) return { ok: false, done, error: `read job ${job}: ${existing.error}` };
|
|
293
|
-
if (existing.image === null) parallelism = AUDIT_PARALLELISM_DEFAULT;
|
|
294
|
-
}
|
|
274
|
+
// 5. The job: the admin image, its own SA, no secrets, no VPC, and no
|
|
275
|
+
// fixed parallelism: the audit runner sizes each execution's taskCount
|
|
276
|
+
// from the quota. `0` unsets the 15 an older install's job carries.
|
|
295
277
|
const envVars = [
|
|
296
278
|
`CAELO_PROVIDER=${provider}`,
|
|
297
279
|
`CAELO_AUDIT_RESULTS_BUCKET=${results}`,
|
|
@@ -314,7 +296,7 @@ export async function ensureAuditJob(
|
|
|
314
296
|
// Lighthouse wants two cores: the browser and the trace processing.
|
|
315
297
|
"--cpu=2",
|
|
316
298
|
"--memory=2Gi",
|
|
317
|
-
|
|
299
|
+
"--parallelism=0",
|
|
318
300
|
"--quiet",
|
|
319
301
|
]);
|
|
320
302
|
if (!deploy.ok) return fail(`deploy job ${job}`, deploy);
|
|
@@ -12,12 +12,9 @@ import {
|
|
|
12
12
|
readConvergeCheckpoint,
|
|
13
13
|
writeConvergeCheckpoint,
|
|
14
14
|
} from "./converge-checkpoint.js";
|
|
15
|
-
import {
|
|
16
|
-
convergeExecutionNameError,
|
|
17
|
-
deployedOwnerMismatch,
|
|
18
|
-
deployedSiteMismatch,
|
|
19
|
-
} from "./converge-job-gcp.js";
|
|
15
|
+
import { convergeExecutionNameError, deployedSiteMismatch } from "./converge-job-gcp.js";
|
|
20
16
|
import type { GcloudResult } from "./gcloud.js";
|
|
17
|
+
import { deployedOwnerMismatch } from "./operator-access.js";
|
|
21
18
|
import type { SyncGcloud } from "./state-store.js";
|
|
22
19
|
import { installStateCondition } from "./upgrader-setup.js";
|
|
23
20
|
|
package/src/converge-job-gcp.ts
CHANGED
|
@@ -42,7 +42,7 @@ import {
|
|
|
42
42
|
} from "./install-state.js";
|
|
43
43
|
import { jobExecutionNameError, selfHandoverDeps } from "./job-handover-gcp.js";
|
|
44
44
|
import { runMigrationsViaCloudRunJob } from "./migration-runner.js";
|
|
45
|
-
import {
|
|
45
|
+
import { deployedOwnerMismatch } from "./operator-access.js";
|
|
46
46
|
import { provisionerServiceAccountEmail } from "./provisioner-identity.js";
|
|
47
47
|
import { fetchVerifiedReleaseManifest, manifestServiceImages } from "./release-manifest.js";
|
|
48
48
|
import type { HttpFetch } from "./runtime-secrets.js";
|
|
@@ -56,54 +56,9 @@ import { upgradeGcpInstallOutcome } from "./upgrade/upgrade.js";
|
|
|
56
56
|
import { gcloudIamTester, healthProbeFor, type UpgraderPlacement } from "./upgrader-gcp.js";
|
|
57
57
|
import type { JobLog } from "./upgrader-reporter.js";
|
|
58
58
|
|
|
59
|
-
/** The operator-access job's env var listing the install's fixed IAP members. */
|
|
60
|
-
const STATIC_MEMBERS_ENV = "CAELO_OPERATOR_ACCESS_STATIC_MEMBERS";
|
|
61
|
-
|
|
62
59
|
/** The admin env var naming the public site (stack-contract.ts adminEnvContract). */
|
|
63
60
|
const SITE_URL_ENV = "CAELO_SITE_URL";
|
|
64
61
|
|
|
65
|
-
/**
|
|
66
|
-
* Why install.json's Owner email does not match the IAP members the
|
|
67
|
-
* deployed operator-access job admits (operator-access.ts deploys them as
|
|
68
|
-
* `installIapAllowlist(ownerEmail)`), or null when it does. Read from
|
|
69
|
-
* `gcloud run jobs describe --format=json` (v1 or v2 shape).
|
|
70
|
-
*/
|
|
71
|
-
export function deployedOwnerMismatch(describeJson: string, ownerEmail: string): string | null {
|
|
72
|
-
let parsed: unknown;
|
|
73
|
-
try {
|
|
74
|
-
parsed = JSON.parse(describeJson);
|
|
75
|
-
} catch {
|
|
76
|
-
return "the operator-access job's description is not JSON";
|
|
77
|
-
}
|
|
78
|
-
const p = parsed as {
|
|
79
|
-
spec?: {
|
|
80
|
-
template?: {
|
|
81
|
-
spec?: {
|
|
82
|
-
template?: { spec?: { containers?: { env?: { name?: string; value?: string }[] }[] } };
|
|
83
|
-
};
|
|
84
|
-
};
|
|
85
|
-
};
|
|
86
|
-
template?: { template?: { containers?: { env?: { name?: string; value?: string }[] }[] } };
|
|
87
|
-
};
|
|
88
|
-
const env =
|
|
89
|
-
p.spec?.template?.spec?.template?.spec?.containers?.[0]?.env ??
|
|
90
|
-
p.template?.template?.containers?.[0]?.env ??
|
|
91
|
-
[];
|
|
92
|
-
const deployed = env.find((e) => e.name === STATIC_MEMBERS_ENV)?.value;
|
|
93
|
-
if (deployed === undefined) return `the operator-access job sets no ${STATIC_MEMBERS_ENV}`;
|
|
94
|
-
const want = installIapAllowlist(ownerEmail).join(",");
|
|
95
|
-
const have = deployed
|
|
96
|
-
.split(",")
|
|
97
|
-
.map((m) => m.trim().toLowerCase())
|
|
98
|
-
.filter(Boolean)
|
|
99
|
-
.sort()
|
|
100
|
-
.join(",");
|
|
101
|
-
if (have !== [...installIapAllowlist(ownerEmail)].sort().join(",")) {
|
|
102
|
-
return `the admin admits ${deployed || "nobody"}, the records would make it ${want}`;
|
|
103
|
-
}
|
|
104
|
-
return null;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
62
|
/**
|
|
108
63
|
* Why install.json's site does not match what the admin serves today, or
|
|
109
64
|
* null when it does (#883 review, round 2). install.json is writable by the
|
|
@@ -20,8 +20,9 @@ describe("infrastructure contract steps", () => {
|
|
|
20
20
|
);
|
|
21
21
|
});
|
|
22
22
|
|
|
23
|
-
it("is at 28: 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), the static bucket read for those headers (24), the quality-audit runner (25), the site-import crawler (26), the build carrier (27), the upgrader's actAs on the staging gateway (28), plugin collections (29), the visitor AI's keys (30)", () => {
|
|
24
|
-
expect(INFRA_CONTRACT_VERSION).toBe(
|
|
23
|
+
it("is at 28: 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), the static bucket read for those headers (24), the quality-audit runner (25), the site-import crawler (26), the build carrier (27), the upgrader's actAs on the staging gateway (28), plugin collections (29), the visitor AI's keys (30), the CPU quota read and jobs without a fixed width (31)", () => {
|
|
24
|
+
expect(INFRA_CONTRACT_VERSION).toBe(31);
|
|
25
|
+
expect(INFRA_CONTRACT_STEPS[31]).toContain("#1764");
|
|
25
26
|
expect(INFRA_CONTRACT_STEPS[30]).toContain("#1654");
|
|
26
27
|
expect(INFRA_CONTRACT_STEPS[29]).toContain("#1644");
|
|
27
28
|
expect(INFRA_CONTRACT_STEPS[27]).toContain("#1574");
|
|
@@ -60,6 +61,6 @@ describe("infrastructure contract steps", () => {
|
|
|
60
61
|
});
|
|
61
62
|
|
|
62
63
|
it("names a version a newer release added by number", () => {
|
|
63
|
-
expect(infraStepsText(
|
|
64
|
+
expect(infraStepsText(31, 32)).toBe("infrastructure step 32 (see that release's notes)");
|
|
64
65
|
});
|
|
65
66
|
});
|
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 = 31;
|
|
26
26
|
|
|
27
27
|
// History (why each bump happened — an install below a number needs the
|
|
28
28
|
// converge that introduced it):
|
|
@@ -277,6 +277,15 @@ export const INFRA_CONTRACT_VERSION = 30;
|
|
|
277
277
|
// admin. The new admin starts those builds on that job and the
|
|
278
278
|
// app-roll moves its image, so an in-cloud upgrader must not roll an
|
|
279
279
|
// install onto it before it exists.
|
|
280
|
+
// 31 — #1764: job widths follow the project's Cloud Run CPU quota. The
|
|
281
|
+
// admin's run SA gets roles/serviceusage.serviceUsageViewer on the
|
|
282
|
+
// project (read-only: enabled services and quotas), because the new
|
|
283
|
+
// admin reads the regional CPU quota at every job start and sizes the
|
|
284
|
+
// quality check's Lighthouse runs and a search index's tasks from it;
|
|
285
|
+
// without the grant every Stage audit fails to start. The quality-
|
|
286
|
+
// audit job loses its fixed parallelism of 15 (`--parallelism=0`) and
|
|
287
|
+
// the collection index job's task timeout grows to 6 hours. IAM and
|
|
288
|
+
// job writes the in-cloud upgrader may not make.
|
|
280
289
|
//
|
|
281
290
|
// #1029 is deliberately NOT a bump. The upgrader job's stage 1 moves the job
|
|
282
291
|
// onto the target's ops image with rights it has held on itself since
|
|
@@ -321,6 +330,7 @@ export const INFRA_CONTRACT_STEPS: Readonly<Record<number, string>> = {
|
|
|
321
330
|
28: "the upgrader's right to run the staging gateway as its service account, so updates from Settings → Updates roll every service (#1596)",
|
|
322
331
|
29: "plugin collections such as a site search: two private storage buckets for the staging and the live index, a job of its own that builds a Stage's index, each gateway's read access to its own index only and more memory for it, search answers cached at the edge, and visitors' search queries kept out of the logs (#1644)",
|
|
323
332
|
30: "the visitor AI's own keys: one secret for the live site and one for staging, which the admin can store a key in but never read, each mounted only in its own gateway (#1654)",
|
|
333
|
+
31: "the admin's read of the project's Cloud Run CPU quota, which sizes the quality check and search index jobs, and those jobs without a fixed width (#1764)",
|
|
324
334
|
};
|
|
325
335
|
|
|
326
336
|
/**
|