@caelo-cms/provisioning 0.12.10 → 0.12.12

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 (131) 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 +25 -0
  37. package/dist/runtime-secrets.d.ts.map +1 -1
  38. package/dist/runtime-secrets.js +34 -0
  39. package/dist/runtime-secrets.js.map +1 -1
  40. package/dist/self-hosted-backup.d.ts.map +1 -1
  41. package/dist/self-hosted-backup.js +18 -6
  42. package/dist/self-hosted-backup.js.map +1 -1
  43. package/dist/stack-contract.d.ts +75 -22
  44. package/dist/stack-contract.d.ts.map +1 -1
  45. package/dist/stack-contract.js +142 -51
  46. package/dist/stack-contract.js.map +1 -1
  47. package/dist/stack-converge.d.ts +20 -1
  48. package/dist/stack-converge.d.ts.map +1 -1
  49. package/dist/stack-converge.js +105 -2
  50. package/dist/stack-converge.js.map +1 -1
  51. package/dist/staging-gateway-setup.d.ts.map +1 -1
  52. package/dist/staging-gateway-setup.js +10 -5
  53. package/dist/staging-gateway-setup.js.map +1 -1
  54. package/dist/upgrade/admin-image-jobs.d.ts +4 -3
  55. package/dist/upgrade/admin-image-jobs.d.ts.map +1 -1
  56. package/dist/upgrade/admin-image-jobs.js +9 -16
  57. package/dist/upgrade/admin-image-jobs.js.map +1 -1
  58. package/dist/upgrade/app-roll.d.ts +16 -0
  59. package/dist/upgrade/app-roll.d.ts.map +1 -1
  60. package/dist/upgrade/app-roll.js +35 -23
  61. package/dist/upgrade/app-roll.js.map +1 -1
  62. package/dist/upgrade/converge.d.ts +1 -1
  63. package/dist/upgrade/converge.d.ts.map +1 -1
  64. package/dist/upgrade/converge.js +83 -87
  65. package/dist/upgrade/converge.js.map +1 -1
  66. package/dist/upgrade/upgrade.d.ts +7 -5
  67. package/dist/upgrade/upgrade.d.ts.map +1 -1
  68. package/dist/upgrade/upgrade.js +31 -14
  69. package/dist/upgrade/upgrade.js.map +1 -1
  70. package/dist/upgrader-iam-preflight.d.ts.map +1 -1
  71. package/dist/upgrader-iam-preflight.js +8 -18
  72. package/dist/upgrader-iam-preflight.js.map +1 -1
  73. package/dist/upgrader-setup.d.ts.map +1 -1
  74. package/dist/upgrader-setup.js +7 -15
  75. package/dist/upgrader-setup.js.map +1 -1
  76. package/dist/visitor-query-logs.d.ts +40 -0
  77. package/dist/visitor-query-logs.d.ts.map +1 -0
  78. package/dist/visitor-query-logs.js +41 -0
  79. package/dist/visitor-query-logs.js.map +1 -0
  80. package/dist/wizards/gcp-cost.d.ts.map +1 -1
  81. package/dist/wizards/gcp-cost.js +17 -9
  82. package/dist/wizards/gcp-cost.js.map +1 -1
  83. package/dist/wizards/gcp.d.ts.map +1 -1
  84. package/dist/wizards/gcp.js +45 -35
  85. package/dist/wizards/gcp.js.map +1 -1
  86. package/package.json +2 -2
  87. package/src/admin-memory.test.ts +57 -1
  88. package/src/cli.ts +23 -1
  89. package/src/collection-stores.ts +28 -0
  90. package/src/collections-setup.test.ts +237 -0
  91. package/src/collections-setup.ts +317 -0
  92. package/src/compose.ts +54 -1
  93. package/src/gateway-edge.test.ts +28 -0
  94. package/src/gateway-edge.ts +24 -0
  95. package/src/gateway-env-isolation.test.ts +141 -3
  96. package/src/gcp-names.ts +28 -84
  97. package/src/infra-contract.test.ts +5 -3
  98. package/src/infra-contract.ts +35 -1
  99. package/src/remote-mcp.test.ts +13 -1
  100. package/src/reporting-job-catalog.test.ts +156 -0
  101. package/src/reporting-job-catalog.ts +426 -0
  102. package/src/reporting-job-setup.test.ts +119 -6
  103. package/src/reporting-job-setup.ts +51 -158
  104. package/src/runtime-secrets.test.ts +19 -4
  105. package/src/runtime-secrets.ts +42 -0
  106. package/src/self-hosted-backup.test.ts +2 -2
  107. package/src/self-hosted-backup.ts +18 -6
  108. package/src/self-hosted-compose.test.ts +9 -3
  109. package/src/stack-contract.test.ts +62 -4
  110. package/src/stack-contract.ts +172 -59
  111. package/src/stack-converge-secrets.test.ts +4 -0
  112. package/src/stack-converge.test.ts +81 -3
  113. package/src/stack-converge.ts +124 -3
  114. package/src/staging-gateway-setup.test.ts +4 -0
  115. package/src/staging-gateway-setup.ts +16 -6
  116. package/src/upgrade/admin-image-jobs.ts +13 -25
  117. package/src/upgrade/app-roll.ts +54 -28
  118. package/src/upgrade/converge.ts +100 -122
  119. package/src/upgrade/upgrade.test.ts +159 -6
  120. package/src/upgrade/upgrade.ts +46 -32
  121. package/src/upgrader-iam-preflight.ts +7 -20
  122. package/src/upgrader-job.test.ts +3 -0
  123. package/src/upgrader-setup.test.ts +3 -0
  124. package/src/upgrader-setup.ts +6 -17
  125. package/src/visitor-query-logs.ts +46 -0
  126. package/src/wizards/gcp-cost.ts +19 -9
  127. package/src/wizards/gcp.ts +51 -45
  128. package/stacks/aws/index.ts +18 -9
  129. package/stacks/azure/index.ts +19 -8
  130. package/stacks/gcp/index.ts +54 -1
  131. package/stacks/gcp-firebase/index.ts +28 -1
@@ -103,6 +103,10 @@ describe("adminEnvContract", () => {
103
103
  CAELO_OPERATOR_ACCESS_JOB:
104
104
  "projects/acme/locations/europe-west1/jobs/caelo-production-operator-access-sync",
105
105
  CAELO_UPGRADER_JOB: "projects/acme/locations/europe-west1/jobs/caelo-production-upgrader",
106
+ // #1654 — where the Owner's visitor-AI keys are added; never read.
107
+ CAELO_VISITOR_AI_KEY_STORE: "projects/acme/secrets/caelo-production-visitor-ai-key",
108
+ CAELO_VISITOR_AI_STAGING_KEY_STORE:
109
+ "projects/acme/secrets/caelo-production-visitor-ai-staging-key",
106
110
  CAELO_CONVERGE_JOB: "projects/acme/locations/europe-west1/jobs/caelo-production-converge",
107
111
  CAELO_AUDIT_JOB: "projects/acme/locations/europe-west1/jobs/caelo-production-audit",
108
112
  CAELO_AUDIT_RESULTS_BUCKET: "acme-caelo-production-audit-results",
@@ -118,6 +122,17 @@ describe("adminEnvContract", () => {
118
122
  // #1574 — and for the build carrier.
119
123
  CAELO_BUILD_CARRIER_JOB: "projects/acme/locations/europe-west1/jobs/caelo-production-build",
120
124
  CAELO_BUILD_CARRIER_SERVICE_ACCOUNT: "caelo-production-build@acme.iam.gserviceaccount.com",
125
+ // Epic #1644 — the collection index job and the plugin batch job
126
+ // (reporting-job-catalog.ts), and both collection stores.
127
+ CAELO_COLLECTION_INDEX_JOB:
128
+ "projects/acme/locations/europe-west1/jobs/caelo-production-index",
129
+ CAELO_COLLECTION_INDEX_SERVICE_ACCOUNT: "caelo-production-index@acme.iam.gserviceaccount.com",
130
+ CAELO_PLUGIN_BATCH_JOB:
131
+ "projects/acme/locations/europe-west1/jobs/caelo-production-plugin-batch",
132
+ CAELO_PLUGIN_BATCH_SERVICE_ACCOUNT:
133
+ "caelo-production-plugin-batch@acme.iam.gserviceaccount.com",
134
+ CAELO_COLLECTIONS_STAGING_STORE: "gs://acme-caelo-production-coll-staging",
135
+ CAELO_COLLECTIONS_LIVE_STORE: "gs://acme-caelo-production-coll-live",
121
136
  CAELO_STATIC_BUCKET: "acme-caelo-production-static",
122
137
  CAELO_STAGING_BUCKET: "acme-caelo-production-staging",
123
138
  // #1330 — every provider serves staging at its own host now.
@@ -161,6 +176,10 @@ describe("adminEnvContract", () => {
161
176
  CAELO_OPERATOR_ACCESS_JOB:
162
177
  "projects/acme/locations/europe-west1/jobs/caelo-production-operator-access-sync",
163
178
  CAELO_UPGRADER_JOB: "projects/acme/locations/europe-west1/jobs/caelo-production-upgrader",
179
+ // #1654 — where the Owner's visitor-AI keys are added; never read.
180
+ CAELO_VISITOR_AI_KEY_STORE: "projects/acme/secrets/caelo-production-visitor-ai-key",
181
+ CAELO_VISITOR_AI_STAGING_KEY_STORE:
182
+ "projects/acme/secrets/caelo-production-visitor-ai-staging-key",
164
183
  CAELO_CONVERGE_JOB: "projects/acme/locations/europe-west1/jobs/caelo-production-converge",
165
184
  CAELO_AUDIT_JOB: "projects/acme/locations/europe-west1/jobs/caelo-production-audit",
166
185
  CAELO_AUDIT_RESULTS_BUCKET: "acme-caelo-production-audit-results",
@@ -176,6 +195,17 @@ describe("adminEnvContract", () => {
176
195
  // #1574 — and for the build carrier.
177
196
  CAELO_BUILD_CARRIER_JOB: "projects/acme/locations/europe-west1/jobs/caelo-production-build",
178
197
  CAELO_BUILD_CARRIER_SERVICE_ACCOUNT: "caelo-production-build@acme.iam.gserviceaccount.com",
198
+ // Epic #1644 — the collection index job and the plugin batch job
199
+ // (reporting-job-catalog.ts), and both collection stores.
200
+ CAELO_COLLECTION_INDEX_JOB:
201
+ "projects/acme/locations/europe-west1/jobs/caelo-production-index",
202
+ CAELO_COLLECTION_INDEX_SERVICE_ACCOUNT: "caelo-production-index@acme.iam.gserviceaccount.com",
203
+ CAELO_PLUGIN_BATCH_JOB:
204
+ "projects/acme/locations/europe-west1/jobs/caelo-production-plugin-batch",
205
+ CAELO_PLUGIN_BATCH_SERVICE_ACCOUNT:
206
+ "caelo-production-plugin-batch@acme.iam.gserviceaccount.com",
207
+ CAELO_COLLECTIONS_STAGING_STORE: "gs://acme-caelo-production-coll-staging",
208
+ CAELO_COLLECTIONS_LIVE_STORE: "gs://acme-caelo-production-coll-live",
179
209
  CAELO_FIREBASE_SITE: "caelo-production-site-abc123",
180
210
  CAELO_GATEWAY_SERVICE: "caelo-production-gateway-1a2b3c4",
181
211
  CAELO_GATEWAY_REGION: "europe-west1",
@@ -236,9 +266,13 @@ describe("gatewayEnvContract", () => {
236
266
  CAELO_TRUSTED_PROXY_HOPS: "2",
237
267
  PUBLIC_DATABASE_URL:
238
268
  "postgresql://public_role@db1.p-label.europe-west1.sql-psa.goog:5432/cms_public?sslmode=verify-full&sslrootcert=/etc/caelo/db-ca/cloudsql-global.pem",
269
+ // Epic #1644 — the live collection store, never the staging one.
270
+ CAELO_COLLECTIONS_LIVE_STORE: "gs://acme-caelo-production-coll-live",
239
271
  // The only account whose refresh pings it takes: the admin's runtime
240
272
  // account. An identity, nothing secret.
241
273
  CAELO_GATEWAY_REFRESH_ACCOUNT: "caelo-production-run-sa@acme.iam.gserviceaccount.com",
274
+ // #1654 — the live site's visitor-AI key, a file only this gateway mounts.
275
+ CAELO_VISITOR_AI_KEY_FILE: "/secrets/visitor-ai/key.json",
242
276
  PUBLIC_DATABASE_PASSWORD: "secret:caelo-production-public-role-password:latest",
243
277
  // No remote-MCP env: the broker is the MCP-Auth-Proxy's (#1328); no
244
278
  // staging gate key: the staging gateway's, through its projection (#1330).
@@ -269,7 +303,11 @@ describe("gatewayEnvContract", () => {
269
303
  PUBLIC_DATABASE_URL:
270
304
  "postgresql://public_staging_role@db1.p-label.europe-west1.sql-psa.goog:5432/cms_public_staging?sslmode=verify-full&sslrootcert=/etc/caelo/db-ca/cloudsql-global.pem",
271
305
  CAELO_STAGING_STORAGE: "gs://acme-caelo-production-staging",
306
+ // Epic #1644 — the staging collection store, never the live one.
307
+ CAELO_COLLECTIONS_STAGING_STORE: "gs://acme-caelo-production-coll-staging",
272
308
  CAELO_GATEWAY_REFRESH_ACCOUNT: "caelo-production-run-sa@acme.iam.gserviceaccount.com",
309
+ // #1654 — staging's own key file (its own secret), at the same path.
310
+ CAELO_VISITOR_AI_KEY_FILE: "/secrets/visitor-ai/key.json",
273
311
  PUBLIC_DATABASE_PASSWORD: "secret:caelo-production-public-staging-role-password:latest",
274
312
  });
275
313
  }
@@ -286,7 +324,11 @@ describe("gatewayEnvContract", () => {
286
324
  });
287
325
 
288
326
  it("shares no secret with the live gateway and reads exactly its own login", () => {
289
- expect(serviceSecrets("staging-gateway")).toEqual(["public-staging-role-password"]);
327
+ expect(serviceSecrets("staging-gateway")).toEqual([
328
+ "public-staging-role-password",
329
+ // #1654 — staging's own visitor-AI key: never the live one's secret.
330
+ "visitor-ai-staging-key",
331
+ ]);
290
332
  const live = new Set(serviceSecrets("gateway"));
291
333
  expect(serviceSecrets("staging-gateway").some((x) => live.has(x))).toBe(false);
292
334
  expect(serviceSecrets("gateway")).not.toContain("staging-gate-secret");
@@ -318,7 +360,8 @@ describe("gatewayEnvContract", () => {
318
360
  });
319
361
 
320
362
  it("the gateway's run SA reads no admin-only secret (admin password, KEK, internal, tool approval)", () => {
321
- expect(serviceSecrets("gateway")).toEqual(["public-role-password"]);
363
+ // #1654 — plus the live site's visitor-AI key, which no admin reads.
364
+ expect(serviceSecrets("gateway")).toEqual(["public-role-password", "visitor-ai-key"]);
322
365
  for (const v of gateway) {
323
366
  expect(v.name).not.toMatch(/KEK|INTERNAL|TOOL_APPROVAL|PUBLIC_ADMIN/);
324
367
  }
@@ -411,12 +454,24 @@ describe("runtime secrets", () => {
411
454
  secret: "public-role-password",
412
455
  stackResource: "gateway-public-role-password-binding",
413
456
  },
457
+ // #1654 — the live site's visitor-AI key (a file), the live gateway only.
458
+ {
459
+ service: "gateway",
460
+ secret: "visitor-ai-key",
461
+ stackResource: "gateway-visitor-ai-key-binding",
462
+ },
414
463
  // #1330 — the staging gateway: its own login only.
415
464
  {
416
465
  service: "staging-gateway",
417
466
  secret: "public-staging-role-password",
418
467
  stackResource: "staging-gateway-public-staging-role-password-binding",
419
468
  },
469
+ // #1654 — and its own visitor-AI key, never the live one's.
470
+ {
471
+ service: "staging-gateway",
472
+ secret: "visitor-ai-staging-key",
473
+ stackResource: "staging-gateway-visitor-ai-staging-key-binding",
474
+ },
420
475
  // #1328 — the broker's seal key (env) and Google sign-in client (a
421
476
  // file, which counts like an env secret: the SA reads it).
422
477
  {
@@ -502,19 +557,21 @@ describe("stackIamInvariants", () => {
502
557
  }
503
558
  });
504
559
 
505
- it("grants the gateway SA only its own role password + telemetry roles (#1330: no staging gate key)", () => {
560
+ it("grants the gateway SA only its own role password, its visitor-AI key + telemetry roles (#1330: no staging gate key)", () => {
506
561
  for (const provider of ["gcp", "gcp-firebase"] as const) {
507
562
  const gateway = stackIamInvariants(provider).filter((i) => i.member === "gateway-sa");
508
563
  expect(gateway.map((i) => `${i.role} ${JSON.stringify(i.target)}`).sort()).toEqual([
509
564
  'roles/logging.logWriter {"kind":"project"}',
510
565
  'roles/monitoring.metricWriter {"kind":"project"}',
511
566
  'roles/secretmanager.secretAccessor {"kind":"secret","name":"public-role-password"}',
567
+ 'roles/secretmanager.secretAccessor {"kind":"secret","name":"visitor-ai-key"}',
512
568
  ]);
513
569
  const staging = stackIamInvariants(provider).filter((i) => i.member === "staging-gateway-sa");
514
570
  expect(staging.map((i) => `${i.role} ${JSON.stringify(i.target)}`).sort()).toEqual([
515
571
  'roles/logging.logWriter {"kind":"project"}',
516
572
  'roles/monitoring.metricWriter {"kind":"project"}',
517
573
  'roles/secretmanager.secretAccessor {"kind":"secret","name":"public-staging-role-password"}',
574
+ 'roles/secretmanager.secretAccessor {"kind":"secret","name":"visitor-ai-staging-key"}',
518
575
  ]);
519
576
  }
520
577
  });
@@ -612,7 +669,8 @@ describe("MCP-Auth-Proxy contract (#1328)", () => {
612
669
  }
613
670
  expect(SERVICE_VPC_EGRESS["mcp-auth-proxy"]).toBe(false);
614
671
  expect(SERVICE_SECRET_FILES["mcp-auth-proxy"]).toHaveLength(1);
615
- expect(SERVICE_SECRET_FILES.gateway).toEqual([]);
672
+ // #1654 — the gateways hold their visitor-AI key, never the sign-in client.
673
+ expect(SERVICE_SECRET_FILES.gateway.map((f) => f.secret)).toEqual(["visitor-ai-key"]);
616
674
  });
617
675
 
618
676
  it("retires the broker's env, file and secret access on the gateway", () => {
@@ -42,20 +42,19 @@ import {
42
42
  } from "@caelo-cms/shared";
43
43
  import { z } from "zod";
44
44
  import type { SupportedProvider } from "./adapter.js";
45
+ import {
46
+ COLLECTIONS_LIVE_STORE_ENV,
47
+ COLLECTIONS_STAGING_STORE_ENV,
48
+ gcpCollectionStore,
49
+ } from "./collection-stores.js";
45
50
  import {
46
51
  auditJobResource,
47
- auditRunnerJobResource,
48
- auditRunnerServiceAccountEmail,
49
- buildCarrierJobResource,
50
- buildCarrierServiceAccountEmail,
51
52
  captureJobResource,
52
53
  convergeJobResource,
53
54
  gatewayServiceAccountEmail,
54
55
  gcpBucketName,
55
56
  gcpNamePrefix,
56
57
  gcpSecretId,
57
- importCrawlJobResource,
58
- importCrawlServiceAccountEmail,
59
58
  mcpAuthProxyServiceAccountEmail,
60
59
  mcpIapServiceAccountEmail,
61
60
  operatorAccessJobResource,
@@ -66,6 +65,7 @@ import {
66
65
  staticPublisherServiceAccountId,
67
66
  upgraderJobResource,
68
67
  } from "./gcp-names.js";
68
+ import { reportingJobAdminEnv } from "./reporting-job-catalog.js";
69
69
 
70
70
  export type GcpProvider = "gcp" | "gcp-firebase";
71
71
  /**
@@ -400,28 +400,11 @@ export const CAPTURE_BUCKET_ENV_VAR = "CAELO_CAPTURE_BUCKET";
400
400
  export const MEDIA_BUCKET_ENV_VAR = "CAELO_MEDIA_BUCKET";
401
401
 
402
402
  /**
403
- * #1359 — the admin env vars naming the quality-audit runner job (the
404
- * whole audit of a Stage, a reporting job: reporting-job-setup.ts) and the
405
- * one service account whose reports the admin takes for it (admin-core
406
- * quality/audit-job-kind.ts). `upgrade` leaves them untouched when it could
407
- * not set the job up.
408
- */
409
- export const AUDIT_RUNNER_JOB_ENV_VAR = "CAELO_AUDIT_RUNNER_JOB";
410
- export const AUDIT_RUNNER_SERVICE_ACCOUNT_ENV_VAR = "CAELO_AUDIT_RUNNER_SERVICE_ACCOUNT";
411
-
412
- /**
413
- * #1360 — the same pair for the site-import crawler (a site import's crawl,
414
- * a reporting job; admin-core site-import/import-job-kind.ts).
403
+ * #1359, #1360, #1574, epic #1644 — each reporting job's pair of admin env
404
+ * vars (the job, and the one service account whose reports the admin takes
405
+ * for it) is its catalog entry's (reporting-job-catalog.ts
406
+ * `REPORTING_JOB_CATALOG`); {@link adminEnvContract} sets every entry's.
415
407
  */
416
- export const IMPORT_CRAWL_JOB_ENV_VAR = "CAELO_IMPORT_CRAWL_JOB";
417
- export const IMPORT_CRAWL_SERVICE_ACCOUNT_ENV_VAR = "CAELO_IMPORT_CRAWL_SERVICE_ACCOUNT";
418
-
419
- /**
420
- * #1574 — the same pair for the build carrier (the job that holds the
421
- * request a build runs in; admin-core build-carrier/kind.ts).
422
- */
423
- export const BUILD_CARRIER_JOB_ENV_VAR = "CAELO_BUILD_CARRIER_JOB";
424
- export const BUILD_CARRIER_SERVICE_ACCOUNT_ENV_VAR = "CAELO_BUILD_CARRIER_SERVICE_ACCOUNT";
425
408
 
426
409
  /**
427
410
  * #1140 — the admin env var naming the service account of the scheduler
@@ -560,7 +543,20 @@ export type RuntimeSecret =
560
543
  * #806 — the broker's AES-256-GCM key (base64, 32 bytes) that seals its
561
544
  * stateless OAuth state, codes and refresh tokens. Gateway only.
562
545
  */
563
- | "mcp-oauth-seal-key";
546
+ | "mcp-oauth-seal-key"
547
+ /**
548
+ * #1654 — the visitor AI's key of the live site: JSON
549
+ * `{"provider","apiKey"}`, `{}` while none is set. The Owner pastes it on
550
+ * the approval card or under Settings → Visitor AI (the admin may add
551
+ * versions, never read them); only the live gateway reads it, from a file.
552
+ */
553
+ | "visitor-ai-key"
554
+ /**
555
+ * #1654 — staging's own visitor-AI key (the same key or none, the Owner's
556
+ * choice), read only by the staging gateway: a staging gateway never
557
+ * holds the live key unless the Owner gave staging the same one.
558
+ */
559
+ | "visitor-ai-staging-key";
564
560
 
565
561
  /**
566
562
  * Every {@link RuntimeSecret} as a value (the record makes the compiler
@@ -577,6 +573,8 @@ export const RUNTIME_SECRETS = Object.keys({
577
573
  "staging-gate-secret": true,
578
574
  "operator-oauth-client": true,
579
575
  "mcp-oauth-seal-key": true,
576
+ "visitor-ai-key": true,
577
+ "visitor-ai-staging-key": true,
580
578
  } satisfies Record<RuntimeSecret, true>) as readonly RuntimeSecret[];
581
579
 
582
580
  /** The Postgres roles Caelo's services log in as, with their passwords. */
@@ -625,6 +623,9 @@ export const CLI_GENERATED_SECRETS = [
625
623
  // ({@link GENERATED_SECRET_FORMAT}).
626
624
  "operator-oauth-client",
627
625
  "mcp-oauth-seal-key",
626
+ // #1654 — the visitor AI's keys start as `{}` (no key); the Owner adds one.
627
+ "visitor-ai-key",
628
+ "visitor-ai-staging-key",
628
629
  ] as const satisfies readonly RuntimeSecret[];
629
630
 
630
631
  /**
@@ -661,6 +662,9 @@ export const GENERATED_SECRET_FORMAT: Readonly<
661
662
  // exist from the start: Cloud Run refuses a revision whose secret volume
662
663
  // points at a secret without an enabled version.
663
664
  "operator-oauth-client": { kind: "placeholder", value: "{}" },
665
+ // #1654 — "no key" until the Owner pastes one; a version must exist for the volume.
666
+ "visitor-ai-key": { kind: "placeholder", value: "{}" },
667
+ "visitor-ai-staging-key": { kind: "placeholder", value: "{}" },
664
668
  };
665
669
 
666
670
  /**
@@ -763,16 +767,44 @@ export const OPERATOR_OAUTH_CLIENT_FILE: SecretFileContract = {
763
767
  version: "latest",
764
768
  };
765
769
 
770
+ /** #1654 — the env var naming the visitor-AI key file a gateway reads. */
771
+ export const VISITOR_AI_KEY_FILE_ENV = "CAELO_VISITOR_AI_KEY_FILE";
772
+
773
+ /**
774
+ * #1654 — the live gateway's visitor-AI key file. Read per turn: a file at
775
+ * `latest`, so a key the Owner rotates or removes takes effect at once.
776
+ */
777
+ export const VISITOR_AI_KEY_FILE: SecretFileContract = {
778
+ secret: "visitor-ai-key",
779
+ volumeName: "visitor-ai-key",
780
+ mountDir: "/secrets/visitor-ai",
781
+ fileName: "key.json",
782
+ version: "latest",
783
+ };
784
+
785
+ /** #1654 — the staging gateway's own key, at the same path (one image, one env). */
786
+ export const VISITOR_AI_STAGING_KEY_FILE: SecretFileContract = {
787
+ secret: "visitor-ai-staging-key",
788
+ volumeName: "visitor-ai-staging-key",
789
+ mountDir: "/secrets/visitor-ai",
790
+ fileName: "key.json",
791
+ version: "latest",
792
+ };
793
+
766
794
  /** Full path of a secret file inside the container. */
767
795
  export function secretFilePath(file: SecretFileContract): string {
768
796
  return `${file.mountDir}/${file.fileName}`;
769
797
  }
770
798
 
771
- /** Each service's secret files. Only the MCP-Auth-Proxy has one. */
799
+ /**
800
+ * Each service's secret files: the MCP-Auth-Proxy's Google sign-in client,
801
+ * and (#1654) each gateway's own visitor-AI key. The admin has none: it
802
+ * adds key versions and never reads one.
803
+ */
772
804
  export const SERVICE_SECRET_FILES: Readonly<Record<CloudRunSlug, readonly SecretFileContract[]>> = {
773
805
  admin: [],
774
- gateway: [],
775
- "staging-gateway": [],
806
+ gateway: [VISITOR_AI_KEY_FILE],
807
+ "staging-gateway": [VISITOR_AI_STAGING_KEY_FILE],
776
808
  "mcp-auth-proxy": [OPERATOR_OAUTH_CLIENT_FILE],
777
809
  };
778
810
 
@@ -1040,12 +1072,20 @@ export function gatewayEnvContract<V>(inputs: RuntimeEnvInputs<V>): CloudRunEnvV
1040
1072
  { name: GATEWAY_ENVIRONMENT_ENV, value: "live" },
1041
1073
  { name: TRUSTED_PROXY_HOPS_ENV, value: String(GATEWAY_TRUSTED_PROXY_HOPS[inputs.provider]) },
1042
1074
  { name: "PUBLIC_DATABASE_URL", value: inputs.databaseUrls.public },
1075
+ // Epic #1644 — the live collection store, read-only for its account
1076
+ // (collections-setup.ts): search, suggest and read answer from it.
1077
+ {
1078
+ name: COLLECTIONS_LIVE_STORE_ENV,
1079
+ value: gcpCollectionStore(inputs.projectId, inputs.env, "live"),
1080
+ },
1043
1081
  // The only account whose refresh pings the gateway takes: the admin's
1044
1082
  // (@caelo-cms/shared gateway-refresh.ts). An identity, not a secret.
1045
1083
  {
1046
1084
  name: GATEWAY_REFRESH_ACCOUNT_ENV,
1047
1085
  value: runServiceAccountEmail(inputs.projectId, inputs.env),
1048
1086
  },
1087
+ // #1654 — the live site's visitor-AI key, a file only this gateway mounts.
1088
+ { name: VISITOR_AI_KEY_FILE_ENV, value: secretFilePath(VISITOR_AI_KEY_FILE) },
1049
1089
  ...secretEnv("gateway", inputs.env),
1050
1090
  ];
1051
1091
  }
@@ -1070,11 +1110,19 @@ export function stagingGatewayEnvContract<V>(
1070
1110
  },
1071
1111
  { name: "PUBLIC_DATABASE_URL", value: inputs.databaseUrls.publicStaging },
1072
1112
  { name: STAGING_STORAGE_ENV, value: gcpStagingStorage(inputs.projectId, inputs.env) },
1113
+ // Epic #1644 — the staging collection store, read-only for its account:
1114
+ // staging's search answers from the Stage's releases, never the live ones.
1115
+ {
1116
+ name: COLLECTIONS_STAGING_STORE_ENV,
1117
+ value: gcpCollectionStore(inputs.projectId, inputs.env, "staging"),
1118
+ },
1073
1119
  // As the live gateway's: whose refresh pings it takes.
1074
1120
  {
1075
1121
  name: GATEWAY_REFRESH_ACCOUNT_ENV,
1076
1122
  value: runServiceAccountEmail(inputs.projectId, inputs.env),
1077
1123
  },
1124
+ // #1654 — staging's own visitor-AI key file, never the live one's secret.
1125
+ { name: VISITOR_AI_KEY_FILE_ENV, value: secretFilePath(VISITOR_AI_STAGING_KEY_FILE) },
1078
1126
  ...secretEnv("staging-gateway", inputs.env),
1079
1127
  ];
1080
1128
  }
@@ -1204,6 +1252,19 @@ export const SERVICE_VPC_EGRESS: Readonly<Record<CloudRunSlug, boolean>> = {
1204
1252
  "mcp-auth-proxy": false,
1205
1253
  };
1206
1254
 
1255
+ /** #1654 — admin env vars naming the secrets the Owner's visitor-AI key is added to. */
1256
+ export const VISITOR_AI_KEY_STORE_ENV = "CAELO_VISITOR_AI_KEY_STORE";
1257
+ export const VISITOR_AI_STAGING_KEY_STORE_ENV = "CAELO_VISITOR_AI_STAGING_KEY_STORE";
1258
+
1259
+ /** `projects/<project>/secrets/<id>` of an environment's visitor-AI key (#1654). */
1260
+ export function visitorAiKeySecretResource(
1261
+ projectId: string,
1262
+ env: string,
1263
+ environment: "live" | "staging",
1264
+ ): string {
1265
+ return `projects/${projectId}/secrets/${gcpSecretId(env, environment === "live" ? "visitor-ai-key" : "visitor-ai-staging-key")}`;
1266
+ }
1267
+
1207
1268
  /** Admin env var naming the Secret Manager secret the Owner writes the Google sign-in client to. */
1208
1269
  export const OPERATOR_OAUTH_CLIENT_STORE_ENV = "CAELO_OPERATOR_OAUTH_CLIENT_STORE";
1209
1270
 
@@ -1498,36 +1559,18 @@ export function adminEnvContract<V>(inputs: AdminEnvInputs<V>): CloudRunEnvVar<V
1498
1559
  { name: CAPTURE_JOB_ENV_VAR, value: captureJobResource(projectId, inputs.region, env) },
1499
1560
  { name: CAPTURE_BUCKET_ENV_VAR, value: gcpBucketName(projectId, env, "capture") },
1500
1561
  { name: MEDIA_BUCKET_ENV_VAR, value: gcpBucketName(projectId, env, "media") },
1501
- // #1359 — the job a Stage's quality audit runs in, and the only IAP
1502
- // identity whose reports the admin takes for it (reporting-job-setup.ts).
1562
+ // #1359, #1360, #1574, epic #1644 — each reporting job and the only IAP
1563
+ // identity whose reports the admin takes for it, in catalog order
1564
+ // (reporting-job-catalog.ts).
1565
+ ...reportingJobAdminEnv(projectId, inputs.region, env),
1566
+ // Epic #1644 — both collection stores: the admin writes change files to
1567
+ // staging and copies a Stage's releases to live at Publish live
1568
+ // (collections-setup.ts).
1503
1569
  {
1504
- name: AUDIT_RUNNER_JOB_ENV_VAR,
1505
- value: auditRunnerJobResource(projectId, inputs.region, env),
1506
- },
1507
- {
1508
- name: AUDIT_RUNNER_SERVICE_ACCOUNT_ENV_VAR,
1509
- value: auditRunnerServiceAccountEmail(projectId, env),
1510
- },
1511
- // #1360 — the job a site import's crawl runs in, and the only IAP
1512
- // identity whose reports the admin takes for it.
1513
- {
1514
- name: IMPORT_CRAWL_JOB_ENV_VAR,
1515
- value: importCrawlJobResource(projectId, inputs.region, env),
1516
- },
1517
- {
1518
- name: IMPORT_CRAWL_SERVICE_ACCOUNT_ENV_VAR,
1519
- value: importCrawlServiceAccountEmail(projectId, env),
1520
- },
1521
- // #1574 — the job that holds the request a build nobody else waits for
1522
- // runs in, and the only IAP identity whose reports the admin takes for it.
1523
- {
1524
- name: BUILD_CARRIER_JOB_ENV_VAR,
1525
- value: buildCarrierJobResource(projectId, inputs.region, env),
1526
- },
1527
- {
1528
- name: BUILD_CARRIER_SERVICE_ACCOUNT_ENV_VAR,
1529
- value: buildCarrierServiceAccountEmail(projectId, env),
1570
+ name: COLLECTIONS_STAGING_STORE_ENV,
1571
+ value: gcpCollectionStore(projectId, env, "staging"),
1530
1572
  },
1573
+ { name: COLLECTIONS_LIVE_STORE_ENV, value: gcpCollectionStore(projectId, env, "live") },
1531
1574
  // #1140 — the only IAP identity the admin's scheduler tick endpoint
1532
1575
  // accepts (scheduler-setup.ts).
1533
1576
  {
@@ -1541,6 +1584,13 @@ export function adminEnvContract<V>(inputs: AdminEnvInputs<V>): CloudRunEnvVar<V
1541
1584
  name: OPERATOR_OAUTH_CLIENT_STORE_ENV,
1542
1585
  value: operatorOAuthClientSecretResource(projectId, env),
1543
1586
  },
1587
+ // #1654 — where the Owner's visitor-AI keys are added (add-version only,
1588
+ // the run SA's secretVersionAdder invariants below).
1589
+ { name: VISITOR_AI_KEY_STORE_ENV, value: visitorAiKeySecretResource(projectId, env, "live") },
1590
+ {
1591
+ name: VISITOR_AI_STAGING_KEY_STORE_ENV,
1592
+ value: visitorAiKeySecretResource(projectId, env, "staging"),
1593
+ },
1544
1594
  ];
1545
1595
  // #1330 — the staging bucket: the full staged build in two slots that the
1546
1596
  // staging gateway serves from (gcp: Stage also keeps its per-run prefixes
@@ -1591,6 +1641,31 @@ export const STATIC_CDN_POLICY = {
1591
1641
  clientTtl: 31536000,
1592
1642
  } as const;
1593
1643
 
1644
+ /**
1645
+ * Epic #1644 (#1649) — Cloud CDN on the `gcp` stack's live gateway backend.
1646
+ * `USE_ORIGIN_HEADERS`: the CDN keeps only what the gateway marks
1647
+ * `public` with an `s-maxage`, which is exactly a collection operation's
1648
+ * answer for the release the request names (apps/api-gateway
1649
+ * collections.ts); every other gateway answer is `no-store` and passes
1650
+ * through. The query string is part of the cache key (the query, the
1651
+ * language, the release), and a cached error is never served
1652
+ * (`negativeCaching` off). Cache hits never reach the gateway, nor the
1653
+ * backend's Cloud Armor policy, which judges only what goes to the origin.
1654
+ * The staging gateway's backend gets no CDN: staged pages stay behind the
1655
+ * staging gate.
1656
+ */
1657
+ export const GATEWAY_CDN_POLICY = {
1658
+ cacheMode: "USE_ORIGIN_HEADERS",
1659
+ negativeCaching: false,
1660
+ serveWhileStale: 0,
1661
+ cacheKeyPolicy: { includeHost: true, includeProtocol: true, includeQueryString: true },
1662
+ } as const;
1663
+
1664
+ /** The `gcp` stack's live gateway backend service (Pulumi adds a suffix). */
1665
+ export function gatewayBackendPrefix(env: string): string {
1666
+ return `${gcpNamePrefix(env)}-gateway-backend`;
1667
+ }
1668
+
1594
1669
  /** Who an IAM invariant grants a role to. */
1595
1670
  export type IamPrincipal =
1596
1671
  /** The runtime SA the admin (and the migration jobs) run as. */
@@ -1696,6 +1771,25 @@ const GCP_COMMON: readonly IamInvariant[] = [
1696
1771
  onFailure: "warn",
1697
1772
  why: "the Owner's Google sign-in setup (Settings → Google sign-in) stores the OAuth client; without it only that setup fails",
1698
1773
  },
1774
+ // #1654 — the Owner's visitor-AI keys: the same add-version-only grant, one
1775
+ // per environment's secret. The admin can replace or remove a key, never
1776
+ // read it; each gateway reads only its own (secretAccessors).
1777
+ {
1778
+ stackResource: "admin-visitor-ai-key-version-adder",
1779
+ role: SECRET_VERSION_ADDER,
1780
+ member: "run-sa",
1781
+ target: { kind: "secret", name: "visitor-ai-key" },
1782
+ onFailure: "warn",
1783
+ why: "the Owner's visitor-AI key (approval card, Settings → Visitor AI) is stored for the live gateway; without it only storing the key fails",
1784
+ },
1785
+ {
1786
+ stackResource: "admin-visitor-ai-staging-key-version-adder",
1787
+ role: SECRET_VERSION_ADDER,
1788
+ member: "run-sa",
1789
+ target: { kind: "secret", name: "visitor-ai-staging-key" },
1790
+ onFailure: "warn",
1791
+ why: "staging's visitor-AI key is stored for the staging gateway; without it only storing the key fails",
1792
+ },
1699
1793
  ];
1700
1794
 
1701
1795
  /** v0.6.6 — a custom runtime SA gets no telemetry roles implicitly. */
@@ -2104,6 +2198,25 @@ export function staticBackendBucketPrefix(env: string): string {
2104
2198
  */
2105
2199
  export const ADMIN_MEMORY_DEFAULT = "2Gi";
2106
2200
 
2201
+ /**
2202
+ * Epic #1644 (#1649) — the live and the staging gateway's memory. Search,
2203
+ * suggest and read answer from collection index files the gateway keeps
2204
+ * parsed in memory (`CAELO_COLLECTIONS_CACHE_MB`, 256 MiB by default, plus
2205
+ * the release being opened), next to its visitor handlers: 512 MiB left no
2206
+ * room for that. AWS (1024 MB Fargate tasks) and Azure (1.0Gi apps) already
2207
+ * run every service at 1 GiB; `upgrade` raises a Google Cloud gateway below
2208
+ * it (never lowers a larger value, stack-converge.ts planServiceMemory).
2209
+ */
2210
+ export const GATEWAY_MEMORY_DEFAULT = "1Gi";
2211
+
2212
+ /** The memory upgrade raises each Cloud Run service to (null: the stacks' alone). */
2213
+ export const SERVICE_MEMORY_FLOOR: Readonly<Record<CloudRunSlug, string | null>> = {
2214
+ admin: ADMIN_MEMORY_DEFAULT,
2215
+ gateway: GATEWAY_MEMORY_DEFAULT,
2216
+ "staging-gateway": GATEWAY_MEMORY_DEFAULT,
2217
+ "mcp-auth-proxy": null,
2218
+ };
2219
+
2107
2220
  /**
2108
2221
  * Parse a memory quantity (`512Mi`, `2Gi`, `2G`, `1.5Gi`) to MiB; null when
2109
2222
  * it is not a quantity this contract understands.
@@ -365,6 +365,8 @@ describe("upgrading a v0.10.35 install: the gateway leaves admin_role (#613)", (
365
365
  expect(plan.ok && plan.services.gateway.changes.map((c) => c.name).sort()).toEqual([
366
366
  "ADMIN_DATABASE_PASSWORD",
367
367
  "ADMIN_DATABASE_URL",
368
+ // Epic #1644 — where it reads the live collection releases.
369
+ "CAELO_COLLECTIONS_LIVE_STORE",
368
370
  // #1329 — the gateway says it is the live site's.
369
371
  "CAELO_GATEWAY_ENVIRONMENT",
370
372
  // Whose refresh pings it takes: the admin's account.
@@ -374,6 +376,8 @@ describe("upgrading a v0.10.35 install: the gateway leaves admin_role (#613)", (
374
376
  // staging projection (#1330), never the live gateway.
375
377
  // #845 — and which forwarded address is the visitor.
376
378
  "CAELO_TRUSTED_PROXY_HOPS",
379
+ // #1654 — the visitor-AI key file only this gateway mounts.
380
+ "CAELO_VISITOR_AI_KEY_FILE",
377
381
  "PUBLIC_DATABASE_PASSWORD",
378
382
  ]);
379
383
  });