@caelo-cms/provisioning 0.11.13 → 0.11.15

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 (186) hide show
  1. package/dist/__tests__/stack-under-mocks.d.ts +2 -0
  2. package/dist/__tests__/stack-under-mocks.d.ts.map +1 -0
  3. package/dist/__tests__/stack-under-mocks.js +59 -0
  4. package/dist/__tests__/stack-under-mocks.js.map +1 -0
  5. package/dist/admin-domain.d.ts +4 -46
  6. package/dist/admin-domain.d.ts.map +1 -1
  7. package/dist/admin-domain.js +4 -101
  8. package/dist/admin-domain.js.map +1 -1
  9. package/dist/agent-db.js +29 -5
  10. package/dist/audit-job-setup.d.ts.map +1 -1
  11. package/dist/audit-job-setup.js +14 -19
  12. package/dist/audit-job-setup.js.map +1 -1
  13. package/dist/caddy.d.ts +2 -1
  14. package/dist/caddy.d.ts.map +1 -1
  15. package/dist/caddy.js +21 -3
  16. package/dist/caddy.js.map +1 -1
  17. package/dist/cli.js +111 -62
  18. package/dist/cli.js.map +1 -1
  19. package/dist/compose.d.ts +22 -2
  20. package/dist/compose.d.ts.map +1 -1
  21. package/dist/compose.js +53 -3
  22. package/dist/compose.js.map +1 -1
  23. package/dist/converge-checkpoint.d.ts +1 -0
  24. package/dist/converge-checkpoint.d.ts.map +1 -1
  25. package/dist/converge-checkpoint.js +1 -0
  26. package/dist/converge-checkpoint.js.map +1 -1
  27. package/dist/deployed-release.d.ts.map +1 -1
  28. package/dist/deployed-release.js +42 -8
  29. package/dist/deployed-release.js.map +1 -1
  30. package/dist/gateway-bootstrap.d.ts +68 -0
  31. package/dist/gateway-bootstrap.d.ts.map +1 -0
  32. package/dist/gateway-bootstrap.js +145 -0
  33. package/dist/gateway-bootstrap.js.map +1 -0
  34. package/dist/gcp-names.d.ts +33 -14
  35. package/dist/gcp-names.d.ts.map +1 -1
  36. package/dist/gcp-names.js +43 -0
  37. package/dist/gcp-names.js.map +1 -1
  38. package/dist/gcp-url-map.d.ts +19 -4
  39. package/dist/gcp-url-map.d.ts.map +1 -1
  40. package/dist/gcp-url-map.js +33 -5
  41. package/dist/gcp-url-map.js.map +1 -1
  42. package/dist/infra-contract.d.ts +1 -1
  43. package/dist/infra-contract.d.ts.map +1 -1
  44. package/dist/infra-contract.js +18 -1
  45. package/dist/infra-contract.js.map +1 -1
  46. package/dist/lifecycle.d.ts.map +1 -1
  47. package/dist/lifecycle.js +5 -39
  48. package/dist/lifecycle.js.map +1 -1
  49. package/dist/mcp-auth-proxy-setup.d.ts +8 -2
  50. package/dist/mcp-auth-proxy-setup.d.ts.map +1 -1
  51. package/dist/mcp-auth-proxy-setup.js +4 -0
  52. package/dist/mcp-auth-proxy-setup.js.map +1 -1
  53. package/dist/release-manifest.d.ts +1 -1
  54. package/dist/release-manifest.d.ts.map +1 -1
  55. package/dist/release-manifest.js +2 -0
  56. package/dist/release-manifest.js.map +1 -1
  57. package/dist/remote-mcp.d.ts.map +1 -1
  58. package/dist/remote-mcp.js +11 -1
  59. package/dist/remote-mcp.js.map +1 -1
  60. package/dist/runtime-secrets.d.ts +10 -0
  61. package/dist/runtime-secrets.d.ts.map +1 -1
  62. package/dist/runtime-secrets.js +10 -1
  63. package/dist/runtime-secrets.js.map +1 -1
  64. package/dist/stack-contract.d.ts +61 -20
  65. package/dist/stack-contract.d.ts.map +1 -1
  66. package/dist/stack-contract.js +173 -35
  67. package/dist/stack-contract.js.map +1 -1
  68. package/dist/stack-converge.d.ts.map +1 -1
  69. package/dist/stack-converge.js +4 -2
  70. package/dist/stack-converge.js.map +1 -1
  71. package/dist/stack-gateways.d.ts +31 -0
  72. package/dist/stack-gateways.d.ts.map +1 -0
  73. package/dist/stack-gateways.js +40 -0
  74. package/dist/stack-gateways.js.map +1 -0
  75. package/dist/staging-admin.d.ts +2 -2
  76. package/dist/staging-admin.d.ts.map +1 -1
  77. package/dist/staging-gateway-setup.d.ts +140 -0
  78. package/dist/staging-gateway-setup.d.ts.map +1 -0
  79. package/dist/staging-gateway-setup.js +848 -0
  80. package/dist/staging-gateway-setup.js.map +1 -0
  81. package/dist/state-command.d.ts.map +1 -1
  82. package/dist/state-command.js +3 -0
  83. package/dist/state-command.js.map +1 -1
  84. package/dist/upgrade/app-roll.d.ts +4 -4
  85. package/dist/upgrade/app-roll.d.ts.map +1 -1
  86. package/dist/upgrade/app-roll.js +7 -5
  87. package/dist/upgrade/app-roll.js.map +1 -1
  88. package/dist/upgrade/converge.d.ts.map +1 -1
  89. package/dist/upgrade/converge.js +36 -27
  90. package/dist/upgrade/converge.js.map +1 -1
  91. package/dist/upgrade/image-forms.d.ts +3 -3
  92. package/dist/upgrade/image-forms.d.ts.map +1 -1
  93. package/dist/upgrade/image-forms.js +2 -2
  94. package/dist/upgrade/image-forms.js.map +1 -1
  95. package/dist/upgrade/release-images.d.ts +20 -0
  96. package/dist/upgrade/release-images.d.ts.map +1 -1
  97. package/dist/upgrade/release-images.js +28 -0
  98. package/dist/upgrade/release-images.js.map +1 -1
  99. package/dist/upgrade/upgrade.d.ts +3 -1
  100. package/dist/upgrade/upgrade.d.ts.map +1 -1
  101. package/dist/upgrade/upgrade.js +22 -1
  102. package/dist/upgrade/upgrade.js.map +1 -1
  103. package/dist/upgrader-job.d.ts.map +1 -1
  104. package/dist/upgrader-job.js +30 -5
  105. package/dist/upgrader-job.js.map +1 -1
  106. package/dist/upgrader-records.d.ts +2 -2
  107. package/dist/upgrader-records.d.ts.map +1 -1
  108. package/dist/upgrader-records.js +2 -2
  109. package/dist/upgrader-records.js.map +1 -1
  110. package/dist/wizard.d.ts.map +1 -1
  111. package/dist/wizard.js +3 -3
  112. package/dist/wizard.js.map +1 -1
  113. package/dist/wizards/gcp-pulumi.d.ts +7 -1
  114. package/dist/wizards/gcp-pulumi.d.ts.map +1 -1
  115. package/dist/wizards/gcp-pulumi.js +2 -0
  116. package/dist/wizards/gcp-pulumi.js.map +1 -1
  117. package/dist/wizards/gcp.d.ts.map +1 -1
  118. package/dist/wizards/gcp.js +168 -22
  119. package/dist/wizards/gcp.js.map +1 -1
  120. package/package.json +2 -2
  121. package/src/__tests__/stack-under-mocks.ts +69 -0
  122. package/src/admin-domain.test.ts +0 -156
  123. package/src/admin-domain.ts +4 -117
  124. package/src/admin-memory.test.ts +2 -0
  125. package/src/audit-job-setup.test.ts +11 -11
  126. package/src/audit-job-setup.ts +14 -19
  127. package/src/caddy-redirects.docker.test.ts +10 -5
  128. package/src/caddy-redirects.test.ts +7 -5
  129. package/src/caddy-validate.test.ts +1 -1
  130. package/src/caddy.test.ts +12 -6
  131. package/src/caddy.ts +23 -4
  132. package/src/cli.ts +138 -77
  133. package/src/compose.ts +67 -2
  134. package/src/converge-checkpoint.ts +1 -0
  135. package/src/database-tls-builders.test.ts +3 -1
  136. package/src/deployed-release.test.ts +37 -0
  137. package/src/deployed-release.ts +44 -7
  138. package/src/gateway-bootstrap.test.ts +381 -0
  139. package/src/gateway-bootstrap.ts +195 -0
  140. package/src/gateway-env-isolation.test.ts +2 -0
  141. package/src/gcp-names.ts +53 -0
  142. package/src/gcp-url-map.test.ts +27 -3
  143. package/src/gcp-url-map.ts +36 -5
  144. package/src/index.test.ts +9 -3
  145. package/src/infra-contract.test.ts +4 -3
  146. package/src/infra-contract.ts +18 -1
  147. package/src/lifecycle.ts +8 -52
  148. package/src/mcp-auth-proxy-setup.test.ts +15 -6
  149. package/src/mcp-auth-proxy-setup.ts +14 -2
  150. package/src/release-manifest.ts +3 -1
  151. package/src/remote-mcp-stack-config.test.ts +3 -1
  152. package/src/remote-mcp.test.ts +5 -1
  153. package/src/remote-mcp.ts +10 -1
  154. package/src/runtime-secrets.test.ts +10 -1
  155. package/src/runtime-secrets.ts +21 -0
  156. package/src/self-hosted-backup.test.ts +6 -4
  157. package/src/self-hosted-compose.test.ts +2 -0
  158. package/src/stack-cloud-run-names.test.ts +49 -0
  159. package/src/stack-contract-parity.test.ts +7 -3
  160. package/src/stack-contract.test.ts +73 -13
  161. package/src/stack-contract.ts +195 -42
  162. package/src/stack-converge-secrets.test.ts +7 -2
  163. package/src/stack-converge.test.ts +37 -9
  164. package/src/stack-converge.ts +4 -1
  165. package/src/stack-gateways.ts +39 -0
  166. package/src/staging-admin.ts +2 -2
  167. package/src/staging-gateway-setup.test.ts +361 -0
  168. package/src/staging-gateway-setup.ts +1083 -0
  169. package/src/state-command.ts +3 -0
  170. package/src/upgrade/app-roll.ts +7 -4
  171. package/src/upgrade/converge.ts +40 -26
  172. package/src/upgrade/image-forms.ts +7 -7
  173. package/src/upgrade/release-images.test.ts +28 -0
  174. package/src/upgrade/release-images.ts +44 -0
  175. package/src/upgrade/upgrade.test.ts +63 -11
  176. package/src/upgrade/upgrade.ts +29 -2
  177. package/src/upgrader-job.test.ts +23 -0
  178. package/src/upgrader-job.ts +45 -11
  179. package/src/upgrader-records.ts +7 -7
  180. package/src/wizard.ts +2 -3
  181. package/src/wizards/gcp-pulumi.ts +9 -0
  182. package/src/wizards/gcp.ts +219 -23
  183. package/stacks/gcp/Pulumi.yaml +4 -0
  184. package/stacks/gcp/index.ts +128 -66
  185. package/stacks/gcp-firebase/index.ts +101 -50
  186. package/stacks/self-hosted/index.ts +9 -2
@@ -29,6 +29,7 @@ import {
29
29
  MCP_IAP_SERVICE_ACCOUNT_ID,
30
30
  mcpAuthProxyServiceAccountId,
31
31
  runServiceAccountId,
32
+ stagingGatewayServiceAccountId,
32
33
  staticPublisherServiceAccountId,
33
34
  } from "../../dist/gcp-names.js";
34
35
  import { createSiteUrlMap } from "../../dist/gcp-url-map.js";
@@ -63,6 +64,7 @@ import {
63
64
  STATIC_CDN_POLICY,
64
65
  secretFileVolumesTemplate,
65
66
  } from "../../dist/stack-contract.js";
67
+ import { DEPLOY_GATEWAYS_CONFIG, parseDeployGateways } from "../../dist/stack-gateways.js";
66
68
  import { GCP_STATIC_RESPONSE_HEADERS } from "../../dist/static-security-headers.js";
67
69
 
68
70
  const cfg = new pulumi.Config();
@@ -513,9 +515,10 @@ new gcp.storage.BucketIAMMember(
513
515
 
514
516
  // v0.2.78 — private staging bucket. Stage uploads here; Confirm-publish
515
517
  // server-side copies to the public static bucket. Never has allUsers
516
- // binding so the staged HTML is reachable ONLY through the admin's
517
- // IAP-gated /_staging-preview/<runId>/ proxy route. The public CDN
518
- // never serves from this bucket.
518
+ // binding: since #1330 the staged build is reachable ONLY through the
519
+ // staging gateway (the staging host, behind the staging gate), whose
520
+ // account may read this bucket and nothing else. The public CDN never
521
+ // serves from it.
519
522
  const stagingBucket = new gcp.storage.Bucket(
520
523
  `${namePrefix}-staging`,
521
524
  {
@@ -570,9 +573,24 @@ const mcpAuthProxySa = new gcp.serviceaccount.Account(
570
573
  },
571
574
  opts,
572
575
  );
576
+ // #1330 — the staging gateway's own SA and (below) its secretAccessor on
577
+ // its one login password, plus the telemetry roles. Its service, its read
578
+ // access to the staging bucket and its edge (gcp: NEG, backend, host rule,
579
+ // certificate; gcp-firebase: the second Hosting site) are the CLI's
580
+ // (staging-gateway-setup.ts, after the first `up` and in every converge).
581
+ const stagingGatewaySa = new gcp.serviceaccount.Account(
582
+ `${namePrefix}-staging-gateway-sa`,
583
+ {
584
+ accountId: stagingGatewayServiceAccountId(env),
585
+ displayName: `Caelo ${env} staging gateway`,
586
+ createIgnoreAlreadyExists: true,
587
+ },
588
+ opts,
589
+ );
573
590
  const serviceSa: Record<CloudRunSlug, gcp.serviceaccount.Account> = {
574
591
  admin: runSa,
575
592
  gateway: gatewaySa,
593
+ "staging-gateway": stagingGatewaySa,
576
594
  "mcp-auth-proxy": mcpAuthProxySa,
577
595
  };
578
596
 
@@ -582,6 +600,7 @@ const serviceSa: Record<CloudRunSlug, gcp.serviceaccount.Account> = {
582
600
  const secretBindings: Record<CloudRunSlug, gcp.secretmanager.SecretIamMember[]> = {
583
601
  admin: [],
584
602
  gateway: [],
603
+ "staging-gateway": [],
585
604
  "mcp-auth-proxy": [],
586
605
  };
587
606
  for (const binding of runtimeSecretBindings()) {
@@ -696,6 +715,24 @@ new gcp.projects.IAMMember(
696
715
  },
697
716
  opts,
698
717
  );
718
+ new gcp.projects.IAMMember(
719
+ `${namePrefix}-staging-gateway-log-writer`,
720
+ {
721
+ project,
722
+ role: "roles/logging.logWriter",
723
+ member: pulumi.interpolate`serviceAccount:${stagingGatewaySa.email}`,
724
+ },
725
+ opts,
726
+ );
727
+ new gcp.projects.IAMMember(
728
+ `${namePrefix}-staging-gateway-metric-writer`,
729
+ {
730
+ project,
731
+ role: "roles/monitoring.metricWriter",
732
+ member: pulumi.interpolate`serviceAccount:${stagingGatewaySa.email}`,
733
+ },
734
+ opts,
735
+ );
699
736
 
700
737
  // `static-publisher` SA used by `bunx @caelo-cms/provisioning deploy` to
701
738
  // upload the static-generator output to the bucket. Pre-v0.2.78 this
@@ -759,8 +796,8 @@ function imageTag(service: string): pulumi.Output<string> {
759
796
  }
760
797
 
761
798
  interface CloudRunArgs {
762
- /** The MCP-Auth-Proxy is CLI-owned on this stack (see mcpAuthProxySa). */
763
- readonly serviceName: Exclude<CloudRunSlug, "mcp-auth-proxy">;
799
+ /** The MCP-Auth-Proxy and the staging gateway are CLI-owned on this stack (see their SAs). */
800
+ readonly serviceName: Exclude<CloudRunSlug, "mcp-auth-proxy" | "staging-gateway">;
764
801
  readonly minInstances: number;
765
802
  readonly maxInstances: number;
766
803
  readonly memory: string;
@@ -911,18 +948,26 @@ const adminSvc = cloudRunService({
911
948
  ],
912
949
  mediaVolume: adminMediaVolumeTemplate(adminMediaVolume(project, env)),
913
950
  });
914
- const gatewaySvc = cloudRunService({
915
- serviceName: "gateway",
916
- minInstances: gatewayMinInstances,
917
- maxInstances: gatewayMaxInstances,
918
- memory: "512Mi",
919
- // Visitor requests only (#1328 moved remote MCP's long streams to the
920
- // MCP-Auth-Proxy): Cloud Run's default.
921
- timeout: "300s",
922
- // public_role on cms_public only: no cms_admin login of any role
923
- // (#613, #635, CLAUDE.md §2).
924
- contractEnv: [...gatewayEnvContract(envContractInputs), ...poolBudget.env.gateway],
925
- });
951
+ // The first `up` of a fresh install withholds the gateway and everything
952
+ // that routes to it (stack-gateways.ts): it refuses to start until the
953
+ // migrations, which run after that `up`, have isolated its database login.
954
+ // The URL map goes with it because its `/api/*` rule must exist at creation
955
+ // (the stack ignores `pathRules` after that, gcp-url-map.ts).
956
+ const deployGateways = parseDeployGateways(cfg.get(DEPLOY_GATEWAYS_CONFIG));
957
+ const gatewaySvc = deployGateways
958
+ ? cloudRunService({
959
+ serviceName: "gateway",
960
+ minInstances: gatewayMinInstances,
961
+ maxInstances: gatewayMaxInstances,
962
+ memory: "512Mi",
963
+ // Visitor requests only (#1328 moved remote MCP's long streams to the
964
+ // MCP-Auth-Proxy): Cloud Run's default.
965
+ timeout: "300s",
966
+ // public_role on cms_public only: no cms_admin login of any role
967
+ // (#613, #635, CLAUDE.md §2).
968
+ contractEnv: [...gatewayEnvContract(envContractInputs), ...poolBudget.env.gateway],
969
+ })
970
+ : null;
926
971
 
927
972
  // =========================================================================
928
973
  // Tier 1 + Tier 2 + Tier 3 LB — single HTTPS LB serves three backends
@@ -1023,26 +1068,28 @@ const staticBackendBucket = new gcp.compute.BackendBucket(
1023
1068
  );
1024
1069
 
1025
1070
  // Tier 3 backend — gateway Cloud Run via serverless NEG
1026
- const gatewayNeg = new gcp.compute.RegionNetworkEndpointGroup(
1027
- `${namePrefix}-gateway-neg`,
1028
- {
1029
- region,
1030
- networkEndpointType: "SERVERLESS",
1031
- cloudRun: { service: gatewaySvc.name },
1032
- },
1033
- opts,
1034
- );
1035
-
1036
- const gatewayBackendService = new gcp.compute.BackendService(
1037
- `${namePrefix}-gateway-backend`,
1038
- {
1039
- protocol: "HTTPS",
1040
- backends: [{ group: gatewayNeg.id }],
1041
- loadBalancingScheme: "EXTERNAL_MANAGED",
1042
- securityPolicy: wafPolicy.id,
1043
- },
1044
- opts,
1045
- );
1071
+ function gatewayBackend(service: gcp.cloudrunv2.Service): gcp.compute.BackendService {
1072
+ const gatewayNeg = new gcp.compute.RegionNetworkEndpointGroup(
1073
+ `${namePrefix}-gateway-neg`,
1074
+ {
1075
+ region,
1076
+ networkEndpointType: "SERVERLESS",
1077
+ cloudRun: { service: service.name },
1078
+ },
1079
+ opts,
1080
+ );
1081
+ return new gcp.compute.BackendService(
1082
+ `${namePrefix}-gateway-backend`,
1083
+ {
1084
+ protocol: "HTTPS",
1085
+ backends: [{ group: gatewayNeg.id }],
1086
+ loadBalancingScheme: "EXTERNAL_MANAGED",
1087
+ securityPolicy: wafPolicy.id,
1088
+ },
1089
+ opts,
1090
+ );
1091
+ }
1092
+ const gatewayBackendService = gatewaySvc ? gatewayBackend(gatewaySvc) : null;
1046
1093
 
1047
1094
  // Tier 2 backend — admin Cloud Run via serverless NEG, IAP-gated.
1048
1095
  const adminNeg = new gcp.compute.RegionNetworkEndpointGroup(
@@ -1222,17 +1269,22 @@ new gcp.iap.WebBackendServiceIamMember(
1222
1269
  // #587 — the public path matcher also carries the redirects table as
1223
1270
  // `urlRedirect` rules, written by the admin on every Confirm-publish; the
1224
1271
  // stack ignores that field after creation (src/gcp-url-map.ts).
1225
- const urlMap = createSiteUrlMap(
1226
- `${namePrefix}-url-map`,
1227
- {
1228
- domain,
1229
- adminDomain,
1230
- staticBackend: staticBackendBucket.id,
1231
- gatewayBackend: gatewayBackendService.id,
1232
- adminBackend: adminBackendService.id,
1233
- },
1234
- opts,
1235
- );
1272
+ // Withheld with the gateway (see `deployGateways`), and the HTTPS proxy and
1273
+ // forwarding rule below with it.
1274
+ function siteUrlMap(gatewayBackendId: pulumi.Input<string>): gcp.compute.URLMap {
1275
+ return createSiteUrlMap(
1276
+ `${namePrefix}-url-map`,
1277
+ {
1278
+ domain,
1279
+ adminDomain,
1280
+ stagingHost,
1281
+ staticBackend: staticBackendBucket.id,
1282
+ gatewayBackend: gatewayBackendId,
1283
+ adminBackend: adminBackendService.id,
1284
+ },
1285
+ opts,
1286
+ );
1287
+ }
1236
1288
 
1237
1289
  // #587 — the admin's run SA may rewrite the URL map's redirect rules through
1238
1290
  // a project custom role. The CLI owns that role, not this stack: the
@@ -1261,22 +1313,29 @@ const adminCert = new gcp.compute.ManagedSslCertificate(
1261
1313
  opts,
1262
1314
  );
1263
1315
 
1264
- const httpsProxy = new gcp.compute.TargetHttpsProxy(
1265
- `${namePrefix}-https-proxy`,
1266
- { urlMap: urlMap.id, sslCertificates: [adminCert.id, managedCert.id] },
1267
- opts,
1268
- );
1316
+ // #1330 — the staging host's own certificate is the CLI's
1317
+ // (staging-gateway-setup.ts, `caelo-<env>-staging-cert`), attached next to
1318
+ // these two after the first `up` and by every converge, so the proxy's
1319
+ // certificate list is left to it after creation.
1320
+ if (gatewayBackendService) {
1321
+ const urlMap = siteUrlMap(gatewayBackendService.id);
1322
+ const httpsProxy = new gcp.compute.TargetHttpsProxy(
1323
+ `${namePrefix}-https-proxy`,
1324
+ { urlMap: urlMap.id, sslCertificates: [adminCert.id, managedCert.id] },
1325
+ { ...opts, ignoreChanges: ["sslCertificates"] },
1326
+ );
1269
1327
 
1270
- new gcp.compute.GlobalForwardingRule(
1271
- `${namePrefix}-https-fwd`,
1272
- {
1273
- target: httpsProxy.id,
1274
- portRange: "443",
1275
- ipAddress: lbIp.address,
1276
- loadBalancingScheme: "EXTERNAL_MANAGED",
1277
- },
1278
- opts,
1279
- );
1328
+ new gcp.compute.GlobalForwardingRule(
1329
+ `${namePrefix}-https-fwd`,
1330
+ {
1331
+ target: httpsProxy.id,
1332
+ portRange: "443",
1333
+ ipAddress: lbIp.address,
1334
+ loadBalancingScheme: "EXTERNAL_MANAGED",
1335
+ },
1336
+ opts,
1337
+ );
1338
+ }
1280
1339
 
1281
1340
  // HTTP → HTTPS redirect: a tiny URLMap with no backend, just a 301
1282
1341
  // redirect rule. Same LB IP, port 80, returns to the request's host
@@ -1330,8 +1389,11 @@ const loggingSink = new gcp.logging.ProjectSink(
1330
1389
  {
1331
1390
  name: `${namePrefix}-edge-log-sink`,
1332
1391
  destination: pulumi.interpolate`bigquery.googleapis.com/projects/${project}/datasets/${edgeLogDataset.datasetId}`,
1333
- // Capture all gateway request logs + admin warnings/errors.
1334
- filter: pulumi.interpolate`(resource.type="cloud_run_revision" AND resource.labels.service_name="${gatewaySvc.name}") OR (resource.type="cloud_run_revision" AND resource.labels.service_name="${adminSvc.name}" AND severity>=WARNING)`,
1392
+ // Capture all gateway request logs + admin warnings/errors (the
1393
+ // gateway's once it is declared).
1394
+ filter: gatewaySvc
1395
+ ? pulumi.interpolate`(resource.type="cloud_run_revision" AND resource.labels.service_name="${gatewaySvc.name}") OR (resource.type="cloud_run_revision" AND resource.labels.service_name="${adminSvc.name}" AND severity>=WARNING)`
1396
+ : pulumi.interpolate`resource.type="cloud_run_revision" AND resource.labels.service_name="${adminSvc.name}" AND severity>=WARNING`,
1335
1397
  uniqueWriterIdentity: true,
1336
1398
  },
1337
1399
  opts,
@@ -1397,7 +1459,7 @@ export const environmentOut = out.environment;
1397
1459
  export const cloudSqlConnectionNameOut = sqlInstance.connectionName;
1398
1460
  export const cloudSqlPrivateIpOut = sqlInstance.privateIpAddress;
1399
1461
  export const adminCloudRunUrlOut = adminSvc.uri;
1400
- export const gatewayCloudRunUrlOut = gatewaySvc.uri;
1462
+ export const gatewayCloudRunUrlOut = gatewaySvc?.uri;
1401
1463
  export const lbIpOut = lbIp.address;
1402
1464
  export const adminDomainOut = adminDomain;
1403
1465
  export const bootstrapTokenExpiresAtOut = tokenInfo.expiresAt;
@@ -33,12 +33,14 @@ import * as random from "@pulumi/random";
33
33
  import type { CloudAdapterOutputs, DnsRecord } from "../../dist/adapter.js";
34
34
  import { generateBootstrapToken } from "../../dist/bootstrap-token.js";
35
35
  import {
36
+ firebaseStagingSiteId,
36
37
  gatewayServiceAccountId,
37
38
  gcpBucketName,
38
39
  gcpSecretId,
39
40
  MCP_IAP_SERVICE_ACCOUNT_ID,
40
41
  mcpAuthProxyServiceAccountId,
41
42
  runServiceAccountId,
43
+ stagingGatewayServiceAccountId,
42
44
  } from "../../dist/gcp-names.js";
43
45
  import {
44
46
  DEFAULT_ADMIN_MAX_INSTANCES,
@@ -65,7 +67,6 @@ import {
65
67
  defaultStagingHost,
66
68
  fixedCloudRunServiceName,
67
69
  gatewayEnvContract,
68
- INTERIM_FORWARD_ORIGIN_ENV,
69
70
  MCP_AUTH_PROXY_TIMEOUT_SECONDS,
70
71
  mcpAuthProxyEnvContract,
71
72
  REMOTE_MCP_IDENTITY_CONFIG,
@@ -76,6 +77,7 @@ import {
76
77
  SERVICE_VPC_EGRESS,
77
78
  secretFileVolumesTemplate,
78
79
  } from "../../dist/stack-contract.js";
80
+ import { DEPLOY_GATEWAYS_CONFIG, parseDeployGateways } from "../../dist/stack-gateways.js";
79
81
 
80
82
  const cfg = new pulumi.Config();
81
83
  const domain = cfg.require("domain");
@@ -482,9 +484,24 @@ const mcpAuthProxySa = new gcp.serviceaccount.Account(
482
484
  },
483
485
  opts,
484
486
  );
487
+ // #1330 — the staging gateway's own SA and (below) its secretAccessor on
488
+ // its one login password, plus the telemetry roles. Its service, its read
489
+ // access to the staging bucket and its edge (gcp: NEG, backend, host rule,
490
+ // certificate; gcp-firebase: the second Hosting site) are the CLI's
491
+ // (staging-gateway-setup.ts, after the first `up` and in every converge).
492
+ const stagingGatewaySa = new gcp.serviceaccount.Account(
493
+ `${namePrefix}-staging-gateway-sa`,
494
+ {
495
+ accountId: stagingGatewayServiceAccountId(env),
496
+ displayName: `Caelo ${env} staging gateway`,
497
+ createIgnoreAlreadyExists: true,
498
+ },
499
+ opts,
500
+ );
485
501
  const serviceSa: Record<CloudRunSlug, gcp.serviceaccount.Account> = {
486
502
  admin: runSa,
487
503
  gateway: gatewaySa,
504
+ "staging-gateway": stagingGatewaySa,
488
505
  "mcp-auth-proxy": mcpAuthProxySa,
489
506
  };
490
507
 
@@ -494,6 +511,7 @@ const serviceSa: Record<CloudRunSlug, gcp.serviceaccount.Account> = {
494
511
  const secretBindings: Record<CloudRunSlug, gcp.secretmanager.SecretIamMember[]> = {
495
512
  admin: [],
496
513
  gateway: [],
514
+ "staging-gateway": [],
497
515
  "mcp-auth-proxy": [],
498
516
  };
499
517
  for (const binding of runtimeSecretBindings()) {
@@ -593,6 +611,24 @@ new gcp.projects.IAMMember(
593
611
  },
594
612
  opts,
595
613
  );
614
+ new gcp.projects.IAMMember(
615
+ `${namePrefix}-staging-gateway-log-writer`,
616
+ {
617
+ project,
618
+ role: "roles/logging.logWriter",
619
+ member: pulumi.interpolate`serviceAccount:${stagingGatewaySa.email}`,
620
+ },
621
+ opts,
622
+ );
623
+ new gcp.projects.IAMMember(
624
+ `${namePrefix}-staging-gateway-metric-writer`,
625
+ {
626
+ project,
627
+ role: "roles/monitoring.metricWriter",
628
+ member: pulumi.interpolate`serviceAccount:${stagingGatewaySa.email}`,
629
+ },
630
+ opts,
631
+ );
596
632
 
597
633
  // =========================================================================
598
634
  // Tier 1 — Firebase Hosting site
@@ -794,26 +830,38 @@ const envContractInputs = {
794
830
  },
795
831
  } as const;
796
832
 
797
- // The data gateway is provisioned first so its name/region can go into the
798
- // admin's env (the Firebase publisher wires the /api/** rewrite to it).
799
- // #1328 — a service of its own (`caelo-<env>-data-gateway`); before, the
800
- // gateway was also the remote-MCP broker.
801
- const gatewaySvc = cloudRunService({
802
- serviceName: "gateway",
803
- minInstances: gatewayMinInstances,
804
- maxInstances: gatewayMaxInstances,
805
- memory: "512Mi",
806
- // Firebase Hosting cuts a rewritten request at 60 s anyway.
807
- timeout: "300s",
808
- // #650 — all traffic: `cms-provision staging-domain enable` maps the
809
- // staging host onto the data gateway (Cloud Run refuses domain-mapped
810
- // requests under an internal-only ingress), and it is invokable by
811
- // allUsers anyway (data-gateway-public-invoker below): every /api request
812
- // passes its rate limits, captcha and honeypot; staging requests pass the
813
- // staging access gate.
814
- ingress: "INGRESS_TRAFFIC_ALL",
815
- contractEnv: [...gatewayEnvContract(envContractInputs), ...poolBudget.env.gateway],
816
- });
833
+ // #1328 — the data gateway, a service of its own (`caelo-<env>-data-gateway`);
834
+ // before, the gateway was also the remote-MCP broker. Its fixed name goes into
835
+ // the admin's env (the Firebase publisher wires the /api/** rewrite to it).
836
+ //
837
+ // The first `up` of a fresh install withholds it (stack-gateways.ts): it
838
+ // refuses to start until the migrations, which run after that `up`, have
839
+ // isolated its database login. The admin names it by its fixed name, not by
840
+ // this resource, so the admin does not wait for it and keeps its env when it
841
+ // is declared.
842
+ const deployGateways = parseDeployGateways(cfg.get(DEPLOY_GATEWAYS_CONFIG));
843
+ const dataGatewayName = fixedCloudRunServiceName("gcp-firebase", env, "gateway");
844
+ if (!dataGatewayName) throw new Error("the gcp-firebase data gateway has no fixed service name");
845
+ const gatewaySvc = deployGateways
846
+ ? cloudRunService({
847
+ serviceName: "gateway",
848
+ // Its own logical name: `${namePrefix}-gateway` belongs to the
849
+ // MCP-Auth-Proxy (E13 a, below), and two resources with one URN fail
850
+ // every `pulumi up` (a fresh install could not converge, 2026-11-04).
851
+ resourceName: `${namePrefix}-data-gateway`,
852
+ minInstances: gatewayMinInstances,
853
+ maxInstances: gatewayMaxInstances,
854
+ memory: "512Mi",
855
+ // Firebase Hosting cuts a rewritten request at 60 s anyway.
856
+ timeout: "300s",
857
+ // All traffic: the Firebase rewrite arrives from Google's edge, and it is
858
+ // invokable by allUsers anyway (data-gateway-public-invoker below): every
859
+ // /api request passes its rate limits, captcha and honeypot. Staging has a
860
+ // gateway of its own since #1330 (staging-gateway-setup.ts).
861
+ ingress: "INGRESS_TRAFFIC_ALL",
862
+ contractEnv: [...gatewayEnvContract(envContractInputs), ...poolBudget.env.gateway],
863
+ })
864
+ : null;
817
865
 
818
866
  // #1328 — the MCP-Auth-Proxy: remote MCP's sign-in broker and its stream to
819
867
  // the IAP-protected admin, with no database, no VPC route and an account
@@ -832,15 +880,11 @@ const mcpAuthProxySvc = cloudRunService({
832
880
  // MCP clients call its run.app URL, never the Firebase rewrite (which
833
881
  // buffers streams and cuts at 60 s).
834
882
  timeout: `${MCP_AUTH_PROXY_TIMEOUT_SECONDS}s`,
835
- // Public: MCP clients reach it directly; until #1331 the staging host's
836
- // domain mapping (#650) still points at this service too, and the proxy
837
- // forwards that traffic to the data gateway (INTERIM_FORWARD_ORIGIN_ENV).
883
+ // Public: MCP clients reach it directly.
838
884
  ingress: "INGRESS_TRAFFIC_ALL",
839
885
  contractEnv: [
840
886
  ...mcpAuthProxyEnvContract({ provider: "gcp-firebase", env }),
841
887
  ...remoteMcpEnv["mcp-auth-proxy"],
842
- // FIXME(issue #1331): goes with the staging cutover.
843
- { name: INTERIM_FORWARD_ORIGIN_ENV, value: gatewaySvc.uri },
844
888
  ],
845
889
  });
846
890
 
@@ -861,7 +905,10 @@ const adminSvc = cloudRunService({
861
905
  ...adminEnvContract({
862
906
  ...envContractInputs,
863
907
  firebaseSiteId,
864
- gatewayService: gatewaySvc.name,
908
+ firebaseStagingSiteId: pulumi
909
+ .output(firebaseSiteId)
910
+ .apply((id) => firebaseStagingSiteId(env, id)),
911
+ gatewayService: dataGatewayName,
865
912
  }),
866
913
  ...remoteMcpEnv.admin,
867
914
  ...poolBudget.env.admin,
@@ -898,17 +945,19 @@ const adminSvc = cloudRunService({
898
945
  // in-app rate-limit middleware + form CAPTCHA + per-endpoint
899
946
  // authentication remain the real security boundary, exactly as
900
947
  // designed.
901
- new gcp.cloudrunv2.ServiceIamMember(
902
- `${namePrefix}-data-gateway-public-invoker`,
903
- {
904
- project,
905
- location: region,
906
- name: gatewaySvc.name,
907
- role: "roles/run.invoker",
908
- member: "allUsers",
909
- },
910
- opts,
911
- );
948
+ if (gatewaySvc) {
949
+ new gcp.cloudrunv2.ServiceIamMember(
950
+ `${namePrefix}-data-gateway-public-invoker`,
951
+ {
952
+ project,
953
+ location: region,
954
+ name: gatewaySvc.name,
955
+ role: "roles/run.invoker",
956
+ member: "allUsers",
957
+ },
958
+ opts,
959
+ );
960
+ }
912
961
 
913
962
  // #1328 — the MCP-Auth-Proxy: MCP clients sign in and call it without a
914
963
  // Google identity of their own. The binding the service had as the gateway,
@@ -943,17 +992,19 @@ new gcp.cloudrunv2.ServiceIamMember(
943
992
  // service for the runSa to act as itself. The gateway needs the
944
993
  // explicit cross-service grant because the admin's runSa is a
945
994
  // DIFFERENT-resource caller from the gateway's perspective.
946
- new gcp.cloudrunv2.ServiceIamMember(
947
- `${namePrefix}-data-gateway-viewer-for-admin-sa`,
948
- {
949
- project,
950
- location: region,
951
- name: gatewaySvc.name,
952
- role: "roles/run.viewer",
953
- member: pulumi.interpolate`serviceAccount:${runSa.email}`,
954
- },
955
- opts,
956
- );
995
+ if (gatewaySvc) {
996
+ new gcp.cloudrunv2.ServiceIamMember(
997
+ `${namePrefix}-data-gateway-viewer-for-admin-sa`,
998
+ {
999
+ project,
1000
+ location: region,
1001
+ name: gatewaySvc.name,
1002
+ role: "roles/run.viewer",
1003
+ member: pulumi.interpolate`serviceAccount:${runSa.email}`,
1004
+ },
1005
+ opts,
1006
+ );
1007
+ }
957
1008
 
958
1009
  // =========================================================================
959
1010
  // Admin custom domain — Cloud Run domain mapping
@@ -1286,7 +1337,7 @@ export const edgeLogSinkUrlOut = out.edgeLogSinkUrl;
1286
1337
  export const providerOut = out.provider;
1287
1338
  export const environmentOut = out.environment;
1288
1339
  export const adminCloudRunUrlOut = adminSvc.uri;
1289
- export const gatewayCloudRunUrlOut = gatewaySvc.uri;
1340
+ export const gatewayCloudRunUrlOut = gatewaySvc?.uri;
1290
1341
  export const mcpAuthProxyCloudRunUrlOut = mcpAuthProxySvc.uri;
1291
1342
  export const adminDomainOut = adminDomain;
1292
1343
  export const firebaseSiteIdOut = firebaseSiteId;
@@ -30,6 +30,7 @@ import {
30
30
  COMPOSE_ADMIN_UPSTREAM,
31
31
  COMPOSE_GATEWAY_UPSTREAM,
32
32
  COMPOSE_MCP_AUTH_PROXY_UPSTREAM,
33
+ COMPOSE_STAGING_GATEWAY_UPSTREAM,
33
34
  composeProjectName,
34
35
  generateDockerCompose,
35
36
  SITE_OUTPUT_ROOT,
@@ -89,6 +90,9 @@ const publicRolePassword = pulumi.secret(randomHex(32));
89
90
  const publicStagingRolePassword = pulumi.secret(randomHex(32));
90
91
  // P18 — the KEK that encrypts stored provider keys.
91
92
  const caeloSecretKek = pulumi.secret(randomHex(32));
93
+ // #650 / #1330 — the staging gate's key (admin only; the admin publishes it
94
+ // to the staging gateway through the staging projection).
95
+ const stagingGateSecret = pulumi.secret(randomHex(32));
92
96
 
93
97
  const composeYaml = pulumi
94
98
  .all([
@@ -97,10 +101,13 @@ const composeYaml = pulumi
97
101
  publicRolePassword,
98
102
  publicStagingRolePassword,
99
103
  caeloSecretKek,
104
+ stagingGateSecret,
100
105
  ])
101
- .apply(([pgPw, adminPw, publicPw, publicStagingPw, kek]) =>
106
+ .apply(([pgPw, adminPw, publicPw, publicStagingPw, kek, gateSecret]) =>
102
107
  generateDockerCompose({
103
108
  domain,
109
+ stagingHost,
110
+ stagingGateSecret: gateSecret,
104
111
  postgresPassword: pgPw,
105
112
  rolePasswords: { admin: adminPw, public: publicPw, publicStaging: publicStagingPw },
106
113
  caeloSecretKek: kek,
@@ -126,7 +133,7 @@ const caddyConf = generateCaddyfile({
126
133
  ownerEmail,
127
134
  tls: "acme",
128
135
  publicSiteRoot: `${SITE_OUTPUT_ROOT}/output/production/current`,
129
- stagingSiteRoot: `${SITE_OUTPUT_ROOT}/output/staging/current`,
136
+ stagingGatewayUpstream: COMPOSE_STAGING_GATEWAY_UPSTREAM,
130
137
  adminUpstream: COMPOSE_ADMIN_UPSTREAM,
131
138
  gatewayUpstream: COMPOSE_GATEWAY_UPSTREAM,
132
139
  mcpAuthProxyUpstream: COMPOSE_MCP_AUTH_PROXY_UPSTREAM,