@caelo-cms/shared 0.11.9 → 0.11.11
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/certs/aws-rds-global.pem +2888 -0
- package/certs/cloudsql-global.pem +1897 -0
- package/dist/body-cap.d.ts +35 -0
- package/dist/body-cap.d.ts.map +1 -0
- package/dist/body-cap.js +63 -0
- package/dist/body-cap.js.map +1 -0
- package/dist/change-journal.d.ts.map +1 -1
- package/dist/change-journal.js +3 -0
- package/dist/change-journal.js.map +1 -1
- package/dist/client-address.d.ts +69 -0
- package/dist/client-address.d.ts.map +1 -0
- package/dist/client-address.js +99 -0
- package/dist/client-address.js.map +1 -0
- package/dist/context.d.ts +8 -0
- package/dist/context.d.ts.map +1 -1
- package/dist/database-tls.d.ts +64 -0
- package/dist/database-tls.d.ts.map +1 -0
- package/dist/database-tls.js +95 -0
- package/dist/database-tls.js.map +1 -0
- package/dist/database-url.d.ts +19 -15
- package/dist/database-url.d.ts.map +1 -1
- package/dist/database-url.js +37 -1
- package/dist/database-url.js.map +1 -1
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -1
- package/dist/interim-forwarded-host.d.ts +15 -0
- package/dist/interim-forwarded-host.d.ts.map +1 -0
- package/dist/interim-forwarded-host.js +16 -0
- package/dist/interim-forwarded-host.js.map +1 -0
- package/dist/json-security-headers.d.ts +23 -0
- package/dist/json-security-headers.d.ts.map +1 -0
- package/dist/json-security-headers.js +53 -0
- package/dist/json-security-headers.js.map +1 -0
- package/dist/live-events.d.ts.map +1 -1
- package/dist/live-events.js +6 -3
- package/dist/live-events.js.map +1 -1
- package/dist/media.d.ts +8 -0
- package/dist/media.d.ts.map +1 -1
- package/dist/media.js +11 -0
- package/dist/media.js.map +1 -1
- package/dist/pool-budget.d.ts +54 -8
- package/dist/pool-budget.d.ts.map +1 -1
- package/dist/pool-budget.js +60 -8
- package/dist/pool-budget.js.map +1 -1
- package/dist/redirect-emit-gcp.d.ts +16 -8
- package/dist/redirect-emit-gcp.d.ts.map +1 -1
- package/dist/redirect-emit-gcp.js +22 -11
- package/dist/redirect-emit-gcp.js.map +1 -1
- package/dist/release-manifest.d.ts +18 -2
- package/dist/release-manifest.d.ts.map +1 -1
- package/dist/release-manifest.js +32 -4
- package/dist/release-manifest.js.map +1 -1
- package/dist/session-cookie.d.ts +88 -0
- package/dist/session-cookie.d.ts.map +1 -0
- package/dist/session-cookie.js +151 -0
- package/dist/session-cookie.js.map +1 -0
- package/dist/staging-plugin-stub.d.ts +28 -0
- package/dist/staging-plugin-stub.d.ts.map +1 -0
- package/dist/staging-plugin-stub.js +34 -0
- package/dist/staging-plugin-stub.js.map +1 -0
- package/dist/version.d.ts +2 -2
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/package.json +2 -1
- package/src/body-cap.test.ts +44 -0
- package/src/body-cap.ts +83 -0
- package/src/change-journal.ts +5 -0
- package/src/client-address.test.ts +90 -0
- package/src/client-address.ts +111 -0
- package/src/context.ts +8 -0
- package/src/database-tls.test.ts +83 -0
- package/src/database-tls.ts +99 -0
- package/src/database-url.test.ts +73 -11
- package/src/database-url.ts +57 -1
- package/src/index.ts +7 -0
- package/src/interim-forwarded-host.ts +16 -0
- package/src/json-security-headers.test.ts +31 -0
- package/src/json-security-headers.ts +53 -0
- package/src/live-events.ts +6 -3
- package/src/media.test.ts +27 -0
- package/src/media.ts +13 -0
- package/src/pool-budget.test.ts +52 -10
- package/src/pool-budget.ts +82 -9
- package/src/redirect-emit-gcp.ts +24 -11
- package/src/redirect-emit.test.ts +6 -5
- package/src/release-manifest.ts +33 -4
- package/src/session-cookie.test.ts +96 -0
- package/src/session-cookie.ts +163 -0
- package/src/staging-plugin-stub.test.ts +23 -0
- package/src/staging-plugin-stub.ts +37 -0
- package/src/version.ts +1 -1
package/src/pool-budget.test.ts
CHANGED
|
@@ -6,20 +6,26 @@ import { describe, expect, it } from "bun:test";
|
|
|
6
6
|
import {
|
|
7
7
|
ADMIN_POOL_FLOOR,
|
|
8
8
|
ADMIN_PUBLIC_POOL_MAX,
|
|
9
|
+
ADMIN_PUBLIC_STAGING_POOL_MAX,
|
|
9
10
|
computePoolBudget,
|
|
10
11
|
DB_POOL_MAX_ENV,
|
|
11
12
|
DB_PUBLIC_POOL_MAX_ENV,
|
|
12
13
|
GATEWAY_POOL_MAX,
|
|
14
|
+
GATEWAY_ROLE_CONNECTION_LIMIT,
|
|
13
15
|
GENERATOR_POOL_MAX,
|
|
14
16
|
LISTEN_CONNECTIONS_PER_ADMIN_INSTANCE,
|
|
17
|
+
LISTEN_CONNECTIONS_PER_GATEWAY_INSTANCE,
|
|
18
|
+
MIN_POOL_MAX,
|
|
15
19
|
type PoolBudgetInput,
|
|
16
20
|
poolBudgetEnv,
|
|
21
|
+
STAGING_GATEWAY_ROLE_CONNECTION_LIMIT,
|
|
17
22
|
} from "./pool-budget.js";
|
|
18
23
|
|
|
19
24
|
const GCP_DEFAULT: PoolBudgetInput = {
|
|
20
25
|
maxConnections: 100,
|
|
21
|
-
adminMaxInstances:
|
|
26
|
+
adminMaxInstances: 4,
|
|
22
27
|
gatewayMaxInstances: 10,
|
|
28
|
+
stagingGatewayMaxInstances: 1,
|
|
23
29
|
concurrentBuilds: 2,
|
|
24
30
|
maintenanceReserve: 5,
|
|
25
31
|
migrationsReserve: 2,
|
|
@@ -29,9 +35,10 @@ const GCP_DEFAULT: PoolBudgetInput = {
|
|
|
29
35
|
describe("computePoolBudget", () => {
|
|
30
36
|
it("splits what the reserves leave across the admin instances", () => {
|
|
31
37
|
const b = computePoolBudget(GCP_DEFAULT);
|
|
32
|
-
// 100 - (5 + 2 + 4 + 8 + 20 +
|
|
38
|
+
// 100 - (5 + 2 + 4 + 8 + 20 + 4 + 10 + 16 + 3 + 8) = 20 → floor(20 / 4) = 5, 0 left.
|
|
33
39
|
expect(b.adminPoolMax).toBe(5);
|
|
34
|
-
expect(b.unassigned).toBe(
|
|
40
|
+
expect(b.unassigned).toBe(0);
|
|
41
|
+
expect(b.adminPublicStagingPoolMax).toBe(ADMIN_PUBLIC_STAGING_POOL_MAX);
|
|
35
42
|
expect(b.adminPublicPoolMax).toBe(ADMIN_PUBLIC_POOL_MAX);
|
|
36
43
|
expect(b.gatewayPoolMax).toBe(GATEWAY_POOL_MAX);
|
|
37
44
|
expect(b.generatorPoolMax).toBe(GENERATOR_POOL_MAX);
|
|
@@ -63,23 +70,58 @@ describe("computePoolBudget", () => {
|
|
|
63
70
|
const r = new Map(computePoolBudget(GCP_DEFAULT).reserves.map((x) => [x.name, x.connections]));
|
|
64
71
|
expect(r.get("gateway")).toBe(10 * GATEWAY_POOL_MAX);
|
|
65
72
|
expect(r.get("generator")).toBe(2 * 2 * GENERATOR_POOL_MAX);
|
|
66
|
-
expect(r.get("admin-public")).toBe(
|
|
73
|
+
expect(r.get("admin-public")).toBe(4 * ADMIN_PUBLIC_POOL_MAX);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it("budgets the staging gateway and the admin's staging pool (#1329)", () => {
|
|
77
|
+
const r = new Map(computePoolBudget(GCP_DEFAULT).reserves.map((x) => [x.name, x.connections]));
|
|
78
|
+
expect(r.get("staging-gateway")).toBe(
|
|
79
|
+
1 * (GATEWAY_POOL_MAX + LISTEN_CONNECTIONS_PER_GATEWAY_INSTANCE),
|
|
80
|
+
);
|
|
81
|
+
expect(ADMIN_PUBLIC_STAGING_POOL_MAX).toBe(MIN_POOL_MAX);
|
|
82
|
+
expect(r.get("admin-public-staging")).toBe(4 * ADMIN_PUBLIC_STAGING_POOL_MAX);
|
|
83
|
+
// On today's default the five admin instances before #1329 no longer
|
|
84
|
+
// fit: the stacks lower their default to four (connection-budget.md).
|
|
85
|
+
expect(() => computePoolBudget({ ...GCP_DEFAULT, adminMaxInstances: 5 })).toThrow(
|
|
86
|
+
/minimum of 4 cms_admin connections/,
|
|
87
|
+
);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it("refuses a staging scale-out beyond public_staging_role's CONNECTION LIMIT (#1329)", () => {
|
|
91
|
+
expect(STAGING_GATEWAY_ROLE_CONNECTION_LIMIT).toBe(GATEWAY_ROLE_CONNECTION_LIMIT);
|
|
92
|
+
expect(() =>
|
|
93
|
+
computePoolBudget({ ...GCP_DEFAULT, maxConnections: 1000, stagingGatewayMaxInstances: 11 }),
|
|
94
|
+
).toThrow(
|
|
95
|
+
"11 staging gateway instances need 33 connections, but the database lets the staging gateway's login (public_staging_role) hold at most 30",
|
|
96
|
+
);
|
|
67
97
|
});
|
|
68
98
|
|
|
69
99
|
it("refuses a budget below the admin floor, naming the connections needed", () => {
|
|
70
|
-
//
|
|
71
|
-
expect(() => computePoolBudget({ ...GCP_DEFAULT,
|
|
72
|
-
/Raise maxConnections to at least
|
|
100
|
+
// Ten gateway instances on 60 slots: 30 for the gateway leave too little.
|
|
101
|
+
expect(() => computePoolBudget({ ...GCP_DEFAULT, maxConnections: 60 })).toThrow(
|
|
102
|
+
/Raise maxConnections to at least 96/,
|
|
73
103
|
);
|
|
74
104
|
expect(() => computePoolBudget({ ...GCP_DEFAULT, maxConnections: 50 })).toThrow(
|
|
75
105
|
new RegExp(`minimum of ${ADMIN_POOL_FLOOR}`),
|
|
76
106
|
);
|
|
77
107
|
});
|
|
78
108
|
|
|
109
|
+
it("refuses a gateway scale-out beyond public_role's CONNECTION LIMIT (#1338)", () => {
|
|
110
|
+
expect(GATEWAY_ROLE_CONNECTION_LIMIT).toBe(
|
|
111
|
+
10 * (GATEWAY_POOL_MAX + LISTEN_CONNECTIONS_PER_GATEWAY_INSTANCE),
|
|
112
|
+
);
|
|
113
|
+
expect(() =>
|
|
114
|
+
computePoolBudget({ ...GCP_DEFAULT, maxConnections: 1000, gatewayMaxInstances: 11 }),
|
|
115
|
+
).toThrow(
|
|
116
|
+
"11 gateway instances need 33 connections, but the database lets the gateway's login (public_role) hold at most 30",
|
|
117
|
+
);
|
|
118
|
+
expect(() => computePoolBudget({ ...GCP_DEFAULT, gatewayMaxInstances: 10 })).not.toThrow();
|
|
119
|
+
});
|
|
120
|
+
|
|
79
121
|
it("accepts exactly the floor", () => {
|
|
80
|
-
// reserves
|
|
81
|
-
expect(computePoolBudget({ ...GCP_DEFAULT, maxConnections:
|
|
82
|
-
expect(() => computePoolBudget({ ...GCP_DEFAULT, maxConnections:
|
|
122
|
+
// reserves 80 + 4 × 4 = 96.
|
|
123
|
+
expect(computePoolBudget({ ...GCP_DEFAULT, maxConnections: 96 }).adminPoolMax).toBe(4);
|
|
124
|
+
expect(() => computePoolBudget({ ...GCP_DEFAULT, maxConnections: 95 })).toThrow();
|
|
83
125
|
});
|
|
84
126
|
|
|
85
127
|
it("rejects malformed input instead of guessing", () => {
|
package/src/pool-budget.ts
CHANGED
|
@@ -53,6 +53,14 @@ export const ADMIN_POOL_FLOOR = 4;
|
|
|
53
53
|
/** The admin's cms_public pool: plugin-data reads and the gateway projection. */
|
|
54
54
|
export const ADMIN_PUBLIC_POOL_MAX = 4;
|
|
55
55
|
|
|
56
|
+
/**
|
|
57
|
+
* #1329 — the admin's cms_public_staging pool: the staging database's
|
|
58
|
+
* plugin schemas and its half of the two-target projection. Fixed at the
|
|
59
|
+
* minimum pool, set by the admin in code (no env var): its work is a few
|
|
60
|
+
* short DDL and publish transactions, one at a time per instance.
|
|
61
|
+
*/
|
|
62
|
+
export const ADMIN_PUBLIC_STAGING_POOL_MAX = 2;
|
|
63
|
+
|
|
56
64
|
/** The gateway's only pool (public_role on cms_public), per instance. */
|
|
57
65
|
export const GATEWAY_POOL_MAX = 2;
|
|
58
66
|
|
|
@@ -78,6 +86,33 @@ export const LISTEN_CONNECTIONS_PER_ADMIN_INSTANCE = 1;
|
|
|
78
86
|
*/
|
|
79
87
|
export const LISTEN_CONNECTIONS_PER_GATEWAY_INSTANCE = 1;
|
|
80
88
|
|
|
89
|
+
/**
|
|
90
|
+
* #1338 — public_role's `CONNECTION LIMIT` (cms_admin migration 0500,
|
|
91
|
+
* bootstrap.sh; the role audit's `PUBLIC_ROLE_LIMITS` pins the same value):
|
|
92
|
+
* the gateway's share at ten instances, `10 × (GATEWAY_POOL_MAX +
|
|
93
|
+
* LISTEN_CONNECTIONS_PER_GATEWAY_INSTANCE)`. The database refuses the
|
|
94
|
+
* gateway's connections beyond it, so {@link computePoolBudget} refuses a
|
|
95
|
+
* scale-out that would need more instead of letting instances fail to
|
|
96
|
+
* connect under load.
|
|
97
|
+
*/
|
|
98
|
+
export const GATEWAY_ROLE_CONNECTION_LIMIT = 30;
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* #1329 — public_staging_role's `CONNECTION LIMIT` (cms_admin migration
|
|
102
|
+
* 0530, bootstrap.sh): the same bound as the live gateway's login. The
|
|
103
|
+
* database refuses the staging gateway's connections beyond it.
|
|
104
|
+
*/
|
|
105
|
+
export const STAGING_GATEWAY_ROLE_CONNECTION_LIMIT = 30;
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* #1329 — staging gateway instances the stacks let start. Staging serves
|
|
109
|
+
* the team, the audit and the crawlers the Owner admits, never the public,
|
|
110
|
+
* so one instance (Cloud Run: 80 concurrent requests) carries it, and the
|
|
111
|
+
* budget leaves the admin its cms_admin pool on the default server
|
|
112
|
+
* (docs/dev/connection-budget.md has the numbers).
|
|
113
|
+
*/
|
|
114
|
+
export const DEFAULT_STAGING_GATEWAY_MAX_INSTANCES = 1;
|
|
115
|
+
|
|
81
116
|
/** What the budget is computed from: the server and the scale-out limits. */
|
|
82
117
|
export interface PoolBudgetInput {
|
|
83
118
|
/** The server's `max_connections`, as provisioning sets it. */
|
|
@@ -86,6 +121,11 @@ export interface PoolBudgetInput {
|
|
|
86
121
|
readonly adminMaxInstances: number;
|
|
87
122
|
/** Most gateway instances that may run at once. */
|
|
88
123
|
readonly gatewayMaxInstances: number;
|
|
124
|
+
/**
|
|
125
|
+
* #1329 — most staging gateway instances that may run at once (the same
|
|
126
|
+
* image on cms_public_staging, its own pool and LISTEN connection each).
|
|
127
|
+
*/
|
|
128
|
+
readonly stagingGatewayMaxInstances: number;
|
|
89
129
|
/**
|
|
90
130
|
* Static-generator subprocesses that may run at once across the install
|
|
91
131
|
* (a Stage, a Publish live and a plugin-data build can overlap).
|
|
@@ -117,7 +157,11 @@ export type PoolBudgetReserveName =
|
|
|
117
157
|
| "listen"
|
|
118
158
|
/** The gateway's settings LISTEN, one per gateway instance ({@link LISTEN_CONNECTIONS_PER_GATEWAY_INSTANCE}). */
|
|
119
159
|
| "gateway-listen"
|
|
120
|
-
| "admin-public"
|
|
160
|
+
| "admin-public"
|
|
161
|
+
/** #1329 — the staging gateway's pool + LISTEN, per staging gateway instance. */
|
|
162
|
+
| "staging-gateway"
|
|
163
|
+
/** #1329 — the admin's cms_public_staging pool ({@link ADMIN_PUBLIC_STAGING_POOL_MAX}), per admin instance. */
|
|
164
|
+
| "admin-public-staging";
|
|
121
165
|
|
|
122
166
|
/** One consumer of the server's connections the budget sets aside. */
|
|
123
167
|
export interface PoolBudgetReserve {
|
|
@@ -133,6 +177,8 @@ export interface PoolBudget {
|
|
|
133
177
|
readonly adminPublicPoolMax: number;
|
|
134
178
|
/** The gateway's cms_public pool ({@link DB_PUBLIC_POOL_MAX_ENV} on the gateway). */
|
|
135
179
|
readonly gatewayPoolMax: number;
|
|
180
|
+
/** #1329 — the admin's cms_public_staging pool (fixed, {@link ADMIN_PUBLIC_STAGING_POOL_MAX}). */
|
|
181
|
+
readonly adminPublicStagingPoolMax: number;
|
|
136
182
|
/** Each pool of a generator subprocess (the admin sets it on the child). */
|
|
137
183
|
readonly generatorPoolMax: number;
|
|
138
184
|
readonly reserves: readonly PoolBudgetReserve[];
|
|
@@ -154,25 +200,45 @@ function positiveInteger(value: number, name: string, min: number): void {
|
|
|
154
200
|
* `gateway = gatewayMaxInstances × GATEWAY_POOL_MAX`,
|
|
155
201
|
* `generator = concurrentBuilds × 2 × GENERATOR_POOL_MAX`,
|
|
156
202
|
* `listen = adminMaxInstances × LISTEN_CONNECTIONS_PER_ADMIN_INSTANCE`,
|
|
157
|
-
* `gateway-listen = gatewayMaxInstances × LISTEN_CONNECTIONS_PER_GATEWAY_INSTANCE
|
|
158
|
-
* `admin-public = adminMaxInstances × ADMIN_PUBLIC_POOL_MAX
|
|
203
|
+
* `gateway-listen = gatewayMaxInstances × LISTEN_CONNECTIONS_PER_GATEWAY_INSTANCE`,
|
|
204
|
+
* `admin-public = adminMaxInstances × ADMIN_PUBLIC_POOL_MAX`,
|
|
205
|
+
* `staging-gateway = stagingGatewayMaxInstances × (GATEWAY_POOL_MAX +
|
|
206
|
+
* LISTEN_CONNECTIONS_PER_GATEWAY_INSTANCE)` and
|
|
207
|
+
* `admin-public-staging = adminMaxInstances × ADMIN_PUBLIC_STAGING_POOL_MAX` (#1329).
|
|
159
208
|
*
|
|
160
209
|
* @throws Error naming what to change when the server cannot give every
|
|
161
210
|
* admin instance at least {@link ADMIN_POOL_FLOOR} cms_admin connections.
|
|
162
211
|
*
|
|
163
212
|
* @example
|
|
164
|
-
* computePoolBudget({ maxConnections: 100, adminMaxInstances:
|
|
165
|
-
* gatewayMaxInstances: 10,
|
|
166
|
-
* migrationsReserve: 2, jobsReserve: 4 }).adminPoolMax // →
|
|
213
|
+
* computePoolBudget({ maxConnections: 100, adminMaxInstances: 4,
|
|
214
|
+
* gatewayMaxInstances: 10, stagingGatewayMaxInstances: 1, concurrentBuilds: 2,
|
|
215
|
+
* maintenanceReserve: 5, migrationsReserve: 2, jobsReserve: 4 }).adminPoolMax // → 5
|
|
167
216
|
*/
|
|
168
217
|
export function computePoolBudget(input: PoolBudgetInput): PoolBudget {
|
|
169
218
|
positiveInteger(input.maxConnections, "maxConnections", 1);
|
|
170
219
|
positiveInteger(input.adminMaxInstances, "adminMaxInstances", 1);
|
|
171
220
|
positiveInteger(input.gatewayMaxInstances, "gatewayMaxInstances", 0);
|
|
221
|
+
positiveInteger(input.stagingGatewayMaxInstances, "stagingGatewayMaxInstances", 0);
|
|
172
222
|
positiveInteger(input.concurrentBuilds, "concurrentBuilds", 0);
|
|
173
223
|
positiveInteger(input.maintenanceReserve, "maintenanceReserve", 0);
|
|
174
224
|
positiveInteger(input.migrationsReserve, "migrationsReserve", 0);
|
|
175
225
|
positiveInteger(input.jobsReserve, "jobsReserve", 0);
|
|
226
|
+
const gatewayConnections =
|
|
227
|
+
input.gatewayMaxInstances * (GATEWAY_POOL_MAX + LISTEN_CONNECTIONS_PER_GATEWAY_INSTANCE);
|
|
228
|
+
if (gatewayConnections > GATEWAY_ROLE_CONNECTION_LIMIT) {
|
|
229
|
+
throw new Error(
|
|
230
|
+
`pool budget: ${input.gatewayMaxInstances} gateway instances need ${gatewayConnections} connections, but the database lets the gateway's login (public_role) hold at most ${GATEWAY_ROLE_CONNECTION_LIMIT} (CONNECTION LIMIT, #1338). ` +
|
|
231
|
+
`Lower gatewayMaxInstances to at most ${Math.floor(GATEWAY_ROLE_CONNECTION_LIMIT / (GATEWAY_POOL_MAX + LISTEN_CONNECTIONS_PER_GATEWAY_INSTANCE))}.`,
|
|
232
|
+
);
|
|
233
|
+
}
|
|
234
|
+
const stagingGatewayConnections =
|
|
235
|
+
input.stagingGatewayMaxInstances * (GATEWAY_POOL_MAX + LISTEN_CONNECTIONS_PER_GATEWAY_INSTANCE);
|
|
236
|
+
if (stagingGatewayConnections > STAGING_GATEWAY_ROLE_CONNECTION_LIMIT) {
|
|
237
|
+
throw new Error(
|
|
238
|
+
`pool budget: ${input.stagingGatewayMaxInstances} staging gateway instances need ${stagingGatewayConnections} connections, but the database lets the staging gateway's login (public_staging_role) hold at most ${STAGING_GATEWAY_ROLE_CONNECTION_LIMIT} (CONNECTION LIMIT, #1329). ` +
|
|
239
|
+
`Lower stagingGatewayMaxInstances to at most ${Math.floor(STAGING_GATEWAY_ROLE_CONNECTION_LIMIT / (GATEWAY_POOL_MAX + LISTEN_CONNECTIONS_PER_GATEWAY_INSTANCE))}.`,
|
|
240
|
+
);
|
|
241
|
+
}
|
|
176
242
|
|
|
177
243
|
const reserves: PoolBudgetReserve[] = [
|
|
178
244
|
{ name: "maintenance", connections: input.maintenanceReserve },
|
|
@@ -189,6 +255,11 @@ export function computePoolBudget(input: PoolBudgetInput): PoolBudget {
|
|
|
189
255
|
connections: input.gatewayMaxInstances * LISTEN_CONNECTIONS_PER_GATEWAY_INSTANCE,
|
|
190
256
|
},
|
|
191
257
|
{ name: "admin-public", connections: input.adminMaxInstances * ADMIN_PUBLIC_POOL_MAX },
|
|
258
|
+
{ name: "staging-gateway", connections: stagingGatewayConnections },
|
|
259
|
+
{
|
|
260
|
+
name: "admin-public-staging",
|
|
261
|
+
connections: input.adminMaxInstances * ADMIN_PUBLIC_STAGING_POOL_MAX,
|
|
262
|
+
},
|
|
192
263
|
];
|
|
193
264
|
const reserved = reserves.reduce((sum, r) => sum + r.connections, 0);
|
|
194
265
|
const forAdmin = input.maxConnections - reserved;
|
|
@@ -199,13 +270,14 @@ export function computePoolBudget(input: PoolBudgetInput): PoolBudget {
|
|
|
199
270
|
throw new Error(
|
|
200
271
|
`pool budget: max_connections ${input.maxConnections} cannot give each of ${input.adminMaxInstances} admin instances the minimum of ${ADMIN_POOL_FLOOR} cms_admin connections ` +
|
|
201
272
|
`(reserved: ${breakdown}; ${needed} needed). Raise maxConnections to at least ${needed} (a larger database tier may be required), ` +
|
|
202
|
-
"or lower adminMaxInstances / gatewayMaxInstances.",
|
|
273
|
+
"or lower adminMaxInstances / gatewayMaxInstances / stagingGatewayMaxInstances.",
|
|
203
274
|
);
|
|
204
275
|
}
|
|
205
276
|
return {
|
|
206
277
|
adminPoolMax,
|
|
207
278
|
adminPublicPoolMax: ADMIN_PUBLIC_POOL_MAX,
|
|
208
279
|
gatewayPoolMax: GATEWAY_POOL_MAX,
|
|
280
|
+
adminPublicStagingPoolMax: ADMIN_PUBLIC_STAGING_POOL_MAX,
|
|
209
281
|
generatorPoolMax: GENERATOR_POOL_MAX,
|
|
210
282
|
reserves,
|
|
211
283
|
unassigned: forAdmin - adminPoolMax * input.adminMaxInstances,
|
|
@@ -217,8 +289,9 @@ export type PoolBudgetService = "admin" | "gateway";
|
|
|
217
289
|
|
|
218
290
|
/**
|
|
219
291
|
* The env that sizes `service`'s pools from `budget`, for the stacks to set.
|
|
220
|
-
* The admin gets both pools
|
|
221
|
-
*
|
|
292
|
+
* The admin gets both pools (its cms_public_staging pool is fixed in code,
|
|
293
|
+
* #1329); a gateway, live or staging, whose only pool is its public
|
|
294
|
+
* database's, gets just that one.
|
|
222
295
|
*/
|
|
223
296
|
export function poolBudgetEnv(
|
|
224
297
|
budget: PoolBudget,
|
package/src/redirect-emit-gcp.ts
CHANGED
|
@@ -161,19 +161,32 @@ export function assertGcpRedirectBudget(
|
|
|
161
161
|
withGcpRedirects({ name: "budget-check", pathRules: baseRules }, plan);
|
|
162
162
|
}
|
|
163
163
|
|
|
164
|
+
/** The paths the `gcp` load balancer sends to the visitor gateway: its whole API. */
|
|
165
|
+
export const GCP_GATEWAY_PATHS: readonly string[] = ["/api/*"];
|
|
166
|
+
|
|
164
167
|
/**
|
|
165
|
-
*
|
|
166
|
-
*
|
|
167
|
-
*
|
|
168
|
-
*
|
|
169
|
-
*
|
|
170
|
-
*
|
|
171
|
-
*
|
|
172
|
-
* `openid-configuration` prefix: the broker
|
|
173
|
-
* serves no such document (#899), so the site
|
|
168
|
+
* #1328 — the paths the `gcp` load balancer sends to the MCP-Auth-Proxy, the
|
|
169
|
+
* remote-MCP broker's own service (#806 put it inside the gateway). The
|
|
170
|
+
* endpoints and the broker's OAuth routes under `/api/mcp/*` — the more
|
|
171
|
+
* specific prefix wins over `/api/*` in one path matcher — and the two
|
|
172
|
+
* `/.well-known/oauth-*` prefixes, the broker's discovery documents, which
|
|
173
|
+
* MCP clients look up at the host root (RFC 9728 protected-resource
|
|
174
|
+
* metadata, RFC 8414 authorization-server metadata); they must reach the
|
|
175
|
+
* proxy, not 404 in the bucket. No `openid-configuration` prefix: the broker
|
|
176
|
+
* is not an OpenID provider and serves no such document (#899), so the site
|
|
177
|
+
* keeps that path.
|
|
174
178
|
*/
|
|
175
|
-
export const
|
|
176
|
-
"/api/*",
|
|
179
|
+
export const GCP_MCP_AUTH_PROXY_PATHS: readonly string[] = [
|
|
180
|
+
"/api/mcp/*",
|
|
177
181
|
"/.well-known/oauth-protected-resource/*",
|
|
178
182
|
"/.well-known/oauth-authorization-server/*",
|
|
179
183
|
];
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* The site's own routing in the `public` path matcher (stack + budget): the
|
|
187
|
+
* paths the load balancer sends to a service instead of the static bucket.
|
|
188
|
+
*/
|
|
189
|
+
export const GCP_PUBLIC_BASE_PATHS: readonly string[] = [
|
|
190
|
+
...GCP_GATEWAY_PATHS,
|
|
191
|
+
...GCP_MCP_AUTH_PROXY_PATHS,
|
|
192
|
+
];
|
|
@@ -153,8 +153,9 @@ describe("GCP URL-map rules", () => {
|
|
|
153
153
|
});
|
|
154
154
|
|
|
155
155
|
it("refuses a plan over the 1,000-predicate quota with the counts, before any change", () => {
|
|
156
|
-
// The base
|
|
157
|
-
|
|
156
|
+
// The base rules route /api/* to the gateway and /api/mcp/* plus the
|
|
157
|
+
// remote-MCP discovery paths to the MCP-Auth-Proxy (#806, #1328).
|
|
158
|
+
expect(GCP_PUBLIC_BASE_PATHS).toHaveLength(4);
|
|
158
159
|
const base = [{ paths: [...GCP_PUBLIC_BASE_PATHS] }];
|
|
159
160
|
const rows = (n: number) => Array.from({ length: n }, (_, i) => row(`/p${i}`, "/x"));
|
|
160
161
|
expect(() => assertGcpRedirectBudget(planOf(rows(498)), base)).not.toThrow();
|
|
@@ -163,12 +164,12 @@ describe("GCP URL-map rules", () => {
|
|
|
163
164
|
throw new Error("expected GcpUrlMapBudgetError");
|
|
164
165
|
} catch (e) {
|
|
165
166
|
expect(e).toBeInstanceOf(GcpUrlMapBudgetError);
|
|
166
|
-
expect((e as GcpUrlMapBudgetError).predicatesNeeded).toBe(
|
|
167
|
-
expect((e as Error).message).toContain("499 redirect(s) need
|
|
167
|
+
expect((e as GcpUrlMapBudgetError).predicatesNeeded).toBe(1002);
|
|
168
|
+
expect((e as Error).message).toContain("499 redirect(s) need 1002 paths");
|
|
168
169
|
expect((e as Error).message).toContain("bulk_delete_redirects");
|
|
169
170
|
}
|
|
170
171
|
// File-like paths cost one predicate each.
|
|
171
|
-
const files = Array.from({ length:
|
|
172
|
+
const files = Array.from({ length: 996 }, (_, i) => row(`/p${i}.html`, "/x"));
|
|
172
173
|
expect(() => assertGcpRedirectBudget(planOf(files), base)).not.toThrow();
|
|
173
174
|
});
|
|
174
175
|
|
package/src/release-manifest.ts
CHANGED
|
@@ -19,10 +19,25 @@ import { z } from "zod";
|
|
|
19
19
|
export const RELEASE_CHANNELS = ["stable", "rc", "beta", "alpha"] as const;
|
|
20
20
|
export type ReleaseChannel = (typeof RELEASE_CHANNELS)[number];
|
|
21
21
|
|
|
22
|
-
/**
|
|
23
|
-
|
|
22
|
+
/**
|
|
23
|
+
* The services a release ships images for. Every release cut from now on
|
|
24
|
+
* signs all of them (scripts/release-manifest.ts requires a digest each);
|
|
25
|
+
* `mcp-auth-proxy` (#1328) is the one manifests of older releases lack —
|
|
26
|
+
* see {@link OPTIONAL_RELEASE_IMAGES}.
|
|
27
|
+
*/
|
|
28
|
+
export const RELEASE_IMAGES = ["admin", "gateway", "ops", "mcp-auth-proxy"] as const;
|
|
24
29
|
export type ReleaseImage = (typeof RELEASE_IMAGES)[number];
|
|
25
30
|
|
|
31
|
+
/**
|
|
32
|
+
* Images a signed manifest may lack because they were added after
|
|
33
|
+
* releases that are still installable or rolled back to: the
|
|
34
|
+
* MCP-Auth-Proxy got its own image in #1328, so every manifest signed
|
|
35
|
+
* before it names none. Optional in the schema (manifestVersion stays 1;
|
|
36
|
+
* readers older than the key strip it as an unknown key), required by the
|
|
37
|
+
* release script for every new release.
|
|
38
|
+
*/
|
|
39
|
+
export const OPTIONAL_RELEASE_IMAGES: readonly ReleaseImage[] = ["mcp-auth-proxy"];
|
|
40
|
+
|
|
26
41
|
/** A `sha256:<64 hex>` image / blob digest. */
|
|
27
42
|
export const IMAGE_DIGEST = /^sha256:[0-9a-f]{64}$/;
|
|
28
43
|
|
|
@@ -39,7 +54,13 @@ export const ReleaseManifestSchema = z.object({
|
|
|
39
54
|
manifestVersion: z.literal(1),
|
|
40
55
|
version: z.string().regex(SEMVER, "expected a SemVer version without a leading v"),
|
|
41
56
|
channel: z.enum(RELEASE_CHANNELS),
|
|
42
|
-
digests: z.object({
|
|
57
|
+
digests: z.object({
|
|
58
|
+
admin: digest,
|
|
59
|
+
gateway: digest,
|
|
60
|
+
ops: digest,
|
|
61
|
+
/** Absent on releases before #1328 (see {@link OPTIONAL_RELEASE_IMAGES}). */
|
|
62
|
+
"mcp-auth-proxy": digest.optional(),
|
|
63
|
+
}),
|
|
43
64
|
/**
|
|
44
65
|
* #1025 — the linux/amd64 platform manifest inside each image index of
|
|
45
66
|
* `digests`. The release images are OCI indexes (buildx adds an
|
|
@@ -52,7 +73,15 @@ export const ReleaseManifestSchema = z.object({
|
|
|
52
73
|
* and older readers ignore it; readers then list the index itself
|
|
53
74
|
* (content-addressed, so it cannot be forged either).
|
|
54
75
|
*/
|
|
55
|
-
platformDigests: z
|
|
76
|
+
platformDigests: z
|
|
77
|
+
.object({
|
|
78
|
+
admin: digest,
|
|
79
|
+
gateway: digest,
|
|
80
|
+
ops: digest,
|
|
81
|
+
/** Absent on releases before #1328 (see {@link OPTIONAL_RELEASE_IMAGES}). */
|
|
82
|
+
"mcp-auth-proxy": digest.optional(),
|
|
83
|
+
})
|
|
84
|
+
.optional(),
|
|
56
85
|
minFromVersion: z.string().regex(SEMVER),
|
|
57
86
|
infraContractVersion: z.number().int().positive(),
|
|
58
87
|
migrations: z.object({
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MPL-2.0
|
|
2
|
+
|
|
3
|
+
import { describe, expect, it } from "bun:test";
|
|
4
|
+
import {
|
|
5
|
+
readSessionCookie,
|
|
6
|
+
SESSION_COOKIE_NAME,
|
|
7
|
+
SESSION_ENTRY,
|
|
8
|
+
type SessionEntry,
|
|
9
|
+
sessionCookieValue,
|
|
10
|
+
sessionSetCookieHeader,
|
|
11
|
+
} from "./session-cookie.js";
|
|
12
|
+
|
|
13
|
+
const NOW = 1_800_000_000;
|
|
14
|
+
const SIGNED_VID = "0b1c2d3e-4f50-4617-8899-aabbccddeeff.1799999000.ab12";
|
|
15
|
+
const STAGING = "session.1800003600.Zm9v-_bar";
|
|
16
|
+
|
|
17
|
+
function entries(o: Record<string, SessionEntry>): Map<string, SessionEntry> {
|
|
18
|
+
return new Map(Object.entries(o));
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** The Cookie header a browser sends back for a Set-Cookie value. */
|
|
22
|
+
function cookieFor(setCookie: string, others = ""): string {
|
|
23
|
+
return `${others}${setCookie.split(";")[0]}`;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
describe("__session container (#1343)", () => {
|
|
27
|
+
it("is named __session: the only cookie Firebase Hosting forwards", () => {
|
|
28
|
+
expect(SESSION_COOKIE_NAME).toBe("__session");
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it("round-trips several owners' entries without one clobbering another", () => {
|
|
32
|
+
const written = entries({
|
|
33
|
+
[SESSION_ENTRY.visitorId]: { value: SIGNED_VID, expiresAt: NOW + 100 },
|
|
34
|
+
[SESSION_ENTRY.staging]: { value: STAGING, expiresAt: NOW + 3600 },
|
|
35
|
+
});
|
|
36
|
+
const header = sessionSetCookieHeader(written, { nowSeconds: NOW, secure: true });
|
|
37
|
+
const read = readSessionCookie(cookieFor(header, "other=1; "), NOW);
|
|
38
|
+
expect([...read]).toEqual([...written].sort(([a], [b]) => a.localeCompare(b)));
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it("sets HttpOnly, SameSite=Lax, Secure and the longest entry's Max-Age", () => {
|
|
42
|
+
const header = sessionSetCookieHeader(
|
|
43
|
+
entries({
|
|
44
|
+
vid: { value: SIGNED_VID, expiresAt: NOW + 100 },
|
|
45
|
+
login: { value: "a.1.b", expiresAt: NOW + 50 },
|
|
46
|
+
}),
|
|
47
|
+
{ nowSeconds: NOW, secure: true },
|
|
48
|
+
);
|
|
49
|
+
expect(header).toStartWith("__session=");
|
|
50
|
+
expect(header).toContain("; Path=/; HttpOnly; SameSite=Lax; Max-Age=100; Secure");
|
|
51
|
+
expect(sessionSetCookieHeader(new Map(), { nowSeconds: NOW, secure: false })).toBe(
|
|
52
|
+
"__session=; Path=/; HttpOnly; SameSite=Lax; Max-Age=0",
|
|
53
|
+
);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it("leaves out expired, malformed and unknown-shaped entries", () => {
|
|
57
|
+
const value = encodeURIComponent(
|
|
58
|
+
new URLSearchParams([
|
|
59
|
+
["vid", `${NOW - 1}.${SIGNED_VID}`],
|
|
60
|
+
["login", "notanumber.abc"],
|
|
61
|
+
["Bad-Key", `${NOW + 9}.x`],
|
|
62
|
+
["staging", `${NOW + 9}.has space`],
|
|
63
|
+
["vid", `${NOW + 9}.fine`],
|
|
64
|
+
["vid", `${NOW + 9}.repeated`],
|
|
65
|
+
]).toString(),
|
|
66
|
+
);
|
|
67
|
+
const read = readSessionCookie(`__session=${value}`, NOW);
|
|
68
|
+
expect([...read]).toEqual([["vid", { value: "fine", expiresAt: NOW + 9 }]]);
|
|
69
|
+
expect(readSessionCookie("__session=%E0%A4%A", NOW).size).toBe(0);
|
|
70
|
+
expect(readSessionCookie("caelo_visitor_id=x", NOW).size).toBe(0);
|
|
71
|
+
expect(readSessionCookie(null, NOW).size).toBe(0);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it("refuses to write what it could not read back", () => {
|
|
75
|
+
expect(() => sessionCookieValue(entries({ vid: { value: "a;b", expiresAt: NOW } }))).toThrow(
|
|
76
|
+
"invalid value",
|
|
77
|
+
);
|
|
78
|
+
expect(() => sessionCookieValue(entries({ other: { value: "a", expiresAt: NOW } }))).toThrow(
|
|
79
|
+
"unknown entry key",
|
|
80
|
+
);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it("holds only the known owners' keys, so no visitor input can grow it (PR #1354 review)", () => {
|
|
84
|
+
const crafted = new URLSearchParams(
|
|
85
|
+
Array.from({ length: 20 }, (_, i) => [`k${i}`, `${NOW + 9}.x`] as [string, string]),
|
|
86
|
+
);
|
|
87
|
+
crafted.append("login", `${NOW + 9}.kept`);
|
|
88
|
+
const read = readSessionCookie(`__session=${encodeURIComponent(crafted.toString())}`, NOW);
|
|
89
|
+
expect([...read.keys()]).toEqual(["login"]);
|
|
90
|
+
// A gateway write on top of the full known set still serialises.
|
|
91
|
+
const all = new Map(read);
|
|
92
|
+
all.set("vid", { value: "v", expiresAt: NOW + 9 });
|
|
93
|
+
all.set("staging", { value: "s", expiresAt: NOW + 9 });
|
|
94
|
+
expect(() => sessionCookieValue(all)).not.toThrow();
|
|
95
|
+
});
|
|
96
|
+
});
|