@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
@@ -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)",
@@ -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
 
@@ -14,8 +14,9 @@
14
14
  * domain with a managed certificate — files served as files, no compute
15
15
  * on the request path (CLAUDE.md §11.B Tier 1).
16
16
  * 5. Azure Container Apps (admin/gateway/orchestrator/runner, and the
17
- * MCP-Auth-Proxy without any secret, #1328),
18
- * mounted with Key Vault secrets via managed identity.
17
+ * MCP-Auth-Proxy without any secret, #1328). Database passwords are
18
+ * Key Vault references read through a user-assigned identity per
19
+ * service (#1339): the URLs carry no password.
19
20
  * 6. Key Vault entries (postgres-password, csrf-secret, cookie-secret,
20
21
  * anthropic-api-key, resend-api-key).
21
22
  * 7. Log Analytics workspace receives Container Apps logs;
@@ -40,6 +41,11 @@ import * as azure from "@pulumi/azure-native";
40
41
  import * as pulumi from "@pulumi/pulumi";
41
42
  import type { CloudAdapterOutputs, DnsRecord } from "../../dist/adapter.js";
42
43
  import { azureFrontDoorDnsRecords } from "../../dist/azure-front-door.js";
44
+ import {
45
+ AZURE_SERVICE_DATABASE_SECRETS,
46
+ type AzureDatabaseSecret,
47
+ type AzureSecretReader,
48
+ } from "../../dist/azure-secrets.js";
43
49
  import { generateBootstrapToken } from "../../dist/bootstrap-token.js";
44
50
  import {
45
51
  DEFAULT_MAX_CONNECTIONS,
@@ -86,6 +92,10 @@ const maxConnections = Number.parseInt(
86
92
  );
87
93
  /** Replicas each Container App may scale to (see containerApp). */
88
94
  const MAX_REPLICAS = 10;
95
+ // The §11.B knob, same name and default as every adapter: the public API
96
+ // gateway scales to zero unless the operator keeps replicas warm (E14 a of
97
+ // #763: a public service is provisioned at zero minimum instances).
98
+ const gatewayMinInstances = Number.parseInt(cfg.get("gatewayMinInstances") ?? "0", 10);
89
99
  // The admin, orchestrator and runner apps all open the admin's two pools,
90
100
  // so the budget counts their replicas together as admin instances.
91
101
  const ADMIN_SIDE_APPS = 3;
@@ -153,8 +163,8 @@ function keyVaultSecret(shortName: string, value: pulumi.Output<string>): azure.
153
163
  });
154
164
  }
155
165
 
156
- const _pgSecret = keyVaultSecret("pg-password", postgresPassword);
157
- keyVaultSecret("public-role-password", publicRolePassword);
166
+ const pgSecret = keyVaultSecret("pg-password", postgresPassword);
167
+ const publicRoleSecret = keyVaultSecret("public-role-password", publicRolePassword);
158
168
  // #1329 — read by nothing yet: the staging gateway's app (#750) will.
159
169
  keyVaultSecret("public-staging-role-password", publicStagingRolePassword);
160
170
  keyVaultSecret("csrf-secret", csrfSecret);
@@ -220,31 +230,22 @@ const _pgPublicStaging = new azure.dbforpostgresql.Database(`${namePrefix}-cms-p
220
230
  // Bun trusts out of the box, so no sslrootcert (shared database-tls.ts).
221
231
  const AZURE_TLS = verifyFullQuery();
222
232
 
223
- const adminDatabaseUrl = pulumi
224
- .all([pgServer.fullyQualifiedDomainName, postgresPassword])
225
- .apply(([host, pw]) => `postgresql://caelo_admin:${pw}@${host}:5432/cms_admin?${AZURE_TLS}`);
233
+ // #1339 (epic #763 L5) — password-less, like on GCP: the password is a Key
234
+ // Vault reference on the Container App (AZURE_SERVICE_DATABASE_SECRETS),
235
+ // never part of the URL, so it shows up neither in the app's env nor in its
236
+ // revision history (shared database-url.ts `<NAME>_PASSWORD`).
237
+ const dbUrl = (role: string, db: string) =>
238
+ pulumi.interpolate`postgresql://${role}@${pgServer.fullyQualifiedDomainName}:5432/${db}?${AZURE_TLS}`;
239
+ const adminDatabaseUrl = dbUrl("caelo_admin", "cms_admin");
226
240
  // What the admin connects to cms_public with (DDL, migrations, moderation).
227
- const publicAdminDatabaseUrl = pulumi
228
- .all([pgServer.fullyQualifiedDomainName, postgresPassword])
229
- .apply(([host, pw]) => `postgresql://caelo_admin:${pw}@${host}:5432/cms_public?${AZURE_TLS}`);
241
+ const publicAdminDatabaseUrl = dbUrl("caelo_admin", "cms_public");
230
242
  // The gateway's only login (#613, #635): public_role on cms_public. It has
231
243
  // no cms_admin login at all (CLAUDE.md §2).
232
- const publicDatabaseUrl = pulumi
233
- .all([pgServer.fullyQualifiedDomainName, publicRolePassword])
234
- .apply(([host, pw]) => `postgresql://public_role:${pw}@${host}:5432/cms_public?${AZURE_TLS}`);
244
+ const publicDatabaseUrl = dbUrl("public_role", "cms_public");
235
245
  // #1329 — the admin's pool on the staging database (plugin schemas, the
236
246
  // staging half of the projection), and the staging gateway's only login.
237
- const publicStagingAdminDatabaseUrl = pulumi
238
- .all([pgServer.fullyQualifiedDomainName, postgresPassword])
239
- .apply(
240
- ([host, pw]) => `postgresql://caelo_admin:${pw}@${host}:5432/cms_public_staging?${AZURE_TLS}`,
241
- );
242
- const publicStagingDatabaseUrl = pulumi
243
- .all([pgServer.fullyQualifiedDomainName, publicStagingRolePassword])
244
- .apply(
245
- ([host, pw]) =>
246
- `postgresql://public_staging_role:${pw}@${host}:5432/cms_public_staging?${AZURE_TLS}`,
247
- );
247
+ const publicStagingAdminDatabaseUrl = dbUrl("caelo_admin", "cms_public_staging");
248
+ const publicStagingDatabaseUrl = dbUrl("public_staging_role", "cms_public_staging");
248
249
 
249
250
  // === 4. Storage account + containers ===
250
251
  const storage = new azure.storage.StorageAccount(`${namePrefix}-st`, {
@@ -477,8 +478,57 @@ const cappEnv = new azure.app.ManagedEnvironment(`${namePrefix}-capp-env`, {
477
478
  },
478
479
  });
479
480
 
481
+ // #1339 — one user-assigned identity per secret reader, with "Key Vault
482
+ // Secrets User" on exactly the secrets AZURE_SERVICE_DATABASE_SECRETS gives
483
+ // it (RBAC on the secret, not the vault): the gateway's identity can read
484
+ // public_role's password and nothing else.
485
+ const KEY_VAULT_SECRETS_USER_ROLE = "4633458b-17de-408a-b874-0445c86b69e6";
486
+ const clientConfig = azure.authorization.getClientConfigOutput();
487
+ const keyVaultSecrets: Record<AzureDatabaseSecret, azure.keyvault.Secret> = {
488
+ "pg-password": pgSecret,
489
+ "public-role-password": publicRoleSecret,
490
+ };
491
+
492
+ interface SecretReader {
493
+ readonly identity: azure.managedidentity.UserAssignedIdentity;
494
+ readonly reader: AzureSecretReader;
495
+ /**
496
+ * Its grants on the secrets. A Container App resolves its Key Vault
497
+ * references when it is created, so it must wait for them (Azure: grant
498
+ * the identity access before referencing the secret).
499
+ */
500
+ readonly grants: readonly azure.authorization.RoleAssignment[];
501
+ }
502
+
503
+ function secretReader(reader: AzureSecretReader): SecretReader {
504
+ const identity = new azure.managedidentity.UserAssignedIdentity(`${namePrefix}-${reader}-id`, {
505
+ resourceGroupName: rg.name,
506
+ resourceName: `${namePrefix}-${reader}-id`,
507
+ location,
508
+ });
509
+ const grants: azure.authorization.RoleAssignment[] = [];
510
+ for (const name of new Set(Object.values(AZURE_SERVICE_DATABASE_SECRETS[reader]))) {
511
+ const grant = new azure.authorization.RoleAssignment(`${namePrefix}-${reader}-reads-${name}`, {
512
+ principalId: identity.principalId,
513
+ principalType: "ServicePrincipal",
514
+ roleDefinitionId: pulumi.interpolate`/subscriptions/${clientConfig.subscriptionId}/providers/Microsoft.Authorization/roleDefinitions/${KEY_VAULT_SECRETS_USER_ROLE}`,
515
+ scope: keyVaultSecrets[name].id,
516
+ });
517
+ grants.push(grant);
518
+ }
519
+ return { identity, reader, grants };
520
+ }
521
+
522
+ const adminSecretReader = secretReader("admin");
523
+ const gatewaySecretReader = secretReader("gateway");
524
+
480
525
  interface ContainerAppArgs {
481
526
  readonly serviceName: string;
527
+ /**
528
+ * #1339 — the identity whose Key Vault references become the app's
529
+ * `<NAME>_PASSWORD` env vars; none for an app that reads no secret.
530
+ */
531
+ readonly secrets?: SecretReader;
482
532
  /**
483
533
  * The service's database connection env. The admin-side services get
484
534
  * admin_role's URLs; the gateway gets only its own two logins (#613,
@@ -494,51 +544,80 @@ interface ContainerAppArgs {
494
544
  * minimum replicas in every environment (E14 a of #763).
495
545
  */
496
546
  readonly isolated?: true;
547
+ /** Minimum replicas; unset: 0 outside production, 1 in production. */
548
+ readonly minReplicas?: number;
497
549
  }
498
550
 
499
551
  function containerApp(args: ContainerAppArgs): azure.app.ContainerApp {
500
- return new azure.app.ContainerApp(`${namePrefix}-${args.serviceName}`, {
501
- resourceGroupName: rg.name,
502
- containerAppName: `${namePrefix}-${args.serviceName}`,
503
- location,
504
- managedEnvironmentId: cappEnv.id,
505
- configuration: {
506
- activeRevisionsMode: "Single",
507
- ingress: {
508
- external: false,
509
- targetPort: 8080,
510
- transport: "Auto",
511
- },
512
- },
513
- template: {
514
- scale: {
515
- minReplicas: args.isolated || env !== "production" ? 0 : 1,
516
- maxReplicas: MAX_REPLICAS,
552
+ const passwords = args.secrets
553
+ ? Object.entries(AZURE_SERVICE_DATABASE_SECRETS[args.secrets.reader])
554
+ : [];
555
+ const secretNames = [...new Set(passwords.map(([, name]) => name))];
556
+ return new azure.app.ContainerApp(
557
+ `${namePrefix}-${args.serviceName}`,
558
+ {
559
+ resourceGroupName: rg.name,
560
+ containerAppName: `${namePrefix}-${args.serviceName}`,
561
+ location,
562
+ managedEnvironmentId: cappEnv.id,
563
+ ...(args.secrets
564
+ ? {
565
+ identity: {
566
+ type: "UserAssigned",
567
+ userAssignedIdentities: [args.secrets.identity.id],
568
+ },
569
+ }
570
+ : {}),
571
+ configuration: {
572
+ activeRevisionsMode: "Single",
573
+ ...(args.secrets
574
+ ? {
575
+ secrets: secretNames.map((name) => ({
576
+ name,
577
+ keyVaultUrl: keyVaultSecrets[name].properties.apply((p) => p.secretUri ?? ""),
578
+ identity: (args.secrets as SecretReader).identity.id,
579
+ })),
580
+ }
581
+ : {}),
582
+ ingress: {
583
+ external: false,
584
+ targetPort: 8080,
585
+ transport: "Auto",
586
+ },
517
587
  },
518
- containers: [
519
- {
520
- name: args.serviceName,
521
- // Image pushed via `az acr build` for v1 (operator's job).
522
- image:
523
- cfg.get(`image-${args.serviceName}`) ??
524
- `${namePrefix}.azurecr.io/${args.serviceName}:latest`,
525
- env: args.isolated
526
- ? [{ name: "CAELO_PROVIDER", value: "azure" }, ...(args.extraEnv ?? [])]
527
- : [
528
- { name: "CAELO_PROVIDER", value: "azure" },
529
- { name: "CAELO_ENV", value: env },
530
- ...args.databaseEnv,
531
- {
532
- name: "MEDIA_STORAGE_URL",
533
- value: pulumi.interpolate`https://${storage.name}.blob.core.windows.net/media`,
534
- },
535
- ...(args.extraEnv ?? []),
536
- ],
537
- resources: args.resources ?? { cpu: 0.5, memory: "1.0Gi" },
588
+ template: {
589
+ scale: {
590
+ minReplicas: args.isolated ? 0 : (args.minReplicas ?? (env !== "production" ? 0 : 1)),
591
+ maxReplicas: MAX_REPLICAS,
538
592
  },
539
- ],
593
+ containers: [
594
+ {
595
+ name: args.serviceName,
596
+ // Image pushed via `az acr build` for v1 (operator's job).
597
+ image:
598
+ cfg.get(`image-${args.serviceName}`) ??
599
+ `${namePrefix}.azurecr.io/${args.serviceName}:latest`,
600
+ env: args.isolated
601
+ ? [{ name: "CAELO_PROVIDER", value: "azure" }, ...(args.extraEnv ?? [])]
602
+ : [
603
+ { name: "CAELO_PROVIDER", value: "azure" },
604
+ { name: "CAELO_ENV", value: env },
605
+ ...args.databaseEnv,
606
+ ...passwords.map(([envName, name]) => ({ name: envName, secretRef: name })),
607
+ {
608
+ name: "MEDIA_STORAGE_URL",
609
+ value: pulumi.interpolate`https://${storage.name}.blob.core.windows.net/media`,
610
+ },
611
+ ...(args.extraEnv ?? []),
612
+ ],
613
+ resources: args.resources ?? { cpu: 0.5, memory: "1.0Gi" },
614
+ },
615
+ ],
616
+ },
540
617
  },
541
- });
618
+ // Its Key Vault references resolve at creation: the grants come first.
619
+ { dependsOn: [...(args.secrets?.grants ?? [])] },
620
+ );
542
621
  }
543
622
 
544
623
  const adminDatabaseEnv = [
@@ -550,6 +629,7 @@ const adminDatabaseEnv = [
550
629
  const adminApp = containerApp({
551
630
  serviceName: "admin",
552
631
  databaseEnv: adminDatabaseEnv,
632
+ secrets: adminSecretReader,
553
633
  resources: adminResources,
554
634
  // #551 — the public site URL; the admin seeds site_defaults.site_base_url
555
635
  // from it (canonical, og:url, sitemap) when it is not configured yet.
@@ -557,6 +637,8 @@ const adminApp = containerApp({
557
637
  });
558
638
  const _gatewayApp = containerApp({
559
639
  serviceName: "gateway",
640
+ secrets: gatewaySecretReader,
641
+ minReplicas: gatewayMinInstances,
560
642
  databaseEnv: [
561
643
  { name: "PUBLIC_DATABASE_URL", value: publicDatabaseUrl },
562
644
  ...poolBudget.env.gateway,
@@ -592,8 +674,13 @@ const _mcpAuthProxyApp = containerApp({
592
674
  const _orchestratorApp = containerApp({
593
675
  serviceName: "orchestrator",
594
676
  databaseEnv: adminDatabaseEnv,
677
+ secrets: adminSecretReader,
678
+ });
679
+ const _runnerApp = containerApp({
680
+ serviceName: "runner",
681
+ databaseEnv: adminDatabaseEnv,
682
+ secrets: adminSecretReader,
595
683
  });
596
- const _runnerApp = containerApp({ serviceName: "runner", databaseEnv: adminDatabaseEnv });
597
684
  // === 7. Bootstrap token ===
598
685
  const tokenInfo = generateBootstrapToken();
599
686
 
@@ -609,6 +696,7 @@ const dnsRecordsRequired = pulumi
609
696
  );
610
697
 
611
698
  const out: CloudAdapterOutputs = {
699
+ // Password-less — the passwords live only in Key Vault (#1339).
612
700
  adminDatabaseUrl: adminDatabaseUrl as unknown as string,
613
701
  publicDatabaseUrl: publicDatabaseUrl as unknown as string,
614
702
  publicStagingDatabaseUrl: publicStagingDatabaseUrl as unknown as string,