@caelo-cms/provisioning 0.12.9 → 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 +76 -3
  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
@@ -11,6 +11,8 @@ import { readFileSync } from "node:fs";
11
11
  import { resolve } from "node:path";
12
12
  import { ensureGatewayArmorRules } from "./gateway-armor.js";
13
13
  import {
14
+ API_BAN_PRIORITY,
15
+ COLLECTION_OPERATION_PATH_PATTERN,
14
16
  CREDENTIAL_PATH_PATTERN,
15
17
  DEFAULT_RULE_PRIORITY,
16
18
  GATEWAY_ARMOR_BILLED_RULES,
@@ -75,6 +77,31 @@ describe("the gateway's Cloud Armor rules (#1339)", () => {
75
77
  expect(credential?.kind === "rate" && credential.count).toBe(30);
76
78
  });
77
79
 
80
+ it("throttles collection reads instead of banning, and only GETs of that shape (#1644)", () => {
81
+ expect(COLLECTION_OPERATION_PATH_PATTERN).not.toMatch(/\((?!\?:)/);
82
+ const re = new RegExp(COLLECTION_OPERATION_PATH_PATTERN);
83
+ for (const p of [
84
+ "/api/plugin/site-search/search",
85
+ "/api/plugin/site-search/suggest",
86
+ "/api/plugin/site-search/search/release",
87
+ ]) {
88
+ expect(re.test(p)).toBe(true);
89
+ }
90
+ for (const p of [
91
+ "/api/plugin/site-search/search/x",
92
+ "/api/plugin/Site/search",
93
+ "/api/plugin/site-search/../auth/login",
94
+ "/api/captcha/challenge",
95
+ ]) {
96
+ expect(re.test(p)).toBe(false);
97
+ }
98
+ const rule = GATEWAY_ARMOR_RULES.find((r) => r.priority === 820);
99
+ expect(rule?.kind === "rate" && rule.action).toBe("throttle");
100
+ expect(rule?.expression.startsWith("request.method == 'GET' && ")).toBe(true);
101
+ // Before the /api/ ban: a conforming read is allowed there and never counts toward it.
102
+ expect(820).toBeLessThan(API_BAN_PRIORITY);
103
+ });
104
+
78
105
  it("keeps staged pages out of the general ban: it matches /api/ paths only", () => {
79
106
  const general = GATEWAY_ARMOR_RULES.find((r) => r.priority === 1001);
80
107
  expect(general?.expression).toBe("request.path.contains('/api/')");
@@ -167,6 +194,7 @@ describe("ensureGatewayArmorRules (the converge, contract 22)", () => {
167
194
  expect(writes).toEqual([
168
195
  "create 800",
169
196
  "create 810",
197
+ "create 820",
170
198
  "create 1001",
171
199
  "update 2000",
172
200
  "update 2001",
@@ -24,6 +24,13 @@
24
24
  * falls through to the general rule below.
25
25
  * - The captcha challenge is throttled (429, no ban) at 60 a minute, the
26
26
  * gateway's own per-client budget (`CAPTCHA_CHALLENGE_RATE_LIMIT`).
27
+ * - Epic #1644 — a plugin's collection operations (search, suggest,
28
+ * read: GETs that read a published index, write nothing) are throttled
29
+ * (429, no ban) at 600 a minute. Search-as-you-type sends a request
30
+ * per pause in typing, and a visitor must never be banned for using
31
+ * the site's search; Cloud CDN answers repeats before this policy
32
+ * sees them (stack-contract.ts GATEWAY_CDN_POLICY), and the gateway
33
+ * limits every client and operation itself.
27
34
  * - Every other path containing `/api/` keeps the original ban of 100 a
28
35
  * minute. It used to match every request, so a reviewer who browsed a
29
36
  * few staged pages (each with its styles, scripts, fonts and images)
@@ -90,6 +97,14 @@ export type GatewayArmorRule = ArmorRateRule | ArmorDenyRule;
90
97
  export const CREDENTIAL_PATH_PATTERN =
91
98
  "^/api/plugin/auth/(?:signup|login|request_password_reset|reset_password)$";
92
99
 
100
+ /**
101
+ * Epic #1644 — a declared collection operation and its release lookup
102
+ * (apps/api-gateway collections.ts `parseCollectionPath`), anchored. No
103
+ * capture group: Cloud Armor refuses them.
104
+ */
105
+ export const COLLECTION_OPERATION_PATH_PATTERN =
106
+ "^/api/plugin/[a-z][a-z0-9-]{0,54}/[a-z_][a-z0-9_]{0,119}(?:/release)?$";
107
+
93
108
  /** Priority of Cloud Armor's default rule (it allows; every policy has one). */
94
109
  export const DEFAULT_RULE_PRIORITY = 2147483647;
95
110
 
@@ -114,6 +129,15 @@ export const GATEWAY_ARMOR_RULES: readonly GatewayArmorRule[] = [
114
129
  count: 60,
115
130
  intervalSec: 60,
116
131
  },
132
+ {
133
+ kind: "rate",
134
+ priority: 820,
135
+ description: "Caelo gateway: per-IP throttle on collection reads (site search)",
136
+ expression: `request.method == 'GET' && request.path.matches('${COLLECTION_OPERATION_PATH_PATTERN}')`,
137
+ action: "throttle",
138
+ count: 600,
139
+ intervalSec: 60,
140
+ },
117
141
  {
118
142
  kind: "rate",
119
143
  priority: API_BAN_PRIORITY,
@@ -36,6 +36,7 @@ import {
36
36
  secretsReadPolicy,
37
37
  } from "./aws-task-roles.js";
38
38
  import { AZURE_SERVICE_DATABASE_SECRETS } from "./azure-secrets.js";
39
+ import { COLLECTION_STORE_GRANTS } from "./collections-setup.js";
39
40
  import { generateDockerCompose } from "./compose.js";
40
41
  import {
41
42
  databaseUrls,
@@ -44,7 +45,9 @@ import {
44
45
  RETIRED_SERVICE_ENV,
45
46
  runtimeSecretBindings,
46
47
  SERVICE_SECRET_ENV,
48
+ SERVICE_SECRET_FILES,
47
49
  stackIamInvariants,
50
+ stagingGatewayEnvContract,
48
51
  } from "./stack-contract.js";
49
52
 
50
53
  /** Anything in a gateway env value or name that reaches the authoring database. */
@@ -67,6 +70,9 @@ const GCP_GATEWAY_SECRETS = [
67
70
  // key. Neither is a cms_admin credential.
68
71
  "mcp-oauth-seal-key",
69
72
  "operator-oauth-client",
73
+ // #1654 — the live site's visitor-AI key: a provider key of its own, never
74
+ // the admin's AI key and no database credential.
75
+ "visitor-ai-key",
70
76
  ];
71
77
 
72
78
  /** The source of a stack program. */
@@ -158,6 +164,55 @@ describe("gcp + gcp-firebase: the gateway env contract (#635)", () => {
158
164
  });
159
165
  });
160
166
 
167
+ describe("gcp + gcp-firebase: the visitor-AI keys (#1654)", () => {
168
+ for (const provider of ["gcp", "gcp-firebase"] as const) {
169
+ it(`${provider}: each gateway reads only its own environment's key, and the admin none`, () => {
170
+ const inv = stackIamInvariants(provider);
171
+ const readers = (secret: string) =>
172
+ inv
173
+ .filter(
174
+ (i) =>
175
+ i.role === "roles/secretmanager.secretAccessor" &&
176
+ i.target.kind === "secret" &&
177
+ i.target.name === secret,
178
+ )
179
+ .map((i) => i.member);
180
+ expect(readers("visitor-ai-key")).toEqual(["gateway-sa"]);
181
+ expect(readers("visitor-ai-staging-key")).toEqual(["staging-gateway-sa"]);
182
+ // The admin may add a version (store or remove a key), on these two only.
183
+ const adders = inv
184
+ .filter((i) => i.role === "roles/secretmanager.secretVersionAdder")
185
+ .map((i) => (i.target.kind === "secret" ? `${i.member} ${i.target.name}` : "project-wide"));
186
+ expect(adders.sort()).toEqual([
187
+ "run-sa operator-oauth-client",
188
+ "run-sa visitor-ai-key",
189
+ "run-sa visitor-ai-staging-key",
190
+ ]);
191
+ });
192
+ }
193
+
194
+ it("the live gateway's env names the live key file, the staging gateway's its own secret", () => {
195
+ const inputs = {
196
+ provider: "gcp" as const,
197
+ projectId: "acme",
198
+ env: "production",
199
+ domain: "example.com",
200
+ region: "europe-west1",
201
+ stagingHost: "staging.example.com",
202
+ databaseUrls: databaseUrls("db1.p-label.europe-west1.sql-psa.goog"),
203
+ };
204
+ const file = (env: readonly { name: string; value?: unknown }[]) =>
205
+ env.find((v) => v.name === "CAELO_VISITOR_AI_KEY_FILE")?.value;
206
+ expect(file(gatewayEnvContract(inputs) as never)).toBe("/secrets/visitor-ai/key.json");
207
+ expect(file(stagingGatewayEnvContract(inputs) as never)).toBe("/secrets/visitor-ai/key.json");
208
+ expect(SERVICE_SECRET_FILES.gateway.map((f) => f.secret)).toEqual(["visitor-ai-key"]);
209
+ expect(SERVICE_SECRET_FILES["staging-gateway"].map((f) => f.secret)).toEqual([
210
+ "visitor-ai-staging-key",
211
+ ]);
212
+ expect(SERVICE_SECRET_FILES.admin).toEqual([]);
213
+ });
214
+ });
215
+
161
216
  describe("self-hosted: the generated compose gateway service (#635)", () => {
162
217
  it("holds public_role on cms_public and nothing else", () => {
163
218
  const out = generateDockerCompose({
@@ -186,20 +241,25 @@ describe("self-hosted: the generated compose gateway service (#635)", () => {
186
241
  expect(gateway).not.toMatch(STAGING_ACCESS);
187
242
  expect(gateway).not.toMatch(/superpw|adminpw|gatewaypw|stagingpw/);
188
243
  expect(gateway).toContain('CAELO_GATEWAY_ENVIRONMENT: "live"');
189
- // No other way in: no Compose secrets, no env file, and exactly one
190
- // mount — the database CA certificate (#1338), public, no credential.
244
+ // No other way in: no Compose secrets, no env file, and three read-only
245
+ // mounts — the database CA certificate (#1338), public, no credential,
246
+ // the live collection store (epic #1644), never the staging one, and
247
+ // (#1654) the live site's visitor-AI key directory, never staging's.
191
248
  expect(gateway).not.toMatch(/^ {4}(secrets|env_file):/m);
192
249
  expect(gateway).toContain(
193
- " volumes:\n - ./postgres-tls/ca.crt:/etc/caelo/db-ca/self-hosted-ca.pem:ro\n restart:",
250
+ " 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:",
194
251
  );
195
252
  const env = gateway.slice(gateway.indexOf(" environment:"));
196
253
  const keys = [...env.matchAll(/^ {6}([A-Z_][A-Z0-9_]*):/gm)].map((m) => m[1]);
197
254
  expect(keys.sort()).toEqual([
198
255
  // #1254 — its cms_public pool size (pool-budget-stack.ts).
256
+ "CAELO_COLLECTIONS_LIVE_STORE",
199
257
  "CAELO_DB_PUBLIC_POOL_MAX",
200
258
  // #1329 — the live site's gateway.
201
259
  "CAELO_GATEWAY_ENVIRONMENT",
202
260
  "CAELO_TRUSTED_PROXY_HOPS",
261
+ // #1654 — the live site's visitor-AI key file (its own directory, read-only).
262
+ "CAELO_VISITOR_AI_KEY_FILE",
203
263
  "GATEWAY_PORT",
204
264
  "NODE_ENV",
205
265
  "PUBLIC_DATABASE_URL",
@@ -304,3 +364,81 @@ describe("aws: the stack (#635)", () => {
304
364
  }
305
365
  });
306
366
  });
367
+
368
+ /**
369
+ * Epic #1644 — the collection stores follow the same split: the live
370
+ * gateway reads only the live index, the staging gateway only the staging
371
+ * one (staged content never reaches the live side, and a staging gateway
372
+ * cannot serve what is live), and neither writes.
373
+ */
374
+ describe("collection stores: each gateway reads only its own environment's (#1644)", () => {
375
+ const inputs = {
376
+ projectId: "acme",
377
+ env: "production",
378
+ domain: "example.com",
379
+ region: "europe-west1",
380
+ stagingHost: "staging.example.com",
381
+ databaseUrls: databaseUrls("db1.p-label.europe-west1.sql-psa.goog"),
382
+ };
383
+ const STAGING_STORE = /coll-staging|COLLECTIONS_STAGING|collections\/staging/;
384
+ const LIVE_STORE = /coll-live|COLLECTIONS_LIVE|collections\/live/;
385
+ const flat = (env: { name: string; value?: unknown }[]) =>
386
+ env.map((v) => `${v.name}=${typeof v.value === "string" ? v.value : ""}`).join("\n");
387
+
388
+ for (const provider of ["gcp", "gcp-firebase"] as const) {
389
+ it(`${provider}: the env contracts name only the gateway's own store`, () => {
390
+ const live = flat(gatewayEnvContract({ ...inputs, provider }));
391
+ const staging = flat(stagingGatewayEnvContract({ ...inputs, provider }));
392
+ expect(live).toMatch(LIVE_STORE);
393
+ expect(live).not.toMatch(STAGING_STORE);
394
+ expect(staging).toMatch(STAGING_STORE);
395
+ expect(staging).not.toMatch(LIVE_STORE);
396
+ });
397
+ }
398
+
399
+ it("Google Cloud: the gateways' accounts get read access to their own store and nothing else", () => {
400
+ const byMember = (m: string) =>
401
+ COLLECTION_STORE_GRANTS.filter((g) => g.member === m).map((g) => [g.bucket, g.role]);
402
+ expect(byMember("gateway")).toEqual([["coll-live", "roles/storage.objectViewer"]]);
403
+ expect(byMember("staging-gateway")).toEqual([["coll-staging", "roles/storage.objectViewer"]]);
404
+ });
405
+
406
+ it("self-hosted: each gateway mounts its own store read-only and is told only that one", () => {
407
+ const out = generateDockerCompose({
408
+ domain: "example.com",
409
+ postgresPassword: "superpw",
410
+ rolePasswords: { admin: "adminpw", public: "publicpw", publicStaging: "stagingpw" },
411
+ caeloSecretKek: "0".repeat(64),
412
+ dbTlsServerCertSha256: "ab".repeat(32),
413
+ internalSecret: "i".repeat(48),
414
+ stagingHost: "staging.example.com",
415
+ stagingGateSecret: "g".repeat(64),
416
+ diskSize: "20Gi",
417
+ images: {
418
+ mode: "release" as const,
419
+ admin: `ghcr.io/caelo-cms/admin@sha256:${"a".repeat(64)}`,
420
+ gateway: `ghcr.io/caelo-cms/gateway@sha256:${"b".repeat(64)}`,
421
+ },
422
+ ports: { http: 80, https: 443 },
423
+ project: "caelo-example-com",
424
+ });
425
+ const service = (name: string) => {
426
+ const start = out.indexOf(` ${name}:`);
427
+ const end = out.indexOf("\n caelo-", start + 1);
428
+ return out.slice(start, end === -1 ? undefined : end);
429
+ };
430
+ const live = service("caelo-gateway");
431
+ const staging = service("caelo-staging-gateway");
432
+ expect(live).toContain("- ./collections/live:/srv/collections/live:ro");
433
+ expect(live).toContain('CAELO_COLLECTIONS_LIVE_STORE: "file:///srv/collections/live"');
434
+ expect(live).not.toMatch(STAGING_STORE);
435
+ expect(staging).toContain("- ./collections/staging:/srv/collections/staging:ro");
436
+ expect(staging).toContain('CAELO_COLLECTIONS_STAGING_STORE: "file:///srv/collections/staging"');
437
+ expect(staging).not.toMatch(LIVE_STORE);
438
+ // The admin writes both (it builds a Stage's index in-process here).
439
+ const admin = service("caelo-admin");
440
+ expect(admin).toContain("- ./collections:/data/collections\n");
441
+ expect(admin).toContain('CAELO_COLLECTIONS_STAGING_STORE: "file:///data/collections/staging"');
442
+ expect(admin).toContain('CAELO_COLLECTIONS_LIVE_STORE: "file:///data/collections/live"');
443
+ });
444
+ });
package/src/gcp-names.ts CHANGED
@@ -149,12 +149,24 @@ export function staticPublisherServiceAccountId(env: string): string {
149
149
  return `caelo-${short}-publisher`;
150
150
  }
151
151
 
152
+ /**
153
+ * A bucket of the install: the stacks' (media, static, staging) and the
154
+ * CLI's (audit results, capture; epic #1644: the two collection stores,
155
+ * `coll-staging` and `coll-live`, collections-setup.ts). Kept short: a
156
+ * bucket name has at most 63 characters, and a project id can take 30 of
157
+ * them (`<project>-caelo-production-coll-staging` is 60 then).
158
+ */
159
+ export type GcpBucketKind =
160
+ | "media"
161
+ | "static"
162
+ | "staging"
163
+ | "audit-results"
164
+ | "capture"
165
+ | "coll-staging"
166
+ | "coll-live";
167
+
152
168
  /** Globally unique GCS bucket name the stacks give each bucket. */
153
- export function gcpBucketName(
154
- projectId: string,
155
- env: string,
156
- bucket: "media" | "static" | "staging" | "audit-results" | "capture",
157
- ): string {
169
+ export function gcpBucketName(projectId: string, env: string, bucket: GcpBucketKind): string {
158
170
  return `${projectId}-${gcpNamePrefix(env)}-${bucket}`;
159
171
  }
160
172
 
@@ -247,90 +259,22 @@ export function auditServiceAccountEmail(projectId: string, env: string): string
247
259
  }
248
260
 
249
261
  /**
250
- * #1359 — Cloud Run job that runs a Stage's whole quality audit (the
251
- * findings checks and the Lighthouse fan-out to {@link auditJobName}) and
252
- * reports back to the admin, one execution per audit (reporting-job-setup.ts).
253
- */
254
- export function auditRunnerJobName(env: string): string {
255
- return `${gcpNamePrefix(env)}-audit-run`;
256
- }
257
-
258
- /** Full resource name of the audit runner job, as the admin's env carries it. */
259
- export function auditRunnerJobResource(projectId: string, region: string, env: string): string {
260
- return `projects/${projectId}/locations/${region}/jobs/${auditRunnerJobName(env)}`;
261
- }
262
-
263
- /**
264
- * Account id of the audit runner's own service account: reads the staged
265
- * build and the Lighthouse results, runs the Lighthouse job, and reports to
266
- * the admin through IAP — no database, no secret (reporting-job-setup.ts).
267
- * `caelo-production-audit-run` is 26 of the 30 characters an id may have.
268
- */
269
- export function auditRunnerServiceAccountId(env: string): string {
270
- return `${gcpNamePrefix(env)}-audit-run`;
271
- }
272
-
273
- /** Email of the audit runner's service account. */
274
- export function auditRunnerServiceAccountEmail(projectId: string, env: string): string {
275
- return `${auditRunnerServiceAccountId(env)}@${projectId}.iam.gserviceaccount.com`;
276
- }
277
-
278
- /**
279
- * #1360 — Cloud Run job that crawls a site import and reports each page to
280
- * the admin, one execution per attempt (reporting-job-setup.ts). The admin
281
- * renders the pages it asks for through the capture job.
282
- */
283
- export function importCrawlJobName(env: string): string {
284
- return `${gcpNamePrefix(env)}-import`;
285
- }
286
-
287
- /** Full resource name of the crawl job, as the admin's env carries it. */
288
- export function importCrawlJobResource(projectId: string, region: string, env: string): string {
289
- return `projects/${projectId}/locations/${region}/jobs/${importCrawlJobName(env)}`;
290
- }
291
-
292
- /**
293
- * Account id of the crawl job's own service account: reports to the admin
294
- * through IAP and fetches robots.txt and sitemaps through the SSRF guard —
295
- * no database, no secret, no bucket, no other job (reporting-job-setup.ts).
296
- * `caelo-production-import` is 23 of the 30 characters an id may have.
297
- */
298
- export function importCrawlServiceAccountId(env: string): string {
299
- return `${gcpNamePrefix(env)}-import`;
300
- }
301
-
302
- /** Email of the crawl job's service account. */
303
- export function importCrawlServiceAccountEmail(projectId: string, env: string): string {
304
- return `${importCrawlServiceAccountId(env)}@${projectId}.iam.gserviceaccount.com`;
305
- }
306
-
307
- /**
308
- * #1574 — Cloud Run job that carries a build: one execution per Stage,
309
- * Publish live or production build nobody else waits for, holding the
310
- * admin request the build runs in (reporting-job-setup.ts).
262
+ * #1359, #1360, #1574, epic #1644 — the reporting jobs (a Stage's quality
263
+ * audit, a site import's crawl, a carried build, a Stage's collection
264
+ * index, a plugin's batch run) each run as a Cloud Run job of their own
265
+ * under an account of their own, both named `caelo-<env>-<kind name>`:
266
+ * reporting-job-catalog.ts derives them from its one entry per kind.
311
267
  */
312
- export function buildCarrierJobName(env: string): string {
313
- return `${gcpNamePrefix(env)}-build`;
314
- }
315
-
316
- /** Full resource name of the build carrier's job, as the admin's env carries it. */
317
- export function buildCarrierJobResource(projectId: string, region: string, env: string): string {
318
- return `projects/${projectId}/locations/${region}/jobs/${buildCarrierJobName(env)}`;
268
+ export function reportingJobAccountId(env: string, name: string): string {
269
+ return `${gcpNamePrefix(env)}-${name}`;
319
270
  }
320
271
 
321
272
  /**
322
- * Account id of the build carrier's own service account: it reports to the
323
- * admin through IAP and holds nothing else — no database, no secret, no
324
- * bucket, no other job (reporting-job-setup.ts). `caelo-production-build`
325
- * is 22 of the 30 characters an id may have.
273
+ * Epic #1644 (#1649) — the Cloud Logging exclusion that keeps visitors'
274
+ * search queries out of the install's logs (visitor-query-logs.ts).
326
275
  */
327
- export function buildCarrierServiceAccountId(env: string): string {
328
- return `${gcpNamePrefix(env)}-build`;
329
- }
330
-
331
- /** Email of the build carrier's service account. */
332
- export function buildCarrierServiceAccountEmail(projectId: string, env: string): string {
333
- return `${buildCarrierServiceAccountId(env)}@${projectId}.iam.gserviceaccount.com`;
276
+ export function visitorQueryLogExclusionName(env: string): string {
277
+ return `${gcpNamePrefix(env)}-visitor-queries`;
334
278
  }
335
279
 
336
280
  /**
@@ -20,8 +20,10 @@ 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)", () => {
24
- expect(INFRA_CONTRACT_VERSION).toBe(28);
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(30);
25
+ expect(INFRA_CONTRACT_STEPS[30]).toContain("#1654");
26
+ expect(INFRA_CONTRACT_STEPS[29]).toContain("#1644");
25
27
  expect(INFRA_CONTRACT_STEPS[27]).toContain("#1574");
26
28
  expect(INFRA_CONTRACT_STEPS[28]).toContain("#1596");
27
29
  expect(INFRA_CONTRACT_STEPS[26]).toContain("#1360");
@@ -58,6 +60,6 @@ describe("infrastructure contract steps", () => {
58
60
  });
59
61
 
60
62
  it("names a version a newer release added by number", () => {
61
- expect(infraStepsText(28, 29)).toBe("infrastructure step 29 (see that release's notes)");
63
+ expect(infraStepsText(30, 31)).toBe("infrastructure step 31 (see that release's notes)");
62
64
  });
63
65
  });
@@ -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 = 28;
25
+ export const INFRA_CONTRACT_VERSION = 30;
26
26
 
27
27
  // History (why each bump happened — an install below a number needs the
28
28
  // converge that introduced it):
@@ -224,6 +224,38 @@ export const INFRA_CONTRACT_VERSION = 28;
224
224
  // the admin. The new admin starts every crawl on that job and the
225
225
  // app-roll moves its image, so an in-cloud upgrader must not roll an
226
226
  // install onto it before it exists.
227
+ // 30 — #1654: the visitor AI's keys. Two CLI-generated secrets,
228
+ // `visitor-ai-key` (live) and `visitor-ai-staging-key` (staging), each
229
+ // created as `{}` (no key); the admin's run SA holds
230
+ // secretVersionAdder on both (stack-contract.ts GCP_COMMON: it adds a
231
+ // key the Owner pasted or removes one, never reads one); the live
232
+ // gateway's SA holds secretAccessor on `visitor-ai-key` only and
233
+ // mounts it at /secrets/visitor-ai/key.json, the staging gateway's on
234
+ // `visitor-ai-staging-key` only, at the same path
235
+ // (SERVICE_SECRET_FILES); CAELO_VISITOR_AI_KEY_FILE on both gateways,
236
+ // CAELO_VISITOR_AI_KEY_STORE / CAELO_VISITOR_AI_STAGING_KEY_STORE on
237
+ // the admin. The new gateways mount the secret and the new admin
238
+ // writes to it, so an in-cloud upgrader must not roll an install onto
239
+ // them before the secrets exist (Cloud Run refuses a revision whose
240
+ // secret volume has no version).
241
+ // 29 — epic #1644 (#1648, #1649): plugin collections (a site search's
242
+ // index). The two private collection stores (collections-setup.ts,
243
+ // `coll-staging` / `coll-live`) with the admin's objectAdmin on both,
244
+ // the live gateway's objectViewer on live and the staging gateway's on
245
+ // staging; the collection index job (reporting-job-setup.ts,
246
+ // `caelo-<env>-index`: its own account with the shared grants plus
247
+ // read + create on the staging store), the admin's run-with-overrides
248
+ // and viewer on it, the upgrader's actAs on its account and the
249
+ // account in the operator-access job's IAP list; the env
250
+ // CAELO_COLLECTIONS_STAGING_STORE / CAELO_COLLECTIONS_LIVE_STORE /
251
+ // CAELO_COLLECTION_INDEX_JOB / CAELO_COLLECTION_INDEX_SERVICE_ACCOUNT on
252
+ // the admin and each gateway's own store; both gateways at 1 GiB; the
253
+ // `caelo-<env>-visitor-queries` exclusion on `_Default` (and the gcp
254
+ // edge log sink); on gcp Cloud CDN on the gateway backend and the
255
+ // collection-read throttle in its Cloud Armor policy. The new gateways
256
+ // read their store and the new admin starts the index job, so an
257
+ // in-cloud upgrader must not roll an install onto them before they
258
+ // exist.
227
259
  // 28 — #1596: the upgrader's actAs on the staging gateway's account. The
228
260
  // app-roll rolls the staging gateway since v0.12.0 (#1330), but the
229
261
  // setup never granted it, so every in-product app-roll on an install
@@ -287,6 +319,8 @@ export const INFRA_CONTRACT_STEPS: Readonly<Record<number, string>> = {
287
319
  26: "the site-import crawler: a job of its own that crawls each site import and reports every page to the admin, its service account and grants (#1360)",
288
320
  27: "the build carrier: a job of its own that holds the request a Stage, Publish live or production build runs in when nobody else waits for it, its service account and grants (#1574)",
289
321
  28: "the upgrader's right to run the staging gateway as its service account, so updates from Settings → Updates roll every service (#1596)",
322
+ 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
+ 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)",
290
324
  };
291
325
 
292
326
  /**
@@ -195,6 +195,17 @@ describe("remote-MCP secrets + IAM (contract)", () => {
195
195
  target: { kind: "secret", name: "operator-oauth-client" },
196
196
  onFailure: "warn",
197
197
  }),
198
+ // #1654 — the visitor AI's keys, the same add-version-only grant.
199
+ expect.objectContaining({
200
+ stackResource: "admin-visitor-ai-key-version-adder",
201
+ member: "run-sa",
202
+ target: { kind: "secret", name: "visitor-ai-key" },
203
+ }),
204
+ expect.objectContaining({
205
+ stackResource: "admin-visitor-ai-staging-key-version-adder",
206
+ member: "run-sa",
207
+ target: { kind: "secret", name: "visitor-ai-staging-key" },
208
+ }),
198
209
  ]);
199
210
  const adminReads = stackIamInvariants(provider).filter(
200
211
  (i) =>
@@ -209,7 +220,8 @@ describe("remote-MCP secrets + IAM (contract)", () => {
209
220
 
210
221
  it("mounts the OAuth client on the MCP-Auth-Proxy only, at latest, as the file its env names", () => {
211
222
  expect(SERVICE_SECRET_FILES.admin).toEqual([]);
212
- expect(SERVICE_SECRET_FILES.gateway).toEqual([]);
223
+ // #1654 — the gateway's one file is its visitor-AI key, never the sign-in client.
224
+ expect(SERVICE_SECRET_FILES.gateway.map((f) => f.secret)).toEqual(["visitor-ai-key"]);
213
225
  expect(SERVICE_SECRET_FILES["mcp-auth-proxy"]).toEqual([OPERATOR_OAUTH_CLIENT_FILE]);
214
226
  expect(secretFileVolumesTemplate("mcp-auth-proxy", "production")).toEqual({
215
227
  volumes: [