@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
@@ -30,7 +30,12 @@
30
30
  import { describe, expect, it } from "bun:test";
31
31
  import { readFileSync } from "node:fs";
32
32
  import { resolve } from "node:path";
33
- import { AWS_SERVICE_SECRETS, secretsReadPolicy } from "./aws-task-roles.js";
33
+ import {
34
+ AWS_SERVICE_DATABASE_PASSWORDS,
35
+ AWS_SERVICE_SECRETS,
36
+ secretsReadPolicy,
37
+ } from "./aws-task-roles.js";
38
+ import { AZURE_SERVICE_DATABASE_SECRETS } from "./azure-secrets.js";
34
39
  import { generateDockerCompose } from "./compose.js";
35
40
  import {
36
41
  databaseUrls,
@@ -220,13 +225,35 @@ describe("azure: the gateway container app (#635)", () => {
220
225
  expect(stack("azure")).not.toMatch(/gateway_role:\$\{/);
221
226
  });
222
227
 
223
- it("gives no container app an identity or Key Vault access (review finding)", () => {
224
- // The vault uses RBAC authorisation: without a role assignment or a
225
- // managed identity no container app can read any vault secret, so the
226
- // gateway's only credential is the public_role URL in its env.
228
+ it("the gateway's identity reads public_role's password and no other secret (#1339, review finding)", () => {
229
+ // #1339 — the passwords left the URLs for Key Vault references. The vault
230
+ // uses RBAC authorisation, so an identity reads only the secrets it holds
231
+ // a role assignment on: one assignment per (reader, secret) from
232
+ // AZURE_SERVICE_DATABASE_SECRETS, scoped to the secret, never the vault.
227
233
  const src = stack("azure");
228
234
  expect(src).toContain("enableRbacAuthorization: true");
229
- expect(src).not.toMatch(/RoleAssignment|accessPolicies|identity\s*:|keyVaultUrl|secretRef/);
235
+ expect(src).not.toMatch(/accessPolicies/);
236
+ expect(src.match(/new azure\.authorization\.RoleAssignment\(/g)).toHaveLength(1);
237
+ expect(src).toContain("scope: keyVaultSecrets[name].id,");
238
+ // An app resolves its Key Vault references at creation: grants first (#1429 review).
239
+ expect(src).toContain("{ dependsOn: [...(args.secrets?.grants ?? [])] }");
240
+ expect(src).toContain(
241
+ "for (const name of new Set(Object.values(AZURE_SERVICE_DATABASE_SECRETS[reader]))) {",
242
+ );
243
+ expect(AZURE_SERVICE_DATABASE_SECRETS.gateway).toEqual({
244
+ PUBLIC_DATABASE_PASSWORD: "public-role-password",
245
+ });
246
+ const start = src.indexOf('serviceName: "gateway"');
247
+ const block = src.slice(start, src.indexOf("});", start));
248
+ expect(block).toContain("secrets: gatewaySecretReader,");
249
+ // The proxy reads nothing (#1328).
250
+ const proxy = src.slice(src.indexOf('serviceName: "mcp-auth-proxy"'));
251
+ expect(proxy.slice(0, proxy.indexOf("});"))).not.toContain("secrets:");
252
+ });
253
+
254
+ it("puts no password into a database URL (#1339)", () => {
255
+ const src = stack("azure");
256
+ expect(src).not.toMatch(/postgresql:\/\/[a-z_]+:\$\{/);
230
257
  });
231
258
  });
232
259
 
@@ -264,4 +291,16 @@ describe("aws: the stack (#635)", () => {
264
291
  });
265
292
  expect(() => secretsReadPolicy([])).toThrow();
266
293
  });
294
+
295
+ it("database passwords come from Secrets Manager, never inside a URL (#1339)", () => {
296
+ expect(stack("aws")).not.toMatch(/postgresql:\/\/[a-z_]+:\$\{/);
297
+ expect(AWS_SERVICE_DATABASE_PASSWORDS.gateway).toEqual({
298
+ PUBLIC_DATABASE_PASSWORD: "public-role-password",
299
+ });
300
+ for (const [service, vars] of Object.entries(AWS_SERVICE_DATABASE_PASSWORDS)) {
301
+ for (const secret of Object.values(vars)) {
302
+ expect(AWS_SERVICE_SECRETS[service as keyof typeof AWS_SERVICE_SECRETS]).toContain(secret);
303
+ }
304
+ }
305
+ });
267
306
  });
@@ -20,8 +20,8 @@ describe("infrastructure contract steps", () => {
20
20
  );
21
21
  });
22
22
 
23
- it("is at 20: 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)", () => {
24
- expect(INFRA_CONTRACT_VERSION).toBe(20);
23
+ it("is at 22: 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)", () => {
24
+ expect(INFRA_CONTRACT_VERSION).toBe(22);
25
25
  expect(INFRA_CONTRACT_STEPS[3]).toContain("#633");
26
26
  expect(INFRA_CONTRACT_STEPS[4]).toContain("#587");
27
27
  expect(INFRA_CONTRACT_STEPS[5]).toContain("#635");
@@ -40,6 +40,8 @@ describe("infrastructure contract steps", () => {
40
40
  expect(INFRA_CONTRACT_STEPS[18]).toContain("#1140");
41
41
  expect(INFRA_CONTRACT_STEPS[19]).toContain("JSON");
42
42
  expect(INFRA_CONTRACT_STEPS[20]).toContain("#1330");
43
+ expect(INFRA_CONTRACT_STEPS[21]).toContain("#1463");
44
+ expect(INFRA_CONTRACT_STEPS[22]).toContain("#1339");
43
45
  });
44
46
 
45
47
  it("lists the pending steps oldest first", () => {
@@ -50,6 +52,6 @@ describe("infrastructure contract steps", () => {
50
52
  });
51
53
 
52
54
  it("names a version a newer release added by number", () => {
53
- expect(infraStepsText(20, 21)).toBe("infrastructure step 21 (see that release's notes)");
55
+ expect(infraStepsText(22, 23)).toBe("infrastructure step 23 (see that release's notes)");
54
56
  });
55
57
  });
@@ -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 = 20;
25
+ export const INFRA_CONTRACT_VERSION = 22;
26
26
 
27
27
  // History (why each bump happened — an install below a number needs the
28
28
  // converge that introduced it):
@@ -169,6 +169,24 @@ export const INFRA_CONTRACT_VERSION = 20;
169
169
  // forwarder. New service, account, bucket, IAM and edge resources the
170
170
  // in-cloud upgrader may not create, and the app-roll rolls four
171
171
  // services from now on.
172
+ // 21 — #1463 and the plain-gcp repairs. The app-roll now brings the gateways
173
+ // to the connection budget (max instances, CAELO_DB_PUBLIC_POOL_MAX),
174
+ // but an in-cloud upgrader rolls with the code of the release it runs
175
+ // from, so without this bump an install would keep 100 gateway
176
+ // instances until the update after next; the converge job runs the
177
+ // target release's code. On `gcp` the gateway also gets its allUsers
178
+ // run.invoker (the stack never declared it, so every /api/ call
179
+ // answered Cloud Run's 403) and the CLI-owned backends created with
180
+ // the `https` port name get `http` and their NEG: IAM and
181
+ // load-balancer writes the in-cloud upgrader may not make.
182
+ // 22 — #1339: on `gcp` the gateway's Cloud Armor policy gets per-path
183
+ // rules (gateway-edge.ts): a tighter ban on the auth plugin's
184
+ // credential operations, a captcha throttle, the general ban limited
185
+ // to /api/ paths (it banned staging reviewers, whose pages share the
186
+ // policy since #1330) and the OWASP packs at sensitivity 1. Policy
187
+ // writes the in-cloud upgrader holds no compute rights for, so the
188
+ // converge applies them (gateway-armor.ts). Other providers have
189
+ // nothing to converge for it.
172
190
 
173
191
  /**
174
192
  * What each contract version adds, in operator terms — the upgrader's
@@ -196,6 +214,8 @@ export const INFRA_CONTRACT_STEPS: Readonly<Record<number, string>> = {
196
214
  18: "the scheduler tick that runs the admin's periodic work and plugin workers every few minutes: its service account, workflow and Cloud Scheduler job, and its IAP access (#1140)",
197
215
  19: "the scheduler tick sent as a JSON request, because the admin refused every tick before (#1140)",
198
216
  20: "the staging gateway that serves the staged site behind the staging gate on every address: its service, service account and grants, the private staging bucket, and the staging host's own route (a second Firebase Hosting site, or a host rule and certificate on the load balancer); the live gateway no longer holds the staging gate key (#1330, #1331)",
217
+ 21: "the gateways' scale-out and connection pool kept inside the database connection budget, and on Google Cloud load-balancer installs the gateway open to visitors and the sign-in and staging routes repaired (#1463)",
218
+ 22: "per-path Cloud Armor rules for the visitor and staging gateways on Google Cloud load-balancer installs: a tighter ban on sign-up, login and password reset, a captcha throttle, the general ban only on the visitor API, and fewer false positives from the OWASP rules (#1339)",
199
219
  };
200
220
 
201
221
  /**
package/src/lifecycle.ts CHANGED
@@ -74,6 +74,7 @@ import { restoreCommand, takeSqlBackup } from "./upgrade/backup.js";
74
74
  import { findServiceUrl, lookupFailure, resolveGcpResourceName } from "./upgrade/gcp-lookup.js";
75
75
  import { createIapHealthProbe, type HealthProbe } from "./upgrade/health.js";
76
76
  import { createReleaseImageForms, platformDigestsOf } from "./upgrade/image-forms.js";
77
+ import { httpsLoadBalancerGet } from "./upgrade/load-balancer-get.js";
77
78
  import { recordRolledDigests } from "./upgrade/record-rolled.js";
78
79
  import {
79
80
  canonicalReleaseTag,
@@ -692,7 +693,13 @@ async function gcpHealthProbe(
692
693
  gatewayServiceUrl: urls.gateway as string,
693
694
  mcpAuthProxyServiceUrl: urls["mcp-auth-proxy"] as string,
694
695
  },
695
- { run, http, sleep: realSleep, accessJustChanged: context.accessJustChanged },
696
+ {
697
+ run,
698
+ http,
699
+ loadBalancerGet: httpsLoadBalancerGet,
700
+ sleep: realSleep,
701
+ accessJustChanged: context.accessJustChanged,
702
+ },
696
703
  ),
697
704
  };
698
705
  }
@@ -14,7 +14,9 @@
14
14
 
15
15
  import {
16
16
  computePoolBudget,
17
+ DB_PUBLIC_POOL_MAX_ENV,
17
18
  DEFAULT_STAGING_GATEWAY_MAX_INSTANCES,
19
+ GATEWAY_POOL_MAX,
18
20
  type PoolBudget,
19
21
  type PoolBudgetInput,
20
22
  poolBudgetEnv,
@@ -87,6 +89,29 @@ export const DEFAULT_MAX_CONNECTIONS: Readonly<Record<BudgetProvider, number>> =
87
89
  */
88
90
  export const DEFAULT_GATEWAY_MAX_INSTANCES = 10;
89
91
 
92
+ /**
93
+ * #1463 — the most instances each gateway may run, for what `upgrade` applies
94
+ * to an existing install. An upgrade reads no stack config, so this is a
95
+ * ceiling, not a target: the live value is lowered to it and never raised
96
+ * (app-roll.ts), which keeps a smaller `gatewayMaxInstances` an operator set.
97
+ * Above it the database refuses the gateway's connections (`public_role`'s
98
+ * CONNECTION LIMIT, pool-budget.ts).
99
+ */
100
+ export const GATEWAY_MAX_INSTANCES_CEILING = {
101
+ gateway: DEFAULT_GATEWAY_MAX_INSTANCES,
102
+ "staging-gateway": DEFAULT_STAGING_GATEWAY_MAX_INSTANCES,
103
+ } as const;
104
+
105
+ /**
106
+ * #1463 — the pool env of one gateway instance, live or staging: what the
107
+ * stacks set from {@link stackPoolBudget} and `upgrade` sets on an install
108
+ * that has none. It does not depend on the scale-out, so a roll that cannot
109
+ * see stack config still sets the right value.
110
+ */
111
+ export const GATEWAY_POOL_ENV: readonly { readonly name: string; readonly value: string }[] = [
112
+ { name: DB_PUBLIC_POOL_MAX_ENV, value: String(GATEWAY_POOL_MAX) },
113
+ ];
114
+
90
115
  /**
91
116
  * Admin instances a GCP or AWS stack lets start (`adminMaxInstances` knob).
92
117
  * Five before #1329; the staging database added the admin's
@@ -9,6 +9,12 @@
9
9
  import { describe, expect, it } from "bun:test";
10
10
  import { readFileSync } from "node:fs";
11
11
  import { resolve } from "node:path";
12
+ import {
13
+ GATEWAY_POOL_MAX,
14
+ GATEWAY_ROLE_CONNECTION_LIMIT,
15
+ LISTEN_CONNECTIONS_PER_GATEWAY_INSTANCE,
16
+ STAGING_GATEWAY_ROLE_CONNECTION_LIMIT,
17
+ } from "@caelo-cms/shared";
12
18
  import { COMPOSE_POOL_BUDGET } from "./compose.js";
13
19
  import {
14
20
  type BudgetProvider,
@@ -16,6 +22,8 @@ import {
16
22
  DEFAULT_GATEWAY_MAX_INSTANCES,
17
23
  DEFAULT_MAX_CONNECTIONS,
18
24
  DEFAULT_STAGING_GATEWAY_MAX_INSTANCES,
25
+ GATEWAY_MAX_INSTANCES_CEILING,
26
+ GATEWAY_POOL_ENV,
19
27
  stackPoolBudget,
20
28
  } from "./pool-budget-stack.js";
21
29
 
@@ -123,3 +131,26 @@ describe("stacks set the budget on their services", () => {
123
131
  expect(COMPOSE_POOL_BUDGET.budget.adminPoolMax).toBe(EXPECTED["self-hosted"][0]);
124
132
  });
125
133
  });
134
+
135
+ describe("#1463 — what an upgrade applies to an existing install's gateways", () => {
136
+ const atCeiling = stackPoolBudget("gcp", {
137
+ maxConnections: DEFAULT_MAX_CONNECTIONS.gcp,
138
+ adminMaxInstances: DEFAULT_ADMIN_MAX_INSTANCES,
139
+ gatewayMaxInstances: GATEWAY_MAX_INSTANCES_CEILING.gateway,
140
+ stagingGatewayMaxInstances: GATEWAY_MAX_INSTANCES_CEILING["staging-gateway"],
141
+ });
142
+
143
+ it("is the budget the stacks deploy", () => {
144
+ expect(GATEWAY_POOL_ENV).toEqual(atCeiling.env.gateway);
145
+ });
146
+
147
+ it("stays inside what the database lets each gateway login hold", () => {
148
+ for (const [slug, limit] of [
149
+ ["gateway", GATEWAY_ROLE_CONNECTION_LIMIT],
150
+ ["staging-gateway", STAGING_GATEWAY_ROLE_CONNECTION_LIMIT],
151
+ ] as const) {
152
+ const perInstance = GATEWAY_POOL_MAX + LISTEN_CONNECTIONS_PER_GATEWAY_INSTANCE;
153
+ expect(GATEWAY_MAX_INSTANCES_CEILING[slug] * perInstance).toBeLessThanOrEqual(limit);
154
+ }
155
+ });
156
+ });
@@ -0,0 +1,166 @@
1
+ // SPDX-License-Identifier: MPL-2.0
2
+
3
+ /**
4
+ * Epic #763 E11 / #1339 — every adapter provisions the public services in
5
+ * the shape of PUBLIC_SERVICE_SHAPE: at zero minimum instances, behind the
6
+ * edge the table names, with a WAF only where the table says so, and the
7
+ * GCP cost table prices what is provisioned. Pure-string checks on the
8
+ * stack programs and the CLI setup modules, like the other stack tests.
9
+ */
10
+
11
+ import { describe, expect, it } from "bun:test";
12
+ import { readFileSync } from "node:fs";
13
+ import { resolve } from "node:path";
14
+ import type { SupportedProvider } from "./adapter.js";
15
+ import { generateDockerCompose } from "./compose.js";
16
+ import { GATEWAY_ARMOR_BILLED_RULES } from "./gateway-edge.js";
17
+ import { PUBLIC_SERVICE_SHAPE, type PublicService } from "./public-service-shape.js";
18
+ import {
19
+ CLOUD_ARMOR_POLICY_USD,
20
+ CLOUD_ARMOR_RULE_USD,
21
+ estimateGcpCost,
22
+ } from "./wizards/gcp-cost.js";
23
+
24
+ const stack = (provider: SupportedProvider) =>
25
+ readFileSync(resolve(import.meta.dir, `../stacks/${provider}/index.ts`), "utf8");
26
+ const src = (file: string) => readFileSync(resolve(import.meta.dir, file), "utf8");
27
+
28
+ const SERVICES: readonly PublicService[] = ["gateway", "staging-gateway", "mcp-auth-proxy"];
29
+
30
+ /** The `cloudRunService({ serviceName: "<name>", … })` call of a GCP stack. */
31
+ function cloudRunBlock(source: string, name: string): string | null {
32
+ const m = new RegExp(
33
+ `cloudRunService\\(\\{\\s*serviceName: "${name}",([\\s\\S]*?)\\n\\s*\\}\\)`,
34
+ ).exec(source);
35
+ return m?.[1] ?? null;
36
+ }
37
+
38
+ describe("E11: one public-service shape for every provider", () => {
39
+ for (const provider of ["gcp", "gcp-firebase"] as const) {
40
+ describe(provider, () => {
41
+ const source = stack(provider);
42
+ for (const service of SERVICES) {
43
+ const shape = PUBLIC_SERVICE_SHAPE[provider][service];
44
+ it(`${service}: ${shape.owner.kind}-owned at zero minimum instances`, () => {
45
+ if (shape.owner.kind === "stack") {
46
+ const block = cloudRunBlock(source, service);
47
+ expect(block).not.toBeNull();
48
+ // The gateway's minimum is the §11.B knob, which defaults to 0.
49
+ const min = service === "gateway" ? "gatewayMinInstances" : "0";
50
+ expect(block).toContain(`minInstances: ${min},`);
51
+ expect(source).toContain(
52
+ `const gatewayMinInstances = Number.parseInt(cfg.get("gatewayMinInstances") ?? "0", 10);`,
53
+ );
54
+ } else if (shape.owner.kind === "cli") {
55
+ const setup = src(shape.owner.module);
56
+ expect(setup).toContain('"--min-instances=0"');
57
+ expect(setup).toContain('"--cpu-throttling"');
58
+ // The stack does not declare what the CLI owns.
59
+ expect(cloudRunBlock(source, service)).toBeNull();
60
+ } else {
61
+ throw new Error(`${provider} ${service}: unexpected owner ${shape.owner.kind}`);
62
+ }
63
+ });
64
+ }
65
+ it(`a WAF only where the table says so (${provider})`, () => {
66
+ const anyWaf = SERVICES.some((s) => PUBLIC_SERVICE_SHAPE[provider][s].waf !== "none");
67
+ if (anyWaf) {
68
+ expect(source).toContain("new gcp.compute.SecurityPolicy(");
69
+ expect(source).toMatch(/function gatewayBackend\([\s\S]*?securityPolicy: wafPolicy\.id/);
70
+ } else {
71
+ // E3: the cheap setup has no load balancer and no WAF.
72
+ expect(source).not.toContain("SecurityPolicy");
73
+ expect(source).not.toContain("gcp.compute.URLMap");
74
+ expect(source).not.toContain("BackendService(");
75
+ }
76
+ });
77
+ });
78
+ }
79
+
80
+ it("self-hosted runs every public service in Compose", () => {
81
+ const compose = generateDockerCompose({
82
+ domain: "acme.com",
83
+ postgresPassword: "pw",
84
+ rolePasswords: { admin: "a", public: "b", publicStaging: "ps" },
85
+ caeloSecretKek: "0".repeat(64),
86
+ dbTlsServerCertSha256: "ab".repeat(32),
87
+ internalSecret: "i".repeat(48),
88
+ stagingHost: "staging.acme.com",
89
+ stagingGateSecret: "g".repeat(64),
90
+ diskSize: "20Gi",
91
+ ports: { http: 80, https: 443 },
92
+ project: "caelo-acme-com",
93
+ images: {
94
+ mode: "release" as const,
95
+ admin: `ghcr.io/caelo-cms/admin@sha256:${"a".repeat(64)}`,
96
+ gateway: `ghcr.io/caelo-cms/gateway@sha256:${"b".repeat(64)}`,
97
+ "mcp-auth-proxy": `ghcr.io/caelo-cms/mcp-auth-proxy@sha256:${"c".repeat(64)}`,
98
+ },
99
+ });
100
+ for (const service of SERVICES) {
101
+ const owner = PUBLIC_SERVICE_SHAPE["self-hosted"][service].owner;
102
+ if (owner.kind !== "compose") throw new Error(`self-hosted ${service} is not in Compose`);
103
+ expect(compose).toContain(`\n ${owner.service}:\n`);
104
+ }
105
+ });
106
+
107
+ it("aws refuses honestly until #749: no public service, the gap named", () => {
108
+ const source = stack("aws");
109
+ for (const service of SERVICES) {
110
+ expect(PUBLIC_SERVICE_SHAPE.aws[service].owner).toEqual({ kind: "refused", issue: "#749" });
111
+ }
112
+ expect(source).not.toContain("new aws.ecs.Service(");
113
+ expect(source).not.toContain("new aws.ecs.TaskDefinition(");
114
+ expect(source).toContain("FIXME(issue #749)");
115
+ });
116
+
117
+ it("azure: the gateway scales to zero by default, the proxy always; staging refused until #750", () => {
118
+ const source = stack("azure");
119
+ expect(source).toContain(
120
+ `const gatewayMinInstances = Number.parseInt(cfg.get("gatewayMinInstances") ?? "0", 10);`,
121
+ );
122
+ expect(source).toMatch(/serviceName: "gateway",[\s\S]*?minReplicas: gatewayMinInstances,/);
123
+ expect(source).toMatch(/serviceName: "mcp-auth-proxy",[\s\S]*?isolated: true,/);
124
+ expect(source).toContain("minReplicas: args.isolated ? 0 :");
125
+ expect(PUBLIC_SERVICE_SHAPE.azure["staging-gateway"].owner).toEqual({
126
+ kind: "refused",
127
+ issue: "#750",
128
+ });
129
+ expect(source).not.toContain('serviceName: "staging-gateway"');
130
+ expect(source).not.toContain("WebApplicationFirewallPolicy");
131
+ });
132
+ });
133
+
134
+ describe("the GCP cost table prices every provisioned public service (§11.C)", () => {
135
+ for (const provider of ["gcp", "gcp-firebase"] as const) {
136
+ const { lines } = estimateGcpCost({
137
+ cloudSqlTier: "db-f1-micro",
138
+ cloudSqlHa: false,
139
+ adminMinInstances: 0,
140
+ gatewayMinInstances: 0,
141
+ wafAdaptiveProtection: false,
142
+ provider,
143
+ region: "europe-west1",
144
+ });
145
+ const names = lines.map((l) => l.name);
146
+ it(`${provider}: a Cloud Run line per public service`, () => {
147
+ expect(names.some((n) => /Cloud Run (data )?gateway$/.test(n))).toBe(true);
148
+ expect(names).toContain("Cloud Run staging gateway");
149
+ expect(names).toContain("Cloud Run MCP-Auth-Proxy");
150
+ });
151
+ it(`${provider}: Cloud Armor lines exactly where the table has a WAF`, () => {
152
+ const armor = lines.filter((l) => l.name.includes("Cloud Armor"));
153
+ const wafs = SERVICES.filter((s) => PUBLIC_SERVICE_SHAPE[provider][s].waf === "cloud-armor");
154
+ if (wafs.length === 0) {
155
+ expect(armor).toEqual([]);
156
+ expect(names.some((n) => n.startsWith("Load balancer"))).toBe(false);
157
+ return;
158
+ }
159
+ // Two policies: the gateways' (shared with the staging gateway) and the proxy's.
160
+ expect(armor.map((l) => l.monthlyUsd)).toEqual([
161
+ CLOUD_ARMOR_POLICY_USD + GATEWAY_ARMOR_BILLED_RULES * CLOUD_ARMOR_RULE_USD,
162
+ CLOUD_ARMOR_POLICY_USD + 2 * CLOUD_ARMOR_RULE_USD,
163
+ ]);
164
+ });
165
+ }
166
+ });
@@ -0,0 +1,131 @@
1
+ // SPDX-License-Identifier: MPL-2.0
2
+
3
+ /**
4
+ * Epic #763 E11 — one shape for every provider: the three public services,
5
+ * which edge sits in front of each, whether a WAF is part of it, and who
6
+ * provisions it. Only the primitive differs per provider. aws and azure
7
+ * host the shape once #749 / #750 land; until then they refuse honestly
8
+ * (no service, or a service that answers the fixed 404).
9
+ *
10
+ * Two rules hold for every row (E14 a): a public service is always
11
+ * provisioned at zero minimum instances (the gateway's minimum is the
12
+ * operator's `gatewayMinInstances` knob, default 0), and while its feature
13
+ * is off it answers a fixed 404 before it reads the request. No row needs
14
+ * a WAF (E3): `cloud-armor` is an extra layer where the provider has one.
15
+ *
16
+ * public-service-shape.test.ts pins every stack, CLI setup module and the
17
+ * Compose file to this table, and the GCP cost table to its billable rows.
18
+ */
19
+
20
+ import type { SupportedProvider } from "./adapter.js";
21
+
22
+ /** The public services of an install (CLAUDE.md §11.B Tier 3 and the MCP-Auth-Proxy). */
23
+ export type PublicService = "gateway" | "staging-gateway" | "mcp-auth-proxy";
24
+
25
+ /** One provider's primitive for one public service. */
26
+ export interface PublicServiceShape {
27
+ /**
28
+ * Who creates it: the Pulumi stack, the CLI's setup module (named), the
29
+ * self-hosted Compose file, or nobody yet (`refused`, with the issue).
30
+ */
31
+ readonly owner:
32
+ | { readonly kind: "stack" }
33
+ | { readonly kind: "cli"; readonly module: string }
34
+ | { readonly kind: "compose"; readonly service: string }
35
+ | { readonly kind: "refused"; readonly issue: string };
36
+ /** What is in front of it on the public internet. */
37
+ readonly edge: string;
38
+ /** A WAF in front of it, as an extra layer only. */
39
+ readonly waf: "cloud-armor" | "none";
40
+ }
41
+
42
+ /** The E11 table. */
43
+ export const PUBLIC_SERVICE_SHAPE: Readonly<
44
+ Record<SupportedProvider, Readonly<Record<PublicService, PublicServiceShape>>>
45
+ > = {
46
+ gcp: {
47
+ gateway: {
48
+ owner: { kind: "stack" },
49
+ edge: "the site's load balancer: /api/* → serverless NEG → backend service",
50
+ waf: "cloud-armor",
51
+ },
52
+ "staging-gateway": {
53
+ owner: { kind: "cli", module: "staging-gateway-setup.ts" },
54
+ edge: "the site's load balancer: the staging host's rule → its own backend service",
55
+ waf: "cloud-armor",
56
+ },
57
+ "mcp-auth-proxy": {
58
+ owner: { kind: "cli", module: "mcp-auth-proxy-setup.ts" },
59
+ edge: "the site's load balancer: the MCP paths → its own backend service",
60
+ waf: "cloud-armor",
61
+ },
62
+ },
63
+ "gcp-firebase": {
64
+ gateway: {
65
+ owner: { kind: "stack" },
66
+ edge: "Firebase Hosting rewrite of /api/**, and its run.app URL",
67
+ waf: "none",
68
+ },
69
+ "staging-gateway": {
70
+ owner: { kind: "cli", module: "staging-gateway-setup.ts" },
71
+ edge: "a second Firebase Hosting site's ** rewrite, and its run.app URL",
72
+ waf: "none",
73
+ },
74
+ "mcp-auth-proxy": {
75
+ owner: { kind: "stack" },
76
+ edge: "its own run.app URL",
77
+ waf: "none",
78
+ },
79
+ },
80
+ "self-hosted": {
81
+ gateway: {
82
+ owner: { kind: "compose", service: "caelo-gateway" },
83
+ edge: "Caddy: /api/* on the site's host",
84
+ waf: "none",
85
+ },
86
+ "staging-gateway": {
87
+ owner: { kind: "compose", service: "caelo-staging-gateway" },
88
+ edge: "Caddy: every path of the staging host",
89
+ waf: "none",
90
+ },
91
+ "mcp-auth-proxy": {
92
+ owner: { kind: "compose", service: "caelo-mcp-auth-proxy" },
93
+ edge: "none until remote MCP is available on self-hosted (fixed 404 on the Compose network)",
94
+ waf: "none",
95
+ },
96
+ },
97
+ aws: {
98
+ gateway: {
99
+ owner: { kind: "refused", issue: "#749" },
100
+ edge: "CloudFront → ALB → Fargate, with #749",
101
+ waf: "none",
102
+ },
103
+ "staging-gateway": {
104
+ owner: { kind: "refused", issue: "#749" },
105
+ edge: "with #749",
106
+ waf: "none",
107
+ },
108
+ "mcp-auth-proxy": {
109
+ owner: { kind: "refused", issue: "#749" },
110
+ edge: "its own origin, with #749",
111
+ waf: "none",
112
+ },
113
+ },
114
+ azure: {
115
+ gateway: {
116
+ owner: { kind: "stack" },
117
+ edge: "Front Door route to its Container App, with #750",
118
+ waf: "none",
119
+ },
120
+ "staging-gateway": {
121
+ owner: { kind: "refused", issue: "#750" },
122
+ edge: "with #750",
123
+ waf: "none",
124
+ },
125
+ "mcp-auth-proxy": {
126
+ owner: { kind: "stack" },
127
+ edge: "its own Container App FQDN (fixed 404: remote MCP needs Google IAP)",
128
+ waf: "none",
129
+ },
130
+ },
131
+ };
@@ -33,7 +33,7 @@
33
33
  * slows down instead of locking everyone out. Below the threshold the
34
34
  * rule's action is `allow`, which ends evaluation: the OWASP packs and the
35
35
  * general ban do not run for these paths. Abuse stays bounded by the
36
- * gateway's max instances (100) and by IAP, which rejects every request
36
+ * proxy's max instances and by IAP, which rejects every request
37
37
  * without a valid token of an allowlisted user before it reaches the admin.
38
38
  */
39
39
 
@@ -51,7 +51,7 @@
51
51
  * The dotted metadata aliases (`/.well-known/…`, `oauth/.well-known/…`) are
52
52
  * one-off GETs per connection and stay under the general rules.
53
53
  */
54
- export const MCP_ARMOR_PATH_PATTERN = "^/api/mcp/(chat|admin|oauth/[a-z-]+(/[a-z-]+)?)$";
54
+ export const MCP_ARMOR_PATH_PATTERN = "^/api/mcp/(?:chat|admin|oauth/[a-z-]+(?:/[a-z-]+)?)$";
55
55
 
56
56
  /** The general per-IP ban rule and the OWASP rule packs the MCP rule must precede. */
57
57
  export const GENERAL_RATE_LIMIT_PRIORITY = 1000;