@caelo-cms/provisioning 0.12.10 → 0.12.11

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.
Files changed (123) hide show
  1. package/dist/agent-db.js +51 -2
  2. package/dist/cli.js +23 -2
  3. package/dist/cli.js.map +1 -1
  4. package/dist/collection-stores.d.ts +5 -0
  5. package/dist/collection-stores.d.ts.map +1 -0
  6. package/dist/collection-stores.js +21 -0
  7. package/dist/collection-stores.js.map +1 -0
  8. package/dist/collections-setup.d.ts +66 -0
  9. package/dist/collections-setup.d.ts.map +1 -0
  10. package/dist/collections-setup.js +252 -0
  11. package/dist/collections-setup.js.map +1 -0
  12. package/dist/compose.d.ts +27 -0
  13. package/dist/compose.d.ts.map +1 -1
  14. package/dist/compose.js +52 -1
  15. package/dist/compose.js.map +1 -1
  16. package/dist/gateway-edge.d.ts +13 -0
  17. package/dist/gateway-edge.d.ts.map +1 -1
  18. package/dist/gateway-edge.js +22 -0
  19. package/dist/gateway-edge.js.map +1 -1
  20. package/dist/gcp-names.d.ts +18 -48
  21. package/dist/gcp-names.d.ts.map +1 -1
  22. package/dist/gcp-names.js +11 -69
  23. package/dist/gcp-names.js.map +1 -1
  24. package/dist/infra-contract.d.ts +1 -1
  25. package/dist/infra-contract.d.ts.map +1 -1
  26. package/dist/infra-contract.js +35 -1
  27. package/dist/infra-contract.js.map +1 -1
  28. package/dist/reporting-job-catalog.d.ts +111 -0
  29. package/dist/reporting-job-catalog.d.ts.map +1 -0
  30. package/dist/reporting-job-catalog.js +306 -0
  31. package/dist/reporting-job-catalog.js.map +1 -0
  32. package/dist/reporting-job-setup.d.ts +11 -68
  33. package/dist/reporting-job-setup.d.ts.map +1 -1
  34. package/dist/reporting-job-setup.js +44 -100
  35. package/dist/reporting-job-setup.js.map +1 -1
  36. package/dist/runtime-secrets.d.ts.map +1 -1
  37. package/dist/runtime-secrets.js +3 -0
  38. package/dist/runtime-secrets.js.map +1 -1
  39. package/dist/self-hosted-backup.d.ts.map +1 -1
  40. package/dist/self-hosted-backup.js +18 -6
  41. package/dist/self-hosted-backup.js.map +1 -1
  42. package/dist/stack-contract.d.ts +75 -22
  43. package/dist/stack-contract.d.ts.map +1 -1
  44. package/dist/stack-contract.js +142 -51
  45. package/dist/stack-contract.js.map +1 -1
  46. package/dist/stack-converge.d.ts +20 -1
  47. package/dist/stack-converge.d.ts.map +1 -1
  48. package/dist/stack-converge.js +105 -2
  49. package/dist/stack-converge.js.map +1 -1
  50. package/dist/staging-gateway-setup.d.ts.map +1 -1
  51. package/dist/staging-gateway-setup.js +10 -5
  52. package/dist/staging-gateway-setup.js.map +1 -1
  53. package/dist/upgrade/admin-image-jobs.d.ts +4 -3
  54. package/dist/upgrade/admin-image-jobs.d.ts.map +1 -1
  55. package/dist/upgrade/admin-image-jobs.js +9 -16
  56. package/dist/upgrade/admin-image-jobs.js.map +1 -1
  57. package/dist/upgrade/app-roll.d.ts.map +1 -1
  58. package/dist/upgrade/app-roll.js +8 -7
  59. package/dist/upgrade/app-roll.js.map +1 -1
  60. package/dist/upgrade/converge.d.ts.map +1 -1
  61. package/dist/upgrade/converge.js +78 -50
  62. package/dist/upgrade/converge.js.map +1 -1
  63. package/dist/upgrader-iam-preflight.d.ts.map +1 -1
  64. package/dist/upgrader-iam-preflight.js +8 -18
  65. package/dist/upgrader-iam-preflight.js.map +1 -1
  66. package/dist/upgrader-setup.d.ts.map +1 -1
  67. package/dist/upgrader-setup.js +7 -15
  68. package/dist/upgrader-setup.js.map +1 -1
  69. package/dist/visitor-query-logs.d.ts +40 -0
  70. package/dist/visitor-query-logs.d.ts.map +1 -0
  71. package/dist/visitor-query-logs.js +41 -0
  72. package/dist/visitor-query-logs.js.map +1 -0
  73. package/dist/wizards/gcp-cost.d.ts.map +1 -1
  74. package/dist/wizards/gcp-cost.js +17 -9
  75. package/dist/wizards/gcp-cost.js.map +1 -1
  76. package/dist/wizards/gcp.d.ts.map +1 -1
  77. package/dist/wizards/gcp.js +45 -35
  78. package/dist/wizards/gcp.js.map +1 -1
  79. package/package.json +2 -2
  80. package/src/admin-memory.test.ts +57 -1
  81. package/src/cli.ts +23 -1
  82. package/src/collection-stores.ts +28 -0
  83. package/src/collections-setup.test.ts +237 -0
  84. package/src/collections-setup.ts +317 -0
  85. package/src/compose.ts +54 -1
  86. package/src/gateway-edge.test.ts +28 -0
  87. package/src/gateway-edge.ts +24 -0
  88. package/src/gateway-env-isolation.test.ts +141 -3
  89. package/src/gcp-names.ts +28 -84
  90. package/src/infra-contract.test.ts +5 -3
  91. package/src/infra-contract.ts +35 -1
  92. package/src/remote-mcp.test.ts +13 -1
  93. package/src/reporting-job-catalog.test.ts +156 -0
  94. package/src/reporting-job-catalog.ts +426 -0
  95. package/src/reporting-job-setup.test.ts +119 -6
  96. package/src/reporting-job-setup.ts +51 -158
  97. package/src/runtime-secrets.test.ts +19 -4
  98. package/src/runtime-secrets.ts +3 -0
  99. package/src/self-hosted-backup.test.ts +2 -2
  100. package/src/self-hosted-backup.ts +18 -6
  101. package/src/self-hosted-compose.test.ts +9 -3
  102. package/src/stack-contract.test.ts +62 -4
  103. package/src/stack-contract.ts +172 -59
  104. package/src/stack-converge-secrets.test.ts +4 -0
  105. package/src/stack-converge.test.ts +81 -3
  106. package/src/stack-converge.ts +124 -3
  107. package/src/staging-gateway-setup.test.ts +4 -0
  108. package/src/staging-gateway-setup.ts +16 -6
  109. package/src/upgrade/admin-image-jobs.ts +13 -25
  110. package/src/upgrade/app-roll.ts +7 -6
  111. package/src/upgrade/converge.ts +94 -77
  112. package/src/upgrade/upgrade.test.ts +97 -2
  113. package/src/upgrader-iam-preflight.ts +7 -20
  114. package/src/upgrader-job.test.ts +3 -0
  115. package/src/upgrader-setup.test.ts +3 -0
  116. package/src/upgrader-setup.ts +6 -17
  117. package/src/visitor-query-logs.ts +46 -0
  118. package/src/wizards/gcp-cost.ts +19 -9
  119. package/src/wizards/gcp.ts +51 -45
  120. package/stacks/aws/index.ts +18 -9
  121. package/stacks/azure/index.ts +19 -8
  122. package/stacks/gcp/index.ts +54 -1
  123. package/stacks/gcp-firebase/index.ts +28 -1
@@ -14,18 +14,36 @@ import { describe, expect, it } from "bun:test";
14
14
  import { existsSync } from "node:fs";
15
15
  import { join } from "node:path";
16
16
  import type { GcloudResult } from "./gcloud.js";
17
+ import type { GcloudRunner, Sleep } from "./gcloud-retry.js";
17
18
  import {
18
- auditRunnerJobSpec,
19
- buildCarrierJobSpec,
20
- ensureAuditRunnerJob,
21
- ensureBuildCarrierJob,
22
- ensureImportCrawlJob,
23
- importCrawlJobSpec,
19
+ type ReportingJobPlace,
20
+ reportingJobEntry,
21
+ reportingJobSpec,
22
+ } from "./reporting-job-catalog.js";
23
+ import {
24
+ ensureReportingJobKind,
24
25
  REPORTING_JOB_FORBIDDEN_ROLES,
25
26
  REPORTING_JOB_SCRIPT,
26
27
  type ReportingJobTarget,
27
28
  } from "./reporting-job-setup.js";
28
29
 
30
+ // #1646 — every kind is one catalog entry; these tests drive each through
31
+ // it, so the kinds from before the catalog must behave exactly as they did.
32
+ type Deps = { run?: GcloudRunner; sleep?: Sleep };
33
+ const ensureOf = (kind: string) => (t: ReportingJobTarget, d: Deps) =>
34
+ ensureReportingJobKind(reportingJobEntry(kind), t, d);
35
+ const specOf = (kind: string) => (p: Pick<ReportingJobPlace, "provider" | "env">) =>
36
+ reportingJobSpec(reportingJobEntry(kind), { projectId: "acme", region: "europe-west1", ...p });
37
+ const ensureAuditRunnerJob = ensureOf("quality_audit");
38
+ const ensureImportCrawlJob = ensureOf("site_import");
39
+ const ensureBuildCarrierJob = ensureOf("build");
40
+ const ensureCollectionIndexJob = ensureOf("collection_index");
41
+ const ensurePluginBatchJob = ensureOf("plugin_batch");
42
+ const auditRunnerJobSpec = (p: ReportingJobPlace) =>
43
+ reportingJobSpec(reportingJobEntry("quality_audit"), p);
44
+ const importCrawlJobSpec = specOf("site_import");
45
+ const buildCarrierJobSpec = specOf("build");
46
+
29
47
  const ok = (stdout = ""): GcloudResult => ({ ok: true, stdout, stderr: "", exitCode: 0 });
30
48
  const fail = (stderr: string): GcloudResult => ({ ok: false, stdout: "", stderr, exitCode: 1 });
31
49
 
@@ -390,3 +408,98 @@ describe("ensureBuildCarrierJob (#1574)", () => {
390
408
  expect(spec.runJobs).toEqual([]);
391
409
  });
392
410
  });
411
+
412
+ describe("the collection index job (epic #1644)", () => {
413
+ const INDEX_SA = "caelo-production-index@acme.iam.gserviceaccount.com";
414
+ const INDEX = `serviceAccount:${INDEX_SA}`;
415
+
416
+ it("grants the shared line plus read and create on the staging collection store, nothing of live", async () => {
417
+ const { run, calls } = fakeGcloud();
418
+ const r = await ensureCollectionIndexJob(TARGET, { run, sleep: async () => {} });
419
+ expect(r.ok).toBe(true);
420
+ const mine = grants(calls).filter((g) => g.member === INDEX);
421
+ expect(mine.map((g) => [g.where, g.role])).toEqual([
422
+ [
423
+ `iam service-accounts add-iam-policy-binding ${INDEX_SA}`,
424
+ "roles/iam.serviceAccountTokenCreator",
425
+ ],
426
+ ["projects add-iam-policy-binding acme", "roles/logging.logWriter"],
427
+ [
428
+ "iap web add-iam-policy-binding --resource-type=backend-services",
429
+ "roles/iap.httpsResourceAccessor",
430
+ ],
431
+ [
432
+ "storage buckets add-iam-policy-binding gs://acme-caelo-production-coll-staging",
433
+ "roles/storage.objectViewer",
434
+ ],
435
+ [
436
+ "storage buckets add-iam-policy-binding gs://acme-caelo-production-coll-staging",
437
+ "roles/storage.objectCreator",
438
+ ],
439
+ ]);
440
+ // objectCreator is forbidden but where a kind declares the bucket.
441
+ for (const g of mine.filter((g) => !g.where.endsWith("coll-staging"))) {
442
+ for (const forbidden of REPORTING_JOB_FORBIDDEN_ROLES) {
443
+ expect(g.role.startsWith(forbidden)).toBe(false);
444
+ }
445
+ }
446
+ expect(mine.some((g) => g.where.includes("coll-live"))).toBe(false);
447
+ expect(mine.some((g) => g.role === "roles/storage.objectAdmin")).toBe(false);
448
+ });
449
+
450
+ it("deploys on 2 vCPU / 4 GiB with the staging store and nothing else in its env", async () => {
451
+ const { run, calls } = fakeGcloud();
452
+ await ensureCollectionIndexJob(TARGET, { run, sleep: async () => {} });
453
+ const deploy = deployOf(calls);
454
+ expect(deploy.slice(0, 4)).toEqual(["run", "jobs", "deploy", "caelo-production-index"]);
455
+ expect(flag(deploy, "service-account")).toBe(INDEX_SA);
456
+ expect(flag(deploy, "cpu")).toBe("2");
457
+ expect(flag(deploy, "memory")).toBe("4Gi");
458
+ // admin-core JOB_TIMING.collection_index.maxRunSeconds.
459
+ expect(flag(deploy, "task-timeout")).toBe("3600s");
460
+ expect(flag(deploy, "set-env-vars")?.split(",").sort()).toEqual([
461
+ "CAELO_COLLECTIONS_STAGING_STORE=gs://acme-caelo-production-coll-staging",
462
+ "CAELO_PROVIDER=gcp",
463
+ ]);
464
+ for (const a of deploy) {
465
+ expect(a).not.toMatch(/^--(set|update)-secrets|^--(vpc-connector|network|subnet|vpc-egress)/);
466
+ }
467
+ });
468
+ });
469
+
470
+ describe("the plugin batch job (#1646)", () => {
471
+ const BATCH_SA = "caelo-production-plugin-batch@acme.iam.gserviceaccount.com";
472
+ const BATCH = `serviceAccount:${BATCH_SA}`;
473
+
474
+ it("holds exactly the shared line: no bucket, no other job, no secret", async () => {
475
+ const { run, calls } = fakeGcloud();
476
+ const r = await ensurePluginBatchJob(TARGET, { run, sleep: async () => {} });
477
+ expect(r.ok).toBe(true);
478
+ if (r.ok) expect(r.serviceAccount).toBe(BATCH_SA);
479
+ const mine = grants(calls).filter((g) => g.member === BATCH);
480
+ expect(mine.map((g) => g.role)).toEqual([
481
+ "roles/iam.serviceAccountTokenCreator",
482
+ "roles/logging.logWriter",
483
+ "roles/iap.httpsResourceAccessor",
484
+ ]);
485
+ for (const g of mine) {
486
+ for (const forbidden of REPORTING_JOB_FORBIDDEN_ROLES) {
487
+ expect(g.role.startsWith(forbidden)).toBe(false);
488
+ }
489
+ }
490
+ });
491
+
492
+ it("deploys the admin image (the sandbox runs inside it) on 1 vCPU / 2 GiB", async () => {
493
+ const { run, calls } = fakeGcloud();
494
+ await ensurePluginBatchJob(TARGET, { run, sleep: async () => {} });
495
+ const deploy = deployOf(calls);
496
+ expect(deploy.slice(0, 4)).toEqual(["run", "jobs", "deploy", "caelo-production-plugin-batch"]);
497
+ expect(flag(deploy, "image")).toBe(ADMIN_IMAGE);
498
+ expect(flag(deploy, "args")).toBe(`--bun,${REPORTING_JOB_SCRIPT}`);
499
+ expect(flag(deploy, "cpu")).toBe("1");
500
+ expect(flag(deploy, "memory")).toBe("2Gi");
501
+ expect(flag(deploy, "task-timeout")).toBe("3900s");
502
+ expect(flag(deploy, "set-env-vars")).toBe("CAELO_PROVIDER=gcp");
503
+ expect(flag(deploy, "max-retries")).toBe("0");
504
+ });
505
+ });
@@ -4,7 +4,8 @@
4
4
  * #1359 (#1140 category A) — set up (and converge) a reporting job on a
5
5
  * Google Cloud install (`gcp`, `gcp-firebase`): a Cloud Run job that runs
6
6
  * long, bounded work (a Stage's quality audit, #1359; a site import's crawl,
7
- * #1360) outside the admin and reports back to it by request, so the admin
7
+ * #1360; a Stage's collection index and a plugin's batch run, epic #1644)
8
+ * outside the admin and reports back to it by request, so the admin
8
9
  * only works inside requests (CLAUDE.md §11.B Tier 5) — or, the build
9
10
  * carrier (#1574), holds the request a build runs in. Run by the wizard
10
11
  * after `pulumi up` and by `cms-provision upgrade`'s converge (and the
@@ -24,9 +25,11 @@
24
25
  * operator-access sync job keeps it there, operator-access.ts);
25
26
  * - `roles/logging.logWriter`.
26
27
  *
27
- * plus its kind's own grants (the audit runner: {@link auditRunnerJobSpec};
28
- * the site-import crawler and the build carrier have none,
29
- * {@link importCrawlJobSpec}, {@link buildCarrierJobSpec}).
28
+ * plus its kind's own grants, declared by its entry in reporting-job-catalog.ts
29
+ * (the audit runner reads the staged build and the Lighthouse results and
30
+ * starts the Lighthouse tasks; the collection index job reads and creates
31
+ * files in the staging collection store; the site-import crawler, the build
32
+ * carrier and the plugin batch job have none).
30
33
  * Nothing else: no Secret Manager, no Cloud SQL, no VPC egress. Passing IAP
31
34
  * reaches nothing by itself: the admin's report endpoint takes a report of
32
35
  * a kind only from that kind's account AND with the token the admin minted
@@ -36,29 +39,29 @@
36
39
  * the job has none of. IAP access goes only to jobs that run no browser
37
40
  * and execute nothing they fetch; every render stays in the capture job
38
41
  * and the Lighthouse tasks, which have no IAP access (capture-job-setup.ts).
42
+ * The plugin batch job runs plugin code, but only an Owner-approved
43
+ * artifact, in the Deno sandbox (no network, no files, no env): the
44
+ * plugin reaches the admin only through the job's host side, report by
45
+ * report, never with the job's credential.
39
46
  *
40
47
  * The admin's run SA may run the job WITH overrides (it passes each
41
48
  * attempt's order: the work, the attempt, its token, the admin's URL) and
42
49
  * read its executions. {@link REPORTING_JOB_FORBIDDEN_ROLES} names the line;
43
- * the tests assert no grant crosses it.
50
+ * the tests assert no grant crosses it, but for the two reviewed exceptions
51
+ * a kind declares itself: the jobs it starts ({@link ReportingJobSpec.runJobs})
52
+ * and the buckets it creates files in ({@link ReportingJobSpec.writeBuckets}).
44
53
  */
45
54
 
46
55
  import { gcloud as defaultGcloud, type GcloudResult } from "./gcloud.js";
47
56
  import { type GcloudRunner, realSleep, runWithRetry, type Sleep } from "./gcloud-retry.js";
48
- import {
49
- auditJobName,
50
- auditJobResource,
51
- auditRunnerJobName,
52
- auditRunnerServiceAccountId,
53
- buildCarrierJobName,
54
- buildCarrierServiceAccountId,
55
- gcpBucketName,
56
- importCrawlJobName,
57
- importCrawlServiceAccountId,
58
- runServiceAccountEmail,
59
- } from "./gcp-names.js";
57
+ import { runServiceAccountEmail } from "./gcp-names.js";
60
58
  import { type IapResource, iapResourceArgs } from "./mcp-iap.js";
61
- import type { GcpProvider } from "./stack-contract.js";
59
+ import {
60
+ type ReportingJobKindEntry,
61
+ type ReportingJobPlace,
62
+ type ReportingJobSpec,
63
+ reportingJobSpec,
64
+ } from "./reporting-job-catalog.js";
62
65
 
63
66
  /** Where the admin image ships every reporting job's entry point. */
64
67
  export const REPORTING_JOB_SCRIPT = "/app/packages/admin-core/src/reporting-jobs/job-entry.ts";
@@ -67,7 +70,10 @@ export const REPORTING_JOB_SCRIPT = "/app/packages/admin-core/src/reporting-jobs
67
70
  * Roles a reporting job's identity must never hold anywhere. Prefix matches
68
71
  * (`roles/secretmanager.` = every Secret Manager role). `roles/run.` roles
69
72
  * are allowed only on a job a kind names in {@link ReportingJobSpec.runJobs}
70
- * (the audit runner starts the Lighthouse tasks); the tests assert that.
73
+ * (the audit runner starts the Lighthouse tasks), and
74
+ * `roles/storage.objectCreator` only on a bucket a kind names in
75
+ * {@link ReportingJobSpec.writeBuckets} (the collection index job writes
76
+ * its releases); the tests assert both.
71
77
  */
72
78
  export const REPORTING_JOB_FORBIDDEN_ROLES = [
73
79
  "roles/owner",
@@ -91,33 +97,8 @@ export const REPORTING_JOB_FORBIDDEN_ROLES = [
91
97
  "roles/run.invoker",
92
98
  ] as const;
93
99
 
94
- /** What one kind of reporting job needs beyond the shared grants. */
95
- export interface ReportingJobSpec {
96
- /** How the CLI names it ("quality-audit runner"). */
97
- readonly label: string;
98
- readonly jobName: string;
99
- readonly serviceAccountId: string;
100
- readonly displayName: string;
101
- readonly description: string;
102
- /** The job's env (`KEY=value`; never a secret). */
103
- readonly env: readonly string[];
104
- readonly cpu: string;
105
- readonly memory: string;
106
- /** One execution's ceiling (admin-core protocol.ts `JOB_TIMING.maxRunSeconds`). */
107
- readonly taskTimeoutSeconds: number;
108
- /** Read-only bucket access it needs, each with the reason. */
109
- readonly readBuckets: readonly { readonly bucket: string; readonly why: string }[];
110
- /** Jobs it starts itself, with its order as an override (and reads their executions). */
111
- readonly runJobs: readonly { readonly job: string; readonly why: string }[];
112
- }
113
-
114
100
  /** Where one install's reporting job goes. */
115
- export interface ReportingJobTarget {
116
- readonly provider: GcpProvider;
117
- readonly projectId: string;
118
- readonly region: string;
119
- /** Pulumi stack name (`production`). */
120
- readonly env: string;
101
+ export interface ReportingJobTarget extends ReportingJobPlace {
121
102
  /** The admin image the job runs, digest-pinned (`…/admin@sha256:…`). */
122
103
  readonly adminImageRef: string;
123
104
  /** The admin's IAP resource (the service on gcp-firebase, the LB backend on gcp). */
@@ -128,100 +109,6 @@ export type ReportingJobResult =
128
109
  | { readonly ok: true; readonly done: string[]; readonly serviceAccount: string }
129
110
  | { readonly ok: false; readonly done: string[]; readonly error: string };
130
111
 
131
- /**
132
- * The audit runner (#1359): the whole quality audit of a Stage. It serves
133
- * the staged build from its staging slot to its own findings checks, starts
134
- * the Lighthouse tasks on the audit job (#875) and reads their results.
135
- */
136
- export function auditRunnerJobSpec(
137
- target: Pick<ReportingJobTarget, "provider" | "projectId" | "region" | "env">,
138
- ): ReportingJobSpec {
139
- const { projectId, region, env, provider } = target;
140
- const staging = gcpBucketName(projectId, env, "staging");
141
- const results = gcpBucketName(projectId, env, "audit-results");
142
- return {
143
- label: "quality-audit runner",
144
- jobName: auditRunnerJobName(env),
145
- serviceAccountId: auditRunnerServiceAccountId(env),
146
- displayName: "Caelo quality-audit runner",
147
- description:
148
- "Runs a Stage's quality audit and reports to the admin; reads the staged build and the Lighthouse results, starts the Lighthouse tasks, nothing else.",
149
- env: [
150
- `CAELO_PROVIDER=${provider}`,
151
- `CAELO_STAGING_BUCKET=${staging}`,
152
- `CAELO_AUDIT_JOB=${auditJobResource(projectId, region, env)}`,
153
- `CAELO_AUDIT_RESULTS_BUCKET=${results}`,
154
- ],
155
- cpu: "1",
156
- memory: "2Gi",
157
- // admin-core JOB_TIMING.quality_audit.maxRunSeconds.
158
- taskTimeoutSeconds: 3600,
159
- readBuckets: [
160
- { bucket: staging, why: "it serves the staged build to the findings checks" },
161
- { bucket: results, why: "it reads the Lighthouse tasks' results" },
162
- ],
163
- runJobs: [{ job: auditJobName(env), why: "it starts the Lighthouse tasks" }],
164
- };
165
- }
166
-
167
- /**
168
- * The site-import crawler (#1360): one site import's crawl. It reads
169
- * third-party pages, so it holds nothing beyond the shared grants: no
170
- * bucket, no other job. It fetches robots.txt and sitemaps itself, through
171
- * the SSRF guard; every page render is the admin's, which starts the
172
- * capture job and keeps the screenshot, so the crawler never runs a
173
- * browser and never touches the capture job or its bucket.
174
- */
175
- export function importCrawlJobSpec(
176
- target: Pick<ReportingJobTarget, "provider" | "env">,
177
- ): ReportingJobSpec {
178
- return {
179
- label: "site-import crawler",
180
- jobName: importCrawlJobName(target.env),
181
- serviceAccountId: importCrawlServiceAccountId(target.env),
182
- displayName: "Caelo site-import crawler",
183
- description:
184
- "Crawls a site the Owner approved for import and reports each page to the admin; fetches robots.txt and sitemaps through the SSRF guard, nothing else.",
185
- env: [`CAELO_PROVIDER=${target.provider}`],
186
- cpu: "1",
187
- // The frontier and up to four rendered pages' HTML at once.
188
- memory: "2Gi",
189
- // admin-core JOB_TIMING.site_import.maxRunSeconds: a longer crawl goes
190
- // on in the next attempt, from its checkpoint.
191
- taskTimeoutSeconds: 6 * 3600,
192
- readBuckets: [],
193
- runJobs: [],
194
- };
195
- }
196
-
197
- /**
198
- * The build carrier (#1574): one Stage's, Publish live's or production
199
- * build's request. It sends one report, `run`, and the admin runs the build
200
- * inside that request on its own database and rights, so the carrier holds
201
- * nothing beyond the shared grants: it reads nothing, fetches nothing,
202
- * builds nothing. Smallest machine: it only waits for the answer.
203
- */
204
- export function buildCarrierJobSpec(
205
- target: Pick<ReportingJobTarget, "provider" | "env">,
206
- ): ReportingJobSpec {
207
- return {
208
- label: "build carrier",
209
- jobName: buildCarrierJobName(target.env),
210
- serviceAccountId: buildCarrierServiceAccountId(target.env),
211
- displayName: "Caelo build carrier",
212
- description:
213
- "Holds the admin request a Stage, Publish live or production build runs in, so the build ends when nobody waits for it; reports to the admin, nothing else.",
214
- env: [`CAELO_PROVIDER=${target.provider}`],
215
- cpu: "1",
216
- memory: "512Mi",
217
- // admin-core JOB_TIMING.build.maxRunSeconds: the admin's request limit
218
- // (the build stops two minutes before it) plus room to start and end.
219
- taskTimeoutSeconds: 3600 + 5 * 60,
220
- readBuckets: [],
221
- runJobs: [],
222
- };
223
- }
224
-
225
112
  /** Ensure a reporting job and everything it needs. Never throws for a gcloud failure. */
226
113
  export async function ensureReportingJob(
227
114
  target: ReportingJobTarget,
@@ -342,6 +229,24 @@ export async function ensureReportingJob(
342
229
  done.push(`${spec.label}: roles/storage.objectViewer on gs://${b.bucket}`);
343
230
  }
344
231
 
232
+ // 5b. Where its kind creates files (create only: no overwrite, no delete).
233
+ for (const b of spec.writeBuckets) {
234
+ const r = await retry([
235
+ "storage",
236
+ "buckets",
237
+ "add-iam-policy-binding",
238
+ `gs://${b.bucket}`,
239
+ `--member=${member}`,
240
+ "--role=roles/storage.objectCreator",
241
+ "--condition=None",
242
+ project,
243
+ "--quiet",
244
+ "--format=none",
245
+ ]);
246
+ if (!r.ok) return fail(`grant roles/storage.objectCreator on gs://${b.bucket} (${b.why})`, r);
247
+ done.push(`${spec.label}: roles/storage.objectCreator on gs://${b.bucket}`);
248
+ }
249
+
345
250
  // 6. The jobs its kind starts.
346
251
  for (const j of spec.runJobs) {
347
252
  for (const role of ["roles/run.jobsExecutorWithOverrides", "roles/run.viewer"]) {
@@ -406,26 +311,14 @@ export async function ensureReportingJob(
406
311
  return { ok: true, done, serviceAccount: sa };
407
312
  }
408
313
 
409
- /** Ensure the quality-audit runner (#1359). */
410
- export function ensureAuditRunnerJob(
411
- target: ReportingJobTarget,
412
- deps: { run?: GcloudRunner; sleep?: Sleep } = {},
413
- ): Promise<ReportingJobResult> {
414
- return ensureReportingJob(target, auditRunnerJobSpec(target), deps);
415
- }
416
-
417
- /** Ensure the site-import crawler (#1360). */
418
- export function ensureImportCrawlJob(
419
- target: ReportingJobTarget,
420
- deps: { run?: GcloudRunner; sleep?: Sleep } = {},
421
- ): Promise<ReportingJobResult> {
422
- return ensureReportingJob(target, importCrawlJobSpec(target), deps);
423
- }
424
-
425
- /** Ensure the build carrier (#1574). */
426
- export function ensureBuildCarrierJob(
314
+ /**
315
+ * Ensure the job of one catalog kind (reporting-job-catalog.ts): what the
316
+ * wizard and every converge run for each entry, in catalog order.
317
+ */
318
+ export function ensureReportingJobKind(
319
+ entry: ReportingJobKindEntry,
427
320
  target: ReportingJobTarget,
428
321
  deps: { run?: GcloudRunner; sleep?: Sleep } = {},
429
322
  ): Promise<ReportingJobResult> {
430
- return ensureReportingJob(target, buildCarrierJobSpec(target), deps);
323
+ return ensureReportingJob(target, reportingJobSpec(entry, target), deps);
431
324
  }
@@ -115,7 +115,7 @@ describe("ensureGeneratedSecrets", () => {
115
115
  { ...secretsInstall, replication: regional },
116
116
  { run },
117
117
  );
118
- expect(outcomes.map((o) => o.status)).toEqual(Array(7).fill("present"));
118
+ expect(outcomes.map((o) => o.status)).toEqual(Array(9).fill("present"));
119
119
  expect(lines().some((l) => l.includes(" create ") || l.includes(" add "))).toBe(false);
120
120
  });
121
121
 
@@ -126,7 +126,7 @@ describe("ensureGeneratedSecrets", () => {
126
126
  { ...secretsInstall, replication: regional },
127
127
  { run, generate: () => `generated-value-${++n}` },
128
128
  );
129
- expect(outcomes.map((o) => o.status)).toEqual(Array(7).fill("applied"));
129
+ expect(outcomes.map((o) => o.status)).toEqual(Array(9).fill("applied"));
130
130
  const creates = calls.filter((c) => c.line.startsWith("secrets create"));
131
131
  // #806 — the seal key is 32 random bytes in base64 (not the injected hex generator).
132
132
  const sealKey = creates.find((c) => c.line.includes("mcp-oauth-seal-key"))?.stdin ?? "";
@@ -165,6 +165,15 @@ describe("ensureGeneratedSecrets", () => {
165
165
  line: "secrets create caelo-production-mcp-oauth-seal-key --project=acme --replication-policy=user-managed --locations=europe-west1 --data-file=- --quiet",
166
166
  stdin: sealKey,
167
167
  },
168
+ // #1654 — the visitor AI's keys start as "no key"; the Owner adds one.
169
+ {
170
+ line: "secrets create caelo-production-visitor-ai-key --project=acme --replication-policy=user-managed --locations=europe-west1 --data-file=- --quiet",
171
+ stdin: "{}",
172
+ },
173
+ {
174
+ line: "secrets create caelo-production-visitor-ai-staging-key --project=acme --replication-policy=user-managed --locations=europe-west1 --data-file=- --quiet",
175
+ stdin: "{}",
176
+ },
168
177
  ]);
169
178
  for (const c of calls) expect(c.line).not.toContain("generated-value");
170
179
  });
@@ -204,6 +213,8 @@ describe("ensureGeneratedSecrets", () => {
204
213
  "secrets versions list caelo-production-staging-gate-secret": [ok("v/1")],
205
214
  "secrets versions list caelo-production-operator-oauth-client": [ok("v/1")],
206
215
  "secrets versions list caelo-production-mcp-oauth-seal-key": [ok("v/1")],
216
+ "secrets versions list caelo-production-visitor-ai-key": [ok("v/1")],
217
+ "secrets versions list caelo-production-visitor-ai-staging-key": [ok("v/1")],
207
218
  });
208
219
  const outcomes = await ensureGeneratedSecrets(
209
220
  { ...secretsInstall, replication: { kind: "automatic" } },
@@ -217,6 +228,8 @@ describe("ensureGeneratedSecrets", () => {
217
228
  "present",
218
229
  "present",
219
230
  "present",
231
+ "present",
232
+ "present",
220
233
  ]);
221
234
  expect(calls.filter((c) => c.line.startsWith("secrets versions add"))).toEqual([
222
235
  {
@@ -251,7 +264,7 @@ describe("ensureGeneratedSecrets", () => {
251
264
  { ...secretsInstall, replication: { kind: "automatic" } },
252
265
  { run, generate: () => "v" },
253
266
  );
254
- expect(outcomes.map((o) => o.status)).toEqual(Array(7).fill("applied"));
267
+ expect(outcomes.map((o) => o.status)).toEqual(Array(9).fill("applied"));
255
268
  expect(outcomes.every((o) => o.detail?.includes("gcp.resourceLocations"))).toBe(true);
256
269
  const creates = lines().filter((l) => l.startsWith("secrets create"));
257
270
  // One refused automatic attempt; then every secret — the refused one
@@ -266,6 +279,8 @@ describe("ensureGeneratedSecrets", () => {
266
279
  "secrets create caelo-production-staging-gate-secret --project=acme --replication-policy=user-managed --locations=europe-west1 --data-file=- --quiet",
267
280
  "secrets create caelo-production-operator-oauth-client --project=acme --replication-policy=user-managed --locations=europe-west1 --data-file=- --quiet",
268
281
  "secrets create caelo-production-mcp-oauth-seal-key --project=acme --replication-policy=user-managed --locations=europe-west1 --data-file=- --quiet",
282
+ "secrets create caelo-production-visitor-ai-key --project=acme --replication-policy=user-managed --locations=europe-west1 --data-file=- --quiet",
283
+ "secrets create caelo-production-visitor-ai-staging-key --project=acme --replication-policy=user-managed --locations=europe-west1 --data-file=- --quiet",
269
284
  ]);
270
285
  });
271
286
 
@@ -293,7 +308,7 @@ describe("ensureGeneratedSecrets", () => {
293
308
  { run, generate: () => "v" },
294
309
  );
295
310
  expect(outcomes.every((o) => o.status === "failed")).toBe(true);
296
- expect(lines().filter((l) => l.startsWith("secrets create"))).toHaveLength(7);
311
+ expect(lines().filter((l) => l.startsWith("secrets create"))).toHaveLength(9);
297
312
  });
298
313
  });
299
314
 
@@ -483,6 +483,9 @@ export function rotationRefusal(name: string): string | null {
483
483
  if (name === "operator-oauth-client") {
484
484
  return "operator-oauth-client is the install's Google sign-in client (IAP sign-in and remote MCP); the Owner replaces it under Settings → Google sign-in (create a new client secret in the Google console first).";
485
485
  }
486
+ if (name === "visitor-ai-key" || name === "visitor-ai-staging-key") {
487
+ return `${name} holds the visitor AI's provider key, which the Owner sets: rotate it under Settings → Visitor AI (create a new key at the provider first, then revoke the old one there).`;
488
+ }
486
489
  if (name === "secret-kek") {
487
490
  return "secret-kek encrypts the AI provider keys and other at-rest secrets in cms_admin; a new KEK would make them unreadable. Rotating it needs a re-encryption step that does not exist yet.";
488
491
  }
@@ -113,7 +113,7 @@ describe("backupSelfHosted", () => {
113
113
  "exec -T postgres pg_dumpall -U caelo --globals-only",
114
114
  "exec -T postgres pg_dump -U caelo -Fc cms_admin",
115
115
  "exec -T postgres pg_dump -U caelo -Fc cms_public",
116
- "run --rm --no-deps -T --entrypoint tar caelo-admin -C / -cf - srv/caelo data/media",
116
+ "run --rm --no-deps -T --entrypoint tar caelo-admin -C / -cf - srv/caelo data/media data/collections/staging data/collections/live",
117
117
  "up -d caelo-admin caelo-gateway caelo-staging-gateway",
118
118
  "exec -T caelo-admin bun -e <probe>",
119
119
  "exec -T caelo-gateway bun -e <probe>",
@@ -206,7 +206,7 @@ describe("restoreSelfHosted", () => {
206
206
  `${MIGRATE} admin`,
207
207
  `${MIGRATE} public`,
208
208
  `${MIGRATE} public-staging`,
209
- "run --rm --no-deps -T --entrypoint sh caelo-admin -c set -e; find /srv/caelo /data/media -mindepth 1 -delete; tar -C / -xf -",
209
+ "run --rm --no-deps -T --entrypoint sh caelo-admin -c set -e; find /srv/caelo /data/media /data/collections/staging /data/collections/live -mindepth 1 -delete; tar -C / -xf -",
210
210
  "up -d --remove-orphans",
211
211
  "exec -T caelo-admin bun -e <probe>",
212
212
  "exec -T caelo-gateway bun -e <probe>",
@@ -10,9 +10,10 @@
10
10
  * db/cms_admin.dump pg_dump -Fc (the same dumps `upgrade` takes)
11
11
  * db/cms_public.dump
12
12
  * db/globals.sql the cluster's roles — reference only, see restore
13
- * files.tar the published site (`/srv/caelo`) and the uploaded
14
- * media (`/data/media`), read through the admin's
15
- * own mounts
13
+ * files.tar the published site (`/srv/caelo`), the uploaded
14
+ * media (`/data/media`) and the plugin collection
15
+ * stores (`/data/collections/{staging,live}`, epic
16
+ * #1644), read through the admin's own mounts
16
17
  * Secrets (`.caelo/config.json`, incl. the KEK that decrypts stored
17
18
  * provider keys) are NOT in the archive: it may be copied off-host, and a
18
19
  * restore targets the install whose config is already there.
@@ -54,7 +55,7 @@ import {
54
55
  } from "node:fs";
55
56
  import { basename, join } from "node:path";
56
57
  import { gunzipSync } from "node:zlib";
57
- import { COMPOSE_APP_SERVICES, MEDIA_ROOT, SITE_OUTPUT_ROOT } from "./compose.js";
58
+ import { COLLECTIONS_ROOT, COMPOSE_APP_SERVICES, MEDIA_ROOT, SITE_OUTPUT_ROOT } from "./compose.js";
58
59
  import type { HostRunner } from "./self-hosted-release.js";
59
60
  import type { ConvergeOutcome } from "./self-hosted-roles.js";
60
61
  import {
@@ -73,8 +74,19 @@ const MANIFEST = "manifest.json";
73
74
  const DB_DIR = "db";
74
75
  const FILES_TAR = "files.tar";
75
76
 
76
- /** The content directories inside the admin container, as `tar -C /` paths. */
77
- const CONTENT_PATHS = [SITE_OUTPUT_ROOT, MEDIA_ROOT].map((p) => p.replace(/^\//, ""));
77
+ /**
78
+ * The content directories inside the admin container, as `tar -C /` paths.
79
+ * Epic #1644 — the collection stores go with the site they were published
80
+ * with: the restored databases name the releases they hold. Each store is
81
+ * its own path, so a restore empties it and keeps the directory the
82
+ * gateways mount.
83
+ */
84
+ const CONTENT_PATHS = [
85
+ SITE_OUTPUT_ROOT,
86
+ MEDIA_ROOT,
87
+ `${COLLECTIONS_ROOT}/staging`,
88
+ `${COLLECTIONS_ROOT}/live`,
89
+ ].map((p) => p.replace(/^\//, ""));
78
90
 
79
91
  export interface BackupManifest {
80
92
  readonly format: number;
@@ -145,12 +145,14 @@ describe("self-hosted Compose — release images (#696)", () => {
145
145
  it("mounts the bootstrap-token, site output + media dirs, never .caelo/ with its secrets", () => {
146
146
  const admin = service(yaml, "caelo-admin");
147
147
  expect(admin).toContain(
148
- " volumes:\n - ./bootstrap:/app/.caelo\n - ./output:/srv/caelo\n - ./media:/data/media\n - ./postgres-tls/ca.crt:/etc/caelo/db-ca/self-hosted-ca.pem:ro",
148
+ " volumes:\n - ./bootstrap:/app/.caelo\n - ./output:/srv/caelo\n - ./media:/data/media\n - ./collections:/data/collections\n - ./visitor-ai:/data/visitor-ai\n - ./postgres-tls/ca.crt:/etc/caelo/db-ca/self-hosted-ca.pem:ro",
149
149
  );
150
150
  expect(yaml).not.toMatch(/- \.\/?:/);
151
- // The gateway mounts the database CA (#1338) and nothing else.
151
+ // The gateway mounts the database CA (#1338), the live collection store
152
+ // (epic #1644) and the live site's visitor-AI key directory (#1654),
153
+ // all read-only, nothing else.
152
154
  expect(service(yaml, "caelo-gateway")).toContain(
153
- " volumes:\n - ./postgres-tls/ca.crt:/etc/caelo/db-ca/self-hosted-ca.pem:ro\n restart:",
155
+ " volumes:\n - ./postgres-tls/ca.crt:/etc/caelo/db-ca/self-hosted-ca.pem:ro\n - ./collections/live:/srv/collections/live:ro\n - ./visitor-ai/live:/secrets/visitor-ai:ro\n restart:",
154
156
  );
155
157
  expect(admin).toContain('CAELO_OUTPUT_ROOT: "/srv/caelo"');
156
158
  expect(admin).toContain('MEDIA_ROOT_DIR: "/data/media"');
@@ -196,8 +198,12 @@ describe("self-hosted Compose — release images (#696)", () => {
196
198
  "Caddyfile",
197
199
  "bootstrap",
198
200
  "bootstrap.sh",
201
+ // Epic #1644 — `up` creates collections/staging and collections/live.
202
+ "collections",
199
203
  "media",
200
204
  "output",
205
+ // #1654 — `up` creates visitor-ai/live and visitor-ai/staging with `{}`.
206
+ "visitor-ai",
201
207
  ]);
202
208
  });
203
209