@di-framework/cli-plugin-platform 6.1.2 → 6.3.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.
- package/README.md +154 -12
- package/dist/args.d.ts +8 -0
- package/dist/args.js +73 -28
- package/dist/assets/http-adapter.js +4 -1
- package/dist/assets/platform/README.md +68 -19
- package/dist/assets/platform/index.ts.tmpl +1 -1
- package/dist/assets/platform/tsconfig.json +2 -2
- package/dist/assets/sqlite/BUILD-INFO.txt +1 -1
- package/dist/build.d.ts +27 -4
- package/dist/build.js +159 -18
- package/dist/bundle.d.ts +85 -0
- package/dist/bundle.js +608 -0
- package/dist/command.js +85 -3
- package/dist/console/catalog.js +2 -1
- package/dist/console/cluster.d.ts +4 -2
- package/dist/console/cluster.js +38 -40
- package/dist/control/auth.js +14 -2
- package/dist/controller/client.d.ts +47 -0
- package/dist/controller/client.js +157 -0
- package/dist/controller/commands.d.ts +48 -0
- package/dist/controller/commands.js +584 -0
- package/dist/controller/credentials.d.ts +63 -0
- package/dist/controller/credentials.js +156 -0
- package/dist/controller/index.d.ts +6 -0
- package/dist/controller/index.js +6 -0
- package/dist/controller/oidc.d.ts +54 -0
- package/dist/controller/oidc.js +121 -0
- package/dist/controller/registry.d.ts +15 -0
- package/dist/controller/registry.js +47 -0
- package/dist/controller/schema.d.ts +157 -0
- package/dist/controller/schema.js +1 -0
- package/dist/controller/sse.d.ts +12 -0
- package/dist/controller/sse.js +61 -0
- package/dist/controller/trust.d.ts +14 -0
- package/dist/controller/trust.js +39 -0
- package/dist/deploy.d.ts +14 -7
- package/dist/deploy.js +96 -5
- package/dist/deps.d.ts +4 -0
- package/dist/destroy.js +26 -2
- package/dist/environment-names.d.ts +6 -0
- package/dist/environment-names.js +10 -0
- package/dist/index.d.ts +5 -3
- package/dist/index.js +5 -3
- package/dist/manifest.d.ts +45 -1
- package/dist/manifest.js +197 -4
- package/dist/pglite-encryption.d.ts +79 -0
- package/dist/pglite-encryption.js +196 -0
- package/dist/pglite.d.ts +61 -4
- package/dist/pglite.js +124 -40
- package/dist/project.d.ts +7 -0
- package/dist/project.js +35 -0
- package/dist/publish.d.ts +7 -1
- package/dist/publish.js +33 -1
- package/dist/service.d.ts +34 -0
- package/dist/service.js +156 -145
- package/dist/target.d.ts +7 -1
- package/dist/target.js +19 -0
- package/dist/workload.d.ts +50 -12
- package/dist/workload.js +239 -44
- package/package.json +1 -1
package/dist/manifest.js
CHANGED
|
@@ -21,6 +21,57 @@ export function tenantNamespace(tenant) {
|
|
|
21
21
|
export function tenantHostgroup(tenant) {
|
|
22
22
|
return `tenant-${tenant}`;
|
|
23
23
|
}
|
|
24
|
+
const DOMAIN_LABEL = '[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?';
|
|
25
|
+
const CONTROLLER_DOMAIN_PATTERN = new RegExp(String.raw `^${DOMAIN_LABEL}(?:\.${DOMAIN_LABEL})*(?::([1-9][0-9]{0,4}))?$`);
|
|
26
|
+
const IPV6_HOST_PATTERN = /^\[[0-9a-f:.]+\]$/;
|
|
27
|
+
/** Valid DNS domain (and optional port) used to derive `https://<account>.controller.<domain>`. */
|
|
28
|
+
export function isControllerDomain(value) {
|
|
29
|
+
const match = CONTROLLER_DOMAIN_PATTERN.exec(value);
|
|
30
|
+
if (match === null || value.length > 260)
|
|
31
|
+
return false;
|
|
32
|
+
return match[1] === undefined || Number(match[1]) <= 65535;
|
|
33
|
+
}
|
|
34
|
+
function isPlainHttpAllowedControllerHost(hostname) {
|
|
35
|
+
if (hostname === 'localhost' || hostname === '[::1]')
|
|
36
|
+
return true;
|
|
37
|
+
if (/^127\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(hostname))
|
|
38
|
+
return true;
|
|
39
|
+
return hostname.endsWith('.svc') || hostname.endsWith('.svc.cluster.local');
|
|
40
|
+
}
|
|
41
|
+
function trimTrailingSlashes(value) {
|
|
42
|
+
let result = value;
|
|
43
|
+
while (result.endsWith('/')) {
|
|
44
|
+
result = result.slice(0, -1);
|
|
45
|
+
}
|
|
46
|
+
return result;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Validates and normalizes a tenant controller URL (without trailing slash).
|
|
50
|
+
* Requires `https://`, or `http://` for loopback and in-cluster (`*.svc`) hosts only.
|
|
51
|
+
*/
|
|
52
|
+
export function normalizeControllerUrl(value) {
|
|
53
|
+
let url;
|
|
54
|
+
try {
|
|
55
|
+
url = new URL(value);
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
return undefined;
|
|
59
|
+
}
|
|
60
|
+
if (url.protocol !== 'https:' && url.protocol !== 'http:')
|
|
61
|
+
return undefined;
|
|
62
|
+
if (url.username || url.password || url.search || url.hash)
|
|
63
|
+
return undefined;
|
|
64
|
+
const hostname = url.hostname.toLowerCase();
|
|
65
|
+
const validHost = new RegExp(String.raw `^${DOMAIN_LABEL}(?:\.${DOMAIN_LABEL})*$`).test(hostname) ||
|
|
66
|
+
IPV6_HOST_PATTERN.test(hostname);
|
|
67
|
+
if (!validHost)
|
|
68
|
+
return undefined;
|
|
69
|
+
if (url.protocol === 'http:' && !isPlainHttpAllowedControllerHost(hostname)) {
|
|
70
|
+
return undefined;
|
|
71
|
+
}
|
|
72
|
+
const path = url.pathname === '/' ? '' : trimTrailingSlashes(url.pathname);
|
|
73
|
+
return `${url.origin}${path}`;
|
|
74
|
+
}
|
|
24
75
|
const ENV_TOKEN = /\$\{([A-Za-z_][A-Za-z0-9_]*)\}/g;
|
|
25
76
|
function manifestInvalid(message, details) {
|
|
26
77
|
throw new CommandFailure('WASMCLOUD_DEPLOY_MANIFEST_INVALID', message, 2, details);
|
|
@@ -50,6 +101,9 @@ export function parseDeployManifest(path, source, env) {
|
|
|
50
101
|
const interpolated = interpolateEnv(parsed, env, path);
|
|
51
102
|
const defaultTarget = optionalString(interpolated['default-target'], 'default-target', path);
|
|
52
103
|
const discovery = parseDiscovery(interpolated.discovery, path);
|
|
104
|
+
const manifestEnv = optionalDeployEnvironment(interpolated.env, 'env', path);
|
|
105
|
+
const bindings = parseManifestBindings(interpolated.bindings, 'bindings', path);
|
|
106
|
+
const secrets = parseManifestSecrets(interpolated.secrets, 'secrets', path);
|
|
53
107
|
const targetsValue = interpolated.targets;
|
|
54
108
|
if (targetsValue === undefined) {
|
|
55
109
|
manifestInvalid(`${DEPLOY_MANIFEST_NAME} must declare at least one [targets.<name>] table`, {
|
|
@@ -68,10 +122,17 @@ export function parseDeployManifest(path, source, env) {
|
|
|
68
122
|
if (defaultTarget !== undefined && targets[defaultTarget] === undefined) {
|
|
69
123
|
manifestInvalid(`default-target "${defaultTarget}" does not match any declared target. Known targets: ${Object.keys(targets).join(', ')}`, { manifestPath: path, defaultTarget, targets: Object.keys(targets) });
|
|
70
124
|
}
|
|
71
|
-
const knownKeys = new Set([
|
|
125
|
+
const knownKeys = new Set([
|
|
126
|
+
'default-target',
|
|
127
|
+
'discovery',
|
|
128
|
+
'targets',
|
|
129
|
+
'env',
|
|
130
|
+
'bindings',
|
|
131
|
+
'secrets',
|
|
132
|
+
]);
|
|
72
133
|
const unknown = Object.keys(interpolated).filter((key) => !knownKeys.has(key));
|
|
73
134
|
if (unknown.length > 0) {
|
|
74
|
-
manifestInvalid(`${DEPLOY_MANIFEST_NAME} has unsupported fields: ${unknown.join(', ')}. Valid fields are default-target, discovery, and
|
|
135
|
+
manifestInvalid(`${DEPLOY_MANIFEST_NAME} has unsupported fields: ${unknown.join(', ')}. Valid fields are default-target, discovery, targets, env, bindings, and secrets.`, { manifestPath: path, fields: unknown });
|
|
75
136
|
}
|
|
76
137
|
return {
|
|
77
138
|
path,
|
|
@@ -79,6 +140,9 @@ export function parseDeployManifest(path, source, env) {
|
|
|
79
140
|
defaultTarget,
|
|
80
141
|
discovery,
|
|
81
142
|
targets,
|
|
143
|
+
...(manifestEnv ? { env: manifestEnv } : {}),
|
|
144
|
+
...(bindings ? { bindings } : {}),
|
|
145
|
+
...(secrets ? { secrets } : {}),
|
|
82
146
|
};
|
|
83
147
|
}
|
|
84
148
|
export function interpolateEnv(value, env, manifestPath) {
|
|
@@ -151,6 +215,26 @@ function parseTarget(name, value, manifestPath) {
|
|
|
151
215
|
manifestInvalid(`targets.${name}.namespace must be a Kubernetes namespace (a DNS label of at most 63 characters)`, { manifestPath, target: name });
|
|
152
216
|
}
|
|
153
217
|
const registry = optionalRegistry(value.registry, `targets.${name}.registry`, manifestPath);
|
|
218
|
+
const account = optionalString(value.account, `targets.${name}.account`, manifestPath);
|
|
219
|
+
if (account !== undefined && !isTenantName(account)) {
|
|
220
|
+
manifestInvalid(`targets.${name}.account must be a platform tenant name: 1-40 lowercase letters, digits, and single hyphens, starting with a letter (got "${account}")`, { manifestPath, target: name, account });
|
|
221
|
+
}
|
|
222
|
+
const domain = optionalString(value.domain, `targets.${name}.domain`, manifestPath);
|
|
223
|
+
if (domain !== undefined && !isControllerDomain(domain)) {
|
|
224
|
+
manifestInvalid(`targets.${name}.domain must be a valid DNS domain (got "${domain}")`, {
|
|
225
|
+
manifestPath,
|
|
226
|
+
target: name,
|
|
227
|
+
domain,
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
const rawController = optionalString(value.controller, `targets.${name}.controller`, manifestPath);
|
|
231
|
+
const controller = rawController === undefined ? undefined : normalizeControllerUrl(rawController);
|
|
232
|
+
if (rawController !== undefined && controller === undefined) {
|
|
233
|
+
manifestInvalid(`targets.${name}.controller must be an https:// URL (or http:// for loopback or in-cluster *.svc hosts)`, { manifestPath, target: name, controller: rawController });
|
|
234
|
+
}
|
|
235
|
+
const env = optionalDeployEnvironment(value.env, `targets.${name}.env`, manifestPath);
|
|
236
|
+
const bindings = parseManifestBindings(value.bindings, `targets.${name}.bindings`, manifestPath);
|
|
237
|
+
const secrets = parseManifestSecrets(value.secrets, `targets.${name}.secrets`, manifestPath);
|
|
154
238
|
const known = new Set([
|
|
155
239
|
'platform',
|
|
156
240
|
'stack',
|
|
@@ -161,10 +245,16 @@ function parseTarget(name, value, manifestPath) {
|
|
|
161
245
|
'registry',
|
|
162
246
|
'hostgroup',
|
|
163
247
|
'storage-hostgroup',
|
|
248
|
+
'account',
|
|
249
|
+
'controller',
|
|
250
|
+
'domain',
|
|
251
|
+
'env',
|
|
252
|
+
'bindings',
|
|
253
|
+
'secrets',
|
|
164
254
|
]);
|
|
165
255
|
const unknown = Object.keys(value).filter((key) => !known.has(key));
|
|
166
256
|
if (unknown.length > 0) {
|
|
167
|
-
manifestInvalid(`Target "${name}" has unsupported fields: ${unknown.join(', ')}. Managed targets accept platform and stack; external targets accept kubeconfig, context, tenant, namespace, registry, hostgroup, and storage-hostgroup.`, { manifestPath, target: name, fields: unknown });
|
|
257
|
+
manifestInvalid(`Target "${name}" has unsupported fields: ${unknown.join(', ')}. Managed targets accept platform and stack; external targets accept kubeconfig, context, tenant, namespace, registry, hostgroup, and storage-hostgroup; tenant controller targets accept account, domain, and controller.`, { manifestPath, target: name, fields: unknown });
|
|
168
258
|
}
|
|
169
259
|
const managedFields = [platform ? 'platform' : undefined, stack ? 'stack' : undefined].filter((field) => field !== undefined);
|
|
170
260
|
const externalFields = [
|
|
@@ -176,14 +266,51 @@ function parseTarget(name, value, manifestPath) {
|
|
|
176
266
|
namespace ? 'namespace' : undefined,
|
|
177
267
|
registry ? 'registry' : undefined,
|
|
178
268
|
].filter((field) => field !== undefined);
|
|
269
|
+
const controllerFields = [
|
|
270
|
+
account ? 'account' : undefined,
|
|
271
|
+
controller ? 'controller' : undefined,
|
|
272
|
+
domain ? 'domain' : undefined,
|
|
273
|
+
].filter((field) => field !== undefined);
|
|
179
274
|
if (managedFields.length > 0 && externalFields.length > 0) {
|
|
180
275
|
manifestInvalid(`Target "${name}" mixes managed-platform and kubeconfig fields (${[...managedFields, ...externalFields].join(', ')}). Use either platform (and optional stack), or kubeconfig + registry + tenant or namespace.`, { manifestPath, target: name });
|
|
181
276
|
}
|
|
277
|
+
if (controllerFields.length > 0 && (managedFields.length > 0 || externalFields.length > 0)) {
|
|
278
|
+
manifestInvalid(`Target "${name}" mixes controller/account fields with operator fields (${[...managedFields, ...externalFields, ...controllerFields].join(', ')}). Use account (and optional domain) or controller (and optional account) for tenant controller targets.`, { manifestPath, target: name });
|
|
279
|
+
}
|
|
280
|
+
if (domain !== undefined && controller !== undefined) {
|
|
281
|
+
manifestInvalid(`Target "${name}" sets domain with controller. domain is only valid on account targets without an explicit controller URL.`, { manifestPath, target: name });
|
|
282
|
+
}
|
|
283
|
+
if (domain !== undefined && account === undefined) {
|
|
284
|
+
manifestInvalid(`Target "${name}" sets domain without account. domain is only valid on account targets.`, { manifestPath, target: name });
|
|
285
|
+
}
|
|
182
286
|
if (stack !== undefined && platform === undefined) {
|
|
183
287
|
manifestInvalid(`Target "${name}" sets stack without platform. stack is only valid on managed Pulumi targets.`, { manifestPath, target: name });
|
|
184
288
|
}
|
|
289
|
+
const bundleExtras = {
|
|
290
|
+
...(env ? { env } : {}),
|
|
291
|
+
...(bindings ? { bindings } : {}),
|
|
292
|
+
...(secrets ? { secrets } : {}),
|
|
293
|
+
};
|
|
294
|
+
if (controller !== undefined) {
|
|
295
|
+
return {
|
|
296
|
+
kind: 'controller',
|
|
297
|
+
name,
|
|
298
|
+
controller,
|
|
299
|
+
...(account ? { account } : {}),
|
|
300
|
+
...bundleExtras,
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
if (account !== undefined) {
|
|
304
|
+
return {
|
|
305
|
+
kind: 'account',
|
|
306
|
+
name,
|
|
307
|
+
account,
|
|
308
|
+
...(domain ? { domain } : {}),
|
|
309
|
+
...bundleExtras,
|
|
310
|
+
};
|
|
311
|
+
}
|
|
185
312
|
if (platform !== undefined) {
|
|
186
|
-
return { kind: 'managed', name, platform, stack: stack ?? 'dev' };
|
|
313
|
+
return { kind: 'managed', name, platform, stack: stack ?? 'dev', ...bundleExtras };
|
|
187
314
|
}
|
|
188
315
|
if (kubeconfig !== undefined ||
|
|
189
316
|
tenant !== undefined ||
|
|
@@ -210,10 +337,76 @@ function parseTarget(name, value, manifestPath) {
|
|
|
210
337
|
...(tenant ? { tenant } : {}),
|
|
211
338
|
...(resolvedHostgroup ? { hostgroup: resolvedHostgroup } : {}),
|
|
212
339
|
...(storageHostgroup ? { storageHostgroup } : {}),
|
|
340
|
+
...bundleExtras,
|
|
213
341
|
};
|
|
214
342
|
}
|
|
215
343
|
manifestInvalid(`Target "${name}" is empty. Set platform (and optional stack) for a managed Pulumi platform, or kubeconfig, registry, and tenant (or namespace) for an external cluster.`, { manifestPath, target: name });
|
|
216
344
|
}
|
|
345
|
+
export function optionalDeployEnvironment(value, label, manifestPath) {
|
|
346
|
+
if (value === undefined)
|
|
347
|
+
return undefined;
|
|
348
|
+
if (value !== 'prod' && value !== 'staging') {
|
|
349
|
+
manifestInvalid(`${label} must be "prod" or "staging"`, { manifestPath, field: label });
|
|
350
|
+
}
|
|
351
|
+
return value;
|
|
352
|
+
}
|
|
353
|
+
export function parseManifestSecrets(value, label, manifestPath) {
|
|
354
|
+
const entries = optionalStringArray(value, label, manifestPath);
|
|
355
|
+
return entries === undefined ? undefined : [...new Set(entries)];
|
|
356
|
+
}
|
|
357
|
+
export function parseManifestBindings(value, label, manifestPath) {
|
|
358
|
+
if (value === undefined)
|
|
359
|
+
return undefined;
|
|
360
|
+
if (!isRecord(value)) {
|
|
361
|
+
manifestInvalid(`${label} must be a table of named bindings`, { manifestPath, field: label });
|
|
362
|
+
}
|
|
363
|
+
const result = [];
|
|
364
|
+
for (const [name, entry] of Object.entries(value)) {
|
|
365
|
+
if (!isRecord(entry)) {
|
|
366
|
+
manifestInvalid(`${label}.${name} must be a table`, {
|
|
367
|
+
manifestPath,
|
|
368
|
+
field: `${label}.${name}`,
|
|
369
|
+
});
|
|
370
|
+
}
|
|
371
|
+
const known = new Set(['capability', 'service', 'serviceName', 'service-name', 'config']);
|
|
372
|
+
const unknown = Object.keys(entry).filter((key) => !known.has(key));
|
|
373
|
+
if (unknown.length > 0) {
|
|
374
|
+
manifestInvalid(`${label}.${name} has unsupported fields: ${unknown.join(', ')}`, {
|
|
375
|
+
manifestPath,
|
|
376
|
+
field: `${label}.${name}`,
|
|
377
|
+
fields: unknown,
|
|
378
|
+
});
|
|
379
|
+
}
|
|
380
|
+
const capability = optionalString(entry.capability, `${label}.${name}.capability`, manifestPath);
|
|
381
|
+
if (capability === undefined) {
|
|
382
|
+
manifestInvalid(`${label}.${name}.capability is required`, {
|
|
383
|
+
manifestPath,
|
|
384
|
+
field: `${label}.${name}.capability`,
|
|
385
|
+
});
|
|
386
|
+
}
|
|
387
|
+
const serviceName = optionalString(entry.serviceName ?? entry['service-name'] ?? entry.service, `${label}.${name}.serviceName`, manifestPath) ?? name;
|
|
388
|
+
let config;
|
|
389
|
+
if (entry.config !== undefined) {
|
|
390
|
+
if (!isRecord(entry.config) ||
|
|
391
|
+
Object.values(entry.config).some((v) => typeof v !== 'string')) {
|
|
392
|
+
manifestInvalid(`${label}.${name}.config must be a table of string values`, {
|
|
393
|
+
manifestPath,
|
|
394
|
+
field: `${label}.${name}.config`,
|
|
395
|
+
});
|
|
396
|
+
}
|
|
397
|
+
if (Object.keys(entry.config).length > 0) {
|
|
398
|
+
config = { ...entry.config };
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
result.push({
|
|
402
|
+
name,
|
|
403
|
+
capability,
|
|
404
|
+
serviceName,
|
|
405
|
+
...(config ? { config } : {}),
|
|
406
|
+
});
|
|
407
|
+
}
|
|
408
|
+
return result;
|
|
409
|
+
}
|
|
217
410
|
function optionalString(value, label, manifestPath) {
|
|
218
411
|
if (value === undefined)
|
|
219
412
|
return undefined;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wiring a PGlite encryption layer between the provider and the host filesystem.
|
|
3
|
+
*
|
|
4
|
+
* `wac plug` is best effort: it plugs each export of the layer whose name matches an import of
|
|
5
|
+
* the provider *and* whose type is a subtype of it, silently skips the rest, and exits 0 as soon
|
|
6
|
+
* as one pair plugged. A layer that exports only `wasi:cli/environment`, exports the filesystem
|
|
7
|
+
* at a version wac does not match, or exports it with a different type would compose cleanly and
|
|
8
|
+
* leave PGlite writing plaintext to the host. So the build does not use `wac plug` here: it
|
|
9
|
+
* plans the wiring itself and composes an explicit WAC document with `wac compose`, where every
|
|
10
|
+
* provider import that must go to the layer is a named instantiation argument. wac then
|
|
11
|
+
* type-checks each one and fails loudly instead of skipping it.
|
|
12
|
+
*/
|
|
13
|
+
/** An interface a component's world imports or exports, e.g. `wasi:filesystem/types@0.2.9`. */
|
|
14
|
+
export type WitInterface = {
|
|
15
|
+
name: string;
|
|
16
|
+
version?: string;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* The interfaces a component's world imports and exports, from `jco wit` output. `unrecognized`
|
|
20
|
+
* holds every other `import`/`export` line, such as a plain-named `import fs: interface {` or a
|
|
21
|
+
* bare function, which the wiring cannot reason about.
|
|
22
|
+
*/
|
|
23
|
+
export declare function worldInterfaces(wit: string): {
|
|
24
|
+
imports: WitInterface[];
|
|
25
|
+
exports: WitInterface[];
|
|
26
|
+
unrecognized: string[];
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Interfaces the provider may take straight from the host. Everything else it imports must be
|
|
30
|
+
* wired to the layer, so a provider that reached storage some other way (another filesystem
|
|
31
|
+
* package, a plain-named interface) stops the build instead of bypassing the layer.
|
|
32
|
+
*/
|
|
33
|
+
export declare const HOST_PASS_THROUGH: string[];
|
|
34
|
+
export declare function formatInterface(item: WitInterface): string;
|
|
35
|
+
/**
|
|
36
|
+
* Whether two versions of an interface are on the same semver track, as wac decides it
|
|
37
|
+
* (wac-types `are_semver_compatible`), in either direction: the same major from 1.0 on, the
|
|
38
|
+
* same minor for 0.x with x ≥ 1, and an exact match for 0.0.z and pre-releases. Unversioned
|
|
39
|
+
* names match only each other.
|
|
40
|
+
*/
|
|
41
|
+
export declare function semverCompatible(a?: string, b?: string): boolean;
|
|
42
|
+
/** One provider import wired to one layer export, by their full names. */
|
|
43
|
+
export type Wire = {
|
|
44
|
+
providerImport: string;
|
|
45
|
+
layerExport: string;
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Which layer export each provider import is wired to: the export with the same name and
|
|
49
|
+
* version, else the first on the same semver track (wac's own matching). Every
|
|
50
|
+
* `wasi:filesystem/*` import must be wired, or `problem` says why not; other interfaces the
|
|
51
|
+
* layer re-exports (`wasi:io/streams`, `wasi:cli/*`, …) are wired too, since the filesystem
|
|
52
|
+
* types refer to them.
|
|
53
|
+
*/
|
|
54
|
+
export declare function planWiring(provider: {
|
|
55
|
+
imports: WitInterface[];
|
|
56
|
+
exports?: WitInterface[];
|
|
57
|
+
unrecognized?: string[];
|
|
58
|
+
}, layer: {
|
|
59
|
+
exports: WitInterface[];
|
|
60
|
+
}): {
|
|
61
|
+
wires: Wire[];
|
|
62
|
+
problem?: string;
|
|
63
|
+
};
|
|
64
|
+
/** WAC package names the composition document refers to (bound with `wac compose --dep`). */
|
|
65
|
+
export declare const LAYER_PACKAGE = "pglite:layer";
|
|
66
|
+
export declare const PROVIDER_PACKAGE = "pglite:provider";
|
|
67
|
+
/**
|
|
68
|
+
* The WAC document that instantiates the layer against the host and the provider with every
|
|
69
|
+
* wired import taken from the layer's instance, re-exporting the provider's exports. Imports of
|
|
70
|
+
* either that are not wired stay imports of the result (`...`).
|
|
71
|
+
*/
|
|
72
|
+
export declare function encryptionComposition(wires: readonly Wire[], providerExports: WitInterface[]): string;
|
|
73
|
+
/** Custom section the platform's encryption layer carries (`format=1 codec=aes-256-xts`). */
|
|
74
|
+
export declare const ENCFS_SECTION = "di-framework:pglite-encfs";
|
|
75
|
+
/**
|
|
76
|
+
* The contents of the `di-framework:pglite-encfs` custom section anywhere in a core module or
|
|
77
|
+
* component binary, including nested modules and components, or undefined when there is none.
|
|
78
|
+
*/
|
|
79
|
+
export declare function encfsSection(bytes: Uint8Array): string | undefined;
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wiring a PGlite encryption layer between the provider and the host filesystem.
|
|
3
|
+
*
|
|
4
|
+
* `wac plug` is best effort: it plugs each export of the layer whose name matches an import of
|
|
5
|
+
* the provider *and* whose type is a subtype of it, silently skips the rest, and exits 0 as soon
|
|
6
|
+
* as one pair plugged. A layer that exports only `wasi:cli/environment`, exports the filesystem
|
|
7
|
+
* at a version wac does not match, or exports it with a different type would compose cleanly and
|
|
8
|
+
* leave PGlite writing plaintext to the host. So the build does not use `wac plug` here: it
|
|
9
|
+
* plans the wiring itself and composes an explicit WAC document with `wac compose`, where every
|
|
10
|
+
* provider import that must go to the layer is a named instantiation argument. wac then
|
|
11
|
+
* type-checks each one and fails loudly instead of skipping it.
|
|
12
|
+
*/
|
|
13
|
+
const FILESYSTEM = 'wasi:filesystem/';
|
|
14
|
+
const WORLD_ITEM = /^\s*(import|export)\s+([a-z][a-z0-9-]*:[a-z][a-z0-9-]*\/[a-z][a-z0-9-]*)(?:@([^;\s]+))?;\s*$/;
|
|
15
|
+
const SEMVER = /^(\d+)\.(\d+)\.(\d+)(-[0-9A-Za-z.-]+)?(\+[0-9A-Za-z.-]+)?$/;
|
|
16
|
+
const WORLD_LINE = /^\s*(import|export)\s/;
|
|
17
|
+
/**
|
|
18
|
+
* The interfaces a component's world imports and exports, from `jco wit` output. `unrecognized`
|
|
19
|
+
* holds every other `import`/`export` line, such as a plain-named `import fs: interface {` or a
|
|
20
|
+
* bare function, which the wiring cannot reason about.
|
|
21
|
+
*/
|
|
22
|
+
export function worldInterfaces(wit) {
|
|
23
|
+
const imports = [];
|
|
24
|
+
const exports = [];
|
|
25
|
+
const unrecognized = [];
|
|
26
|
+
for (const line of wit.split('\n')) {
|
|
27
|
+
const match = WORLD_ITEM.exec(line);
|
|
28
|
+
if (match === null) {
|
|
29
|
+
if (WORLD_LINE.test(line))
|
|
30
|
+
unrecognized.push(line.trim());
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
const item = {
|
|
34
|
+
name: match[2],
|
|
35
|
+
...(match[3] === undefined ? {} : { version: match[3] }),
|
|
36
|
+
};
|
|
37
|
+
(match[1] === 'import' ? imports : exports).push(item);
|
|
38
|
+
}
|
|
39
|
+
return { imports, exports, unrecognized };
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Interfaces the provider may take straight from the host. Everything else it imports must be
|
|
43
|
+
* wired to the layer, so a provider that reached storage some other way (another filesystem
|
|
44
|
+
* package, a plain-named interface) stops the build instead of bypassing the layer.
|
|
45
|
+
*/
|
|
46
|
+
export const HOST_PASS_THROUGH = ['wasi:io/', 'wasi:clocks/', 'wasi:random/', 'wasi:cli/'];
|
|
47
|
+
export function formatInterface(item) {
|
|
48
|
+
return item.version === undefined ? item.name : `${item.name}@${item.version}`;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Whether two versions of an interface are on the same semver track, as wac decides it
|
|
52
|
+
* (wac-types `are_semver_compatible`), in either direction: the same major from 1.0 on, the
|
|
53
|
+
* same minor for 0.x with x ≥ 1, and an exact match for 0.0.z and pre-releases. Unversioned
|
|
54
|
+
* names match only each other.
|
|
55
|
+
*/
|
|
56
|
+
export function semverCompatible(a, b) {
|
|
57
|
+
if (a === b)
|
|
58
|
+
return true;
|
|
59
|
+
if (a === undefined || b === undefined)
|
|
60
|
+
return false;
|
|
61
|
+
const x = SEMVER.exec(a);
|
|
62
|
+
const y = SEMVER.exec(b);
|
|
63
|
+
if (x === null || y === null || x[4] !== undefined || y[4] !== undefined)
|
|
64
|
+
return false;
|
|
65
|
+
const [xMajor, xMinor, xPatch] = [1, 2, 3].map((n) => Number(x[n]));
|
|
66
|
+
const [yMajor, yMinor, yPatch] = [1, 2, 3].map((n) => Number(y[n]));
|
|
67
|
+
if (xMajor !== yMajor)
|
|
68
|
+
return false;
|
|
69
|
+
if (xMajor !== 0)
|
|
70
|
+
return true;
|
|
71
|
+
if (xMinor !== yMinor)
|
|
72
|
+
return false;
|
|
73
|
+
if (xMinor !== 0)
|
|
74
|
+
return true;
|
|
75
|
+
return xPatch === yPatch;
|
|
76
|
+
}
|
|
77
|
+
const isFilesystem = (item) => item.name.startsWith(FILESYSTEM);
|
|
78
|
+
/**
|
|
79
|
+
* Which layer export each provider import is wired to: the export with the same name and
|
|
80
|
+
* version, else the first on the same semver track (wac's own matching). Every
|
|
81
|
+
* `wasi:filesystem/*` import must be wired, or `problem` says why not; other interfaces the
|
|
82
|
+
* layer re-exports (`wasi:io/streams`, `wasi:cli/*`, …) are wired too, since the filesystem
|
|
83
|
+
* types refer to them.
|
|
84
|
+
*/
|
|
85
|
+
export function planWiring(provider, layer) {
|
|
86
|
+
if (provider.unrecognized !== undefined && provider.unrecognized.length > 0)
|
|
87
|
+
return {
|
|
88
|
+
wires: [],
|
|
89
|
+
problem: `the provider's world has items the build cannot wire: ${provider.unrecognized.join('; ')}`,
|
|
90
|
+
};
|
|
91
|
+
const required = provider.imports.filter(isFilesystem);
|
|
92
|
+
if (required.length === 0)
|
|
93
|
+
return {
|
|
94
|
+
wires: [],
|
|
95
|
+
problem: 'the provider imports no wasi:filesystem interface, so there is nothing for the layer to encrypt',
|
|
96
|
+
};
|
|
97
|
+
const wires = [];
|
|
98
|
+
const missing = [];
|
|
99
|
+
for (const wanted of provider.imports) {
|
|
100
|
+
const offered = layer.exports.find((item) => item.name === wanted.name && item.version === wanted.version) ??
|
|
101
|
+
layer.exports.find((item) => item.name === wanted.name && semverCompatible(item.version, wanted.version));
|
|
102
|
+
if (offered !== undefined) {
|
|
103
|
+
wires.push({
|
|
104
|
+
providerImport: formatInterface(wanted),
|
|
105
|
+
layerExport: formatInterface(offered),
|
|
106
|
+
});
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
if (!isFilesystem(wanted)) {
|
|
110
|
+
if (!HOST_PASS_THROUGH.some((prefix) => wanted.name.startsWith(prefix)))
|
|
111
|
+
missing.push(`${formatInterface(wanted)} (neither exported by the layer nor allowed from the host)`);
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
const found = layer.exports
|
|
115
|
+
.filter((item) => item.name === wanted.name)
|
|
116
|
+
.map((item) => `@${item.version ?? 'unversioned'}`);
|
|
117
|
+
const detail = found.length === 0 ? 'not exported' : `the layer exports ${found.join(', ')}`;
|
|
118
|
+
missing.push(`${formatInterface(wanted)} (${detail})`);
|
|
119
|
+
}
|
|
120
|
+
return missing.length === 0
|
|
121
|
+
? { wires }
|
|
122
|
+
: {
|
|
123
|
+
wires,
|
|
124
|
+
problem: `the layer does not export what the provider imports: ${missing.join('; ')}`,
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
/** WAC package names the composition document refers to (bound with `wac compose --dep`). */
|
|
128
|
+
export const LAYER_PACKAGE = 'pglite:layer';
|
|
129
|
+
export const PROVIDER_PACKAGE = 'pglite:provider';
|
|
130
|
+
/**
|
|
131
|
+
* The WAC document that instantiates the layer against the host and the provider with every
|
|
132
|
+
* wired import taken from the layer's instance, re-exporting the provider's exports. Imports of
|
|
133
|
+
* either that are not wired stay imports of the result (`...`).
|
|
134
|
+
*/
|
|
135
|
+
export function encryptionComposition(wires, providerExports) {
|
|
136
|
+
const quote = (name) => JSON.stringify(name);
|
|
137
|
+
return [
|
|
138
|
+
'package di-framework:pglite-encrypted;',
|
|
139
|
+
'',
|
|
140
|
+
`let layer = new ${LAYER_PACKAGE} { ... };`,
|
|
141
|
+
`let provider = new ${PROVIDER_PACKAGE} {`,
|
|
142
|
+
...wires.map((wire) => ` ${quote(wire.providerImport)}: layer[${quote(wire.layerExport)}],`),
|
|
143
|
+
' ...',
|
|
144
|
+
'};',
|
|
145
|
+
'',
|
|
146
|
+
...providerExports.map((item) => `export provider[${quote(formatInterface(item))}];`),
|
|
147
|
+
'',
|
|
148
|
+
].join('\n');
|
|
149
|
+
}
|
|
150
|
+
/** Custom section the platform's encryption layer carries (`format=1 codec=aes-256-xts`). */
|
|
151
|
+
export const ENCFS_SECTION = 'di-framework:pglite-encfs';
|
|
152
|
+
/**
|
|
153
|
+
* The contents of the `di-framework:pglite-encfs` custom section anywhere in a core module or
|
|
154
|
+
* component binary, including nested modules and components, or undefined when there is none.
|
|
155
|
+
*/
|
|
156
|
+
export function encfsSection(bytes) {
|
|
157
|
+
const decoder = new TextDecoder();
|
|
158
|
+
const walk = (start, end) => {
|
|
159
|
+
if (end - start < 8 || bytes[start] !== 0 || bytes[start + 1] !== 0x61)
|
|
160
|
+
return undefined;
|
|
161
|
+
const component = bytes[start + 6] === 1;
|
|
162
|
+
let offset = start + 8;
|
|
163
|
+
const leb = () => {
|
|
164
|
+
let result = 0;
|
|
165
|
+
let shift = 0;
|
|
166
|
+
for (;;) {
|
|
167
|
+
const byte = bytes[offset++];
|
|
168
|
+
result += (byte & 0x7f) * 2 ** shift;
|
|
169
|
+
if ((byte & 0x80) === 0 || offset >= end)
|
|
170
|
+
return result;
|
|
171
|
+
shift += 7;
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
while (offset < end) {
|
|
175
|
+
const id = bytes[offset++];
|
|
176
|
+
const size = leb();
|
|
177
|
+
const body = offset;
|
|
178
|
+
const next = Math.min(end, body + size);
|
|
179
|
+
if (id === 0) {
|
|
180
|
+
offset = body;
|
|
181
|
+
const length = leb();
|
|
182
|
+
const name = decoder.decode(bytes.subarray(offset, offset + length));
|
|
183
|
+
if (name === ENCFS_SECTION)
|
|
184
|
+
return decoder.decode(bytes.subarray(offset + length, next));
|
|
185
|
+
}
|
|
186
|
+
else if (component && (id === 1 || id === 4)) {
|
|
187
|
+
const found = walk(body, next);
|
|
188
|
+
if (found !== undefined)
|
|
189
|
+
return found;
|
|
190
|
+
}
|
|
191
|
+
offset = next;
|
|
192
|
+
}
|
|
193
|
+
return undefined;
|
|
194
|
+
};
|
|
195
|
+
return walk(0, bytes.length);
|
|
196
|
+
}
|
package/dist/pglite.d.ts
CHANGED
|
@@ -24,6 +24,45 @@ export declare const EXCLUSIVE_INSTANCE_KEY = "di-framework.dev/exclusive-instan
|
|
|
24
24
|
export declare const DEFAULT_PGLITE_STORAGE_MOUNT = "/data";
|
|
25
25
|
/** File name of the provider inside a cache entry. */
|
|
26
26
|
export declare const PGLITE_WASM_FILE = "di-framework-pglite.wasm";
|
|
27
|
+
/**
|
|
28
|
+
* Encrypting `wasi:filesystem` layer for the provider (`pglite.encryption`), published by
|
|
29
|
+
* di-framework/platform. The build composes it into the provider with an explicit `wac compose`
|
|
30
|
+
* document (`.di-framework/pglite-encryption.wac`, see `encryptProvider`) before the provider is
|
|
31
|
+
* plugged into the guest, so only the engine sees the encrypted view.
|
|
32
|
+
*/
|
|
33
|
+
export declare const PGLITE_ENCFS_REPOSITORY = "ghcr.io/di-framework/pglite-encfs";
|
|
34
|
+
/** Absolute (or cwd-relative) path of a local encryption layer build; wins over the config. */
|
|
35
|
+
export declare const PGLITE_ENCFS_WASM_ENV = "DI_FRAMEWORK_PGLITE_ENCFS_WASM";
|
|
36
|
+
/** File name of the encryption layer inside a cache entry. */
|
|
37
|
+
export declare const PGLITE_ENCFS_WASM_FILE = "di-framework-pglite-encfs.wasm";
|
|
38
|
+
/** The provider with the encryption layer plugged in, as the build plugs it into the guest. */
|
|
39
|
+
export declare const PGLITE_ENCRYPTED_WASM_FILE = "di-framework-pglite.encrypted.wasm";
|
|
40
|
+
/**
|
|
41
|
+
* The guest environment variable the encryption layer reads its master key from. It must come
|
|
42
|
+
* from the control Secret, so the project declares it in `controlSecretKeys`.
|
|
43
|
+
*/
|
|
44
|
+
export declare const PGLITE_KEY_ENV = "DI_PGLITE_KEY";
|
|
45
|
+
/** A digest-pinned component the CLI pulls: the provider or its encryption layer. */
|
|
46
|
+
export type PinnedComponent = {
|
|
47
|
+
/** How messages name it. */
|
|
48
|
+
label: string;
|
|
49
|
+
/** The config object that pins it: `pglite` or `pglite.encryption`. */
|
|
50
|
+
field: string;
|
|
51
|
+
repository: string;
|
|
52
|
+
/** Environment variable naming a local build. */
|
|
53
|
+
localEnv: string;
|
|
54
|
+
/** File name inside a cache entry. */
|
|
55
|
+
file: string;
|
|
56
|
+
};
|
|
57
|
+
export declare const PGLITE_PROVIDER: PinnedComponent;
|
|
58
|
+
export declare const PGLITE_ENCFS: PinnedComponent;
|
|
59
|
+
/** `pglite.encryption`, resolved: where the encryption layer comes from. */
|
|
60
|
+
export type PgliteEncryptionConfig = {
|
|
61
|
+
/** `<repository>@sha256:<hex>` of the encryption layer. */
|
|
62
|
+
image?: string;
|
|
63
|
+
/** Absolute path of a local encryption layer build, used instead of `image`. */
|
|
64
|
+
wasm?: string;
|
|
65
|
+
};
|
|
27
66
|
/** `pglite` in di-framework.config.json, resolved. */
|
|
28
67
|
export type PgliteConfig = {
|
|
29
68
|
/** `<repository>@sha256:<hex>`; the manifest digest the platform publish job records. */
|
|
@@ -34,6 +73,8 @@ export type PgliteConfig = {
|
|
|
34
73
|
storageMount: string;
|
|
35
74
|
/** Database root the guest opens; at or under `storageMount`. */
|
|
36
75
|
dataDir: string;
|
|
76
|
+
/** Encrypt the data directory at rest with this layer, keyed by `DI_PGLITE_KEY`. */
|
|
77
|
+
encryption?: PgliteEncryptionConfig;
|
|
37
78
|
};
|
|
38
79
|
export type ResolvedPglite = {
|
|
39
80
|
/** Verified provider bytes; the build plugs a private copy of these. */
|
|
@@ -44,7 +85,7 @@ export type ResolvedPglite = {
|
|
|
44
85
|
/** The local file, when the bytes came from one. */
|
|
45
86
|
path?: string;
|
|
46
87
|
};
|
|
47
|
-
export declare function parseDigestReference(reference: string): {
|
|
88
|
+
export declare function parseDigestReference(reference: string, repository?: string): {
|
|
48
89
|
repository: string;
|
|
49
90
|
digest: string;
|
|
50
91
|
};
|
|
@@ -68,9 +109,16 @@ export declare const STALE_STAGING_MS: number;
|
|
|
68
109
|
* digest, into the cache. A cached entry is re-verified on every use; a corrupt one is
|
|
69
110
|
* pulled again. Returns the verified bytes, so later readers never see a swapped file.
|
|
70
111
|
*/
|
|
71
|
-
export declare function pullPgliteComponent(image: string, io: CliIo, deps: WasmcloudDeps, cwd: string): Promise<ResolvedPglite>;
|
|
112
|
+
export declare function pullPgliteComponent(image: string, io: CliIo, deps: WasmcloudDeps, cwd: string, component?: PinnedComponent): Promise<ResolvedPglite>;
|
|
72
113
|
/** Set to `1` to let `deploy` or a CI build use a local, unverified provider. */
|
|
73
114
|
export declare const ALLOW_LOCAL_PGLITE_ENV = "DI_FRAMEWORK_ALLOW_LOCAL_PGLITE";
|
|
115
|
+
/**
|
|
116
|
+
* Options for resolving PGlite components.
|
|
117
|
+
*
|
|
118
|
+
* Note: `buildComponent(..., { deploy: true })` enforces the deploy-time refusal of unverified
|
|
119
|
+
* local providers, whereas calling the lower-level `publishComponent` API directly publishes an
|
|
120
|
+
* already-built `.wasm` without re-running provider resolution.
|
|
121
|
+
*/
|
|
74
122
|
export type ResolvePgliteOptions = {
|
|
75
123
|
/** A deploy ships the provider, so a local file needs the explicit opt-in. */
|
|
76
124
|
deploy?: boolean;
|
|
@@ -79,12 +127,21 @@ export type ResolvePgliteOptions = {
|
|
|
79
127
|
* The provider to compose: `DI_FRAMEWORK_PGLITE_WASM`, then `pglite.wasm`, then the
|
|
80
128
|
* digest-pinned `pglite.image`. Local files are only checked to be WebAssembly, and are
|
|
81
129
|
* refused in a deploy or on CI without `DI_FRAMEWORK_ALLOW_LOCAL_PGLITE=1`.
|
|
130
|
+
* Note that `buildComponent(..., { deploy: true })` enforces this deploy-time refusal, whereas
|
|
131
|
+
* calling the lower-level `publishComponent` API directly publishes an already-built `.wasm`
|
|
132
|
+
* without re-running provider resolution.
|
|
82
133
|
*/
|
|
83
134
|
export declare function resolvePgliteComponent(config: PgliteConfig, io: CliIo, deps: WasmcloudDeps, projectRoot: string, options?: ResolvePgliteOptions): Promise<ResolvedPglite>;
|
|
135
|
+
/**
|
|
136
|
+
* The encryption layer to plug into the provider, resolved like the provider:
|
|
137
|
+
* `DI_FRAMEWORK_PGLITE_ENCFS_WASM`, then `pglite.encryption.wasm`, then the digest-pinned
|
|
138
|
+
* `pglite.encryption.image`, with the same local-file refusal in a deploy or on CI.
|
|
139
|
+
*/
|
|
140
|
+
export declare function resolvePgliteEncryption(config: PgliteEncryptionConfig, io: CliIo, deps: WasmcloudDeps, projectRoot: string, options?: ResolvePgliteOptions): Promise<ResolvedPglite>;
|
|
84
141
|
/**
|
|
85
142
|
* Members of one workload share one storage directory, mounted at each member's own
|
|
86
|
-
* `storageMount`. Two members whose `dataDir` is the same path relative to their mount
|
|
87
|
-
* would open
|
|
143
|
+
* `storageMount`. Two members whose `dataDir` is the same or a nested path relative to their mount
|
|
144
|
+
* would open overlapping database directories from separate instances, which exclusivity cannot stop.
|
|
88
145
|
*/
|
|
89
146
|
export declare function assertDistinctPgliteRoots(workload: string, members: Iterable<{
|
|
90
147
|
applicationName: string;
|