@openupstream/sdk 0.5.0 → 0.10.0

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.
@@ -4,7 +4,7 @@
4
4
  * public API: it is served on its own port, never routed by ingress, and
5
5
  * callers authenticate with their Kubernetes ServiceAccount token.
6
6
  */
7
- import type { Account, Database, DatabaseAccess, DatabaseConnection, Domain, Id, Job, Member, Project, ResourceKind, Route, Service, Site, UsageUnit } from './model.js';
7
+ import type { Account, Database, DatabaseAccess, DatabaseConnection, DefinitionDatabaseAccess, Domain, Id, Job, Member, Project, ResourceKind, Route, Service, Site, UsageUnit } from './model.js';
8
8
  /**
9
9
  * Kubernetes names, by id (ARCHITECTURE.md, decision 42): the operators
10
10
  * create these objects, the control plane reads and deletes them.
@@ -14,6 +14,18 @@ export declare const projectNamespace: (projectId: Id) => string;
14
14
  export declare const clusterName: (database: Pick<Database, "id">) => string;
15
15
  /** Cannot share the Cluster's name, nor `<cluster>-rw`, which the Cluster's own Service takes. */
16
16
  export declare const poolerName: (database: Pick<Database, "id">) => string;
17
+ /**
18
+ * The Database's second Pooler, of type `ro`: to its standby, never to its
19
+ * primary (decision 157). The restart guard pauses only `poolerName`'s.
20
+ */
21
+ export declare const readPoolerName: (database: Pick<Database, "id">) => string;
22
+ /**
23
+ * The CPU each instance of a Database is guaranteed (decision 151): one core
24
+ * per 4 GiB of its memory, the ratio of the compute servers (16 threads,
25
+ * 64 GB), as a Kubernetes request with no limit, so it uses idle cores too.
26
+ */
27
+ export declare const DATABASE_MILLICORES_PER_GIB = 250;
28
+ export declare const databaseCpuMillicores: (memoryMb: number) => number;
17
29
  /** The Cluster's own Service to its primary, which CloudNativePG names. */
18
30
  export declare const primaryServiceName: (database: Pick<Database, "id">) => string;
19
31
  /**
@@ -23,6 +35,10 @@ export declare const primaryServiceName: (database: Pick<Database, "id">) => str
23
35
  * hyphen and 8 characters, a Project id in 12.
24
36
  */
25
37
  export declare const tunnelHostname: (projectId: Id, customerDomain: string) => string;
38
+ /** The forwarder's Deployment in a Project's namespace (decision 126). */
39
+ export declare const DATABASE_TUNNEL = "database-tunnel";
40
+ /** Its pods, by label; the control plane deletes them to end every tunnel of the Project (decision 143). */
41
+ export declare const DATABASE_TUNNEL_PODS = "openupstream.io/component=database-tunnel";
26
42
  /** What the tunnel reaches at a level: the Pooler, or the primary at `owner`, so session advisory locks work. */
27
43
  export type DatabaseTunnelTarget = 'pooler' | 'primary';
28
44
  export declare const tunnelTargetOf: (access: DatabaseAccess) => DatabaseTunnelTarget;
@@ -42,16 +58,44 @@ export declare const databaseRoleSecret: (role: {
42
58
  export interface DatabaseRoleRow {
43
59
  readonly id: Id;
44
60
  readonly access: DatabaseAccess;
61
+ /** Taken from its caller (decision 143): the Cluster drops it (`ensure: absent`). */
62
+ readonly dropped?: true;
45
63
  }
46
- /** The Secret CloudNativePG keeps the Database's `app` user in, with its generated `password`. */
64
+ /**
65
+ * The Secret with the Database's `app` user and its `password`: written by
66
+ * the control plane (decision 156), or generated by CloudNativePG for a
67
+ * Database from before.
68
+ */
47
69
  export declare const databaseAppSecret: (database: Pick<Database, "id">) => string;
70
+ /**
71
+ * The Secret with the SCRAM verifier of the `app` user's password, which
72
+ * the Cluster of a Database with `appCredentials` names as its application
73
+ * Secret (decision 156); the control plane writes both.
74
+ */
75
+ export declare const databaseAppVerifierSecret: (database: Pick<Database, "id">) => string;
48
76
  /** Where the Project's Services and Jobs reach the Database: its Pooler, inside the cluster. */
49
77
  export declare const databaseConnection: (database: Pick<Database, "id" | "projectId">) => DatabaseConnection;
50
78
  /**
51
- * The Kubernetes Secret in a Project's namespace that holds all its Secrets'
52
- * values; the control plane writes it, Services and Jobs read it with `envFrom`.
79
+ * Where they reach its standby, for queries that must not load the primary
80
+ * and may read slightly old data (decision 157): the Database's `ro` Pooler.
81
+ * Nothing answers there while no standby is ready.
82
+ */
83
+ export declare const databaseReadConnection: (database: Pick<Database, "id" | "projectId">) => DatabaseConnection;
84
+ /** The Kubernetes Secret with the values of the Secrets a Service's or a Job's definition names (decision 170); it exists only while the definition names one. */
85
+ export declare const serviceEnvSecret: (service: Pick<Service, "id">) => string;
86
+ export declare const jobEnvSecret: (job: Pick<Job, "id">) => string;
87
+ /** `DATABASE_URL_<NAME>`'s suffix: the Database's name upper-cased, `-` as `_`. */
88
+ export declare const databaseEnvSuffix: (database: {
89
+ readonly name: string;
90
+ }) => string;
91
+ /**
92
+ * The names of the URLs the platform sets in every container of a Project
93
+ * with these live Databases (decision 97). A Secret or Variable of one of
94
+ * these names is overridden by the platform's value.
53
95
  */
54
- export declare const PROJECT_SECRETS = "project-secrets";
96
+ export declare const databaseEnvNames: (databases: readonly {
97
+ readonly name: string;
98
+ }[]) => string[];
55
99
  /**
56
100
  * The `kubernetes.io/dockerconfigjson` Secret in a Project's namespace with
57
101
  * the registry credentials of all its Services and Jobs, each under its
@@ -92,6 +136,18 @@ export declare const INTERNAL_ROUTES_PATH = "/internal/v1/routes";
92
136
  export declare const INTERNAL_SERVICES_PATH = "/internal/v1/services";
93
137
  /** `GET` lists every Job with its Project, for the Jobs operator. */
94
138
  export declare const INTERNAL_JOBS_PATH = "/internal/v1/jobs";
139
+ /**
140
+ * For the madAuth sidecar, which passes on madAuth's events (decision 143):
141
+ * `DELETE <path>/<user id>` removes a user madAuth deleted from every
142
+ * Account; `DELETE <path>/<user id>/api-keys/<key id>` drops the Postgres
143
+ * roles of a key madAuth revoked. Both answer 204, also when there was
144
+ * nothing to do, so a retry is harmless.
145
+ */
146
+ export declare const INTERNAL_USERS_PATH = "/internal/v1/users";
147
+ /** A madAuth user or API key id in a path: `usr_` and base64url, kept to URL-safe characters. */
148
+ export declare const MADAUTH_ID: RegExp;
149
+ export declare const internalUserPath: (subject: string) => string;
150
+ export declare const internalApiKeyPath: (subject: string, apiKeyId: string) => string;
95
151
  /** An Account's usage of one month: `${INTERNAL_ACCOUNTS_PATH}/{id}/usage?month=YYYY-MM`, for the billing service. */
96
152
  export declare const internalUsagePath: (accountId: Id, month: string) => string;
97
153
  /**
@@ -153,7 +209,7 @@ export interface DomainRouting {
153
209
  readonly routes: readonly RoutedPath[];
154
210
  }
155
211
  export interface AccountRecord extends Account {
156
- readonly members: readonly Pick<Member, 'authSubject' | 'email'>[];
212
+ readonly members: readonly Pick<Member, 'authSubject' | 'email' | 'role'>[];
157
213
  }
158
214
  /** One Service as the Services operator needs it. */
159
215
  export interface ServiceRow {
@@ -161,7 +217,7 @@ export interface ServiceRow {
161
217
  readonly service: Pick<Service, 'id' | 'name' | 'image' | 'imageDigest' | 'replicas' | 'memoryMb' | 'cpuMillicores' | 'port'>;
162
218
  /** What the Deployment runs: `<registry>/<repository>@<digest>`. */
163
219
  readonly pinnedImage: string;
164
- /** Where a single replica runs: the Service's homeSite, else the Project's oldest Database's, else `hetzner-fsn1`. */
220
+ /** Where a single replica runs: the Service's homeSite, else the Project's oldest Database's, else the default Site. */
165
221
  readonly site: Site;
166
222
  /**
167
223
  * The version of the Project's Secrets in its Kubernetes Secret: it
@@ -169,12 +225,102 @@ export interface ServiceRow {
169
225
  * before. The operator puts it on the pod template, so a change rolls the
170
226
  * Service and its pods read the new values.
171
227
  */
172
- readonly secretsVersion: string;
173
228
  /** The Project's live Databases, oldest first: the Service gets a DATABASE_URL for each (decision 97). */
174
229
  readonly databases: readonly RowDatabase[];
230
+ /**
231
+ * What its definition names for its containers (decision 170): the
232
+ * Secrets' names (their values are in `serviceEnvSecret`, which the
233
+ * control plane writes, when there is at least one), the plain
234
+ * Variables, and the version of the named Secrets' values last written
235
+ * there, which rolls the Service when it changes.
236
+ */
237
+ readonly secrets: readonly string[];
238
+ readonly variables: Readonly<Record<string, string>>;
239
+ readonly envVersion: string;
240
+ /**
241
+ * Its rollout waits for its pre-deploy Job (decision 173): the Services
242
+ * operator leaves the Service's objects as they are, and creates none
243
+ * for a new one. Not part of the spec version.
244
+ */
245
+ readonly held?: boolean;
246
+ /**
247
+ * Whether the Service has a grant on a Key (decision 168): its pods then
248
+ * run as a ServiceAccount of their own with a token for the key API.
249
+ * Absent from a control plane older than Keys.
250
+ */
251
+ readonly keyAccess?: boolean;
252
+ }
253
+ /** The audience of the token a pod presents to the key API (decision 168); the Kubernetes API accepts no such token. */
254
+ export declare const KEYS_AUDIENCE = "openupstream-keys";
255
+ /** The key API's port on the control plane's pods and its Kubernetes Service. */
256
+ export declare const KEYS_PORT = 8084;
257
+ /** Where a pod with a Key grant finds its token: the kubelet renews the file, so it is read on every call. */
258
+ export declare const KEYS_TOKEN_DIRECTORY = "/var/run/secrets/openupstream";
259
+ export declare const KEYS_TOKEN_FILE = "token";
260
+ /** How long such a token lasts; the kubelet replaces it well before. */
261
+ export declare const KEYS_TOKEN_SECONDS = 3600;
262
+ /** The environment variables a pod with a Key grant gets: the key API's URL and its token's path. */
263
+ export declare const KEYS_URL_ENV = "OUP_KEYS_URL";
264
+ export declare const KEYS_TOKEN_FILE_ENV = "OUP_KEYS_TOKEN_FILE";
265
+ /** The name of the control plane's pods' label and of their Kubernetes Service (control-plane/deploy). */
266
+ export declare const CONTROL_PLANE_NAME = "control-plane";
267
+ /** The key API as a pod of any Project reaches it. */
268
+ export declare const keysUrl: () => string;
269
+ /**
270
+ * A Database a Service's or Job's row names (decision 173). With `role`,
271
+ * the definition's own Postgres role there: its containers log in as it,
272
+ * with the password in `databaseRoleSecret(role)`. Without, as the
273
+ * Database's owner. `access` is absent from a control plane before
274
+ * decision 173, whose rows name every Database of the Project as owner.
275
+ */
276
+ export type RowDatabase = Pick<Database, 'id' | 'name'> & {
277
+ readonly access?: DefinitionDatabaseAccess;
278
+ readonly role?: {
279
+ readonly id: Id;
280
+ readonly name: string;
281
+ };
282
+ };
283
+ /** The name of a Service's or Job's own role in a Database: `svc_<name>` or `job_<name>`, the name's `-` as `_`. */
284
+ export declare const definitionRoleName: (definition: {
285
+ readonly kind: "service" | "job";
286
+ readonly name: string;
287
+ }) => string;
288
+ /** The group role a Service's or Job's own role is a member of, which lets it connect (made at a Database's creation). */
289
+ export declare const CONNECT_GROUP_ROLE = "oup_connect";
290
+ /**
291
+ * A Service's or Job's role in a Database, as the Databases operator adds
292
+ * it to the Cluster; without `login` it stays and cannot sign in. `dropped`
293
+ * once its Service or Job is deleted and its grants are taken away: the
294
+ * Cluster then drops it (`ensure: absent`).
295
+ */
296
+ export interface DefinitionRoleRow {
297
+ readonly id: Id;
298
+ readonly name: string;
299
+ readonly login: boolean;
300
+ readonly dropped?: true;
175
301
  }
176
- /** A Database as a Service's or Job's row names it. */
177
- export type RowDatabase = Pick<Database, 'id' | 'name'>;
302
+ /** The role the control plane connects as to delete a deleted Service's or Job's role: it may call the cleanup function and nothing else. */
303
+ export declare const ADMIN_ROLE = "oup_admin";
304
+ /** The role the cleanup function runs as: a member of the owner and of every Service's and Job's role, without a login. */
305
+ export declare const CLEANER_ROLE = "oup_cleaner";
306
+ /** The schema of the platform's in a Database, and its function that takes away a Service's or Job's role's grants. */
307
+ export declare const PLATFORM_SCHEMA = "oup";
308
+ export declare const CLEANUP_FUNCTION = "drop_owned";
309
+ /** The `kubernetes.io/basic-auth` Secret CloudNativePG reads `oup_admin`'s password from, written by the control plane. */
310
+ export declare const databaseAdminSecret: (database: Pick<Database, "id">) => string;
311
+ /** Where the control plane reaches a Database's primary, past the Pooler: one statement, and no pool of its own for it. */
312
+ export declare const databasePrimaryHost: (database: Pick<Database, "id" | "projectId">) => string;
313
+ /** Every node carries its Site's id in this label (ADR-0007). */
314
+ export declare const ZONE_LABEL = "topology.kubernetes.io/zone";
315
+ /** `true` on the nodes of a compute Site, where Databases, Services and Jobs run. */
316
+ export declare const COMPUTE_SITE_LABEL = "openupstream.io/compute-site";
317
+ /** `true` on the nodes of the one compute Site that is the default Home site. */
318
+ export declare const DEFAULT_SITE_LABEL = "openupstream.io/default-site";
319
+ /**
320
+ * The taint (`true`, `NoSchedule`) on every node outside the compute Sites:
321
+ * only etcd, Garage, Loki and the node agents tolerate it.
322
+ */
323
+ export declare const QUORUM_ONLY_TAINT = "openupstream.io/quorum-only";
178
324
  /** On a Service's Deployment and a Job's CronJob: the spec version it was applied from (serviceSpecVersion, jobSpecVersion). */
179
325
  export declare const SPEC_VERSION_ANNOTATION = "openupstream.io/spec-version";
180
326
  /**
@@ -183,17 +329,22 @@ export declare const SPEC_VERSION_ANNOTATION = "openupstream.io/spec-version";
183
329
  * `deploying` until the Deployment carries the version its row asks for,
184
330
  * so a change is not `running` before it has been applied and rolled out.
185
331
  */
186
- export declare const serviceSpecVersion: (row: Pick<ServiceRow, "service" | "pinnedImage" | "site" | "secretsVersion" | "databases">) => string;
332
+ export declare const serviceSpecVersion: (row: Pick<ServiceRow, "service" | "pinnedImage" | "site" | "databases" | "keyAccess" | "secrets" | "variables" | "envVersion">) => string;
187
333
  /** One Job as the Jobs operator needs it. */
188
334
  export interface JobRow {
189
335
  readonly project: Project;
190
336
  readonly job: Pick<Job, 'id' | 'name' | 'image' | 'imageDigest' | 'command' | 'args' | 'memoryMb' | 'cpuMillicores' | 'timeoutSeconds' | 'schedule' | 'timeZone'>;
191
337
  /** What its runs start: `<registry>/<repository>@<digest>`. */
192
338
  readonly pinnedImage: string;
193
- /** Where its runs go: the Job's homeSite, else the Project's oldest Database's, else `hetzner-fsn1`. */
339
+ /** Where its runs go: the Job's homeSite, else the Project's oldest Database's, else the default Site. */
194
340
  readonly site: Site;
195
341
  /** The Project's live Databases, oldest first: its runs get a DATABASE_URL for each (decision 97). */
196
342
  readonly databases: readonly RowDatabase[];
343
+ /** What its definition names for its runs (decision 170), as a ServiceRow's; a run reads the values when it starts, so there is no version. */
344
+ readonly secrets: readonly string[];
345
+ readonly variables: Readonly<Record<string, string>>;
346
+ /** Whether the Job has a grant on a Key (decision 168), as a ServiceRow's. */
347
+ readonly keyAccess?: boolean;
197
348
  }
198
349
  /**
199
350
  * Everything of a Job's row that its CronJob is rendered from. The Jobs
@@ -202,7 +353,7 @@ export interface JobRow {
202
353
  * template. The Secrets are not part of it: a run's pod reads them when it
203
354
  * starts, so nothing needs to change when they do.
204
355
  */
205
- export declare const jobSpecVersion: (row: Pick<JobRow, "job" | "pinnedImage" | "site" | "databases">) => string;
356
+ export declare const jobSpecVersion: (row: Pick<JobRow, "job" | "pinnedImage" | "site" | "databases" | "keyAccess" | "secrets" | "variables">) => string;
206
357
  export interface DatabaseRow {
207
358
  readonly project: Project;
208
359
  readonly database: Database;
@@ -213,8 +364,25 @@ export interface DatabaseRow {
213
364
  * so it no longer depends on the source's ObjectStore.
214
365
  */
215
366
  readonly restoring?: boolean;
216
- /** The callers' own roles in this Database (decision 126), oldest first. */
217
- readonly roles?: readonly DatabaseRoleRow[];
367
+ /**
368
+ * The roles in this Database, oldest first: the callers' own (decision
369
+ * 126), then those of the Services and Jobs that name it (decision 173).
370
+ */
371
+ readonly roles?: readonly (DatabaseRoleRow | DefinitionRoleRow)[];
372
+ /**
373
+ * The control plane holds the `app` user's password and writes its
374
+ * Secrets (decision 156): the Cluster then reads the verifier from
375
+ * `databaseAppVerifierSecret`. Absent for a Database from before.
376
+ */
377
+ readonly appCredentials?: boolean;
378
+ /**
379
+ * The Database has what deleting a deleted Service's or Job's role
380
+ * takes (decision 173), made at its creation, and the control plane
381
+ * holds the password of the role it connects as: the operator then
382
+ * keeps the platform's two roles in the Cluster. Absent for a Database
383
+ * from before.
384
+ */
385
+ readonly cleanup?: boolean;
218
386
  /**
219
387
  * The Project's tunnel host (tunnelHostname), on every row of a Project
220
388
  * that has a role in any Database: the operator then runs the tunnel's
@@ -226,8 +394,9 @@ export interface DatabaseRow {
226
394
  * The platform's own Account, Project and Databases: the control plane's
227
395
  * state (`database`) and madAuth's users (`authDatabase`). The bootstrap
228
396
  * creates these Databases once; the control plane seeds these rows at
229
- * startup, and from then on the operator reconciles them like any
230
- * customer's. Fixed ids, so bootstrap and control plane agree.
397
+ * startup, in the default Site (ADR-0007), and from then on the operator
398
+ * reconciles them like any customer's. Fixed ids, so bootstrap and control
399
+ * plane agree.
231
400
  */
232
401
  export declare const PLATFORM: {
233
402
  readonly account: {
@@ -245,7 +414,6 @@ export declare const PLATFORM: {
245
414
  readonly id: "00000000-0000-4000-8000-000000000003";
246
415
  readonly projectId: "00000000-0000-4000-8000-000000000002";
247
416
  readonly name: "control-plane";
248
- readonly homeSite: "hetzner-fsn1";
249
417
  readonly memoryMb: 512;
250
418
  readonly storageGb: 5;
251
419
  readonly autoGrow: true;
@@ -256,7 +424,6 @@ export declare const PLATFORM: {
256
424
  readonly id: "00000000-0000-4000-8000-000000000004";
257
425
  readonly projectId: "00000000-0000-4000-8000-000000000002";
258
426
  readonly name: "auth";
259
- readonly homeSite: "hetzner-fsn1";
260
427
  readonly memoryMb: 512;
261
428
  readonly storageGb: 2;
262
429
  readonly autoGrow: true;
@@ -268,7 +435,6 @@ export declare const PLATFORM: {
268
435
  readonly id: "00000000-0000-4000-8000-000000000005";
269
436
  readonly projectId: "00000000-0000-4000-8000-000000000002";
270
437
  readonly name: "billing";
271
- readonly homeSite: "hetzner-fsn1";
272
438
  readonly memoryMb: 512;
273
439
  readonly storageGb: 2;
274
440
  readonly autoGrow: true;
@@ -276,5 +442,5 @@ export declare const PLATFORM: {
276
442
  readonly createdAt: "2026-10-20T00:00:00Z";
277
443
  };
278
444
  };
279
- /** The platform's Database rows, as the operator gets them. */
280
- export declare const PLATFORM_ROWS: readonly DatabaseRow[];
445
+ /** The platform's Database rows, as the bootstrap gives them to the operator: in `homeSite`, the default Site. */
446
+ export declare const platformRows: (homeSite: Site) => DatabaseRow[];
package/dist/internal.js CHANGED
@@ -7,6 +7,18 @@ export const projectNamespace = (projectId) => `project-${projectId}`;
7
7
  export const clusterName = (database) => `db-${database.id}`;
8
8
  /** Cannot share the Cluster's name, nor `<cluster>-rw`, which the Cluster's own Service takes. */
9
9
  export const poolerName = (database) => `${clusterName(database)}-pooler`;
10
+ /**
11
+ * The Database's second Pooler, of type `ro`: to its standby, never to its
12
+ * primary (decision 157). The restart guard pauses only `poolerName`'s.
13
+ */
14
+ export const readPoolerName = (database) => `${poolerName(database)}-ro`;
15
+ /**
16
+ * The CPU each instance of a Database is guaranteed (decision 151): one core
17
+ * per 4 GiB of its memory, the ratio of the compute servers (16 threads,
18
+ * 64 GB), as a Kubernetes request with no limit, so it uses idle cores too.
19
+ */
20
+ export const DATABASE_MILLICORES_PER_GIB = 250;
21
+ export const databaseCpuMillicores = (memoryMb) => Math.ceil((memoryMb * DATABASE_MILLICORES_PER_GIB) / 1024);
10
22
  /** The Cluster's own Service to its primary, which CloudNativePG names. */
11
23
  export const primaryServiceName = (database) => `${clusterName(database)}-rw`;
12
24
  /**
@@ -16,6 +28,10 @@ export const primaryServiceName = (database) => `${clusterName(database)}-rw`;
16
28
  * hyphen and 8 characters, a Project id in 12.
17
29
  */
18
30
  export const tunnelHostname = (projectId, customerDomain) => `pg-${projectId}.${customerDomain}`;
31
+ /** The forwarder's Deployment in a Project's namespace (decision 126). */
32
+ export const DATABASE_TUNNEL = 'database-tunnel';
33
+ /** Its pods, by label; the control plane deletes them to end every tunnel of the Project (decision 143). */
34
+ export const DATABASE_TUNNEL_PODS = `openupstream.io/component=${DATABASE_TUNNEL}`;
19
35
  export const tunnelTargetOf = (access) => (access === 'owner' ? 'primary' : 'pooler');
20
36
  /** The tunnel's path on its host, which names the Database and the target. */
21
37
  export const tunnelPath = (databaseId, target) => `/databases/${databaseId}/${target}`;
@@ -24,8 +40,18 @@ export const TUNNEL_PATH = /^\/databases\/([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[
24
40
  export const databaseRoleName = (role) => `oup_${role.access}_${role.id.replaceAll('-', '')}`;
25
41
  /** The `kubernetes.io/basic-auth` Secret in the Project's namespace that CloudNativePG reads a role's password from. */
26
42
  export const databaseRoleSecret = (role) => `pg-role-${role.id}`;
27
- /** The Secret CloudNativePG keeps the Database's `app` user in, with its generated `password`. */
43
+ /**
44
+ * The Secret with the Database's `app` user and its `password`: written by
45
+ * the control plane (decision 156), or generated by CloudNativePG for a
46
+ * Database from before.
47
+ */
28
48
  export const databaseAppSecret = (database) => `${clusterName(database)}-app`;
49
+ /**
50
+ * The Secret with the SCRAM verifier of the `app` user's password, which
51
+ * the Cluster of a Database with `appCredentials` names as its application
52
+ * Secret (decision 156); the control plane writes both.
53
+ */
54
+ export const databaseAppVerifierSecret = (database) => `${clusterName(database)}-app-scram`;
29
55
  /** Where the Project's Services and Jobs reach the Database: its Pooler, inside the cluster. */
30
56
  export const databaseConnection = (database) => ({
31
57
  host: `${poolerName(database)}.${projectNamespace(database.projectId)}.svc.cluster.local`,
@@ -34,10 +60,31 @@ export const databaseConnection = (database) => ({
34
60
  user: 'app',
35
61
  });
36
62
  /**
37
- * The Kubernetes Secret in a Project's namespace that holds all its Secrets'
38
- * values; the control plane writes it, Services and Jobs read it with `envFrom`.
63
+ * Where they reach its standby, for queries that must not load the primary
64
+ * and may read slightly old data (decision 157): the Database's `ro` Pooler.
65
+ * Nothing answers there while no standby is ready.
39
66
  */
40
- export const PROJECT_SECRETS = 'project-secrets';
67
+ export const databaseReadConnection = (database) => ({
68
+ ...databaseConnection(database),
69
+ host: `${readPoolerName(database)}.${projectNamespace(database.projectId)}.svc.cluster.local`,
70
+ });
71
+ /** The Kubernetes Secret with the values of the Secrets a Service's or a Job's definition names (decision 170); it exists only while the definition names one. */
72
+ export const serviceEnvSecret = (service) => `svc-${service.id}-env`;
73
+ export const jobEnvSecret = (job) => `job-${job.id}-env`;
74
+ /** `DATABASE_URL_<NAME>`'s suffix: the Database's name upper-cased, `-` as `_`. */
75
+ export const databaseEnvSuffix = (database) => database.name.toUpperCase().replaceAll('-', '_');
76
+ /**
77
+ * The names of the URLs the platform sets in every container of a Project
78
+ * with these live Databases (decision 97). A Secret or Variable of one of
79
+ * these names is overridden by the platform's value.
80
+ */
81
+ export const databaseEnvNames = (databases) => databases.length === 0
82
+ ? []
83
+ : ['DATABASE_URL', 'DATABASE_READ_URL', ...databases.flatMap((database) => [`DATABASE_URL_${databaseEnvSuffix(database)}`, `DATABASE_READ_URL_${databaseEnvSuffix(database)}`])];
84
+ /** A named Database in a spec version: who the containers log in as is part of it. */
85
+ const rowDatabaseVersion = (database) => `${database.id}=${database.name}${database.role === undefined ? '' : `:${database.role.name}`}`;
86
+ /** A map's entries by name, so two maps with the same entries give the same version. */
87
+ const sortedEntries = (map) => Object.entries(map).sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0));
41
88
  /**
42
89
  * The `kubernetes.io/dockerconfigjson` Secret in a Project's namespace with
43
90
  * the registry credentials of all its Services and Jobs, each under its
@@ -78,6 +125,18 @@ export const INTERNAL_ROUTES_PATH = '/internal/v1/routes';
78
125
  export const INTERNAL_SERVICES_PATH = '/internal/v1/services';
79
126
  /** `GET` lists every Job with its Project, for the Jobs operator. */
80
127
  export const INTERNAL_JOBS_PATH = '/internal/v1/jobs';
128
+ /**
129
+ * For the madAuth sidecar, which passes on madAuth's events (decision 143):
130
+ * `DELETE <path>/<user id>` removes a user madAuth deleted from every
131
+ * Account; `DELETE <path>/<user id>/api-keys/<key id>` drops the Postgres
132
+ * roles of a key madAuth revoked. Both answer 204, also when there was
133
+ * nothing to do, so a retry is harmless.
134
+ */
135
+ export const INTERNAL_USERS_PATH = '/internal/v1/users';
136
+ /** A madAuth user or API key id in a path: `usr_` and base64url, kept to URL-safe characters. */
137
+ export const MADAUTH_ID = /^[A-Za-z0-9_-]{1,128}$/;
138
+ export const internalUserPath = (subject) => `${INTERNAL_USERS_PATH}/${subject}`;
139
+ export const internalApiKeyPath = (subject, apiKeyId) => `${INTERNAL_USERS_PATH}/${subject}/api-keys/${apiKeyId}`;
81
140
  /** An Account's usage of one month: `${INTERNAL_ACCOUNTS_PATH}/{id}/usage?month=YYYY-MM`, for the billing service. */
82
141
  export const internalUsagePath = (accountId, month) => `${INTERNAL_ACCOUNTS_PATH}/${accountId}/usage?month=${month}`;
83
142
  /**
@@ -87,6 +146,48 @@ export const internalUsagePath = (accountId, month) => `${INTERNAL_ACCOUNTS_PATH
87
146
  * metering reads the Resource from them.
88
147
  */
89
148
  export const ingressRouteName = (domainId, resource) => `domain-${domainId}-${resource.kind === 'bucket' ? 'bucket' : 'svc'}-${resource.id}`;
149
+ /** The audience of the token a pod presents to the key API (decision 168); the Kubernetes API accepts no such token. */
150
+ export const KEYS_AUDIENCE = 'openupstream-keys';
151
+ /** The key API's port on the control plane's pods and its Kubernetes Service. */
152
+ export const KEYS_PORT = 8084;
153
+ /** Where a pod with a Key grant finds its token: the kubelet renews the file, so it is read on every call. */
154
+ export const KEYS_TOKEN_DIRECTORY = '/var/run/secrets/openupstream';
155
+ export const KEYS_TOKEN_FILE = 'token';
156
+ /** How long such a token lasts; the kubelet replaces it well before. */
157
+ export const KEYS_TOKEN_SECONDS = 3600;
158
+ /** The environment variables a pod with a Key grant gets: the key API's URL and its token's path. */
159
+ export const KEYS_URL_ENV = 'OUP_KEYS_URL';
160
+ export const KEYS_TOKEN_FILE_ENV = 'OUP_KEYS_TOKEN_FILE';
161
+ /** The name of the control plane's pods' label and of their Kubernetes Service (control-plane/deploy). */
162
+ export const CONTROL_PLANE_NAME = 'control-plane';
163
+ /** The key API as a pod of any Project reaches it. */
164
+ export const keysUrl = () => `http://${CONTROL_PLANE_NAME}.${projectNamespace(PLATFORM.project.id)}.svc.cluster.local:${KEYS_PORT}`;
165
+ /** The name of a Service's or Job's own role in a Database: `svc_<name>` or `job_<name>`, the name's `-` as `_`. */
166
+ export const definitionRoleName = (definition) => `${definition.kind === 'service' ? 'svc' : 'job'}_${definition.name.replaceAll('-', '_')}`;
167
+ /** The group role a Service's or Job's own role is a member of, which lets it connect (made at a Database's creation). */
168
+ export const CONNECT_GROUP_ROLE = 'oup_connect';
169
+ /** The role the control plane connects as to delete a deleted Service's or Job's role: it may call the cleanup function and nothing else. */
170
+ export const ADMIN_ROLE = 'oup_admin';
171
+ /** The role the cleanup function runs as: a member of the owner and of every Service's and Job's role, without a login. */
172
+ export const CLEANER_ROLE = 'oup_cleaner';
173
+ /** The schema of the platform's in a Database, and its function that takes away a Service's or Job's role's grants. */
174
+ export const PLATFORM_SCHEMA = 'oup';
175
+ export const CLEANUP_FUNCTION = 'drop_owned';
176
+ /** The `kubernetes.io/basic-auth` Secret CloudNativePG reads `oup_admin`'s password from, written by the control plane. */
177
+ export const databaseAdminSecret = (database) => `${clusterName(database)}-admin`;
178
+ /** Where the control plane reaches a Database's primary, past the Pooler: one statement, and no pool of its own for it. */
179
+ export const databasePrimaryHost = (database) => `${clusterName(database)}-rw.${projectNamespace(database.projectId)}.svc.cluster.local`;
180
+ /** Every node carries its Site's id in this label (ADR-0007). */
181
+ export const ZONE_LABEL = 'topology.kubernetes.io/zone';
182
+ /** `true` on the nodes of a compute Site, where Databases, Services and Jobs run. */
183
+ export const COMPUTE_SITE_LABEL = 'openupstream.io/compute-site';
184
+ /** `true` on the nodes of the one compute Site that is the default Home site. */
185
+ export const DEFAULT_SITE_LABEL = 'openupstream.io/default-site';
186
+ /**
187
+ * The taint (`true`, `NoSchedule`) on every node outside the compute Sites:
188
+ * only etcd, Garage, Loki and the node agents tolerate it.
189
+ */
190
+ export const QUORUM_ONLY_TAINT = 'openupstream.io/quorum-only';
90
191
  /** On a Service's Deployment and a Job's CronJob: the spec version it was applied from (serviceSpecVersion, jobSpecVersion). */
91
192
  export const SPEC_VERSION_ANNOTATION = 'openupstream.io/spec-version';
92
193
  /**
@@ -102,8 +203,12 @@ export const serviceSpecVersion = (row) => [
102
203
  row.service.cpuMillicores,
103
204
  row.service.port,
104
205
  row.site,
105
- row.secretsVersion,
106
- ...row.databases.map((database) => `${database.id}=${database.name}`),
206
+ // What it names for its containers, and the version of its named Secrets that is in the cluster.
207
+ `env:${row.envVersion}`,
208
+ JSON.stringify([row.secrets, sortedEntries(row.variables)]),
209
+ ...row.databases.map(rowDatabaseVersion),
210
+ // Only when set, so a Service without a grant keeps the version an operator from before Keys computes.
211
+ ...(row.keyAccess === true ? ['keys'] : []),
107
212
  ].join('|');
108
213
  /**
109
214
  * Everything of a Job's row that its CronJob is rendered from. The Jobs
@@ -123,13 +228,17 @@ export const jobSpecVersion = (row) => JSON.stringify([
123
228
  row.job.timeZone,
124
229
  row.site,
125
230
  row.databases,
231
+ // Only when set, as in serviceSpecVersion.
232
+ ...(row.keyAccess === true ? ['keys'] : []),
233
+ { secrets: row.secrets, variables: sortedEntries(row.variables) },
126
234
  ]);
127
235
  /**
128
236
  * The platform's own Account, Project and Databases: the control plane's
129
237
  * state (`database`) and madAuth's users (`authDatabase`). The bootstrap
130
238
  * creates these Databases once; the control plane seeds these rows at
131
- * startup, and from then on the operator reconciles them like any
132
- * customer's. Fixed ids, so bootstrap and control plane agree.
239
+ * startup, in the default Site (ADR-0007), and from then on the operator
240
+ * reconciles them like any customer's. Fixed ids, so bootstrap and control
241
+ * plane agree.
133
242
  */
134
243
  export const PLATFORM = {
135
244
  account: {
@@ -147,7 +256,6 @@ export const PLATFORM = {
147
256
  id: '00000000-0000-4000-8000-000000000003',
148
257
  projectId: '00000000-0000-4000-8000-000000000002',
149
258
  name: 'control-plane',
150
- homeSite: 'hetzner-fsn1',
151
259
  memoryMb: 512,
152
260
  storageGb: 5,
153
261
  autoGrow: true,
@@ -158,7 +266,6 @@ export const PLATFORM = {
158
266
  id: '00000000-0000-4000-8000-000000000004',
159
267
  projectId: '00000000-0000-4000-8000-000000000002',
160
268
  name: 'auth',
161
- homeSite: 'hetzner-fsn1',
162
269
  memoryMb: 512,
163
270
  storageGb: 2,
164
271
  autoGrow: true,
@@ -170,7 +277,6 @@ export const PLATFORM = {
170
277
  id: '00000000-0000-4000-8000-000000000005',
171
278
  projectId: '00000000-0000-4000-8000-000000000002',
172
279
  name: 'billing',
173
- homeSite: 'hetzner-fsn1',
174
280
  memoryMb: 512,
175
281
  storageGb: 2,
176
282
  autoGrow: true,
@@ -178,9 +284,9 @@ export const PLATFORM = {
178
284
  createdAt: '2026-10-20T00:00:00Z',
179
285
  },
180
286
  };
181
- /** The platform's Database rows, as the operator gets them. */
182
- export const PLATFORM_ROWS = [
183
- { project: PLATFORM.project, database: PLATFORM.database },
184
- { project: PLATFORM.project, database: PLATFORM.authDatabase },
287
+ /** The platform's Database rows, as the bootstrap gives them to the operator: in `homeSite`, the default Site. */
288
+ export const platformRows = (homeSite) => [
289
+ { project: PLATFORM.project, database: { ...PLATFORM.database, homeSite } },
290
+ { project: PLATFORM.project, database: { ...PLATFORM.authDatabase, homeSite } },
185
291
  ];
186
292
  //# sourceMappingURL=internal.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"internal.js","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":"AAQA;;;GAGG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,SAAa,EAAU,EAAE,CAAC,WAAW,SAAS,EAAE,CAAC;AAElF,qGAAqG;AACrG,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,QAA8B,EAAU,EAAE,CAAC,MAAM,QAAQ,CAAC,EAAE,EAAE,CAAC;AAE3F,kGAAkG;AAClG,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,QAA8B,EAAU,EAAE,CAAC,GAAG,WAAW,CAAC,QAAQ,CAAC,SAAS,CAAC;AAExG,2EAA2E;AAC3E,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,QAA8B,EAAU,EAAE,CAAC,GAAG,WAAW,CAAC,QAAQ,CAAC,KAAK,CAAC;AAE5G;;;;;GAKG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,SAAa,EAAE,cAAsB,EAAU,EAAE,CAAC,MAAM,SAAS,IAAI,cAAc,EAAE,CAAC;AAIrH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,MAAsB,EAAwB,EAAE,CAAC,CAAC,MAAM,KAAK,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;AAE5H,8EAA8E;AAC9E,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,UAAc,EAAE,MAA4B,EAAU,EAAE,CAAC,cAAc,UAAU,IAAI,MAAM,EAAE,CAAC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sCAAsC;QAC1C,SAAS,EAAE,sCAAsC;QACjD,IAAI,EAAE,SAAS;QACf,QAAQ,EAAE,GAAG;QACb,SAAS,EAAE,CAAC;QACZ,QAAQ,EAAE,IAAI;QACd,YAAY,EAAE,IAAI;QAClB,SAAS,EAAE,sBAAsB;KACpC;CAOJ,CAAC;AAEF,kHAAkH;AAClH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,QAAc,EAAiB,EAAE,CAAC;IAC3D,EAAE,OAAO,EAAE,QAAQ,CAAC,OAAO,EAAE,QAAQ,EAAE,EAAE,GAAG,QAAQ,CAAC,QAAQ,EAAE,QAAQ,EAAE,EAAE;IAC3E,EAAE,OAAO,EAAE,QAAQ,CAAC,OAAO,EAAE,QAAQ,EAAE,EAAE,GAAG,QAAQ,CAAC,YAAY,EAAE,QAAQ,EAAE,EAAE;CAClF,CAAC"}
package/dist/keys.d.ts ADDED
@@ -0,0 +1,54 @@
1
+ /** Strings given with a value when it is encrypted, which must be given again, equal, to decrypt it. Not secret, and recorded. */
2
+ export type KeyContext = Readonly<Record<string, string>>;
3
+ export type KeysError =
4
+ /** This container has no grant on any Key: the two environment variables are missing. */
5
+ {
6
+ readonly kind: 'no-identity';
7
+ readonly message: string;
8
+ }
9
+ /** The key API could not be reached, also after trying again. */
10
+ | {
11
+ readonly kind: 'unreachable';
12
+ readonly message: string;
13
+ }
14
+ /** The key API's answer: 403 without a grant for the operation, 404 for no such Key, 400 for what cannot be decrypted, 429 above the rate limit, … */
15
+ | {
16
+ readonly kind: 'status';
17
+ readonly status: number;
18
+ readonly message: string;
19
+ };
20
+ export type KeysResult<T> = {
21
+ readonly ok: true;
22
+ readonly value: T;
23
+ } | {
24
+ readonly ok: false;
25
+ readonly error: KeysError;
26
+ };
27
+ export interface KeysOptions {
28
+ /** The process's environment by default. */
29
+ readonly env?: Readonly<Record<string, string | undefined>>;
30
+ readonly fetch?: typeof fetch;
31
+ readonly readToken?: (path: string) => Promise<string>;
32
+ /**
33
+ * How often a call that could not connect is tried again, a second
34
+ * apart (5 by default). A container's connections in its first second
35
+ * are refused, until the platform's network knows its address.
36
+ */
37
+ readonly retries?: number;
38
+ readonly retryDelayMs?: number;
39
+ /** How long one attempt may take before it counts as not connected (10 s by default). */
40
+ readonly timeoutMs?: number;
41
+ }
42
+ /** The client for the key API of the container it runs in. */
43
+ export declare function keys(options?: KeysOptions): {
44
+ /**
45
+ * Encrypts at most KEY_CALL_LIMITS.maxPlaintextBytes bytes with the
46
+ * Key `key` of this Project. The result is a string to store
47
+ * anywhere; it names its Key and version.
48
+ */
49
+ encrypt(key: string, plaintext: Uint8Array | string, context?: KeyContext): Promise<KeysResult<string>>;
50
+ /** Decrypts what `encrypt` returned, given the same context. */
51
+ decrypt(key: string, ciphertext: string, context?: KeyContext): Promise<KeysResult<Uint8Array>>;
52
+ /** `decrypt` for a value that was text. */
53
+ decryptText(key: string, ciphertext: string, context?: KeyContext): Promise<KeysResult<string>>;
54
+ };