@caelo-cms/provisioning 0.11.18 → 0.11.20

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 (126) hide show
  1. package/dist/agent-db.js +32 -0
  2. package/dist/aws-task-roles.d.ts +11 -0
  3. package/dist/aws-task-roles.d.ts.map +1 -1
  4. package/dist/aws-task-roles.js +19 -0
  5. package/dist/aws-task-roles.js.map +1 -1
  6. package/dist/azure-secrets.d.ts +22 -0
  7. package/dist/azure-secrets.d.ts.map +1 -0
  8. package/dist/azure-secrets.js +14 -0
  9. package/dist/azure-secrets.js.map +1 -0
  10. package/dist/caddy.d.ts +7 -0
  11. package/dist/caddy.d.ts.map +1 -1
  12. package/dist/caddy.js +22 -1
  13. package/dist/caddy.js.map +1 -1
  14. package/dist/cli.js +3 -0
  15. package/dist/cli.js.map +1 -1
  16. package/dist/gateway-armor.d.ts +24 -0
  17. package/dist/gateway-armor.d.ts.map +1 -0
  18. package/dist/gateway-armor.js +118 -0
  19. package/dist/gateway-armor.js.map +1 -0
  20. package/dist/gateway-edge.d.ts +128 -0
  21. package/dist/gateway-edge.d.ts.map +1 -0
  22. package/dist/gateway-edge.js +211 -0
  23. package/dist/gateway-edge.js.map +1 -0
  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 +21 -1
  27. package/dist/infra-contract.js.map +1 -1
  28. package/dist/lifecycle.d.ts.map +1 -1
  29. package/dist/lifecycle.js +8 -1
  30. package/dist/lifecycle.js.map +1 -1
  31. package/dist/pool-budget-stack.d.ts +22 -0
  32. package/dist/pool-budget-stack.d.ts.map +1 -1
  33. package/dist/pool-budget-stack.js +22 -1
  34. package/dist/pool-budget-stack.js.map +1 -1
  35. package/dist/public-service-shape.d.ts +45 -0
  36. package/dist/public-service-shape.d.ts.map +1 -0
  37. package/dist/public-service-shape.js +90 -0
  38. package/dist/public-service-shape.js.map +1 -0
  39. package/dist/remote-mcp-edge.d.ts +4 -4
  40. package/dist/remote-mcp-edge.d.ts.map +1 -1
  41. package/dist/remote-mcp-edge.js +2 -2
  42. package/dist/remote-mcp-edge.js.map +1 -1
  43. package/dist/remote-mcp.d.ts.map +1 -1
  44. package/dist/remote-mcp.js +30 -19
  45. package/dist/remote-mcp.js.map +1 -1
  46. package/dist/serverless-backend.d.ts +27 -0
  47. package/dist/serverless-backend.d.ts.map +1 -0
  48. package/dist/serverless-backend.js +30 -0
  49. package/dist/serverless-backend.js.map +1 -0
  50. package/dist/stack-contract.d.ts +6 -0
  51. package/dist/stack-contract.d.ts.map +1 -1
  52. package/dist/stack-contract.js +24 -0
  53. package/dist/stack-contract.js.map +1 -1
  54. package/dist/stack-converge.d.ts +13 -0
  55. package/dist/stack-converge.d.ts.map +1 -1
  56. package/dist/stack-converge.js +27 -0
  57. package/dist/stack-converge.js.map +1 -1
  58. package/dist/staging-gateway-setup.d.ts +5 -0
  59. package/dist/staging-gateway-setup.d.ts.map +1 -1
  60. package/dist/staging-gateway-setup.js +88 -28
  61. package/dist/staging-gateway-setup.js.map +1 -1
  62. package/dist/upgrade/app-roll.d.ts +5 -1
  63. package/dist/upgrade/app-roll.d.ts.map +1 -1
  64. package/dist/upgrade/app-roll.js +20 -3
  65. package/dist/upgrade/app-roll.js.map +1 -1
  66. package/dist/upgrade/converge.d.ts.map +1 -1
  67. package/dist/upgrade/converge.js +27 -4
  68. package/dist/upgrade/converge.js.map +1 -1
  69. package/dist/upgrade/health.d.ts +13 -3
  70. package/dist/upgrade/health.d.ts.map +1 -1
  71. package/dist/upgrade/health.js +24 -7
  72. package/dist/upgrade/health.js.map +1 -1
  73. package/dist/upgrade/load-balancer-get.d.ts +17 -0
  74. package/dist/upgrade/load-balancer-get.d.ts.map +1 -0
  75. package/dist/upgrade/load-balancer-get.js +38 -0
  76. package/dist/upgrade/load-balancer-get.js.map +1 -0
  77. package/dist/upgrader-gcp.d.ts.map +1 -1
  78. package/dist/upgrader-gcp.js +8 -1
  79. package/dist/upgrader-gcp.js.map +1 -1
  80. package/dist/wizards/gcp-cost.d.ts +9 -0
  81. package/dist/wizards/gcp-cost.d.ts.map +1 -1
  82. package/dist/wizards/gcp-cost.js +69 -34
  83. package/dist/wizards/gcp-cost.js.map +1 -1
  84. package/dist/wizards/gcp.js +1 -1
  85. package/dist/wizards/gcp.js.map +1 -1
  86. package/package.json +2 -2
  87. package/src/aws-task-roles.ts +22 -0
  88. package/src/azure-secrets.ts +38 -0
  89. package/src/caddy.test.ts +19 -2
  90. package/src/caddy.ts +23 -0
  91. package/src/cli.ts +5 -0
  92. package/src/gateway-armor.ts +135 -0
  93. package/src/gateway-bootstrap.test.ts +1 -0
  94. package/src/gateway-edge.test.ts +262 -0
  95. package/src/gateway-edge.ts +256 -0
  96. package/src/gateway-env-isolation.test.ts +45 -6
  97. package/src/infra-contract.test.ts +5 -3
  98. package/src/infra-contract.ts +21 -1
  99. package/src/lifecycle.ts +8 -1
  100. package/src/pool-budget-stack.ts +25 -0
  101. package/src/pool-budget-stacks.test.ts +31 -0
  102. package/src/public-service-shape.test.ts +166 -0
  103. package/src/public-service-shape.ts +131 -0
  104. package/src/remote-mcp-edge.ts +2 -2
  105. package/src/remote-mcp.test.ts +63 -2
  106. package/src/remote-mcp.ts +42 -19
  107. package/src/serverless-backend.ts +47 -0
  108. package/src/stack-contract.test.ts +13 -0
  109. package/src/stack-contract.ts +25 -0
  110. package/src/stack-converge.test.ts +28 -1
  111. package/src/stack-converge.ts +30 -0
  112. package/src/staging-gateway-setup.test.ts +134 -3
  113. package/src/staging-gateway-setup.ts +107 -36
  114. package/src/upgrade/app-roll.ts +27 -3
  115. package/src/upgrade/converge.ts +33 -4
  116. package/src/upgrade/health.test.ts +88 -13
  117. package/src/upgrade/health.ts +32 -7
  118. package/src/upgrade/load-balancer-get.ts +64 -0
  119. package/src/upgrade/upgrade.test.ts +97 -4
  120. package/src/upgrader-gcp.ts +8 -1
  121. package/src/wizards/gcp-cost.ts +78 -35
  122. package/src/wizards/gcp.ts +2 -1
  123. package/stacks/aws/index.ts +24 -22
  124. package/stacks/azure/index.ts +152 -64
  125. package/stacks/gcp/index.ts +35 -47
  126. package/stacks/gcp-firebase/index.ts +25 -13
@@ -18,6 +18,12 @@
18
18
  * either): it has no database, so it answers once it runs; under
19
19
  * `/api/mcp/`, the prefix the gcp load balancer routes to it.
20
20
  *
21
+ * On `gcp` the public two are asked through the load balancer with the
22
+ * site's Host header on a connection to `admin.<domain>`
23
+ * (load-balancer-get.ts), so an install whose main domain has no record yet
24
+ * (the weeks before go-live, #1459) takes updates like any other. Their
25
+ * `run.app` URLs are no way in: ingress is load-balancer-only.
26
+ *
21
27
  * Both answer with no secrets and no raw database errors. The admin sits
22
28
  * behind IAP, so the probe signs an IAP credential as the install's MCP
23
29
  * service account (`caelo-mcp@`, mcp-iap.ts) exactly like the MCP shim does
@@ -44,6 +50,7 @@
44
50
  import type { GcloudRunner, Sleep } from "../gcloud-retry.js";
45
51
  import { mcpIapServiceAccountEmail } from "../gcp-names.js";
46
52
  import type { HttpFetch } from "../runtime-secrets.js";
53
+ import type { LoadBalancerGet } from "./load-balancer-get.js";
47
54
 
48
55
  export type HealthOutcome =
49
56
  | { readonly ok: true; readonly detail: string }
@@ -186,10 +193,11 @@ export interface HealthTarget {
186
193
  }
187
194
 
188
195
  /**
189
- * The origins the probe calls. On gcp the admin's IAP lives on the load
196
+ * The origins the probe asks. On gcp the admin's IAP lives on the load
190
197
  * balancer (`admin.<domain>`), and the gateway's and the proxy's ingress is
191
- * load-balancer-only (`<domain>/api/*`, `<domain>/api/mcp/*`); on
192
- * gcp-firebase every `run.app` URL is reachable — the admin's through Cloud
198
+ * load-balancer-only (`<domain>/api/*`, `<domain>/api/mcp/*`, connected
199
+ * through the admin's name, see the module comment); on gcp-firebase every
200
+ * `run.app` URL is reachable — the admin's through Cloud
193
201
  * Run's own IAP, the others publicly.
194
202
  */
195
203
  export function healthOrigins(target: HealthTarget): {
@@ -219,6 +227,8 @@ export const IAM_PROPAGATION_WINDOW_MS = 7 * 60_000;
219
227
  export interface HealthProbeDeps {
220
228
  readonly run: GcloudRunner;
221
229
  readonly http: HttpFetch;
230
+ /** How `gcp` reaches the site's host through the load balancer (#1459). */
231
+ readonly loadBalancerGet: LoadBalancerGet;
222
232
  readonly sleep: Sleep;
223
233
  /**
224
234
  * Whether the converge step that ran just before changed the access the
@@ -347,7 +357,7 @@ export function createIapHealthProbe(target: HealthTarget, deps: HealthProbeDeps
347
357
  function gatewayRoutingHelp(): string {
348
358
  return target.provider === "gcp-firebase"
349
359
  ? `Requests to its run.app URL do not reach the Caelo gateway: its Cloud Run ingress likely refuses them. The gcp-firebase stack declares ingress "all"; upgrade's converge step sets it. Check it with: gcloud run services describe <gateway service> --region=<region> --project=${target.projectId} --format='value(metadata.annotations."run.googleapis.com/ingress")'`
350
- : `Requests to ${origins.gateway}/api/ do not reach the Caelo gateway: the load balancer's URL map must route /api/* to the gateway backend. Check the install's load balancer, then re-run upgrade.`;
360
+ : `Requests to ${origins.gateway}/api/ through the load balancer do not reach the Caelo gateway: its URL map must route /api/* to the gateway backend, and the gateway service must admit allUsers as roles/run.invoker (upgrade's converge step grants it; Cloud Run answers 403 without it). Check them, then re-run upgrade.`;
351
361
  }
352
362
 
353
363
  async function get(url: string, headers: Record<string, string>) {
@@ -359,6 +369,21 @@ export function createIapHealthProbe(target: HealthTarget, deps: HealthProbeDeps
359
369
  }
360
370
  }
361
371
 
372
+ /** A GET to a public service: on gcp through the load balancer (#1459). */
373
+ async function getPublic(origin: string, path: string) {
374
+ if (target.provider !== "gcp") return get(`${origin}${path}`, {});
375
+ try {
376
+ const res = await deps.loadBalancerGet({
377
+ connectHost: new URL(origins.admin).hostname,
378
+ hostHeader: new URL(origin).hostname,
379
+ path,
380
+ });
381
+ return { reached: true as const, status: res.status, text: res.text };
382
+ } catch (e) {
383
+ return { reached: false as const, error: e instanceof Error ? e.message : String(e) };
384
+ }
385
+ }
386
+
362
387
  async function baselineOnce(): Promise<BaselineOutcome> {
363
388
  const token = await iapToken();
364
389
  if (!token.ok) {
@@ -385,7 +410,7 @@ export function createIapHealthProbe(target: HealthTarget, deps: HealthProbeDeps
385
410
  refusal: admin.status === 401 || admin.status === 403 ? "iap-refused" : "other",
386
411
  };
387
412
  }
388
- const gateway = await get(`${origins.gateway}/api/_caelo/health`, {});
413
+ const gateway = await getPublic(origins.gateway, "/api/_caelo/health");
389
414
  if (!gateway.reached) {
390
415
  return {
391
416
  ok: false,
@@ -462,12 +487,12 @@ export function createIapHealthProbe(target: HealthTarget, deps: HealthProbeDeps
462
487
  if (!admin.reached) return { ok: false, error: `admin unreachable: ${admin.error}` };
463
488
  const a = evaluateAdminDeepHealth(admin.status, admin.text, expectedVersion);
464
489
  if (!a.ok) return a;
465
- const gateway = await get(`${origins.gateway}/api/_caelo/health?deep=1`, {});
490
+ const gateway = await getPublic(origins.gateway, "/api/_caelo/health?deep=1");
466
491
  if (!gateway.reached) return { ok: false, error: `gateway unreachable: ${gateway.error}` };
467
492
  const g = evaluatePublicServiceDeepHealth("gateway", gateway.status, gateway.text);
468
493
  if (!g.ok) return g;
469
494
  // #1328 — the proxy holds no database login: healthy once it answers.
470
- const proxy = await get(`${origins.mcpAuthProxy}${MCP_AUTH_PROXY_HEALTH_PATH}`, {});
495
+ const proxy = await getPublic(origins.mcpAuthProxy, MCP_AUTH_PROXY_HEALTH_PATH);
471
496
  if (!proxy.reached) return { ok: false, error: `MCP-Auth-Proxy unreachable: ${proxy.error}` };
472
497
  const p = evaluatePublicServiceDeepHealth("MCP-Auth-Proxy", proxy.status, proxy.text);
473
498
  return p.ok ? { ok: true, detail: `${a.detail}; ${g.detail}; ${p.detail}` } : p;
@@ -0,0 +1,64 @@
1
+ // SPDX-License-Identifier: MPL-2.0
2
+
3
+ /**
4
+ * A GET to one of the `gcp` load balancer's hosts, connected through another
5
+ * of its names (#1459).
6
+ *
7
+ * The load balancer routes by Host header, not by the name the connection
8
+ * was opened to, and every host of an install shares its address. So the
9
+ * health check reaches the site's `/api/*` before the site's domain has any
10
+ * record: it connects to `admin.<domain>`, whose record and certificate the
11
+ * install needs anyway, verifies that certificate as usual, and asks for the
12
+ * site's host. The site's own certificate cannot serve here: Google issues it
13
+ * only once the domain points at the load balancer.
14
+ *
15
+ * `node:https` because `fetch` may not set the Host header (undici), and this
16
+ * runs under Bun in the ops image and under either runtime from a terminal.
17
+ */
18
+
19
+ import { request } from "node:https";
20
+
21
+ /** One GET through the load balancer. */
22
+ export interface LoadBalancerRequest {
23
+ /** The name to connect to and verify the certificate against. */
24
+ readonly connectHost: string;
25
+ /** The host the URL map routes on. */
26
+ readonly hostHeader: string;
27
+ /** Path and query. */
28
+ readonly path: string;
29
+ }
30
+
31
+ /** Sends a {@link LoadBalancerRequest}; rejects when no HTTP answer came. */
32
+ export type LoadBalancerGet = (
33
+ req: LoadBalancerRequest,
34
+ ) => Promise<{ readonly status: number; readonly text: string }>;
35
+
36
+ const TIMEOUT_MS = 30_000;
37
+
38
+ /** {@link LoadBalancerGet} over HTTPS, with the default certificate checks. */
39
+ export const httpsLoadBalancerGet: LoadBalancerGet = (req) =>
40
+ new Promise((resolve, reject) => {
41
+ const outgoing = request(
42
+ {
43
+ host: req.connectHost,
44
+ servername: req.connectHost,
45
+ path: req.path,
46
+ method: "GET",
47
+ headers: { Host: req.hostHeader },
48
+ timeout: TIMEOUT_MS,
49
+ },
50
+ (res) => {
51
+ const chunks: Buffer[] = [];
52
+ res.on("data", (chunk: Buffer) => chunks.push(chunk));
53
+ res.on("error", reject);
54
+ res.on("end", () =>
55
+ resolve({ status: res.statusCode ?? 0, text: Buffer.concat(chunks).toString("utf8") }),
56
+ );
57
+ },
58
+ );
59
+ outgoing.on("timeout", () =>
60
+ outgoing.destroy(new Error(`no answer from ${req.connectHost} in ${TIMEOUT_MS / 1000} s`)),
61
+ );
62
+ outgoing.on("error", reject);
63
+ outgoing.end();
64
+ });
@@ -221,11 +221,20 @@ function fakeInstall(events: string[], overrides: [RegExp, Answer][] = []) {
221
221
  return { run, calls };
222
222
  }
223
223
 
224
- /** Cloud SQL Admin API: every operation is done at once. */
224
+ /**
225
+ * Cloud SQL Admin API: every operation is done at once. Firebase Hosting: the
226
+ * staging host's DNS already points at the staging site.
227
+ */
225
228
  const http: HttpFetch = async () => ({
226
229
  ok: true,
227
230
  status: 200,
228
- text: async () => JSON.stringify({ name: "op-1", status: "DONE" }),
231
+ text: async () =>
232
+ JSON.stringify({
233
+ name: "op-1",
234
+ status: "DONE",
235
+ hostState: "HOST_ACTIVE",
236
+ ownershipState: "OWNERSHIP_ACTIVE",
237
+ }),
229
238
  });
230
239
 
231
240
  function recordingReporter() {
@@ -732,6 +741,71 @@ describe("upgradeGcpInstall — converge, then app-roll", () => {
732
741
  ).toBe(false);
733
742
  });
734
743
 
744
+ it("#1463 — an existing install's gateways reach the budget in the revision that rolls their image", async () => {
745
+ const before = (json: string) => {
746
+ const svc = JSON.parse(json);
747
+ svc.spec.template.metadata.annotations["autoscaling.knative.dev/maxScale"] = "100";
748
+ return ok(JSON.stringify(svc));
749
+ };
750
+ const events: string[] = [];
751
+ const { deps } = upgradeDeps(events, {
752
+ overrides: [
753
+ [new RegExp(`describe ${GATEWAY} .*--format=json`), before(GATEWAY_JSON)],
754
+ [new RegExp(`describe ${STAGING} .*--format=json`), before(STAGING_JSON)],
755
+ ],
756
+ });
757
+ expect(await upgradeGcpInstall(TARGET, deps)).toBe(true);
758
+ const roll = (service: string) =>
759
+ events.find((e) => e.startsWith(`gcloud run services update ${service} `)) ?? "";
760
+ expect(roll(GATEWAY)).toContain("--image registry/gateway@");
761
+ expect(roll(GATEWAY)).toContain("--max-instances=10");
762
+ expect(roll(GATEWAY)).toContain("CAELO_DB_PUBLIC_POOL_MAX=2");
763
+ expect(roll(STAGING)).toContain("--image registry/gateway@");
764
+ expect(roll(STAGING)).toContain("--max-instances=1");
765
+ expect(roll(STAGING)).toContain("CAELO_DB_PUBLIC_POOL_MAX=2");
766
+ // Neither reaches the services the budget does not size this way.
767
+ expect(roll(ADMIN)).not.toContain("--max-instances");
768
+ expect(roll(PROXY)).not.toContain("CAELO_DB_PUBLIC_POOL_MAX");
769
+ });
770
+
771
+ it("#1455 — names the records and keeps the old route while the staging host's DNS has not moved", async () => {
772
+ const events: string[] = [];
773
+ const { deps, lines, recorded } = upgradeDeps(events, {
774
+ overrides: [
775
+ [/^beta run domain-mappings describe/, ok("staging.acme.com\n")],
776
+ // Nothing else keeps this converge incomplete.
777
+ [/^compute firewall-rules list/, ok("[]")],
778
+ ],
779
+ });
780
+ const notMoved: HttpFetch = async (url) => ({
781
+ ok: true,
782
+ status: 200,
783
+ text: async () =>
784
+ JSON.stringify(
785
+ url.includes("/customDomains/")
786
+ ? {
787
+ hostState: "HOST_UNHOSTED",
788
+ requiredDnsUpdates: {
789
+ desired: [
790
+ {
791
+ records: [
792
+ { domainName: "staging.acme.com.", type: "A", rdata: "199.36.158.100" },
793
+ ],
794
+ },
795
+ ],
796
+ },
797
+ }
798
+ : { name: "op-1", status: "DONE" },
799
+ ),
800
+ });
801
+ expect(await upgradeGcpInstall(TARGET, { ...deps, http: notMoved })).toBe(true);
802
+ expect(events.some((e) => e.includes("domain-mappings delete"))).toBe(false);
803
+ expect(lines.some((l) => l.includes("staging.acme.com A 199.36.158.100"))).toBe(true);
804
+ expect(lines.some((l) => l.includes("keeps that route"))).toBe(true);
805
+ // The Owner's DNS change must not hold every later update back.
806
+ expect(recorded.contract).toEqual([TARGET.infraContractVersion]);
807
+ });
808
+
735
809
  it("#883 review: an install without caelo-provisioner still records the contract; its admin keeps the terminal path", async () => {
736
810
  const events: string[] = [];
737
811
  const { deps, recorded, lines } = upgradeDeps(events, {
@@ -1162,7 +1236,7 @@ describe("upgradeGcpInstall — converge, then app-roll", () => {
1162
1236
  );
1163
1237
  const backend = indexOf(
1164
1238
  events,
1165
- /^gcloud compute backend-services create caelo-production-mcp-auth-proxy-backend .*--security-policy=caelo-production-mcp-auth-proxy-armor/,
1239
+ /^gcloud compute backend-services update caelo-production-mcp-auth-proxy-backend .*--security-policy=caelo-production-mcp-auth-proxy-armor/,
1166
1240
  );
1167
1241
  const retire = indexOf(
1168
1242
  events,
@@ -1196,6 +1270,17 @@ describe("upgradeGcpInstall — converge, then app-roll", () => {
1196
1270
  expect(neg).toBeLessThan(backend);
1197
1271
  expect(backend).toBeLessThan(retire);
1198
1272
  expect(retire).toBeLessThan(indexOf(events, /^migrate /));
1273
+ // #1339 (contract 22) — the gateway policy's per-path rules, before the
1274
+ // migrations; the general ban is limited to /api/ paths.
1275
+ const general = indexOf(
1276
+ events,
1277
+ /^gcloud compute security-policies rules create 1001 --security-policy=caelo-production-waf-1 .*--expression=request\.path\.contains\('\/api\/'\)/,
1278
+ );
1279
+ expect(
1280
+ indexOf(events, /rules create 800 --security-policy=caelo-production-waf-1 /),
1281
+ ).toBeLessThan(general);
1282
+ expect(general).toBeLessThan(indexOf(events, /^migrate /));
1283
+ expect(lines).toContain("done: Cloud Armor rules of caelo-production-waf-1 in place");
1199
1284
  });
1200
1285
 
1201
1286
  it("on gcp-firebase there is no URL map: no redirects role", async () => {
@@ -1336,7 +1421,15 @@ describe("upgradeGcpInstall — converge, then app-roll", () => {
1336
1421
  gatewayServiceUrl: `https://${GATEWAY}-xyz.a.run.app`,
1337
1422
  mcpAuthProxyServiceUrl: `https://${PROXY}-xyz.a.run.app`,
1338
1423
  },
1339
- { run: deps.run, http: htmlGateway, sleep: noSleep, accessJustChanged: false },
1424
+ {
1425
+ run: deps.run,
1426
+ http: htmlGateway,
1427
+ loadBalancerGet: async () => {
1428
+ throw new Error("gcp-firebase never uses the load balancer path");
1429
+ },
1430
+ sleep: noSleep,
1431
+ accessJustChanged: false,
1432
+ },
1340
1433
  ),
1341
1434
  }),
1342
1435
  }),
@@ -42,6 +42,7 @@ import {
42
42
  } from "./upgrade/gcp-lookup.js";
43
43
  import { createIapHealthProbe } from "./upgrade/health.js";
44
44
  import { createReleaseImageForms } from "./upgrade/image-forms.js";
45
+ import { httpsLoadBalancerGet } from "./upgrade/load-balancer-get.js";
45
46
  import { type IamTester, restIamTester } from "./upgrader-iam-preflight.js";
46
47
  import type { UpdateQueue, UpgraderJobDeps } from "./upgrader-job.js";
47
48
  import type { JobLog } from "./upgrader-reporter.js";
@@ -152,7 +153,13 @@ export async function healthProbeFor(
152
153
  gatewayServiceUrl: urls.gateway as string,
153
154
  mcpAuthProxyServiceUrl: urls["mcp-auth-proxy"] as string,
154
155
  },
155
- { run, http, sleep: realSleep, accessJustChanged: context.accessJustChanged },
156
+ {
157
+ run,
158
+ http,
159
+ loadBalancerGet: httpsLoadBalancerGet,
160
+ sleep: realSleep,
161
+ accessJustChanged: context.accessJustChanged,
162
+ },
156
163
  ),
157
164
  };
158
165
  }
@@ -11,10 +11,12 @@
11
11
  * + AI calls + storage growth on top.
12
12
  */
13
13
 
14
+ import { GATEWAY_ARMOR_BILLED_RULES } from "../gateway-edge.js";
14
15
  import {
15
16
  ADMIN_MEMORY_DEFAULT,
16
17
  memoryQuantityMiB,
17
18
  parseSchedulerIntervalMinutes,
19
+ RUNTIME_SECRETS,
18
20
  SERVICE_CPU_IDLE,
19
21
  } from "../stack-contract.js";
20
22
 
@@ -124,6 +126,27 @@ export function alwaysOnAdminInstanceUsd(gib: number): number {
124
126
  return Math.round(perSecond * MONTH_SECONDS);
125
127
  }
126
128
 
129
+ /**
130
+ * Cloud Armor Standard list prices, USD a month (cloud.google.com/armor/pricing,
131
+ * checked 2026-11-02): $0.006849315 per policy-hour and $0.001369863 per
132
+ * rule-hour, rounded; plus $0.75 per million requests on a global policy.
133
+ */
134
+ export const CLOUD_ARMOR_POLICY_USD = 5;
135
+ export const CLOUD_ARMOR_RULE_USD = 1;
136
+
137
+ /**
138
+ * Secret Manager: $0.06 per active secret version a month, the first 6 per
139
+ * billing account free (cloud.google.com/secret-manager/pricing); access
140
+ * operations are cents at Caelo's volume.
141
+ */
142
+ const SECRET_VERSION_USD = 0.06;
143
+ const SECRET_FREE_VERSIONS = 6;
144
+
145
+ /** What `count` secrets with one active version each cost a month. */
146
+ export function secretManagerMonthlyUsd(count: number): number {
147
+ return Math.round(Math.max(0, count - SECRET_FREE_VERSIONS) * SECRET_VERSION_USD * 100) / 100;
148
+ }
149
+
127
150
  /** The region the price table's list rates are for. */
128
151
  const PRICED_REGION = "europe-west1";
129
152
 
@@ -210,6 +233,16 @@ export function estimateGcpCost(inputs: CostEstimateInputs): {
210
233
  ? "scale-to-zero; ~$1/mo light traffic"
211
234
  : `${inputs.gatewayMinInstances} min-instance${inputs.gatewayMinInstances > 1 ? "s" : ""}`,
212
235
  },
236
+ {
237
+ // #1330 — the staging gateway serves the staged site behind the
238
+ // staging gate. Like every public service it is always provisioned at
239
+ // zero minimum instances with request-based CPU (E14 a of #763), and
240
+ // answers a fixed 404 while no staging host is set.
241
+ name: "Cloud Run staging gateway",
242
+ monthlyUsd: 0,
243
+ notes:
244
+ "scale-to-zero, request-based CPU; only the team's visits to staging wake it, mostly in the free tier",
245
+ },
213
246
  {
214
247
  // #1328 — remote MCP's sign-in service, its own service on every
215
248
  // install (E14 a of #763): always provisioned, zero minimum instances,
@@ -219,17 +252,18 @@ export function estimateGcpCost(inputs: CostEstimateInputs): {
219
252
  notes:
220
253
  "scale-to-zero, request-based CPU; only external AI apps' sign-in and MCP calls wake it, mostly in the free tier",
221
254
  },
222
- // v0.3.3 — LB / Cloud CDN / Cloud Armor lines apply only to the
223
- // gcp variant. gcp-firebase has no LB (Firebase Hosting is the
224
- // edge); no Cloud CDN line (Firebase Hosting has its own CDN
225
- // included in free tier); no Cloud Armor (admin is gated by
226
- // Cloud Run IAP, gateway by run.invoker IAM).
255
+ // Only the gcp variant has a load balancer, Cloud CDN and Cloud Armor.
256
+ // gcp-firebase has none of them (E3 of #763): Firebase Hosting is the
257
+ // edge with its own CDN, the admin is gated by IAP on Cloud Run, and the
258
+ // public services protect themselves without a WAF
259
+ // (docs/dev/gateway-hardening.md).
227
260
  ...(provider === "gcp"
228
261
  ? ([
229
262
  {
230
263
  name: "Load balancer + managed SSL cert",
231
264
  monthlyUsd: 18,
232
- notes: "Global LB base fee + cert (free) — flat",
265
+ notes:
266
+ "Global LB base fee (up to 5 forwarding rules) + certificates (free) — flat; the staging host's route and certificate (#1330) add nothing",
233
267
  },
234
268
  {
235
269
  name: "Cloud CDN cache",
@@ -237,52 +271,61 @@ export function estimateGcpCost(inputs: CostEstimateInputs): {
237
271
  notes: "Free egress at edge cache hits",
238
272
  },
239
273
  {
240
- name: "Cloud Armor WAF",
241
- monthlyUsd: inputs.wafAdaptiveProtection ? 5 : 0,
242
- notes: inputs.wafAdaptiveProtection
243
- ? "Adaptive protection (ML-based bot mitigation)"
244
- : "Free tier — rate limit + OWASP basic rules",
274
+ // #1339 — the gateway's policy (src/gateway-edge.ts): its rules
275
+ // plus the default rule, each billed; the staging gateway's
276
+ // backend shares it. Prices: CLOUD_ARMOR_POLICY_USD above.
277
+ name: "Cloud Armor policy (gateway + staging gateway)",
278
+ monthlyUsd:
279
+ CLOUD_ARMOR_POLICY_USD +
280
+ GATEWAY_ARMOR_BILLED_RULES * CLOUD_ARMOR_RULE_USD +
281
+ (inputs.wafAdaptiveProtection ? 5 : 0),
282
+ notes: `policy ($${CLOUD_ARMOR_POLICY_USD}) with ${GATEWAY_ARMOR_BILLED_RULES} rules ($${GATEWAY_ARMOR_BILLED_RULES * CLOUD_ARMOR_RULE_USD}): per-IP bans on credential operations and the visitor API, a captcha throttle, OWASP sqli/xss at sensitivity 1${inputs.wafAdaptiveProtection ? "; adaptive protection (ML-based bot mitigation) +$5" : ""}; an extra layer, the gateways rate-limit themselves; requests ~$0`,
245
283
  },
246
284
  {
247
285
  // #1328 — the MCP-Auth-Proxy's own backend (serverless NEG +
248
286
  // backend service, no extra LB fee: same URL map) with its own
249
287
  // Cloud Armor policy carrying the remote-MCP throttle
250
- // (src/remote-mcp-edge.ts) and the default rule. Cloud Armor
251
- // Standard: $0.006849315/policy-hour (~$5/mo) and
252
- // $0.001369863/rule-hour (~$1/mo), plus $0.75 per million
253
- // requests on a global policy — cloud.google.com/armor/pricing,
254
- // checked 2026-11-02.
288
+ // (src/remote-mcp-edge.ts) and the default rule.
255
289
  name: "MCP-Auth-Proxy backend + Cloud Armor policy",
256
- monthlyUsd: 7,
290
+ monthlyUsd: CLOUD_ARMOR_POLICY_USD + 2 * CLOUD_ARMOR_RULE_USD,
257
291
  notes:
258
292
  "own policy ($5) with 2 rules ($2): per-IP throttle for remote MCP clients; requests ~$0",
259
293
  },
294
+ {
295
+ name: "Cloud Storage (static + media + staging)",
296
+ monthlyUsd: 1,
297
+ notes:
298
+ "~5 GB storage + low egress; the staging bucket holds two complete builds (#1330 A/B slots); growth roughly $0.02/GB",
299
+ },
300
+ {
301
+ name: "BigQuery edge log sink",
302
+ monthlyUsd: 0,
303
+ notes: "Free tier — pay only on >1 TB/mo query",
304
+ },
260
305
  ] satisfies CostLine[])
261
306
  : ([
262
307
  {
263
- name: "Firebase Hosting",
308
+ name: "Firebase Hosting (live + staging site)",
264
309
  monthlyUsd: 0,
265
- notes: "Free tier: 10 GB storage + 360 MB/day egress",
310
+ notes:
311
+ "Free tier: 10 GB storage + 360 MB/day egress; the staging site (#1330) only rewrites to the staging gateway and stores nothing",
312
+ },
313
+ {
314
+ name: "Cloud Storage (media + staging)",
315
+ monthlyUsd: 1,
316
+ notes:
317
+ "~5 GB storage + low egress; static lives on Firebase; the private staging bucket holds two complete builds (#1330 A/B slots); growth roughly $0.02/GB",
318
+ },
319
+ {
320
+ name: "Cloud Logging (service logs, the edge log sink)",
321
+ monthlyUsd: 0,
322
+ notes: "Free tier: the first 50 GiB of logs a month",
266
323
  },
267
324
  ] satisfies CostLine[])),
268
- {
269
- name:
270
- provider === "gcp"
271
- ? "Cloud Storage (static + media)"
272
- : "Cloud Storage (media only — static lives on Firebase)",
273
- monthlyUsd: 1,
274
- notes: "~5 GB storage + low egress; growth roughly $0.02/GB",
275
- },
276
325
  {
277
326
  name: "Secret Manager (runtime secrets)",
278
- monthlyUsd: 0.2,
279
- notes:
280
- "6 active versions free, then ~$0.06 each; the Google sign-in client (#914), the remote-MCP seal key (#806) and the staging database login's password (#1329; the staging database itself shares the Cloud SQL instance at no extra cost)",
281
- },
282
- {
283
- name: "BigQuery edge log sink",
284
- monthlyUsd: 0,
285
- notes: "Free tier — pay only on >1 TB/mo query",
327
+ monthlyUsd: secretManagerMonthlyUsd(RUNTIME_SECRETS.length),
328
+ notes: `${RUNTIME_SECRETS.length} secrets, one active version each: 6 free, then $${SECRET_VERSION_USD} each (the database logins of the admin and both gateways, the Google sign-in client, the remote-MCP seal key, the staging gate key and three internal keys; the staging database shares the Cloud SQL instance at no extra cost)`,
286
329
  },
287
330
  {
288
331
  name: "Install state (ops bucket + Cloud KMS key)",
@@ -2635,7 +2635,8 @@ async function stepFinalize(installId: string, setupLink: "print" | "secret"): P
2635
2635
  "",
2636
2636
  bold("Protected staging site:"),
2637
2637
  ` ${cyan(installStagingHost(meta))} is served by the staging gateway behind the staging gate,`,
2638
- " once the DNS records printed above (also under Settings → Updates) point at it.",
2638
+ " once the staging gateway step above reported ready and the DNS record it printed",
2639
+ " (also under Settings → Updates) points at it.",
2639
2640
  ` To turn on password protection and print the staging login once, run`,
2640
2641
  ` ${dim(selfCommand("staging-domain", "enable"))}`,
2641
2642
  " The host serves pages after the first Stage.",
@@ -37,6 +37,7 @@ import * as awsx from "@pulumi/awsx";
37
37
  import * as pulumi from "@pulumi/pulumi";
38
38
  import type { CloudAdapterOutputs, DnsRecord } from "../../dist/adapter.js";
39
39
  import {
40
+ AWS_SERVICE_DATABASE_PASSWORDS,
40
41
  AWS_SERVICE_SECRETS,
41
42
  type AwsSecret,
42
43
  type AwsTaskService,
@@ -215,30 +216,19 @@ const db = new aws.rds.Instance(`${namePrefix}-pg`, {
215
216
  applyImmediately: env !== "production",
216
217
  });
217
218
 
218
- const adminDatabaseUrl = pulumi
219
- .all([db.address, db.port, postgresPassword])
220
- .apply(
221
- ([host, port, pw]) => `postgresql://caelo_admin:${pw}@${host}:${port}/cms_admin?${RDS_TLS}`,
222
- );
223
- const publicDatabaseUrl = pulumi
224
- .all([db.address, db.port, publicRolePassword])
225
- .apply(
226
- ([host, port, pw]) => `postgresql://public_role:${pw}@${host}:${port}/cms_public?${RDS_TLS}`,
227
- );
219
+ // #1339 (epic #763 L5) — password-less, like on GCP: each task definition
220
+ // (#749) sets the password as an ECS `secrets` entry from Secrets Manager
221
+ // (AWS_SERVICE_DATABASE_PASSWORDS, exported as databasePasswordSecretsOut),
222
+ // never inside the URL, so it shows up neither in the task's env nor in its
223
+ // revision history (shared database-url.ts `<NAME>_PASSWORD`).
224
+ const dbUrl = (role: string, database: string) =>
225
+ pulumi.interpolate`postgresql://${role}@${db.address}:${db.port}/${database}?${RDS_TLS}`;
226
+ const adminDatabaseUrl = dbUrl("caelo_admin", "cms_admin");
227
+ const publicDatabaseUrl = dbUrl("public_role", "cms_public");
228
228
  // #1329 — the admin's pool on the staging database, and the staging
229
229
  // gateway's only login (no task definition reads them before #749).
230
- const publicStagingAdminDatabaseUrl = pulumi
231
- .all([db.address, db.port, postgresPassword])
232
- .apply(
233
- ([host, port, pw]) =>
234
- `postgresql://caelo_admin:${pw}@${host}:${port}/cms_public_staging?${RDS_TLS}`,
235
- );
236
- const publicStagingDatabaseUrl = pulumi
237
- .all([db.address, db.port, publicStagingRolePassword])
238
- .apply(
239
- ([host, port, pw]) =>
240
- `postgresql://public_staging_role:${pw}@${host}:${port}/cms_public_staging?${RDS_TLS}`,
241
- );
230
+ const publicStagingAdminDatabaseUrl = dbUrl("caelo_admin", "cms_public_staging");
231
+ const publicStagingDatabaseUrl = dbUrl("public_staging_role", "cms_public_staging");
242
232
 
243
233
  // === 4. S3 buckets ===
244
234
  const mediaBucket = new aws.s3.BucketV2(`${namePrefix}-media`, {
@@ -585,6 +575,7 @@ const dnsRecordsRequired: DnsRecord[] = [
585
575
  ];
586
576
 
587
577
  const out: CloudAdapterOutputs = {
578
+ // Password-less — the passwords live only in Secrets Manager (#1339).
588
579
  adminDatabaseUrl: adminDatabaseUrl as unknown as string,
589
580
  publicDatabaseUrl: publicDatabaseUrl as unknown as string,
590
581
  publicStagingDatabaseUrl: publicStagingDatabaseUrl as unknown as string,
@@ -621,6 +612,17 @@ export const adminTaskRoleArnOut = taskRoles.admin.arn;
621
612
  export const gatewayTaskRoleArnOut = taskRoles.gateway.arn;
622
613
  // #1328 — the role the MCP-Auth-Proxy task definition will run as (#749).
623
614
  export const mcpAuthProxyTaskRoleArnOut = taskRoles["mcp-auth-proxy"].arn;
615
+ // #1339 — per task definition (#749): the ECS `secrets` entries
616
+ // (`{ name, valueFrom }`) that carry its database passwords.
617
+ export const databasePasswordSecretsOut = Object.fromEntries(
618
+ Object.entries(AWS_SERVICE_DATABASE_PASSWORDS).map(([service, vars]) => [
619
+ service,
620
+ Object.entries(vars).map(([name, secretName]) => ({
621
+ name,
622
+ valueFrom: secretArns[secretName],
623
+ })),
624
+ ]),
625
+ );
624
626
  // #1254 — the pool env the admin and gateway task definitions set.
625
627
  export const poolBudgetEnvOut = poolBudget.env;
626
628