@caelo-cms/provisioning 0.11.19 → 0.11.21
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.
- package/dist/admin-internal-google.d.ts +13 -1
- package/dist/admin-internal-google.d.ts.map +1 -1
- package/dist/admin-internal-google.js +47 -0
- package/dist/admin-internal-google.js.map +1 -1
- package/dist/agent/command.d.ts +1 -1
- package/dist/agent-db.js +32 -0
- package/dist/aws-task-roles.d.ts +11 -0
- package/dist/aws-task-roles.d.ts.map +1 -1
- package/dist/aws-task-roles.js +19 -0
- package/dist/aws-task-roles.js.map +1 -1
- package/dist/azure-secrets.d.ts +22 -0
- package/dist/azure-secrets.d.ts.map +1 -0
- package/dist/azure-secrets.js +14 -0
- package/dist/azure-secrets.js.map +1 -0
- package/dist/caddy.d.ts +7 -0
- package/dist/caddy.d.ts.map +1 -1
- package/dist/caddy.js +22 -1
- package/dist/caddy.js.map +1 -1
- package/dist/cli-routing.d.ts.map +1 -1
- package/dist/cli-routing.js +2 -2
- package/dist/cli-routing.js.map +1 -1
- package/dist/cli.js +8 -0
- package/dist/cli.js.map +1 -1
- package/dist/converge-checkpoint.d.ts +6 -0
- package/dist/converge-checkpoint.d.ts.map +1 -1
- package/dist/dns/manual.d.ts +5 -1
- package/dist/dns/manual.d.ts.map +1 -1
- package/dist/dns/manual.js +2 -1
- package/dist/dns/manual.js.map +1 -1
- package/dist/gateway-armor.d.ts +24 -0
- package/dist/gateway-armor.d.ts.map +1 -0
- package/dist/gateway-armor.js +118 -0
- package/dist/gateway-armor.js.map +1 -0
- package/dist/gateway-edge.d.ts +128 -0
- package/dist/gateway-edge.d.ts.map +1 -0
- package/dist/gateway-edge.js +211 -0
- package/dist/gateway-edge.js.map +1 -0
- package/dist/infra-contract.d.ts +1 -1
- package/dist/infra-contract.d.ts.map +1 -1
- package/dist/infra-contract.js +21 -1
- package/dist/infra-contract.js.map +1 -1
- package/dist/install-job-runner.d.ts.map +1 -1
- package/dist/install-job-runner.js +4 -3
- package/dist/install-job-runner.js.map +1 -1
- package/dist/install-job.d.ts +25 -1
- package/dist/install-job.d.ts.map +1 -1
- package/dist/install-job.js +72 -3
- package/dist/install-job.js.map +1 -1
- package/dist/lifecycle.d.ts.map +1 -1
- package/dist/lifecycle.js +8 -1
- package/dist/lifecycle.js.map +1 -1
- package/dist/operator-access.d.ts +7 -2
- package/dist/operator-access.d.ts.map +1 -1
- package/dist/operator-access.js +37 -6
- package/dist/operator-access.js.map +1 -1
- package/dist/pool-budget-stack.d.ts +22 -0
- package/dist/pool-budget-stack.d.ts.map +1 -1
- package/dist/pool-budget-stack.js +22 -1
- package/dist/pool-budget-stack.js.map +1 -1
- package/dist/project-status.d.ts +95 -0
- package/dist/project-status.d.ts.map +1 -0
- package/dist/project-status.js +213 -0
- package/dist/project-status.js.map +1 -0
- package/dist/public-service-shape.d.ts +45 -0
- package/dist/public-service-shape.d.ts.map +1 -0
- package/dist/public-service-shape.js +90 -0
- package/dist/public-service-shape.js.map +1 -0
- package/dist/remote-mcp-edge.d.ts +1 -1
- package/dist/remote-mcp-edge.js +1 -1
- package/dist/remote-mcp.d.ts.map +1 -1
- package/dist/remote-mcp.js +12 -2
- package/dist/remote-mcp.js.map +1 -1
- package/dist/serverless-backend.d.ts +27 -0
- package/dist/serverless-backend.d.ts.map +1 -0
- package/dist/serverless-backend.js +30 -0
- package/dist/serverless-backend.js.map +1 -0
- package/dist/stack-contract.d.ts +6 -0
- package/dist/stack-contract.d.ts.map +1 -1
- package/dist/stack-contract.js +24 -0
- package/dist/stack-contract.js.map +1 -1
- package/dist/stack-converge.d.ts +13 -0
- package/dist/stack-converge.d.ts.map +1 -1
- package/dist/stack-converge.js +27 -0
- package/dist/stack-converge.js.map +1 -1
- package/dist/staging-gateway-setup.d.ts +5 -0
- package/dist/staging-gateway-setup.d.ts.map +1 -1
- package/dist/staging-gateway-setup.js +60 -19
- package/dist/staging-gateway-setup.js.map +1 -1
- package/dist/state-attach.d.ts +17 -0
- package/dist/state-attach.d.ts.map +1 -1
- package/dist/state-attach.js +27 -9
- package/dist/state-attach.js.map +1 -1
- package/dist/upgrade/app-roll.d.ts +5 -1
- package/dist/upgrade/app-roll.d.ts.map +1 -1
- package/dist/upgrade/app-roll.js +20 -3
- package/dist/upgrade/app-roll.js.map +1 -1
- package/dist/upgrade/converge.d.ts.map +1 -1
- package/dist/upgrade/converge.js +27 -4
- package/dist/upgrade/converge.js.map +1 -1
- package/dist/upgrade/health.d.ts +13 -3
- package/dist/upgrade/health.d.ts.map +1 -1
- package/dist/upgrade/health.js +24 -7
- package/dist/upgrade/health.js.map +1 -1
- package/dist/upgrade/load-balancer-get.d.ts +17 -0
- package/dist/upgrade/load-balancer-get.d.ts.map +1 -0
- package/dist/upgrade/load-balancer-get.js +38 -0
- package/dist/upgrade/load-balancer-get.js.map +1 -0
- package/dist/upgrader-gcp.d.ts.map +1 -1
- package/dist/upgrader-gcp.js +8 -1
- package/dist/upgrader-gcp.js.map +1 -1
- package/dist/wizards/gcp-cost.d.ts +9 -0
- package/dist/wizards/gcp-cost.d.ts.map +1 -1
- package/dist/wizards/gcp-cost.js +69 -34
- package/dist/wizards/gcp-cost.js.map +1 -1
- package/dist/wizards/gcp-install-job.d.ts +27 -4
- package/dist/wizards/gcp-install-job.d.ts.map +1 -1
- package/dist/wizards/gcp-install-job.js +62 -32
- package/dist/wizards/gcp-install-job.js.map +1 -1
- package/dist/wizards/gcp.d.ts +3 -0
- package/dist/wizards/gcp.d.ts.map +1 -1
- package/dist/wizards/gcp.js +10 -4
- package/dist/wizards/gcp.js.map +1 -1
- package/package.json +2 -2
- package/src/admin-internal-google.ts +48 -0
- package/src/aws-task-roles.ts +22 -0
- package/src/azure-secrets.ts +38 -0
- package/src/caddy.test.ts +19 -2
- package/src/caddy.ts +23 -0
- package/src/cli-routing.ts +3 -2
- package/src/cli.ts +10 -0
- package/src/dns/manual.ts +4 -1
- package/src/gateway-armor.ts +135 -0
- package/src/gateway-bootstrap.test.ts +1 -0
- package/src/gateway-edge.test.ts +262 -0
- package/src/gateway-edge.ts +256 -0
- package/src/gateway-env-isolation.test.ts +45 -6
- package/src/infra-contract.test.ts +5 -3
- package/src/infra-contract.ts +21 -1
- package/src/install-job-runner.ts +4 -2
- package/src/install-job.ts +86 -4
- package/src/lifecycle.ts +8 -1
- package/src/operator-access.test.ts +43 -0
- package/src/operator-access.ts +38 -6
- package/src/pool-budget-stack.ts +25 -0
- package/src/pool-budget-stacks.test.ts +31 -0
- package/src/project-status.test.ts +462 -0
- package/src/project-status.ts +306 -0
- package/src/public-service-shape.test.ts +166 -0
- package/src/public-service-shape.ts +131 -0
- package/src/remote-mcp-edge.ts +1 -1
- package/src/remote-mcp.test.ts +38 -1
- package/src/remote-mcp.ts +25 -3
- package/src/serverless-backend.ts +47 -0
- package/src/stack-contract.test.ts +13 -0
- package/src/stack-contract.ts +25 -0
- package/src/stack-converge.test.ts +28 -1
- package/src/stack-converge.ts +30 -0
- package/src/staging-gateway-setup.test.ts +55 -3
- package/src/staging-gateway-setup.ts +79 -27
- package/src/state-attach.ts +46 -16
- package/src/upgrade/app-roll.ts +27 -3
- package/src/upgrade/converge.ts +33 -4
- package/src/upgrade/health.test.ts +88 -13
- package/src/upgrade/health.ts +32 -7
- package/src/upgrade/load-balancer-get.ts +64 -0
- package/src/upgrade/upgrade.test.ts +96 -3
- package/src/upgrader-gcp.ts +8 -1
- package/src/wizards/gcp-cost.ts +78 -35
- package/src/wizards/gcp-install-job.ts +91 -46
- package/src/wizards/gcp.ts +14 -7
- package/stacks/aws/index.ts +24 -22
- package/stacks/azure/index.ts +152 -64
- package/stacks/gcp/index.ts +35 -47
- 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 {
|
|
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("
|
|
224
|
-
//
|
|
225
|
-
//
|
|
226
|
-
//
|
|
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(/
|
|
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
|
|
24
|
-
expect(INFRA_CONTRACT_VERSION).toBe(
|
|
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(
|
|
55
|
+
expect(infraStepsText(22, 23)).toBe("infrastructure step 23 (see that release's notes)");
|
|
54
56
|
});
|
|
55
57
|
});
|
package/src/infra-contract.ts
CHANGED
|
@@ -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 =
|
|
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
|
/**
|
|
@@ -20,6 +20,7 @@ import { CAELO_VERSION } from "@caelo-cms/shared";
|
|
|
20
20
|
import { assertNoSecrets } from "./checkpoint-secrets.js";
|
|
21
21
|
import {
|
|
22
22
|
type InstallJobStatus,
|
|
23
|
+
isGcpProjectId,
|
|
23
24
|
readInstallJobStatus,
|
|
24
25
|
writeInstallJobStatus,
|
|
25
26
|
} from "./install-job.js";
|
|
@@ -28,14 +29,13 @@ import { attachInstall } from "./state-attach.js";
|
|
|
28
29
|
import { hasLocalPulumiState, opsBucketName, resolveBackend } from "./state-backend.js";
|
|
29
30
|
import { realSyncGcloud, type SyncGcloud } from "./state-store.js";
|
|
30
31
|
|
|
31
|
-
const PROJECT_ID = /^[a-z][a-z0-9-]{4,28}[a-z0-9]$/;
|
|
32
32
|
const ANSI = new RegExp(`${String.fromCharCode(27)}\\[[0-9;?]*[A-Za-z]`, "g");
|
|
33
33
|
|
|
34
34
|
/** The `--project` value of `argv`, validated. */
|
|
35
35
|
export function installJobProject(argv: readonly string[]): string {
|
|
36
36
|
const i = argv.indexOf("--project");
|
|
37
37
|
const value = i === -1 ? undefined : argv[i + 1];
|
|
38
|
-
if (!value || !
|
|
38
|
+
if (!value || !isGcpProjectId(value)) {
|
|
39
39
|
throw new Error("install-job needs --project <gcp-project-id>");
|
|
40
40
|
}
|
|
41
41
|
return value;
|
|
@@ -117,6 +117,7 @@ export async function installJobCommand(
|
|
|
117
117
|
execution,
|
|
118
118
|
state: "running",
|
|
119
119
|
phase: "Starting",
|
|
120
|
+
...(previous?.dnsRecords ? { dnsRecords: previous.dnsRecords } : {}),
|
|
120
121
|
caeloVersion: CAELO_VERSION,
|
|
121
122
|
startedAt: previous?.execution === execution ? previous.startedAt : now,
|
|
122
123
|
updatedAt: now,
|
|
@@ -161,6 +162,7 @@ export async function installJobCommand(
|
|
|
161
162
|
nonInteractive: true,
|
|
162
163
|
setupLink: "secret",
|
|
163
164
|
onPhase: (phase, detail) => record({ phase, detail }),
|
|
165
|
+
onDnsRecords: (dnsRecords) => record({ dnsRecords, detail: status.detail }),
|
|
164
166
|
});
|
|
165
167
|
record({ state: "succeeded", phase: "Done" });
|
|
166
168
|
}
|
package/src/install-job.ts
CHANGED
|
@@ -28,15 +28,20 @@
|
|
|
28
28
|
* The Owner setup link is a secret (#656): it never reaches the bucket or
|
|
29
29
|
* the job's logs. The job stores it in Secret Manager
|
|
30
30
|
* ({@link INSTALL_SETUP_LINK_SECRET}); the operator's terminal reads it there.
|
|
31
|
+
*
|
|
32
|
+
* All of this is readable from the project alone, so `status --project`
|
|
33
|
+
* (project-status.ts, #822) shows the install on any machine signed in to
|
|
34
|
+
* gcloud, after the terminal that started it is gone.
|
|
31
35
|
*/
|
|
32
36
|
|
|
33
37
|
import { z } from "zod";
|
|
34
38
|
import { assertNoSecrets } from "./checkpoint-secrets.js";
|
|
39
|
+
import type { InstallDnsRecord } from "./dns/groups.js";
|
|
35
40
|
import type { GcloudRunner } from "./gcloud-retry.js";
|
|
36
41
|
import { GCP_STACK_ENV } from "./gcp-names.js";
|
|
37
42
|
import { createInstallSecret } from "./runtime-secrets.js";
|
|
38
|
-
import { OPS_INSTALL_PREFIX } from "./state-backend.js";
|
|
39
|
-
import type
|
|
43
|
+
import { OPS_INSTALL_PREFIX, opsBucketName } from "./state-backend.js";
|
|
44
|
+
import { GcsStateStore, type SyncGcloud } from "./state-store.js";
|
|
40
45
|
import { IMAGE_DIGEST } from "./upgrade/release-images.js";
|
|
41
46
|
|
|
42
47
|
/** Name of the Cloud Run job that runs the install. */
|
|
@@ -99,6 +104,20 @@ export function opsImageRef(digest: string): string {
|
|
|
99
104
|
return `${OPS_IMAGE_REPOSITORY}@${digest}`;
|
|
100
105
|
}
|
|
101
106
|
|
|
107
|
+
const GCP_PROJECT_ID = /^[a-z][a-z0-9-]{4,28}[a-z0-9]$/;
|
|
108
|
+
|
|
109
|
+
/** Whether `value` has the shape of a Google Cloud project id. */
|
|
110
|
+
export function isGcpProjectId(value: string): boolean {
|
|
111
|
+
return GCP_PROJECT_ID.test(value);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const DnsRecordSchema = z.object({
|
|
115
|
+
hostname: z.string().min(1),
|
|
116
|
+
type: z.string().min(1),
|
|
117
|
+
value: z.string().min(1),
|
|
118
|
+
purpose: z.string().optional(),
|
|
119
|
+
});
|
|
120
|
+
|
|
102
121
|
/** What `install/install-job.json` records. */
|
|
103
122
|
export const InstallJobStatusSchema = z.object({
|
|
104
123
|
statusVersion: z.literal(1),
|
|
@@ -110,6 +129,12 @@ export const InstallJobStatusSchema = z.object({
|
|
|
110
129
|
phase: z.string(),
|
|
111
130
|
/** Extra context for the phase (the DNS records to set, a failure reason). */
|
|
112
131
|
detail: z.string().optional(),
|
|
132
|
+
/**
|
|
133
|
+
* DNS records the job found out about that are not in the stack's outputs
|
|
134
|
+
* (the staging host's, #822), so `status --project` lists them on any
|
|
135
|
+
* machine. Not secret: anyone can read them from public DNS once set.
|
|
136
|
+
*/
|
|
137
|
+
dnsRecords: z.array(DnsRecordSchema).optional(),
|
|
113
138
|
/** Caelo release the job's image belongs to. */
|
|
114
139
|
caeloVersion: z.string(),
|
|
115
140
|
startedAt: z.string(),
|
|
@@ -134,7 +159,9 @@ export function readJobStatusDoc<T>(url: string, schema: z.ZodType<T>, run: Sync
|
|
|
134
159
|
const r = run(["storage", "cat", url]);
|
|
135
160
|
if (!r.ok) {
|
|
136
161
|
if (NOT_FOUND.test(r.stderr)) return null;
|
|
137
|
-
throw new Error(
|
|
162
|
+
throw new Error(
|
|
163
|
+
`Could not read ${url}: ${r.stderr.trim() || `gcloud exited ${r.exitCode}`}. Check that you are signed in (gcloud auth login) as an account with access to the install's ops bucket.`,
|
|
164
|
+
);
|
|
138
165
|
}
|
|
139
166
|
let json: unknown;
|
|
140
167
|
try {
|
|
@@ -285,7 +312,7 @@ export async function describeExecution(
|
|
|
285
312
|
if (!r.ok) {
|
|
286
313
|
if (NOT_FOUND.test(r.stderr)) return "missing";
|
|
287
314
|
throw new Error(
|
|
288
|
-
`Could not read execution ${target.execution}: ${r.stderr.trim() || `gcloud exited ${r.exitCode}`}
|
|
315
|
+
`Could not read execution ${target.execution}: ${r.stderr.trim() || `gcloud exited ${r.exitCode}`}. Your gcloud account needs run.executions.get on ${target.projectId} (e.g. roles/run.viewer or project Owner).`,
|
|
289
316
|
);
|
|
290
317
|
}
|
|
291
318
|
const d = JSON.parse(r.stdout || "{}") as ExecutionDescription;
|
|
@@ -296,6 +323,61 @@ export async function describeExecution(
|
|
|
296
323
|
: "failed";
|
|
297
324
|
}
|
|
298
325
|
|
|
326
|
+
const RecordedProgressSchema = z.object({ steps: z.record(z.string(), z.unknown()) });
|
|
327
|
+
const RecordedStepSchema = z.object({ outputs: z.record(z.string(), z.unknown()).optional() });
|
|
328
|
+
|
|
329
|
+
/**
|
|
330
|
+
* The stack's outputs as the `pulumi-up` step recorded them in the ops
|
|
331
|
+
* bucket's progress.json — current, never cached (the job writes it), and
|
|
332
|
+
* without touching this machine's install directory. Empty before that step
|
|
333
|
+
* finished.
|
|
334
|
+
*
|
|
335
|
+
* @throws when the bucket can't be read or progress.json is malformed
|
|
336
|
+
*/
|
|
337
|
+
export function readRecordedStackOutputs(
|
|
338
|
+
projectId: string,
|
|
339
|
+
run: SyncGcloud,
|
|
340
|
+
): Record<string, unknown> {
|
|
341
|
+
const bucket = opsBucketName(projectId);
|
|
342
|
+
const text = new GcsStateStore(bucket, "/nonexistent", run).peek("progress.json");
|
|
343
|
+
if (text === null) return {};
|
|
344
|
+
const url = `gs://${bucket}/${OPS_INSTALL_PREFIX}/progress.json`;
|
|
345
|
+
let json: unknown;
|
|
346
|
+
try {
|
|
347
|
+
json = JSON.parse(text);
|
|
348
|
+
} catch {
|
|
349
|
+
throw new Error(`${url} is not valid JSON. Re-run the installer to write it again.`);
|
|
350
|
+
}
|
|
351
|
+
const progress = RecordedProgressSchema.safeParse(json);
|
|
352
|
+
if (!progress.success) {
|
|
353
|
+
throw new Error(
|
|
354
|
+
`${url} is not a checkpoint this CLI understands (${progress.error.message}). Re-run the installer to write it again.`,
|
|
355
|
+
);
|
|
356
|
+
}
|
|
357
|
+
const raw = progress.data.steps[`pulumi-up-${projectId}`];
|
|
358
|
+
if (raw === undefined) return {};
|
|
359
|
+
const step = RecordedStepSchema.safeParse(raw);
|
|
360
|
+
if (!step.success) {
|
|
361
|
+
throw new Error(
|
|
362
|
+
`${url} records the pulumi-up step in a shape this CLI does not understand (${step.error.message}). Re-run the installer to write it again.`,
|
|
363
|
+
);
|
|
364
|
+
}
|
|
365
|
+
return step.data.outputs ?? {};
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
/** The stack's `dnsRecordsRequiredOut` from {@link readRecordedStackOutputs}. */
|
|
369
|
+
export function recordedDnsRecords(outputs: Record<string, unknown>): InstallDnsRecord[] {
|
|
370
|
+
const raw = outputs.dnsRecordsRequiredOut;
|
|
371
|
+
if (raw === undefined) return [];
|
|
372
|
+
const records = z.array(DnsRecordSchema).safeParse(raw);
|
|
373
|
+
if (!records.success) {
|
|
374
|
+
throw new Error(
|
|
375
|
+
`The recorded stack output dnsRecordsRequiredOut is malformed (${records.error.message}). Re-run the installer to refresh it.`,
|
|
376
|
+
);
|
|
377
|
+
}
|
|
378
|
+
return records.data;
|
|
379
|
+
}
|
|
380
|
+
|
|
299
381
|
/** What the launcher does with an install that may already have a job. */
|
|
300
382
|
export type InstallJobDecision =
|
|
301
383
|
| { readonly kind: "start"; readonly previous: InstallJobStatus | null; readonly why: string }
|
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
|
-
{
|
|
696
|
+
{
|
|
697
|
+
run,
|
|
698
|
+
http,
|
|
699
|
+
loadBalancerGet: httpsLoadBalancerGet,
|
|
700
|
+
sleep: realSleep,
|
|
701
|
+
accessJustChanged: context.accessJustChanged,
|
|
702
|
+
},
|
|
696
703
|
),
|
|
697
704
|
};
|
|
698
705
|
}
|
|
@@ -15,6 +15,7 @@ import { withIamAuthFlag } from "./cloudsql-iam-user.js";
|
|
|
15
15
|
import type { GcloudResult } from "./gcloud.js";
|
|
16
16
|
import {
|
|
17
17
|
ensureOperatorAccessSync,
|
|
18
|
+
iapWebPath,
|
|
18
19
|
installIapAllowlist,
|
|
19
20
|
OPERATOR_ACCESS_PROJECT_IAP_ROLE,
|
|
20
21
|
OPERATOR_ACCESS_ROLE,
|
|
@@ -205,6 +206,48 @@ describe("ensureOperatorAccessSync", () => {
|
|
|
205
206
|
);
|
|
206
207
|
});
|
|
207
208
|
|
|
209
|
+
it("#1120 — on plain gcp the job addresses the backend by its numeric id", async () => {
|
|
210
|
+
const { run, calls } = freshInstall();
|
|
211
|
+
const withId: typeof run = async (args) =>
|
|
212
|
+
args.slice(0, 3).join(" ") === "compute backend-services describe"
|
|
213
|
+
? ok("6948347336569833444\n")
|
|
214
|
+
: run(args);
|
|
215
|
+
const r = await ensureOperatorAccessSync(
|
|
216
|
+
{
|
|
217
|
+
...target,
|
|
218
|
+
resource: { kind: "backend-services", service: "caelo-production-admin-backend-1a2b" },
|
|
219
|
+
},
|
|
220
|
+
{ run: withId, sleep: async () => {} },
|
|
221
|
+
);
|
|
222
|
+
expect(r.ok).toBe(true);
|
|
223
|
+
const deploy = calls.find((c) => c.slice(0, 3).join(" ") === "run jobs deploy") ?? [];
|
|
224
|
+
expect(deploy.find((a) => a.startsWith("--set-env-vars="))).toContain(
|
|
225
|
+
"CAELO_OPERATOR_ACCESS_IAP_WEB=compute/services/6948347336569833444|",
|
|
226
|
+
);
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
it("#1120 — iapWebPath refuses a backend without its numeric id", () => {
|
|
230
|
+
expect(() => iapWebPath({ kind: "backend-services", service: "b" })).toThrow("numeric id");
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
it("#1120 — refuses a backend whose id cannot be read instead of deploying by name", async () => {
|
|
234
|
+
const { run, calls } = freshInstall();
|
|
235
|
+
const noId: typeof run = async (args) =>
|
|
236
|
+
args.slice(0, 3).join(" ") === "compute backend-services describe"
|
|
237
|
+
? fail("PERMISSION_DENIED")
|
|
238
|
+
: run(args);
|
|
239
|
+
const r = await ensureOperatorAccessSync(
|
|
240
|
+
{
|
|
241
|
+
...target,
|
|
242
|
+
resource: { kind: "backend-services", service: "caelo-production-admin-backend-1a2b" },
|
|
243
|
+
},
|
|
244
|
+
{ run: noId, sleep: async () => {} },
|
|
245
|
+
);
|
|
246
|
+
expect(r.ok).toBe(false);
|
|
247
|
+
// It stops before anything is written, the revoke of the old path included.
|
|
248
|
+
expect(calls).toEqual([]);
|
|
249
|
+
});
|
|
250
|
+
|
|
208
251
|
it("#1140 — tells the job which service accounts keep IAP access (the scheduler tick)", async () => {
|
|
209
252
|
const { run, calls } = freshInstall();
|
|
210
253
|
await ensureOperatorAccessSync(
|
package/src/operator-access.ts
CHANGED
|
@@ -136,11 +136,20 @@ export const OPERATOR_ACCESS_DB_ROLE = "operator_access_reader";
|
|
|
136
136
|
/** Where the admin image ships the job's entry point. */
|
|
137
137
|
const SYNC_JOB_SCRIPT = "/app/packages/admin-core/src/security/operator-access/sync-job.ts";
|
|
138
138
|
|
|
139
|
-
/**
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
139
|
+
/**
|
|
140
|
+
* The `iap_web` path of an IAP resource, as the IAP REST API names it. A
|
|
141
|
+
* backend service goes by its numeric id: IAM on the job's account is
|
|
142
|
+
* evaluated there, and addressed by name `:iapSettings` answers 403 even with
|
|
143
|
+
* the role bound, so the sync failed every hour on plain gcp (#1120).
|
|
144
|
+
*/
|
|
145
|
+
export function iapWebPath(resource: IapResource, backendServiceId?: string): string {
|
|
146
|
+
if (resource.kind === "cloud-run") {
|
|
147
|
+
return `cloud_run-${resource.region}/services/${resource.service}`;
|
|
148
|
+
}
|
|
149
|
+
if (!backendServiceId) {
|
|
150
|
+
throw new Error(`${resource.service}: an IAP backend is addressed by its numeric id`);
|
|
151
|
+
}
|
|
152
|
+
return `compute/services/${backendServiceId}`;
|
|
144
153
|
}
|
|
145
154
|
|
|
146
155
|
/** Create the custom role, or bring an existing / soft-deleted one to spec. */
|
|
@@ -261,6 +270,29 @@ export async function ensureOperatorAccessSync(
|
|
|
261
270
|
const customRole = customRoleName(projectId, OPERATOR_ACCESS_ROLE.roleId);
|
|
262
271
|
const jobName = operatorAccessJobName(env);
|
|
263
272
|
const done: string[] = [];
|
|
273
|
+
|
|
274
|
+
// Before any write: the steps below revoke the old access path, so an
|
|
275
|
+
// unreadable id must not leave the install without a replacement job.
|
|
276
|
+
let backendServiceId: string | undefined;
|
|
277
|
+
if (target.resource.kind === "backend-services") {
|
|
278
|
+
const described = await run([
|
|
279
|
+
"compute",
|
|
280
|
+
"backend-services",
|
|
281
|
+
"describe",
|
|
282
|
+
target.resource.service,
|
|
283
|
+
"--global",
|
|
284
|
+
project,
|
|
285
|
+
"--format=value(id)",
|
|
286
|
+
]);
|
|
287
|
+
backendServiceId = described.stdout.trim();
|
|
288
|
+
if (!described.ok || !/^\d+$/.test(backendServiceId)) {
|
|
289
|
+
return {
|
|
290
|
+
ok: false,
|
|
291
|
+
done,
|
|
292
|
+
error: `read the id of ${target.resource.service}: ${described.stderr.trim() || "no numeric id"}`,
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
}
|
|
264
296
|
const fail = (step: string, r: GcloudResult): OperatorAccessSyncResult => ({
|
|
265
297
|
ok: false,
|
|
266
298
|
done,
|
|
@@ -427,7 +459,7 @@ export async function ensureOperatorAccessSync(
|
|
|
427
459
|
// 6. The job: the admin image with another entry point, the job's own SA,
|
|
428
460
|
// and its whole input as env the admin cannot override.
|
|
429
461
|
const envVars = [
|
|
430
|
-
`CAELO_OPERATOR_ACCESS_IAP_WEB=${iapWebPath(target.resource)}`,
|
|
462
|
+
`CAELO_OPERATOR_ACCESS_IAP_WEB=${iapWebPath(target.resource, backendServiceId)}`,
|
|
431
463
|
`CAELO_MCP_IAP_SERVICE_ACCOUNT=${mcpSa}`,
|
|
432
464
|
`CAELO_OPERATOR_ACCESS_STATIC_MEMBERS=${installIapAllowlist(target.ownerEmail).join(",")}`,
|
|
433
465
|
`CAELO_OPERATOR_ACCESS_DB_HOST=${target.databaseHost}`,
|
package/src/pool-budget-stack.ts
CHANGED
|
@@ -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
|
+
});
|