@caelo-cms/provisioning 0.11.19 → 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 (121) 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 +1 -1
  40. package/dist/remote-mcp-edge.js +1 -1
  41. package/dist/remote-mcp.d.ts.map +1 -1
  42. package/dist/remote-mcp.js +12 -2
  43. package/dist/remote-mcp.js.map +1 -1
  44. package/dist/serverless-backend.d.ts +27 -0
  45. package/dist/serverless-backend.d.ts.map +1 -0
  46. package/dist/serverless-backend.js +30 -0
  47. package/dist/serverless-backend.js.map +1 -0
  48. package/dist/stack-contract.d.ts +6 -0
  49. package/dist/stack-contract.d.ts.map +1 -1
  50. package/dist/stack-contract.js +24 -0
  51. package/dist/stack-contract.js.map +1 -1
  52. package/dist/stack-converge.d.ts +13 -0
  53. package/dist/stack-converge.d.ts.map +1 -1
  54. package/dist/stack-converge.js +27 -0
  55. package/dist/stack-converge.js.map +1 -1
  56. package/dist/staging-gateway-setup.d.ts +5 -0
  57. package/dist/staging-gateway-setup.d.ts.map +1 -1
  58. package/dist/staging-gateway-setup.js +60 -19
  59. package/dist/staging-gateway-setup.js.map +1 -1
  60. package/dist/upgrade/app-roll.d.ts +5 -1
  61. package/dist/upgrade/app-roll.d.ts.map +1 -1
  62. package/dist/upgrade/app-roll.js +20 -3
  63. package/dist/upgrade/app-roll.js.map +1 -1
  64. package/dist/upgrade/converge.d.ts.map +1 -1
  65. package/dist/upgrade/converge.js +27 -4
  66. package/dist/upgrade/converge.js.map +1 -1
  67. package/dist/upgrade/health.d.ts +13 -3
  68. package/dist/upgrade/health.d.ts.map +1 -1
  69. package/dist/upgrade/health.js +24 -7
  70. package/dist/upgrade/health.js.map +1 -1
  71. package/dist/upgrade/load-balancer-get.d.ts +17 -0
  72. package/dist/upgrade/load-balancer-get.d.ts.map +1 -0
  73. package/dist/upgrade/load-balancer-get.js +38 -0
  74. package/dist/upgrade/load-balancer-get.js.map +1 -0
  75. package/dist/upgrader-gcp.d.ts.map +1 -1
  76. package/dist/upgrader-gcp.js +8 -1
  77. package/dist/upgrader-gcp.js.map +1 -1
  78. package/dist/wizards/gcp-cost.d.ts +9 -0
  79. package/dist/wizards/gcp-cost.d.ts.map +1 -1
  80. package/dist/wizards/gcp-cost.js +69 -34
  81. package/dist/wizards/gcp-cost.js.map +1 -1
  82. package/package.json +2 -2
  83. package/src/aws-task-roles.ts +22 -0
  84. package/src/azure-secrets.ts +38 -0
  85. package/src/caddy.test.ts +19 -2
  86. package/src/caddy.ts +23 -0
  87. package/src/cli.ts +5 -0
  88. package/src/gateway-armor.ts +135 -0
  89. package/src/gateway-bootstrap.test.ts +1 -0
  90. package/src/gateway-edge.test.ts +262 -0
  91. package/src/gateway-edge.ts +256 -0
  92. package/src/gateway-env-isolation.test.ts +45 -6
  93. package/src/infra-contract.test.ts +5 -3
  94. package/src/infra-contract.ts +21 -1
  95. package/src/lifecycle.ts +8 -1
  96. package/src/pool-budget-stack.ts +25 -0
  97. package/src/pool-budget-stacks.test.ts +31 -0
  98. package/src/public-service-shape.test.ts +166 -0
  99. package/src/public-service-shape.ts +131 -0
  100. package/src/remote-mcp-edge.ts +1 -1
  101. package/src/remote-mcp.test.ts +38 -1
  102. package/src/remote-mcp.ts +25 -3
  103. package/src/serverless-backend.ts +47 -0
  104. package/src/stack-contract.test.ts +13 -0
  105. package/src/stack-contract.ts +25 -0
  106. package/src/stack-converge.test.ts +28 -1
  107. package/src/stack-converge.ts +30 -0
  108. package/src/staging-gateway-setup.test.ts +55 -3
  109. package/src/staging-gateway-setup.ts +79 -27
  110. package/src/upgrade/app-roll.ts +27 -3
  111. package/src/upgrade/converge.ts +33 -4
  112. package/src/upgrade/health.test.ts +88 -13
  113. package/src/upgrade/health.ts +32 -7
  114. package/src/upgrade/load-balancer-get.ts +64 -0
  115. package/src/upgrade/upgrade.test.ts +96 -3
  116. package/src/upgrader-gcp.ts +8 -1
  117. package/src/wizards/gcp-cost.ts +78 -35
  118. package/stacks/aws/index.ts +24 -22
  119. package/stacks/azure/index.ts +152 -64
  120. package/stacks/gcp/index.ts +35 -47
  121. package/stacks/gcp-firebase/index.ts +25 -13
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
 
@@ -793,7 +793,8 @@ describe("gcp load balancer (remote-mcp-edge)", () => {
793
793
  expect(planUrlMapPaths([], "acme.com", PROXY_BACKEND).ok).toBe(false);
794
794
  });
795
795
 
796
- const policyJson = (rules: object[]) => ok(JSON.stringify({ rules }));
796
+ // As real gcloud prints it: a one-element list.
797
+ const policyJson = (rules: object[]) => ok(JSON.stringify([{ rules }]));
797
798
  const PROXY_POLICY = "caelo-production-mcp-auth-proxy-armor";
798
799
 
799
800
  it("#1328 — creates the proxy's own policy and its rule when missing", async () => {
@@ -927,6 +928,42 @@ describe("gcp load balancer (remote-mcp-edge)", () => {
927
928
  );
928
929
  });
929
930
 
931
+ it("creates the backend with the http port name a serverless NEG needs", async () => {
932
+ const missing = fakeGcloud({
933
+ "compute network-endpoint-groups describe": ok("caelo-production-mcp-auth-proxy-neg\n"),
934
+ "compute backend-services describe": fail("NOT_FOUND: was not found"),
935
+ "compute backend-services create": ok(JSON.stringify([{ selfLink: PROXY_BACKEND }])),
936
+ });
937
+ await ensureMcpAuthProxyBackend(
938
+ { projectId: "acme", region: "europe-west1", env: "production" },
939
+ missing,
940
+ );
941
+ expect(missing.calls.find((c) => c.startsWith("compute backend-services create"))).toContain(
942
+ "--protocol=HTTPS --port-name=http",
943
+ );
944
+ });
945
+
946
+ it("repairs a backend an earlier run left with the https port name, before add-backend", async () => {
947
+ const left = fakeGcloud({
948
+ "compute network-endpoint-groups describe": ok("caelo-production-mcp-auth-proxy-neg\n"),
949
+ "compute backend-services describe": ok(
950
+ JSON.stringify({ selfLink: PROXY_BACKEND, portName: "https", backends: [] }),
951
+ ),
952
+ "compute backend-services update": ok(),
953
+ "compute backend-services add-backend": ok(),
954
+ });
955
+ const r = await ensureMcpAuthProxyBackend(
956
+ { projectId: "acme", region: "europe-west1", env: "production" },
957
+ left,
958
+ );
959
+ expect(r.ok).toBe(true);
960
+ const writes = left.calls.filter((c) =>
961
+ /^compute backend-services (update|add-backend)/.test(c),
962
+ );
963
+ expect(writes[0]).toContain("--port-name=http");
964
+ expect(writes.at(-1)).toContain("add-backend");
965
+ });
966
+
930
967
  it("#1328 — ensureRemoteMcpEdge: service, policy, backend, URL map, then the gateway rule; no-op on gcp-firebase", async () => {
931
968
  expect(
932
969
  await ensureRemoteMcpEdge({
package/src/remote-mcp.ts CHANGED
@@ -43,6 +43,10 @@ import {
43
43
  mcpArmorRuleFlags,
44
44
  } from "./remote-mcp-edge.js";
45
45
  import type { HttpFetch } from "./runtime-secrets.js";
46
+ import {
47
+ repairServerlessBackendPort,
48
+ SERVERLESS_BACKEND_CREATE_FLAGS,
49
+ } from "./serverless-backend.js";
46
50
  import {
47
51
  CLOUD_RUN_SLUGS,
48
52
  type CloudRunSlug,
@@ -565,7 +569,13 @@ async function describePolicyRules(
565
569
  if (!describe.ok) {
566
570
  return { ok: false, missing: isGcloudNotFound(describe.stderr), error: describe.stderr.trim() };
567
571
  }
568
- const described = parseJson(describe.stdout) as { rules?: LiveArmorRule[] } | null;
572
+ // gcloud prints this one `describe` as a one-element list. Read as an
573
+ // object it has no rules, so a second run tried to create a rule that
574
+ // exists ("Cannot have rules with the same priorities").
575
+ const parsed = parseJson(describe.stdout);
576
+ const described = (Array.isArray(parsed) ? parsed[0] : parsed) as {
577
+ rules?: LiveArmorRule[];
578
+ } | null;
569
579
  if (!described)
570
580
  return { ok: false, missing: false, error: `describe ${policy}: output is not JSON` };
571
581
  return { ok: true, rules: described.rules ?? [] };
@@ -726,7 +736,12 @@ export async function ensureMcpAuthProxyBackend(
726
736
  project,
727
737
  "--format=json",
728
738
  ]);
729
- let backendJson: { selfLink?: string; securityPolicy?: string; backends?: { group?: string }[] };
739
+ let backendJson: {
740
+ selfLink?: string;
741
+ securityPolicy?: string;
742
+ portName?: string;
743
+ backends?: { group?: string }[];
744
+ };
730
745
  if (!backend.ok) {
731
746
  if (!isGcloudNotFound(backend.stderr)) {
732
747
  return { ok: false, error: `describe ${names.backend}: ${backend.stderr.trim()}` };
@@ -739,7 +754,7 @@ export async function ensureMcpAuthProxyBackend(
739
754
  "--global",
740
755
  project,
741
756
  "--load-balancing-scheme=EXTERNAL_MANAGED",
742
- "--protocol=HTTPS",
757
+ ...SERVERLESS_BACKEND_CREATE_FLAGS,
743
758
  "--format=json",
744
759
  "--quiet",
745
760
  ]);
@@ -751,6 +766,13 @@ export async function ensureMcpAuthProxyBackend(
751
766
  } else {
752
767
  backendJson = (parseJson(backend.stdout) ?? {}) as typeof backendJson;
753
768
  }
769
+ const port = await repairServerlessBackendPort(
770
+ run,
771
+ { name: names.backend, portName: backendJson.portName },
772
+ project,
773
+ );
774
+ if (port.error) return { ok: false, error: port.error };
775
+ if (port.repaired) done.push(`set ${names.backend}'s port name to http`);
754
776
  // `backend-services create` has no --security-policy: `update` attaches it,
755
777
  // here and on a backend an earlier run left without one.
756
778
  if (!backendJson.securityPolicy?.endsWith(`/securityPolicies/${names.policy}`)) {
@@ -0,0 +1,47 @@
1
+ // SPDX-License-Identifier: MPL-2.0
2
+
3
+ /**
4
+ * What the CLI-owned backend services on `gcp` (the MCP-Auth-Proxy's and the
5
+ * staging gateway's) need so a serverless NEG can be added to them.
6
+ *
7
+ * `gcloud compute backend-services create --protocol=HTTPS` sets the port
8
+ * name to `https`, and `add-backend` then refuses the NEG: "Port name is not
9
+ * supported for a backend service with Serverless network endpoint groups".
10
+ * The stack's backends carry `protocol: HTTPS` with the port name `http`,
11
+ * which Google accepts; the flags below give these two the same shape.
12
+ */
13
+
14
+ import type { GcloudRunner } from "./gcloud-retry.js";
15
+
16
+ /** The `backend-services create` flags of a backend that will hold a serverless NEG. */
17
+ export const SERVERLESS_BACKEND_CREATE_FLAGS: readonly string[] = [
18
+ "--protocol=HTTPS",
19
+ "--port-name=http",
20
+ ];
21
+
22
+ /**
23
+ * Repair a backend an earlier run created with the `https` port name, so
24
+ * `add-backend` can succeed. No call for any other backend.
25
+ *
26
+ * @returns whether it repaired the backend; `error` says what gcloud answered
27
+ */
28
+ export async function repairServerlessBackendPort(
29
+ run: GcloudRunner,
30
+ backend: { readonly name: string; readonly portName: string | undefined },
31
+ project: string,
32
+ ): Promise<{ readonly repaired: boolean; readonly error?: string }> {
33
+ if (backend.portName !== "https") return { repaired: false };
34
+ const set = await run([
35
+ "compute",
36
+ "backend-services",
37
+ "update",
38
+ backend.name,
39
+ "--global",
40
+ project,
41
+ "--port-name=http",
42
+ "--quiet",
43
+ ]);
44
+ return set.ok
45
+ ? { repaired: true }
46
+ : { repaired: false, error: `set ${backend.name}'s port name: ${set.stderr.trim()}` };
47
+ }
@@ -617,6 +617,19 @@ describe("MCP-Auth-Proxy contract (#1328)", () => {
617
617
  }
618
618
  });
619
619
 
620
+ it("gcp: visitors reach the gateway without a Google identity", () => {
621
+ expect(
622
+ stackIamInvariants("gcp").find(
623
+ (i) => i.target.kind === "run-service" && i.target.service === "gateway",
624
+ ),
625
+ ).toMatchObject({
626
+ stackResource: "data-gateway-public-invoker",
627
+ role: "roles/run.invoker",
628
+ member: "allUsers",
629
+ onFailure: "abort",
630
+ });
631
+ });
632
+
620
633
  it("gcp-firebase: the data gateway is the rewrite target, the proxy public", () => {
621
634
  const inv = stackIamInvariants("gcp-firebase");
622
635
  const on = (service: string) =>
@@ -526,6 +526,23 @@ export type RuntimeSecret =
526
526
  */
527
527
  | "mcp-oauth-seal-key";
528
528
 
529
+ /**
530
+ * Every {@link RuntimeSecret} as a value (the record makes the compiler
531
+ * check the list against the union): the cost table prices one active
532
+ * version of each.
533
+ */
534
+ export const RUNTIME_SECRETS = Object.keys({
535
+ "postgres-password": true,
536
+ "public-role-password": true,
537
+ "public-staging-role-password": true,
538
+ "secret-kek": true,
539
+ "internal-secret": true,
540
+ "tool-approval-secret": true,
541
+ "staging-gate-secret": true,
542
+ "operator-oauth-client": true,
543
+ "mcp-oauth-seal-key": true,
544
+ } satisfies Record<RuntimeSecret, true>) as readonly RuntimeSecret[];
545
+
529
546
  /** The Postgres roles Caelo's services log in as, with their passwords. */
530
547
  export type DatabaseRole = "admin_role" | "public_role" | "public_staging_role";
531
548
 
@@ -1703,6 +1720,14 @@ const GCP_ONLY: readonly IamInvariant[] = [
1703
1720
  onFailure: "abort",
1704
1721
  why: "IAP forwards admin traffic to Cloud Run as its service agent",
1705
1722
  },
1723
+ {
1724
+ stackResource: "data-gateway-public-invoker",
1725
+ role: "roles/run.invoker",
1726
+ member: "allUsers",
1727
+ target: { kind: "run-service", service: "gateway" },
1728
+ onFailure: "abort",
1729
+ why: "visitors reach the gateway through the load balancer without a Google identity; its load-balancer-only ingress is what closes the run.app URL",
1730
+ },
1706
1731
  ];
1707
1732
 
1708
1733
  const GCP_FIREBASE_ONLY: readonly IamInvariant[] = [