@wildo-ai/platform-infra-providers 1.1.2
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/LICENSE +34 -0
- package/dist/esm/aws-s3/aws-s3.infra.module.d.ts +63 -0
- package/dist/esm/aws-s3/aws-s3.infra.module.d.ts.map +1 -0
- package/dist/esm/aws-s3/aws-s3.infra.module.js +110 -0
- package/dist/esm/aws-s3/aws-s3.infra.module.js.map +1 -0
- package/dist/esm/clamav-self/clamav-self.infra.module.d.ts +30 -0
- package/dist/esm/clamav-self/clamav-self.infra.module.d.ts.map +1 -0
- package/dist/esm/clamav-self/clamav-self.infra.module.js +61 -0
- package/dist/esm/clamav-self/clamav-self.infra.module.js.map +1 -0
- package/dist/esm/gotenberg-self/gotenberg-self.infra.module.d.ts +26 -0
- package/dist/esm/gotenberg-self/gotenberg-self.infra.module.d.ts.map +1 -0
- package/dist/esm/gotenberg-self/gotenberg-self.infra.module.js +54 -0
- package/dist/esm/gotenberg-self/gotenberg-self.infra.module.js.map +1 -0
- package/dist/esm/index.d.ts +88 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +125 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/minio-self/minio-self.infra.module.d.ts +64 -0
- package/dist/esm/minio-self/minio-self.infra.module.d.ts.map +1 -0
- package/dist/esm/minio-self/minio-self.infra.module.js +105 -0
- package/dist/esm/minio-self/minio-self.infra.module.js.map +1 -0
- package/dist/esm/mongodb-atlas/mongodb-atlas.infra.module.d.ts +52 -0
- package/dist/esm/mongodb-atlas/mongodb-atlas.infra.module.d.ts.map +1 -0
- package/dist/esm/mongodb-atlas/mongodb-atlas.infra.module.js +201 -0
- package/dist/esm/mongodb-atlas/mongodb-atlas.infra.module.js.map +1 -0
- package/dist/esm/mongodb-self/mongodb-self.infra.module.d.ts +81 -0
- package/dist/esm/mongodb-self/mongodb-self.infra.module.d.ts.map +1 -0
- package/dist/esm/mongodb-self/mongodb-self.infra.module.js +311 -0
- package/dist/esm/mongodb-self/mongodb-self.infra.module.js.map +1 -0
- package/dist/esm/postgres-self/postgres-self.infra.module.d.ts +70 -0
- package/dist/esm/postgres-self/postgres-self.infra.module.d.ts.map +1 -0
- package/dist/esm/postgres-self/postgres-self.infra.module.js +328 -0
- package/dist/esm/postgres-self/postgres-self.infra.module.js.map +1 -0
- package/dist/esm/rabbitmq-self/rabbitmq-self.infra.module.d.ts +88 -0
- package/dist/esm/rabbitmq-self/rabbitmq-self.infra.module.d.ts.map +1 -0
- package/dist/esm/rabbitmq-self/rabbitmq-self.infra.module.js +473 -0
- package/dist/esm/rabbitmq-self/rabbitmq-self.infra.module.js.map +1 -0
- package/dist/esm/redis-self/redis-self.infra.module.d.ts +89 -0
- package/dist/esm/redis-self/redis-self.infra.module.d.ts.map +1 -0
- package/dist/esm/redis-self/redis-self.infra.module.js +331 -0
- package/dist/esm/redis-self/redis-self.infra.module.js.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -0
- package/package.json +52 -0
- package/src/aws-s3/__tests__/aws-s3.infra.module.test.ts +67 -0
- package/src/aws-s3/aws-s3.infra.module.ts +120 -0
- package/src/clamav-self/__tests__/clamav-self.infra.module.test.ts +65 -0
- package/src/clamav-self/clamav-self.infra.module.ts +72 -0
- package/src/gotenberg-self/__tests__/gotenberg-self.infra.module.test.ts +65 -0
- package/src/gotenberg-self/gotenberg-self.infra.module.ts +65 -0
- package/src/index.ts +133 -0
- package/src/minio-self/__tests__/minio-self.infra.module.test.ts +70 -0
- package/src/minio-self/minio-self.infra.module.ts +116 -0
- package/src/mongodb-atlas/__tests__/mongodb-atlas.infra.module.test.ts +198 -0
- package/src/mongodb-atlas/mongodb-atlas.infra.module.ts +236 -0
- package/src/mongodb-self/__tests__/mongodb-self.infra.module.test.ts +419 -0
- package/src/mongodb-self/mongodb-self.infra.module.ts +384 -0
- package/src/postgres-self/__tests__/postgres-self.infra.module.test.ts +344 -0
- package/src/postgres-self/postgres-self.infra.module.ts +377 -0
- package/src/rabbitmq-self/__tests__/rabbitmq-self.infra.module.test.ts +499 -0
- package/src/rabbitmq-self/rabbitmq-self.infra.module.ts +531 -0
- package/src/redis-self/__tests__/redis-self.infra.module.test.ts +341 -0
- package/src/redis-self/redis-self.infra.module.ts +372 -0
|
@@ -0,0 +1,377 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `PostgresSelfInfraProviderModule` — third concrete `InfraProviderModule`
|
|
3
|
+
* (Slice 4.B.2 of `infra-provider-planner.md`, generalizing the
|
|
4
|
+
* Slice 2 / 4.B.1 pattern).
|
|
5
|
+
*
|
|
6
|
+
* Implements the `POSTGRES_SELF` `InfraProvider` over the
|
|
7
|
+
* `IPostgresAdminClient` transport (raw `pg` Pool against the
|
|
8
|
+
* Postgres admin connection, exposed by
|
|
9
|
+
* `PostgreSQLConnectionManagerService` after the Slice 4.B.2 5C
|
|
10
|
+
* policy/transport split). Owns ALL per-app naming policy — the
|
|
11
|
+
* per-app database-name + role-name conventions (`wildo_<sanitized>_user`,
|
|
12
|
+
* `wildo_<sanitized>` mirroring the legacy
|
|
13
|
+
* `PlatformInfrastructureManagerService.provisionPostgreSQLDatabase`).
|
|
14
|
+
*
|
|
15
|
+
* **What this module reads from `AppCredentialMintingContext`**:
|
|
16
|
+
* - `appSlug` — used as the source for the sanitized database +
|
|
17
|
+
* user name. Mirrors the legacy convention at
|
|
18
|
+
* `platform-infrastructure-manager.service.ts:300-302`
|
|
19
|
+
* (`sanitizedName = sanitizeForPostgreSQL(applicationName)`,
|
|
20
|
+
* `databaseName = wildo_${sanitizedName}`,
|
|
21
|
+
* `username = wildo_${sanitizedName}_user`).
|
|
22
|
+
* - `secretInputs['database.postgresql.password']` — orchestrator-
|
|
23
|
+
* supplied password (module is upsert-only, never generator).
|
|
24
|
+
* - `applicationConfigInputs?.['databaseName']` — optional override
|
|
25
|
+
* for the derived database name. Mirrors the legacy
|
|
26
|
+
* `provisionPostgreSQLDatabase(appSlug, { databaseName? })` arg.
|
|
27
|
+
* - `adminClient` — narrowed to `IPostgresAdminClient`.
|
|
28
|
+
*
|
|
29
|
+
* **What this module IGNORES from the context** (Slice 4.A.2 / M4
|
|
30
|
+
* forward-compat documentation):
|
|
31
|
+
* - `applicationNamespace` — Postgres per-app DB names use the
|
|
32
|
+
* slug-derived sanitized form (env-suffix isolation comes from
|
|
33
|
+
* the surrounding env-scoped admin connection). Future modules
|
|
34
|
+
* may switch to namespace-scoped naming if cross-env collision
|
|
35
|
+
* risk surfaces.
|
|
36
|
+
* - `wildoApplicationId` — Postgres role names embed the
|
|
37
|
+
* sanitized slug, NOT the application id. This is the legacy
|
|
38
|
+
* convention; preserved for back-compat with apps already
|
|
39
|
+
* provisioned.
|
|
40
|
+
*
|
|
41
|
+
* **Two audiences this module serves:**
|
|
42
|
+
*
|
|
43
|
+
* 1. **Audience-1 (platform-admin, declared via `plan().platformAdmin`)**:
|
|
44
|
+
* cluster-wide Postgres admin creds. Consumers: `apps-manager`
|
|
45
|
+
* (mints per-app DB+role via `mintAppCredentials`), `companion`
|
|
46
|
+
* (mirrors apps-manager admin role for local dev).
|
|
47
|
+
*
|
|
48
|
+
* 2. **Audience-3 (app-scoped, via `plan().appRuntime` +
|
|
49
|
+
* `mintAppCredentials`)**: per-customer-app Postgres database +
|
|
50
|
+
* role. Result threaded into
|
|
51
|
+
* `Wildo_Application_Secrets.database.postgresql.{
|
|
52
|
+
* databaseName, username, connectUrl}` via
|
|
53
|
+
* `_merge_WildoApplicationSecrets`. Note: the password is
|
|
54
|
+
* embedded in `connectUrl` — there is no separate
|
|
55
|
+
* `database.postgresql.password` blob path today (matches the
|
|
56
|
+
* legacy persistence shape at
|
|
57
|
+
* `wildo-application-lifecycle.service.ts:2191-2200`).
|
|
58
|
+
*
|
|
59
|
+
* **NOT served (D-4 of Slice 4.B locked decisions, 2026-05-10)**:
|
|
60
|
+
* - **Audience-2 (platform-service-scoped)**: no platform service
|
|
61
|
+
* uses Postgres for inter-service messaging today. Method omitted.
|
|
62
|
+
*
|
|
63
|
+
* **`revokeAppCredentials`**: declared and tested, but the integration
|
|
64
|
+
* call site does NOT exist in `wildo-application-lifecycle.service.ts`
|
|
65
|
+
* (no app-deletion ceremony today — F6 of plan review 2026-05-06).
|
|
66
|
+
* Method ships as a forward-compat seam.
|
|
67
|
+
*/
|
|
68
|
+
|
|
69
|
+
import {
|
|
70
|
+
AppCredentialMintingContext,
|
|
71
|
+
AppCredentialMintingResult,
|
|
72
|
+
IPostgresAdminClient,
|
|
73
|
+
InfraCapability,
|
|
74
|
+
InfraPlatformAdminConsumer,
|
|
75
|
+
InfraProvider,
|
|
76
|
+
InfraProviderModule,
|
|
77
|
+
InfraProviderPlanContribution,
|
|
78
|
+
ApplicationRuntimePrincipal,
|
|
79
|
+
ApplicationRuntimePrincipalKind,
|
|
80
|
+
resolveGrantStorageNames,
|
|
81
|
+
} from '@wildo-ai/platform-config-lib';
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Default Postgres port (matches `INFRA_DEFAULT_PORTS.POSTGRES` in
|
|
85
|
+
* the shared platform constants — duplicated as a literal because
|
|
86
|
+
* the planner output is consumed by the CLI which materializes it
|
|
87
|
+
* into `Wildo_Application_Config` blob paths).
|
|
88
|
+
*/
|
|
89
|
+
const DEFAULT_POSTGRES_PORT = 5432;
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* The `Wildo_Application_Secrets` JSON paths this module writes
|
|
93
|
+
* through `mintAppCredentials`. Declared once and reused as
|
|
94
|
+
* `appRuntime.perAppSecretBlobPaths` in `plan()` AND as the keys of
|
|
95
|
+
* `secretBlobValues` in the result, so a refactor that renames a
|
|
96
|
+
* path fails loudly at one place.
|
|
97
|
+
*
|
|
98
|
+
* Note: the password is embedded in `connectUrl` (Postgres
|
|
99
|
+
* convention); there is no separate `database.postgresql.password`
|
|
100
|
+
* blob path today. The orchestrator persists `connectUrl`
|
|
101
|
+
* verbatim into `Wildo_Application_Secrets`.
|
|
102
|
+
*/
|
|
103
|
+
const POSTGRES_DATABASE_NAME_PATH = 'database.postgresql.databaseName';
|
|
104
|
+
const POSTGRES_USERNAME_PATH = 'database.postgresql.username';
|
|
105
|
+
const POSTGRES_CONNECT_URL_PATH = 'database.postgresql.connectUrl';
|
|
106
|
+
/**
|
|
107
|
+
* The paths this module mints PER RUNTIME PRINCIPAL — the single source for both consumers.
|
|
108
|
+
*
|
|
109
|
+
* Read by `InfraProviderModule.perPrincipalSecretBlobPaths` (statically, so apps-manager can strip
|
|
110
|
+
* these from the application blob before delivering a principal's own material) AND spread into
|
|
111
|
+
* `appRuntime.perAppSecretBlobPaths` inside `plan()`. Declaring the list twice is how the delivery
|
|
112
|
+
* path would silently stop covering a path this module still mints.
|
|
113
|
+
*/
|
|
114
|
+
const PER_PRINCIPAL_SECRET_BLOB_PATHS: ReadonlyArray<string> = [
|
|
115
|
+
POSTGRES_DATABASE_NAME_PATH,
|
|
116
|
+
POSTGRES_USERNAME_PATH,
|
|
117
|
+
POSTGRES_CONNECT_URL_PATH,
|
|
118
|
+
];
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Key the module looks for in `secretInputs` to read the
|
|
123
|
+
* orchestrator-supplied password.
|
|
124
|
+
*/
|
|
125
|
+
const POSTGRES_PASSWORD_INPUT_KEY = 'database.postgresql.password';
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Optional key the module looks for in `applicationConfigInputs`
|
|
129
|
+
* for an authored database-name override. When omitted, the module
|
|
130
|
+
* derives the database name from `appSlug` via `sanitizeForPostgreSQL`.
|
|
131
|
+
*/
|
|
132
|
+
const POSTGRES_DATABASE_NAME_INPUT_KEY = 'databaseName';
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Sanitize an application slug for Postgres identifier rules.
|
|
136
|
+
* Mirrors the legacy `sanitizeForPostgreSQL` at
|
|
137
|
+
* `platform-infrastructure-manager.service.ts:371-378`:
|
|
138
|
+
* - lowercase
|
|
139
|
+
* - `[^a-z0-9_]` → `_`
|
|
140
|
+
* - collapse multiple `_`
|
|
141
|
+
* - strip leading/trailing `_`
|
|
142
|
+
* - cap at 50 chars (Postgres identifier limit is 63; leaves room
|
|
143
|
+
* for the `wildo_` prefix and `_user` suffix).
|
|
144
|
+
*
|
|
145
|
+
* Centralized here so the module owns the convention; if the cap
|
|
146
|
+
* or escape rules change, one site changes.
|
|
147
|
+
*/
|
|
148
|
+
function sanitizeForPostgres(value: string): string {
|
|
149
|
+
return value
|
|
150
|
+
.toLowerCase()
|
|
151
|
+
.replace(/[^a-z0-9_]/g, '_')
|
|
152
|
+
.replace(/_+/g, '_')
|
|
153
|
+
.replace(/^_|_$/g, '')
|
|
154
|
+
.substring(0, 50);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Compute the per-app database name. Mirrors legacy convention at
|
|
159
|
+
* `platform-infrastructure-manager.service.ts:301`:
|
|
160
|
+
* `wildo_<sanitized>`
|
|
161
|
+
*/
|
|
162
|
+
function buildDatabaseName(appSlug: string): string {
|
|
163
|
+
return `wildo_${sanitizeForPostgres(appSlug)}`;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Compute the per-app database role. Mirrors legacy convention at
|
|
168
|
+
* `platform-infrastructure-manager.service.ts:302`:
|
|
169
|
+
* `wildo_<sanitized>_user`
|
|
170
|
+
*/
|
|
171
|
+
function buildUsername(appSlug: string): string {
|
|
172
|
+
return `wildo_${sanitizeForPostgres(appSlug)}_user`;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* The schema a per-app database's resource tables live in.
|
|
177
|
+
*
|
|
178
|
+
* `public` is what the schema planner targets today. Named as a constant rather
|
|
179
|
+
* than inlined at the four sites that need it because a grant issued into one
|
|
180
|
+
* schema and revoked from another is a revocation that silently succeeds while
|
|
181
|
+
* narrowing nothing.
|
|
182
|
+
*/
|
|
183
|
+
const POSTGRES_APPLICATION_SCHEMA = 'public';
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Per-principal Postgres role name — the SAME derivation the revoke path uses.
|
|
187
|
+
*
|
|
188
|
+
* Fourth time this shape appears (Redis, RabbitMQ, Mongo, now Postgres), and the
|
|
189
|
+
* consequence is worse here than anywhere else: a revoke that derived the name
|
|
190
|
+
* differently would miss the minion's role AND, on the pre-existing
|
|
191
|
+
* `dropApplicationDatabase` path, take the application's entire database with
|
|
192
|
+
* it. The application backend keeps `wildo_<slug>_user` VERBATIM so an existing
|
|
193
|
+
* deployment's owner role is never orphaned.
|
|
194
|
+
*/
|
|
195
|
+
function buildPostgresPrincipalUsername(
|
|
196
|
+
appSlug: string,
|
|
197
|
+
principal: ApplicationRuntimePrincipal | undefined,
|
|
198
|
+
): string {
|
|
199
|
+
if (!principal || principal.kind === ApplicationRuntimePrincipalKind.APPLICATION_BACKEND) {
|
|
200
|
+
return buildUsername(appSlug);
|
|
201
|
+
}
|
|
202
|
+
return `wildo_${sanitizeForPostgres(appSlug)}_${sanitizeForPostgres(principal.kind)}_`
|
|
203
|
+
+ `${sanitizeForPostgres(principal.name ?? '')}_user`;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
export const PostgresSelfInfraProviderModule: InfraProviderModule = {
|
|
207
|
+
provider: InfraProvider.POSTGRES_SELF,
|
|
208
|
+
supportedCapabilities: [InfraCapability.RELATIONAL_DATABASE],
|
|
209
|
+
perPrincipalSecretBlobPaths: PER_PRINCIPAL_SECRET_BLOB_PATHS,
|
|
210
|
+
|
|
211
|
+
plan(): InfraProviderPlanContribution {
|
|
212
|
+
return {
|
|
213
|
+
dockerComposeServices: ['postgres'],
|
|
214
|
+
k8sResources: ['templates/infra/k8s/internal/postgres/deployment.yaml.hbs'],
|
|
215
|
+
platformAdmin: {
|
|
216
|
+
envVars: {
|
|
217
|
+
PG_HOST: 'postgres',
|
|
218
|
+
PG_PORT: String(DEFAULT_POSTGRES_PORT),
|
|
219
|
+
},
|
|
220
|
+
// Admin user + password to provision per-app DBs/roles. The
|
|
221
|
+
// legacy admin-init code reads these from `PG_ADMIN_USER` /
|
|
222
|
+
// `PG_ADMIN_PASSWORD`; the planner emits the keys, the
|
|
223
|
+
// CLI's `env-vars-builder` writes the values at sync time.
|
|
224
|
+
secretEnvVars: ['PG_ADMIN_USER', 'PG_ADMIN_PASSWORD'],
|
|
225
|
+
// Audience-1 only (DB-admin access). No audience-2
|
|
226
|
+
// platform-service-scoped Postgres use case today (D-4).
|
|
227
|
+
consumers: [
|
|
228
|
+
InfraPlatformAdminConsumer.APPS_MANAGER,
|
|
229
|
+
InfraPlatformAdminConsumer.COMPANION,
|
|
230
|
+
],
|
|
231
|
+
},
|
|
232
|
+
appRuntime: {
|
|
233
|
+
// Static topology — same for every app in this env. The
|
|
234
|
+
// per-app values (databaseName, username, connectUrl) flow
|
|
235
|
+
// through `perAppSecretBlobPaths`.
|
|
236
|
+
perAppConfigBlobPaths: {
|
|
237
|
+
'database.postgresql.host': 'postgres',
|
|
238
|
+
'database.postgresql.port': DEFAULT_POSTGRES_PORT,
|
|
239
|
+
},
|
|
240
|
+
perAppSecretBlobPaths: [...PER_PRINCIPAL_SECRET_BLOB_PATHS],
|
|
241
|
+
},
|
|
242
|
+
};
|
|
243
|
+
},
|
|
244
|
+
|
|
245
|
+
async mintAppCredentials(
|
|
246
|
+
context: AppCredentialMintingContext,
|
|
247
|
+
): Promise<AppCredentialMintingResult> {
|
|
248
|
+
const adminClient = context.adminClient as IPostgresAdminClient;
|
|
249
|
+
const password = context.secretInputs[POSTGRES_PASSWORD_INPUT_KEY];
|
|
250
|
+
if (!password) {
|
|
251
|
+
throw new Error(
|
|
252
|
+
`PostgresSelfInfraProviderModule.mintAppCredentials: ` +
|
|
253
|
+
`secretInputs is missing '${POSTGRES_PASSWORD_INPUT_KEY}'. ` +
|
|
254
|
+
`The orchestrator MUST supply the Postgres password — modules are upsert-only.`,
|
|
255
|
+
);
|
|
256
|
+
}
|
|
257
|
+
if (!context.appSlug) {
|
|
258
|
+
throw new Error(
|
|
259
|
+
`PostgresSelfInfraProviderModule.mintAppCredentials: ` +
|
|
260
|
+
`appSlug is empty. ` +
|
|
261
|
+
`The orchestrator MUST supply a non-empty slug.`,
|
|
262
|
+
);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
// Allow operator override of the derived database name. Without
|
|
266
|
+
// an override, derive from `appSlug` via the legacy convention.
|
|
267
|
+
const databaseName =
|
|
268
|
+
context.applicationConfigInputs?.[POSTGRES_DATABASE_NAME_INPUT_KEY]
|
|
269
|
+
|| buildDatabaseName(context.appSlug);
|
|
270
|
+
const username = buildPostgresPrincipalUsername(context.appSlug, context.principal);
|
|
271
|
+
|
|
272
|
+
if (context.principal && context.principal.kind !== ApplicationRuntimePrincipalKind.APPLICATION_BACKEND) {
|
|
273
|
+
// A named principal gets a TABLE-SCOPED role (Step 3 / R1 / D14): exactly
|
|
274
|
+
// the verbs its `resourceAccess` derived, on exactly the tables that
|
|
275
|
+
// declaration names, inside a database it does not own.
|
|
276
|
+
//
|
|
277
|
+
// `resourceGrants` is REQUIRED and its absence is an error rather than a
|
|
278
|
+
// default. Falling through to `upsertApplicationDatabase` would make the
|
|
279
|
+
// minion the OWNER of the application's database with `ALL PRIVILEGES` —
|
|
280
|
+
// the exact over-grant this path replaces, arriving silently through a
|
|
281
|
+
// code path that reads as if it were doing the narrow thing.
|
|
282
|
+
const grants = context.resourceGrants;
|
|
283
|
+
if (!grants) {
|
|
284
|
+
throw new Error(
|
|
285
|
+
`PostgresSelfInfraProviderModule.mintAppCredentials: `
|
|
286
|
+
+ `principal '${context.principal.kind}:${context.principal.name}' has no resourceGrants. `
|
|
287
|
+
+ `Refusing to fall back to the database-wide application role — a minion with no declared `
|
|
288
|
+
+ `access must get NO database role at all (D11/R3), which is the orchestrator's decision to make.`,
|
|
289
|
+
);
|
|
290
|
+
}
|
|
291
|
+
const { connectionUrl: principalConnectionUrl } = await adminClient.upsertTableScopedDatabaseRole({
|
|
292
|
+
databaseName,
|
|
293
|
+
username,
|
|
294
|
+
password,
|
|
295
|
+
schemaName: POSTGRES_APPLICATION_SCHEMA,
|
|
296
|
+
// Resource types → table names HERE, at the adapter that speaks
|
|
297
|
+
// Postgres. The grant contract itself stays in the platform vocabulary,
|
|
298
|
+
// and passes through the SAME translation Mongo uses, so the two
|
|
299
|
+
// adapters cannot disagree about which rows a resource type addresses.
|
|
300
|
+
readTables: resolveGrantStorageNames(grants.read),
|
|
301
|
+
writeTables: resolveGrantStorageNames(grants.write),
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
return {
|
|
305
|
+
secretBlobValues: {
|
|
306
|
+
[POSTGRES_DATABASE_NAME_PATH]: databaseName,
|
|
307
|
+
[POSTGRES_USERNAME_PATH]: username,
|
|
308
|
+
[POSTGRES_CONNECT_URL_PATH]: principalConnectionUrl,
|
|
309
|
+
},
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
// CREATE/ALTER USER + CREATE DATABASE — idempotent upsert. The
|
|
314
|
+
// admin-client reapplies privileges every time so the call is
|
|
315
|
+
// safe to repeat.
|
|
316
|
+
const { connectionUrl } = await adminClient.upsertApplicationDatabase({
|
|
317
|
+
databaseName,
|
|
318
|
+
username,
|
|
319
|
+
password,
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
return {
|
|
323
|
+
secretBlobValues: {
|
|
324
|
+
[POSTGRES_DATABASE_NAME_PATH]: databaseName,
|
|
325
|
+
[POSTGRES_USERNAME_PATH]: username,
|
|
326
|
+
[POSTGRES_CONNECT_URL_PATH]: connectionUrl,
|
|
327
|
+
},
|
|
328
|
+
};
|
|
329
|
+
},
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* Tear down the per-app Postgres database + role. Idempotent: the
|
|
333
|
+
* underlying admin client treats missing DB / missing user as
|
|
334
|
+
* no-ops.
|
|
335
|
+
*
|
|
336
|
+
* **Caller status** (F6 of 2026-05-06 plan review): no caller
|
|
337
|
+
* wires this in Slices 1–4.B.2. Method ships as a forward-compat
|
|
338
|
+
* seam for whichever future slice designs the app-deletion
|
|
339
|
+
* lifecycle.
|
|
340
|
+
*
|
|
341
|
+
* **Defensive validation** (Slice 4.A.2 / L4 pattern): empty
|
|
342
|
+
* `appSlug` would derive an empty database name; we fail-loud
|
|
343
|
+
* instead so a bad caller surfaces immediately.
|
|
344
|
+
*/
|
|
345
|
+
async revokeAppCredentials(context: AppCredentialMintingContext): Promise<void> {
|
|
346
|
+
if (!context.appSlug) {
|
|
347
|
+
throw new Error(
|
|
348
|
+
`PostgresSelfInfraProviderModule.revokeAppCredentials: ` +
|
|
349
|
+
`appSlug is empty. ` +
|
|
350
|
+
`The orchestrator MUST supply a non-empty slug.`,
|
|
351
|
+
);
|
|
352
|
+
}
|
|
353
|
+
const adminClient = context.adminClient as IPostgresAdminClient;
|
|
354
|
+
const databaseName =
|
|
355
|
+
context.applicationConfigInputs?.[POSTGRES_DATABASE_NAME_INPUT_KEY]
|
|
356
|
+
|| buildDatabaseName(context.appSlug);
|
|
357
|
+
const username = buildPostgresPrincipalUsername(context.appSlug, context.principal);
|
|
358
|
+
|
|
359
|
+
if (context.principal && context.principal.kind !== ApplicationRuntimePrincipalKind.APPLICATION_BACKEND) {
|
|
360
|
+
// A named principal owns NOTHING but its own role. Routing it through
|
|
361
|
+
// `dropApplicationDatabase` — which is what this method did before named
|
|
362
|
+
// principals existed — would DROP THE APPLICATION'S DATABASE while
|
|
363
|
+
// believing it was retiring one minion's access.
|
|
364
|
+
await adminClient.dropTableScopedDatabaseRole({
|
|
365
|
+
databaseName,
|
|
366
|
+
username,
|
|
367
|
+
schemaName: POSTGRES_APPLICATION_SCHEMA,
|
|
368
|
+
});
|
|
369
|
+
return;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
await adminClient.dropApplicationDatabase({ databaseName, username });
|
|
373
|
+
},
|
|
374
|
+
|
|
375
|
+
// No `mintPlatformServiceCredentials` (D-4 of Slice 4.B —
|
|
376
|
+
// audience-2 not applicable to Postgres_Self today).
|
|
377
|
+
};
|