@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
@@ -5,7 +5,10 @@
5
5
  *
6
6
  * Tier 1 — Static site: GCS + Cloud CDN + Managed SSL via single LB
7
7
  * Tier 2 — Admin app: Cloud Run + Identity-Aware Proxy (allowlist)
8
- * Tier 3 — API gateway: Cloud Run + Cloud Armor (path-prefix on the LB)
8
+ * Tier 3 — API gateway: Cloud Run + Cloud Armor (path-prefix on the LB);
9
+ * the staging gateway (#1330) shares the policy.
10
+ * Cloud Armor is an extra layer: the gateways
11
+ * protect themselves without it (E3 of #763)
9
12
  * Tier 4 — Database: Cloud SQL Postgres on private VPC IP only
10
13
  * Tier 5 — Workers: share the admin's Cloud Run process
11
14
  *
@@ -14,7 +17,8 @@
14
17
  * mapping (admin.<domain>) so IAP can gate it independently — IAP can't
15
18
  * be attached selectively to one path of a multi-backend LB.
16
19
  *
17
- * Defaults: minimal-cost (~$30/mo). Operators bump knobs to scale up.
20
+ * Defaults: minimal-cost; src/wizards/gcp-cost.ts prices every resource
21
+ * (the wizard shows it before `up`). Operators bump knobs to scale up.
18
22
  */
19
23
 
20
24
  import * as gcp from "@pulumi/gcp";
@@ -22,6 +26,7 @@ import * as pulumi from "@pulumi/pulumi";
22
26
  import * as random from "@pulumi/random";
23
27
  import type { CloudAdapterOutputs, DnsRecord } from "../../dist/adapter.js";
24
28
  import { generateBootstrapToken } from "../../dist/bootstrap-token.js";
29
+ import { gatewayArmorRuleArgs } from "../../dist/gateway-edge.js";
25
30
  import {
26
31
  gatewayServiceAccountId,
27
32
  gcpBucketName,
@@ -969,6 +974,25 @@ const gatewaySvc = deployGateways
969
974
  })
970
975
  : null;
971
976
 
977
+ // Cloud Run checks a caller's identity whatever the ingress, and a visitor
978
+ // has none: without this binding every /api/ call answers Cloud Run's 403.
979
+ // Public only through the load balancer: the service's ingress closes its
980
+ // run.app URL. The MCP-Auth-Proxy and the staging gateway are CLI-owned and
981
+ // deployed with --allow-unauthenticated.
982
+ if (gatewaySvc) {
983
+ new gcp.cloudrunv2.ServiceIamMember(
984
+ `${namePrefix}-data-gateway-public-invoker`,
985
+ {
986
+ project,
987
+ location: region,
988
+ name: gatewaySvc.name,
989
+ role: "roles/run.invoker",
990
+ member: "allUsers",
991
+ },
992
+ opts,
993
+ );
994
+ }
995
+
972
996
  // =========================================================================
973
997
  // Tier 1 + Tier 2 + Tier 3 LB — single HTTPS LB serves three backends
974
998
  // =========================================================================
@@ -996,54 +1020,18 @@ const lbIp = new gcp.compute.GlobalAddress(
996
1020
  opts,
997
1021
  );
998
1022
 
999
- // Tier 3 — Cloud Armor security policy (rate limit + OWASP basic rules)
1023
+ // Tier 3 — Cloud Armor security policy: per-path rate rules + OWASP packs
1024
+ // (#1339, src/gateway-edge.ts says why each rule is what it is; the converge
1025
+ // applies the same rules to existing installs, gateway-armor.ts). An extra
1026
+ // layer: every protection also lives in the gateway itself (E3 of #763).
1027
+ // #1328 — no remote-MCP rule here any more: the URL map sends /api/mcp/* to
1028
+ // the MCP-Auth-Proxy's backend, whose own policy carries it
1029
+ // (remote-mcp-edge.ts, created by the CLI).
1000
1030
  const wafPolicy = new gcp.compute.SecurityPolicy(
1001
1031
  `${namePrefix}-waf`,
1002
1032
  {
1003
- description: `Caelo ${env} Cloud Armor — rate limit + OWASP`,
1004
- rules: [
1005
- // #1328 — no remote-MCP rule here any more: the URL map sends
1006
- // /api/mcp/* to the MCP-Auth-Proxy's backend, whose own policy carries
1007
- // it (remote-mcp-edge.ts, created by the CLI; `upgrade` drops the old
1008
- // rule from this policy).
1009
- // Rate limit per source IP — 100 req / min sliding window.
1010
- {
1011
- action: "rate_based_ban",
1012
- priority: 1000,
1013
- match: {
1014
- versionedExpr: "SRC_IPS_V1",
1015
- config: { srcIpRanges: ["*"] },
1016
- },
1017
- rateLimitOptions: {
1018
- rateLimitThreshold: { count: 100, intervalSec: 60 },
1019
- conformAction: "allow",
1020
- exceedAction: "deny(429)",
1021
- enforceOnKey: "IP",
1022
- banDurationSec: 600,
1023
- },
1024
- },
1025
- // OWASP rule pack (preconfigured WAF) — free tier covers the basics.
1026
- {
1027
- action: "deny(403)",
1028
- priority: 2000,
1029
- match: {
1030
- expr: { expression: "evaluatePreconfiguredWaf('sqli-v33-stable')" },
1031
- },
1032
- },
1033
- {
1034
- action: "deny(403)",
1035
- priority: 2001,
1036
- match: {
1037
- expr: { expression: "evaluatePreconfiguredWaf('xss-v33-stable')" },
1038
- },
1039
- },
1040
- // Default allow.
1041
- {
1042
- action: "allow",
1043
- priority: 2147483647,
1044
- match: { versionedExpr: "SRC_IPS_V1", config: { srcIpRanges: ["*"] } },
1045
- },
1046
- ],
1033
+ description: `Caelo ${env} Cloud Armor — per-path rate rules + OWASP`,
1034
+ rules: gatewayArmorRuleArgs(),
1047
1035
  ...(wafAdaptiveProtection
1048
1036
  ? { adaptiveProtectionConfig: { layer7DdosDefenseConfig: { enable: true } } }
1049
1037
  : {}),
@@ -9,16 +9,27 @@
9
9
  * + IAP-on-Cloud-Run (no LB IAP)
10
10
  * - Gateway: Cloud Run `caelo-<env>-data-gateway` + Firebase
11
11
  * Hosting `rewrites` (no LB, no Cloud Armor)
12
+ * - Staging gateway: Cloud Run `caelo-<env>-staging-gateway` behind a
13
+ * second Hosting site's `**` rewrite (#1330)
12
14
  * - MCP-Auth-Proxy: Cloud Run on its own run.app URL (#1328; the
13
15
  * service that was the gateway, E13 a of #763)
14
16
  * - Database: Cloud SQL Postgres on private VPC IP only (same
15
17
  * as `gcp/`)
16
18
  * - Workers: share admin Cloud Run (same as `gcp/`)
17
19
  *
18
- * The trade-off (no Cloud Armor on the gateway) was explicitly
19
- * accepted by the operator. Mitigation: Firebase Edge DDoS shield,
20
- * Cloud Run max-instance caps, Caelo's in-app rate-limit
21
- * middleware, form CAPTCHA/PoW.
20
+ * No load balancer and no WAF (epic #763 decision E3): this is the cheap
21
+ * setup. Leaving out the LB, Cloud CDN and the two Cloud Armor policies
22
+ * saves their lines of the cost table (src/wizards/gcp-cost.ts, the
23
+ * source of every price; about $37 a month at list prices). No protection
24
+ * depends on a WAF: the three public services are publicly invokable on
25
+ * their run.app URLs too (`allUsers`, needed by the Firebase rewrites and
26
+ * by MCP clients), so each one sheds junk and rate-limits itself before
27
+ * the database (in-memory budgets per client and per operation, captcha,
28
+ * per-operation database limits, `public_role`'s connection limit and
29
+ * timeouts; docs/dev/gateway-hardening.md), and the instance caps bound
30
+ * the rest. A public service whose feature is off answers a fixed 404
31
+ * before it reads the request (E14 a). Where a provider has a WAF (gcp:
32
+ * Cloud Armor), it is an extra layer.
22
33
  *
23
34
  * Code structure mirrors `packages/provisioning/stacks/gcp/index.ts`
24
35
  * for the shared blocks (VPC, Secrets, Cloud SQL, run SA, Cloud Run
@@ -702,9 +713,9 @@ interface CloudRunArgs {
702
713
  * in-memory filesystem and is lost with the instance.
703
714
  */
704
715
  readonly mediaVolume?: ReturnType<typeof adminMediaVolumeTemplate>;
705
- /** v0.3.1 — admin: ALL (so IAP gates internet traffic). gateway:
706
- * INTERNAL_LOAD_BALANCER (locked down; only Firebase Hosting
707
- * rewrites + run.invoker-authorised callers can reach it). */
716
+ /** v0.3.1 — admin: ALL (so IAP gates internet traffic). Every
717
+ * service is ALL today: the public ones are reached through Firebase
718
+ * Hosting rewrites and their run.app URLs (E3 of #763). */
708
719
  readonly ingress: "INGRESS_TRAFFIC_ALL" | "INGRESS_TRAFFIC_INTERNAL_LOAD_BALANCER";
709
720
  /** v0.3.1 — set true on admin so Cloud Run IAP gates traffic. */
710
721
  readonly iapEnabled?: boolean;
@@ -926,9 +937,9 @@ const adminSvc = cloudRunService({
926
937
  //
927
938
  // v0.3.13 — Gateway is PUBLIC by design.
928
939
  //
929
- // Per the gcp-firebase architecture decision: no Cloud Armor on
930
- // the gateway; in-app rate limits + CAPTCHA on form submission
931
- // endpoints gate abuse. The original plan was to grant the
940
+ // Per the gcp-firebase architecture decision (E3 of #763): no LB and no
941
+ // Cloud Armor on the gateway; its own layers gate abuse (the file
942
+ // comment). The original plan was to grant the
932
943
  // Firebase Hosting SA `roles/run.invoker` so Firebase rewrites
933
944
  // could call the gateway as that SA. But the gcp-sa-firebasehosting
934
945
  // SA is created lazily by Firebase on first Cloud-Run-rewrite
@@ -1319,9 +1330,10 @@ const out: CloudAdapterOutputs = {
1319
1330
  bootstrapUrl:
1320
1331
  pulumi.interpolate`https://${adminDomain}/setup?token=${tokenInfo.token}` as unknown as string,
1321
1332
  dnsRecordsRequired: dnsRecords as unknown as DnsRecord[],
1322
- // gcp-firebase doesn't provision BigQuery sinks today (no LB → no
1323
- // edge log stream). v0.3.x+ adds a Firebase Hosting log export.
1324
- edgeLogSinkUrl: `bigquery://${project}/firebase_logs` as unknown as string,
1333
+ // #1339 — no BigQuery export here (that dataset was never created):
1334
+ // the services' request logs stay in Cloud Logging, the cross-cutting
1335
+ // single sink of CLAUDE.md §11.B, in the project's `_Default` bucket.
1336
+ edgeLogSinkUrl: `logging://${project}/_Default` as unknown as string,
1325
1337
  provider: "gcp-firebase",
1326
1338
  environment: env,
1327
1339
  };