@capybara-hq/kernel 0.1.0-rc.145 → 0.1.0-rc.147
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/admin/extensions.controller.d.ts +0 -11
- package/dist/admin/extensions.controller.js +0 -28
- package/dist/admin/health.service.d.ts +25 -1
- package/dist/admin/health.service.js +50 -18
- package/dist/audit/full-access.d.ts +78 -0
- package/dist/audit/full-access.js +283 -0
- package/dist/automations/automations.service.d.ts +1 -0
- package/dist/automations/automations.service.js +3 -1
- package/dist/automations/calendar.js +3 -1
- package/dist/automations/grant-rules.d.ts +2 -1
- package/dist/automations/grant-rules.js +8 -1
- package/dist/automations/unattended.d.ts +13 -1
- package/dist/automations/unattended.js +13 -1
- package/dist/catalog/admin-catalog.controller.d.ts +8 -0
- package/dist/catalog/admin-catalog.controller.js +8 -2
- package/dist/catalog/admin-catalog.schemas.d.ts +10 -0
- package/dist/catalog/admin-catalog.schemas.js +8 -1
- package/dist/catalog/catalog-content.d.ts +6 -0
- package/dist/catalog/catalog-scope.service.d.ts +22 -2
- package/dist/catalog/catalog-scope.service.js +27 -3
- package/dist/catalog/catalog.service.js +19 -2
- package/dist/catalog/marketplaces.service.d.ts +1 -1
- package/dist/catalog/org-catalog.service.d.ts +8 -1
- package/dist/catalog/org-catalog.service.js +36 -3
- package/dist/catalog/platform-components.js +3 -2
- package/dist/catalog/platform-import-update.d.ts +2 -0
- package/dist/catalog/platform-import-update.js +8 -1
- package/dist/catalog/plugin-connectors.d.ts +11 -0
- package/dist/catalog/plugin-connectors.js +33 -0
- package/dist/catalog/plugin-import.d.ts +35 -15
- package/dist/catalog/plugin-import.js +110 -35
- package/dist/catalog/plugin-install.js +6 -0
- package/dist/catalog/provenance.d.ts +71 -0
- package/dist/catalog/provenance.js +112 -0
- package/dist/config/auto-approve.d.ts +16 -0
- package/dist/config/auto-approve.js +24 -0
- package/dist/config/capacity-presets.d.ts +243 -0
- package/dist/config/capacity-presets.js +195 -0
- package/dist/config/env.d.ts +2 -1
- package/dist/config/env.js +6 -1
- package/dist/config/load.js +15 -0
- package/dist/config/schema.d.ts +46 -9
- package/dist/config/schema.js +154 -30
- package/dist/ctx/create-ctx.d.ts +16 -0
- package/dist/ctx/create-ctx.js +269 -34
- package/dist/ctx/net.d.ts +5 -1
- package/dist/ctx/net.js +62 -12
- package/dist/db/kernel-schema.d.ts +31 -0
- package/dist/db/migrator.js +0 -36
- package/dist/dial-in/routes.js +1 -1
- package/dist/erasure/org-batches.js +1 -6
- package/dist/erasure/org-catalog.js +6 -2
- package/dist/erasure/org-rules.js +1 -0
- package/dist/erasure/org-worker.js +0 -13
- package/dist/errors.d.ts +6 -0
- package/dist/errors.js +6 -0
- package/dist/extensions/admin-ops.d.ts +14 -1
- package/dist/extensions/admin-ops.js +30 -3
- package/dist/extensions/admin-view.d.ts +21 -1
- package/dist/extensions/admin-view.js +43 -0
- package/dist/extensions/bootstrap-packages.d.ts +5 -0
- package/dist/extensions/bootstrap-packages.js +1 -1
- package/dist/extensions/bootstrap-review.d.ts +251 -0
- package/dist/extensions/bootstrap-review.js +676 -0
- package/dist/extensions/bootstrap.d.ts +21 -1
- package/dist/extensions/bootstrap.js +72 -2
- package/dist/extensions/cli.d.ts +6 -0
- package/dist/extensions/cli.js +4 -0
- package/dist/extensions/enabled.d.ts +3 -0
- package/dist/extensions/execution-realm.d.ts +96 -0
- package/dist/extensions/execution-realm.js +141 -0
- package/dist/extensions/extensions.module.js +12 -0
- package/dist/extensions/full-access-disclosure.d.ts +15 -0
- package/dist/extensions/full-access-disclosure.js +57 -0
- package/dist/extensions/grant-epoch.d.ts +9 -2
- package/dist/extensions/grant-epoch.js +13 -2
- package/dist/extensions/host.d.ts +96 -4
- package/dist/extensions/host.js +411 -33
- package/dist/extensions/installs.d.ts +18 -0
- package/dist/extensions/installs.js +28 -0
- package/dist/extensions/instance.d.ts +2 -0
- package/dist/extensions/instance.js +1 -0
- package/dist/extensions/isolated/admission.d.ts +23 -2
- package/dist/extensions/isolated/admission.js +32 -7
- package/dist/extensions/isolated/authorization.d.ts +8 -2
- package/dist/extensions/isolated/authorization.js +11 -3
- package/dist/extensions/isolated/broker.d.ts +3 -0
- package/dist/extensions/isolated/broker.js +50 -14
- package/dist/extensions/isolated/configured-package.d.ts +5 -0
- package/dist/extensions/isolated/configured-package.js +2 -0
- package/dist/extensions/isolated/lanes.d.ts +44 -3
- package/dist/extensions/isolated/lanes.js +263 -80
- package/dist/extensions/isolated/metrics.d.ts +146 -0
- package/dist/extensions/isolated/metrics.js +304 -0
- package/dist/extensions/isolated/revision.d.ts +7 -1
- package/dist/extensions/isolated/revision.js +26 -5
- package/dist/extensions/isolated/rpc.d.ts +5 -0
- package/dist/extensions/isolated/rpc.js +7 -2
- package/dist/extensions/isolated/sandbox.d.ts +23 -0
- package/dist/extensions/isolated/sandbox.js +50 -0
- package/dist/extensions/isolated/status.d.ts +79 -0
- package/dist/extensions/isolated/status.js +216 -0
- package/dist/extensions/isolated/tier.d.ts +127 -2
- package/dist/extensions/isolated/tier.js +266 -7
- package/dist/extensions/isolated/usage.d.ts +134 -0
- package/dist/extensions/isolated/usage.js +322 -0
- package/dist/extensions/ledger.d.ts +5 -0
- package/dist/extensions/ledger.js +16 -0
- package/dist/extensions/lifecycle.d.ts +42 -2
- package/dist/extensions/lifecycle.js +100 -4
- package/dist/extensions/org-config.js +11 -0
- package/dist/extensions/package.d.ts +14 -0
- package/dist/extensions/package.js +23 -0
- package/dist/extensions/permission-view.d.ts +2 -2
- package/dist/extensions/permissions.controller.d.ts +35 -0
- package/dist/extensions/permissions.controller.js +98 -0
- package/dist/extensions/permissions.schemas.d.ts +288 -0
- package/dist/extensions/permissions.schemas.js +96 -0
- package/dist/extensions/permissions.service.d.ts +116 -0
- package/dist/extensions/permissions.service.js +428 -0
- package/dist/extensions/realm-retirement.d.ts +65 -0
- package/dist/extensions/realm-retirement.js +150 -0
- package/dist/extensions/registry.d.ts +6 -0
- package/dist/extensions/registry.js +8 -0
- package/dist/extensions/review-hash.d.ts +114 -0
- package/dist/extensions/review-hash.js +145 -0
- package/dist/extensions/revision-approvals.d.ts +58 -3
- package/dist/extensions/revision-approvals.js +135 -14
- package/dist/extensions/revision-grants.d.ts +10 -0
- package/dist/extensions/revision-review.d.ts +144 -0
- package/dist/extensions/revision-review.js +297 -0
- package/dist/extensions/revocation-leases.d.ts +273 -0
- package/dist/extensions/revocation-leases.js +533 -0
- package/dist/extensions/revocation.d.ts +78 -0
- package/dist/extensions/revocation.js +205 -0
- package/dist/extensions/state.module.js +12 -0
- package/dist/git/run-end.d.ts +35 -7
- package/dist/git/run-end.js +87 -38
- package/dist/http/api.module.js +2 -0
- package/dist/identity/audit.d.ts +2 -1
- package/dist/identity/audit.js +4 -17
- package/dist/index.d.ts +10 -2
- package/dist/index.js +10 -2
- package/dist/infra/config/kernel-config.service.d.ts +6 -0
- package/dist/infra/config/kernel-config.service.js +21 -0
- package/dist/infra/outbox/registry.d.ts +13 -0
- package/dist/infra/outbox/registry.js +8 -0
- package/dist/lifecycle/kernel-lifecycle.d.ts +27 -1
- package/dist/lifecycle/kernel-lifecycle.js +83 -22
- package/dist/net/private-endpoint-preflight.d.ts +159 -0
- package/dist/net/private-endpoint-preflight.js +417 -0
- package/dist/net/private-endpoints.d.ts +68 -0
- package/dist/net/private-endpoints.js +164 -0
- package/dist/net/public-address.d.ts +14 -0
- package/dist/net/public-address.js +15 -1
- package/dist/net/safe-fetch.d.ts +2 -1
- package/dist/net/safe-fetch.js +10 -3
- package/dist/overrides.d.ts +9 -1
- package/dist/overrides.js +4 -0
- package/dist/packages/official-publisher.d.ts +65 -1
- package/dist/packages/official-publisher.js +171 -46
- package/dist/packages/provenance.d.ts +11 -0
- package/dist/packages/provenance.js +24 -0
- package/dist/platform/exclusions.js +4 -4
- package/dist/platform/ops/automations.ops.js +1 -1
- package/dist/platform/ops/catalog-admin.ops.js +25 -4
- package/dist/platform/ops/extension-permissions.ops.d.ts +11 -0
- package/dist/platform/ops/extension-permissions.ops.js +159 -0
- package/dist/platform/platform-ops.module.d.ts +2 -1
- package/dist/platform/platform-ops.module.js +2 -0
- package/dist/platform/route-schemas.js +2 -0
- package/dist/retention/purge-batch.js +10 -14
- package/dist/runtime/maintenance.d.ts +4 -2
- package/dist/runtime/maintenance.js +16 -3
- package/dist/runtime/run-finish.d.ts +3 -3
- package/dist/runtime/run-finish.js +7 -3
- package/dist/sandbox/permission-availability.d.ts +17 -2
- package/dist/sandbox/permission-availability.js +22 -1
- package/dist/sandbox/permission-facts.js +7 -1
- package/dist/tools/builtins/sandbox/common.js +2 -0
- package/dist/tools/pipeline.d.ts +2 -1
- package/dist/tools/pipeline.js +7 -2
- package/package.json +4 -3
- package/src/migrations/0238_extension_usage.sql +40 -0
- package/src/migrations/0239_extension_replica_isolation.sql +28 -0
package/dist/ctx/create-ctx.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CONVERSATION_TARGET_EXTENSION_POINT, CtxReadError, DEVICE_PROVIDER_EXTENSION_POINT, DeviceAccessError, ExtensionPermissionError, FILE_PREVIEW_EXTENSION_POINT, InboxError, resolveUiSlots, SETUP_CHECK_ID_RE, SETUP_GUIDE_PLACES, TriggerError, validateFilePreviewProvider, validateToolSpec, } from "@capybara-hq/plugin-sdk";
|
|
1
|
+
import { AGENTS_KEY, CONVERSATION_TARGET_EXTENSION_POINT, CONVERSATIONS_KEY, CtxReadError, DEVICE_ACCESS_KEY_PREFIX, DEVICE_HOST_KEY_PREFIX, DEVICE_LOOPBACK_PORTS_KEY, DEVICE_PROVIDER_EXTENSION_POINT, DEVICE_SITE_ACCESS_KEY, DeviceAccessError, DIAL_IN_KEY_PREFIX, ExtensionPermissionError, FILE_PREVIEW_EXTENSION_POINT, INBOX_KEY, InboxError, PEOPLE_KEY, POLICY_HOOK_KEY_PREFIX, resolveUiSlots, SETUP_CHECK_ID_RE, SETUP_CHECK_KEY_PREFIX, SETUP_GUIDE_PLACES, TRIGGERS_KEY_PREFIX, TriggerError, UI_COMPONENT_KEY_PREFIX, UI_VIEW_KEY_PREFIX, validateFilePreviewProvider, validateToolSpec, } from "@capybara-hq/plugin-sdk";
|
|
2
2
|
import { conversationTopic } from "../conversations/event-log.js";
|
|
3
3
|
import { checkExternalText } from "../conversations/external/external-calls.js";
|
|
4
4
|
import { pluginSchemaName } from "../db/extension-db.js";
|
|
@@ -226,35 +226,85 @@ identity = { sha256: null }) {
|
|
|
226
226
|
audits.add(p);
|
|
227
227
|
throw new ExtensionPermissionError(name, item);
|
|
228
228
|
};
|
|
229
|
+
// Revocation (plan task 1.3e): the lease of this instance's revision grant. Once enforcing (plan
|
|
230
|
+
// task 1.5a), a capability key the grant no longer serves is refused (ExtensionPermissionError,
|
|
231
|
+
// audited like any denial) and the handles opened under it are aborted; unaffected keys keep
|
|
232
|
+
// serving. In shadow mode the lease only reports what it would refuse and never waits.
|
|
233
|
+
const lease = deps.leases?.open({
|
|
234
|
+
plugin: name,
|
|
235
|
+
sha256: identity.sha256,
|
|
236
|
+
inProcess: identity.inProcess ?? true,
|
|
237
|
+
});
|
|
238
|
+
const revoked = async (key) => {
|
|
239
|
+
if (lease && !(await lease.check(key)))
|
|
240
|
+
deny(`revoked ${key}`);
|
|
241
|
+
};
|
|
242
|
+
/** Refused only when every one of `keys` is refused (a call that may use any of them). */
|
|
243
|
+
const revokedAll = async (keys, item) => {
|
|
244
|
+
if (!lease || keys.length === 0)
|
|
245
|
+
return;
|
|
246
|
+
for (const key of keys)
|
|
247
|
+
if (await lease.check(key))
|
|
248
|
+
return;
|
|
249
|
+
deny(`revoked ${item}`);
|
|
250
|
+
};
|
|
251
|
+
/** The instance's signal, also aborted when `key` is revoked or the lease is fenced. */
|
|
252
|
+
const leaseSignal = (key) => lease ? AbortSignal.any([lifecycle.signal, lease.signal(key)]) : lifecycle.signal;
|
|
253
|
+
/** Every async method of `api` checks its key first. */
|
|
254
|
+
const leased = (api, key) => lease
|
|
255
|
+
? new Proxy(api, {
|
|
256
|
+
get(target, prop, receiver) {
|
|
257
|
+
const value = Reflect.get(target, prop, receiver);
|
|
258
|
+
if (typeof value !== "function")
|
|
259
|
+
return value;
|
|
260
|
+
return async (...args) => {
|
|
261
|
+
await revoked(key);
|
|
262
|
+
return value.apply(target, args);
|
|
263
|
+
};
|
|
264
|
+
},
|
|
265
|
+
})
|
|
266
|
+
: api;
|
|
229
267
|
// 只暴露插件契约中的 get / set(KernelSecrets 的 delete 仅供内核使用)
|
|
230
268
|
const secretsApi = perms.secrets
|
|
231
|
-
? (({ get, set }) => ({ get, set }))(createSecrets(deps.db, deps.keyring, name))
|
|
269
|
+
? leased((({ get, set }) => ({ get, set }))(createSecrets(deps.db, deps.keyring, name)), "permissions.secrets")
|
|
232
270
|
: undefined;
|
|
233
271
|
// ctx.storage:经已加载的 object-store@1 提供方(按调用时取;依赖排序保证提供方先于本插件 setup),
|
|
234
272
|
// 键加前缀 plugins/<name>/<orgId>/。没有提供方时各方法 reject storage.unavailable
|
|
235
273
|
// (宿主不会加载这样的插件,见 approvals.ts;单独构造 ctx 的测试会走到这里)
|
|
236
274
|
const storageApi = perms.storage
|
|
237
|
-
? new PrefixedStorage({
|
|
275
|
+
? leased(new PrefixedStorage({
|
|
238
276
|
provider: objectStore,
|
|
239
277
|
plugins: async () => [name],
|
|
240
|
-
}).forPlugin(name)
|
|
278
|
+
}).forPlugin(name), "permissions.storage")
|
|
241
279
|
: undefined;
|
|
242
280
|
// ctx.models: only with permissions.models; each broker accepts only the purposes declared there
|
|
243
281
|
// with its kind (embedding: spec B §5.4; image_generation: image generation spec §5.5), aborted
|
|
244
282
|
// by this instance's signal
|
|
245
283
|
// a frozen copy: the approved manifest, not an object the extension could change later
|
|
246
284
|
const declaredModels = Object.freeze(structuredClone(perms.models ?? []).map((m) => Object.freeze(m)));
|
|
285
|
+
/** The permission key of a declared model purpose (undefined: not declared, the broker refuses). */
|
|
286
|
+
const modelKey = (req) => {
|
|
287
|
+
const purpose = req?.purpose;
|
|
288
|
+
const declared = declaredModels.find((d) => d.purpose === purpose);
|
|
289
|
+
return declared ? `permissions.models:${declared.purpose} (${declared.kind})` : undefined;
|
|
290
|
+
};
|
|
247
291
|
const modelsApi = declaredModels.length > 0
|
|
248
292
|
? {
|
|
249
293
|
embed: async (req) => {
|
|
250
294
|
if (!deps.models)
|
|
251
295
|
throw new Error(`plugin ${name}: ctx.models is not available`);
|
|
252
|
-
|
|
296
|
+
const key = modelKey(req);
|
|
297
|
+
if (key !== undefined)
|
|
298
|
+
await revoked(key);
|
|
299
|
+
return deps.models.embeddings.embed(name, declaredModels, req, key === undefined ? lifecycle.signal : leaseSignal(key), deps.hooks);
|
|
253
300
|
},
|
|
254
301
|
generateImage: async (req) => {
|
|
255
302
|
if (!deps.models)
|
|
256
303
|
throw new Error(`plugin ${name}: ctx.models is not available`);
|
|
257
|
-
|
|
304
|
+
const key = modelKey(req);
|
|
305
|
+
if (key !== undefined)
|
|
306
|
+
await revoked(key);
|
|
307
|
+
return deps.models.images.generateForExtension(name, declaredModels, req, key === undefined ? lifecycle.signal : leaseSignal(key), deps.hooks);
|
|
258
308
|
},
|
|
259
309
|
// by the declared purpose's kind; an undeclared purpose has none, so its refusal
|
|
260
310
|
// (model.purpose_unknown) names no kind
|
|
@@ -271,6 +321,9 @@ identity = { sha256: null }) {
|
|
|
271
321
|
if (typeof orgId !== "string" || orgId === "" || typeof purpose !== "string") {
|
|
272
322
|
throw new ApiError("validation_failed", "describe needs orgId and purpose strings");
|
|
273
323
|
}
|
|
324
|
+
const key = modelKey(req);
|
|
325
|
+
if (key !== undefined)
|
|
326
|
+
await revoked(key);
|
|
274
327
|
const target = { orgId, purpose };
|
|
275
328
|
return withOrgScope(orgId, () => kind === "image_generation"
|
|
276
329
|
? models.images.describeForExtension(name, declaredModels, target)
|
|
@@ -285,9 +338,11 @@ identity = { sha256: null }) {
|
|
|
285
338
|
const dialInApi = perms.dialIn
|
|
286
339
|
? (() => {
|
|
287
340
|
const access = deps.dialIn;
|
|
341
|
+
const dialInKey = `${DIAL_IN_KEY_PREFIX}${perms.dialIn?.protocol}`;
|
|
288
342
|
const inServedOrg = async (deviceId, run) => {
|
|
289
343
|
if (!access)
|
|
290
344
|
throw new Error(`plugin ${name}: ctx.dialIn is not available`);
|
|
345
|
+
await revoked(dialInKey);
|
|
291
346
|
const orgId = typeof deviceId === "string" ? await access.servedOrg(name, deviceId) : undefined;
|
|
292
347
|
if (orgId === undefined) {
|
|
293
348
|
const item = `dialIn:device ${String(deviceId)}`;
|
|
@@ -302,8 +357,8 @@ identity = { sha256: null }) {
|
|
|
302
357
|
return {
|
|
303
358
|
request: (deviceId, frame, opts) => inServedOrg(deviceId, (dialIn) => {
|
|
304
359
|
const signal = opts?.signal
|
|
305
|
-
? AbortSignal.any([
|
|
306
|
-
:
|
|
360
|
+
? AbortSignal.any([leaseSignal(dialInKey), opts.signal])
|
|
361
|
+
: leaseSignal(dialInKey);
|
|
307
362
|
// Only the options an extension may pass, excluding the kernel's connection fences.
|
|
308
363
|
return dialIn.request(deviceId, frame, {
|
|
309
364
|
timeoutMs: Number(opts?.timeoutMs),
|
|
@@ -322,14 +377,16 @@ identity = { sha256: null }) {
|
|
|
322
377
|
openStream: (deviceId, body, opts) => inServedOrg(deviceId, async (dialIn) => {
|
|
323
378
|
if (!(opts?.signal instanceof AbortSignal))
|
|
324
379
|
throw new TypeError(`plugin ${name}: ctx.dialIn.openStream needs opts.signal`);
|
|
325
|
-
|
|
380
|
+
// the stream closes when the instance stops or its dial-in permission is revoked
|
|
381
|
+
const held = leaseSignal(dialInKey);
|
|
382
|
+
const signal = AbortSignal.any([held, opts.signal]);
|
|
326
383
|
const stream = await dialIn.openStream(deviceId, body, signal);
|
|
327
|
-
const onEnd = () => stream.close("extension stopped");
|
|
328
|
-
if (
|
|
384
|
+
const onEnd = () => stream.close(lifecycle.signal.aborted ? "extension stopped" : "extension permission revoked");
|
|
385
|
+
if (held.aborted)
|
|
329
386
|
onEnd();
|
|
330
387
|
else {
|
|
331
|
-
|
|
332
|
-
void stream.closed.then(() =>
|
|
388
|
+
held.addEventListener("abort", onEnd, { once: true });
|
|
389
|
+
void stream.closed.then(() => held.removeEventListener("abort", onEnd));
|
|
333
390
|
}
|
|
334
391
|
return stream;
|
|
335
392
|
}),
|
|
@@ -405,24 +462,73 @@ identity = { sha256: null }) {
|
|
|
405
462
|
throw new DeviceAccessError("capability_missing", "Device services are not available in this process.");
|
|
406
463
|
return b;
|
|
407
464
|
};
|
|
465
|
+
// revocation: a call naming a service needs that service's key; the others need any of
|
|
466
|
+
// the services still granted (plan task 1.3e)
|
|
467
|
+
const serviceKeys = caller.services.map((svc) => `${DEVICE_ACCESS_KEY_PREFIX}${svc}`);
|
|
468
|
+
const service = (svc) => revoked(`${DEVICE_ACCESS_KEY_PREFIX}${String(svc)}`);
|
|
469
|
+
const host = (svc) => revoked(`${DEVICE_HOST_KEY_PREFIX}${String(svc)}`);
|
|
470
|
+
const anyService = () => revokedAll(serviceKeys, "permissions.deviceaccess");
|
|
471
|
+
const nameOf = (spec) => spec?.name;
|
|
472
|
+
const serviceOf = (req) => req?.service;
|
|
408
473
|
return {
|
|
409
|
-
ensureService: async (call, spec) =>
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
474
|
+
ensureService: async (call, spec) => {
|
|
475
|
+
await service(nameOf(spec));
|
|
476
|
+
return backend().ensureService(caller, call, spec);
|
|
477
|
+
},
|
|
478
|
+
request: async (call, req) => {
|
|
479
|
+
await service(serviceOf(req));
|
|
480
|
+
return backend().request(caller, call, req);
|
|
481
|
+
},
|
|
482
|
+
reportBlockedHosts: async (call, hosts, opts) => {
|
|
483
|
+
await anyService();
|
|
484
|
+
return backend().reportBlockedHosts(caller, call, hosts, opts);
|
|
485
|
+
},
|
|
486
|
+
streamTicket: async (scope) => {
|
|
487
|
+
await anyService();
|
|
488
|
+
return backend().streamTicket(caller, scope);
|
|
489
|
+
},
|
|
490
|
+
addNetworkHosts: async (scope) => {
|
|
491
|
+
await anyService();
|
|
492
|
+
return backend().addNetworkHosts(caller, scope);
|
|
493
|
+
},
|
|
494
|
+
answerHandoff: async (scope) => {
|
|
495
|
+
await anyService();
|
|
496
|
+
return backend().answerHandoff(caller, scope);
|
|
497
|
+
},
|
|
498
|
+
grantLoopbackPort: async (scope) => {
|
|
499
|
+
await revoked(DEVICE_LOOPBACK_PORTS_KEY);
|
|
500
|
+
return backend().grantLoopbackPort(caller, scope);
|
|
501
|
+
},
|
|
502
|
+
// withdrawing a grant stays possible after the permission is revoked
|
|
416
503
|
revokeLoopbackPort: async (scope) => backend().revokeLoopbackPort(caller, scope),
|
|
417
|
-
loopbackPorts: async (scope) =>
|
|
418
|
-
|
|
419
|
-
|
|
504
|
+
loopbackPorts: async (scope) => {
|
|
505
|
+
await revoked(DEVICE_LOOPBACK_PORTS_KEY);
|
|
506
|
+
return backend().loopbackPorts(caller, scope);
|
|
507
|
+
},
|
|
508
|
+
requestSiteAccess: async (call, ask) => {
|
|
509
|
+
await revoked(DEVICE_SITE_ACCESS_KEY);
|
|
510
|
+
return backend().requestSiteAccess(caller, call, ask);
|
|
511
|
+
},
|
|
512
|
+
siteGrants: async (scope) => {
|
|
513
|
+
await revoked(DEVICE_SITE_ACCESS_KEY);
|
|
514
|
+
return backend().siteGrants(caller, scope);
|
|
515
|
+
},
|
|
420
516
|
revokeSiteGrant: async (scope) => backend().revokeSiteGrant(caller, scope),
|
|
421
517
|
// host services: the approved manifest's hostServices, on the person's own machine
|
|
422
|
-
ensureHostService: async (at, spec) =>
|
|
423
|
-
|
|
518
|
+
ensureHostService: async (at, spec) => {
|
|
519
|
+
await host(nameOf(spec));
|
|
520
|
+
return backend().ensureHostService(caller, at, spec);
|
|
521
|
+
},
|
|
522
|
+
hostRequest: async (at, req) => {
|
|
523
|
+
await host(serviceOf(req));
|
|
524
|
+
return backend().hostRequest(caller, at, req);
|
|
525
|
+
},
|
|
526
|
+
// stopping stays possible after the permission is revoked
|
|
424
527
|
stopHostService: async (at, service) => backend().stopHostService(caller, at, service),
|
|
425
|
-
personalDevices: async (args) =>
|
|
528
|
+
personalDevices: async (args) => {
|
|
529
|
+
await anyService();
|
|
530
|
+
return backend().personalDevices(caller, args);
|
|
531
|
+
},
|
|
426
532
|
// during setup only, for a host service of the approved manifest: the deliveries
|
|
427
533
|
// (ServiceEvents, worker role) call it on whichever replica takes the job
|
|
428
534
|
onServiceEvent: (service, handler) => {
|
|
@@ -481,6 +587,7 @@ identity = { sha256: null }) {
|
|
|
481
587
|
return { status: "staged", idempotencyKey: key };
|
|
482
588
|
};
|
|
483
589
|
const addOutbox = (async (effect, options) => {
|
|
590
|
+
await revoked("permissions.outbox");
|
|
484
591
|
const snapshot = structuredClone(effect);
|
|
485
592
|
if (!snapshot?.orgId || typeof snapshot.orgId !== "string") {
|
|
486
593
|
throw new Error("An extension outbox effect requires an org id");
|
|
@@ -505,6 +612,7 @@ identity = { sha256: null }) {
|
|
|
505
612
|
const snap = snapshotTriggerEvent(event);
|
|
506
613
|
if (typeof snap.orgId !== "string" || snap.orgId === "")
|
|
507
614
|
throw new TriggerError("invalid_event", "invalid event: missing_org_id");
|
|
615
|
+
await revoked(`${TRIGGERS_KEY_PREFIX}${String(snap.type)}`);
|
|
508
616
|
return durable(snap.orgId, { kind: "trigger", data: snap }, options);
|
|
509
617
|
}),
|
|
510
618
|
// a handle bound to this extension and the call's run, in the call's org (the service
|
|
@@ -513,6 +621,7 @@ identity = { sha256: null }) {
|
|
|
513
621
|
const b = deps.triggers?.();
|
|
514
622
|
if (!b)
|
|
515
623
|
throw new Error("Trigger events are not available in this process.");
|
|
624
|
+
await revokedAll((perms.triggers?.emit ?? []).map((type) => `${TRIGGERS_KEY_PREFIX}${type}`), "permissions.triggers");
|
|
516
625
|
const orgId = typeof call === "object" && call !== null ? call.orgId : "";
|
|
517
626
|
if (typeof orgId !== "string" || orgId === "")
|
|
518
627
|
throw new TriggerError("invalid_event", "causeOf takes the tool call context the kernel passed to the handler");
|
|
@@ -528,6 +637,7 @@ identity = { sha256: null }) {
|
|
|
528
637
|
const inboxApi = perms.inbox
|
|
529
638
|
? {
|
|
530
639
|
post: (async (p, options) => {
|
|
640
|
+
await revoked(INBOX_KEY);
|
|
531
641
|
let snap;
|
|
532
642
|
try {
|
|
533
643
|
snap = structuredClone(p);
|
|
@@ -546,6 +656,7 @@ identity = { sha256: null }) {
|
|
|
546
656
|
const b = deps.inbox?.();
|
|
547
657
|
if (!b)
|
|
548
658
|
throw new Error("The inbox is not available in this process.");
|
|
659
|
+
await revoked(INBOX_KEY);
|
|
549
660
|
const orgId = args?.orgId;
|
|
550
661
|
const itemId = args?.itemId;
|
|
551
662
|
if (typeof orgId !== "string" || orgId === "" || typeof itemId !== "string")
|
|
@@ -571,6 +682,7 @@ identity = { sha256: null }) {
|
|
|
571
682
|
const agentsApi = perms.agents
|
|
572
683
|
? {
|
|
573
684
|
usableBy: async (args) => {
|
|
685
|
+
await revoked(AGENTS_KEY);
|
|
574
686
|
const a = readArgs(args);
|
|
575
687
|
if (typeof a.accountId !== "string" || a.accountId === "")
|
|
576
688
|
throw new CtxReadError("invalid_args", "accountId is required");
|
|
@@ -596,6 +708,7 @@ identity = { sha256: null }) {
|
|
|
596
708
|
bySubject: async (args) => {
|
|
597
709
|
if (!perms.conversations)
|
|
598
710
|
deny("permissions.conversations");
|
|
711
|
+
await revoked(CONVERSATIONS_KEY);
|
|
599
712
|
const a = readArgs(args);
|
|
600
713
|
const s = a.subject;
|
|
601
714
|
if (typeof s !== "object" ||
|
|
@@ -641,6 +754,7 @@ identity = { sha256: null }) {
|
|
|
641
754
|
const peopleApi = perms.people
|
|
642
755
|
? {
|
|
643
756
|
get: async (args) => {
|
|
757
|
+
await revoked(PEOPLE_KEY);
|
|
644
758
|
const a = readArgs(args);
|
|
645
759
|
const ids = a.accountIds;
|
|
646
760
|
if (!Array.isArray(ids))
|
|
@@ -648,6 +762,7 @@ identity = { sha256: null }) {
|
|
|
648
762
|
return withOrgScope(a.orgId, () => readsBackend().peopleGet(name, a.orgId, [...ids]));
|
|
649
763
|
},
|
|
650
764
|
search: async (args) => {
|
|
765
|
+
await revoked(PEOPLE_KEY);
|
|
651
766
|
const a = readArgs(args);
|
|
652
767
|
return withOrgScope(a.orgId, () => readsBackend().peopleSearch(name, a.orgId, a.query, a.limit));
|
|
653
768
|
},
|
|
@@ -710,20 +825,129 @@ identity = { sha256: null }) {
|
|
|
710
825
|
};
|
|
711
826
|
/** Ids of the extension's `platform.page` contributions (their invalidate takes no orgId). */
|
|
712
827
|
const platformUi = new Set([...uiSlots].filter(([, s]) => s.id === "platform.page").map(([id]) => id));
|
|
828
|
+
/**
|
|
829
|
+
* Withdraws what revoked keys back (plan task 1.3e; called only once revocation is enforced,
|
|
830
|
+
* plan task 1.5a). Registrations: new dispatch finds them gone, and the registry's change
|
|
831
|
+
* listeners (the HTTP dispatcher, the gateway's channel supervisor and webhook cache) refresh.
|
|
832
|
+
* Their ledger entries stay (their dispose is then a no-op). A policy hook on a mount whose
|
|
833
|
+
* policy or observe key is revoked stays registered and denies every call, so a required policy
|
|
834
|
+
* mount fails closed and the hook sees no payload. Handles held under a revoked capability (bus
|
|
835
|
+
* subscriptions, queue workers, `ctx.lock` leases) are disposed from the ledger.
|
|
836
|
+
*/
|
|
837
|
+
const withdraw = (keys) => {
|
|
838
|
+
let changed = false;
|
|
839
|
+
const drop = (list, match) => {
|
|
840
|
+
for (let i = list.length - 1; i >= 0; i--) {
|
|
841
|
+
if (match(list[i])) {
|
|
842
|
+
list.splice(i, 1);
|
|
843
|
+
changed = true;
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
};
|
|
847
|
+
const remove = (map, key) => {
|
|
848
|
+
if (map.delete(key))
|
|
849
|
+
changed = true;
|
|
850
|
+
};
|
|
851
|
+
// The mount stays expected until the admin disables the extension: the hook stays registered
|
|
852
|
+
// and denies every call (a loaded plugin without the hook would be skipped, failing open).
|
|
853
|
+
const denyPolicy = (mount) => {
|
|
854
|
+
for (const hook of registeredHooks) {
|
|
855
|
+
if (hook.mount !== mount || hook.mode !== "policy")
|
|
856
|
+
continue;
|
|
857
|
+
hook.handler = (async () => ({
|
|
858
|
+
deny: `The ${name} hook permission on ${mount} was revoked`,
|
|
859
|
+
}));
|
|
860
|
+
changed = true;
|
|
861
|
+
}
|
|
862
|
+
};
|
|
863
|
+
const disposals = [];
|
|
864
|
+
for (const key of keys) {
|
|
865
|
+
const http = /^permissions\.http(?:\.[a-z]+)?:(\S+) (.+)$/.exec(key);
|
|
866
|
+
if (http) {
|
|
867
|
+
const [, method, path] = http;
|
|
868
|
+
const access = declaredRoutes.get(`${method} ${path}`);
|
|
869
|
+
const full = access === "member" || access === "admin"
|
|
870
|
+
? `/plugins/${name}/orgs/:orgId${path}`
|
|
871
|
+
: `/plugins/${name}${path}`;
|
|
872
|
+
drop(routes, (r) => r.method === method && r.path === full);
|
|
873
|
+
}
|
|
874
|
+
else if (key.startsWith("permissions.tools:")) {
|
|
875
|
+
const tool = key.slice("permissions.tools:".length);
|
|
876
|
+
drop(registeredTools, (t) => t.spec.name === tool);
|
|
877
|
+
}
|
|
878
|
+
else if (key.startsWith(POLICY_HOOK_KEY_PREFIX)) {
|
|
879
|
+
denyPolicy(key.slice(POLICY_HOOK_KEY_PREFIX.length));
|
|
880
|
+
}
|
|
881
|
+
else if (key.startsWith("permissions.hooks:")) {
|
|
882
|
+
// a hook on the mount, of either mode, needs this key: observe hooks go, a policy hook
|
|
883
|
+
// denies (the mount stays expected)
|
|
884
|
+
const mount = key.slice("permissions.hooks:".length);
|
|
885
|
+
drop(registeredHooks, (h) => h.mount === mount && h.mode !== "policy");
|
|
886
|
+
denyPolicy(mount);
|
|
887
|
+
}
|
|
888
|
+
else if (key === "permissions.bus" ||
|
|
889
|
+
key === "permissions.queue" ||
|
|
890
|
+
key === "permissions.lock") {
|
|
891
|
+
const kind = key === "permissions.bus" ? "bus" : key === "permissions.queue" ? "queue" : "lease";
|
|
892
|
+
disposals.push(ledger.disposeKind(kind, (r, err) => deps.log.warn("disposing a revoked extension handle failed", {
|
|
893
|
+
plugin: name,
|
|
894
|
+
kind: r.kind,
|
|
895
|
+
key: r.key,
|
|
896
|
+
err,
|
|
897
|
+
})));
|
|
898
|
+
}
|
|
899
|
+
else if (key.startsWith(UI_VIEW_KEY_PREFIX) || key.startsWith(UI_COMPONENT_KEY_PREFIX)) {
|
|
900
|
+
const id = key.slice(key.indexOf(":") + 1);
|
|
901
|
+
remove(uiReg.views, id);
|
|
902
|
+
remove(uiReg.actions, id);
|
|
903
|
+
remove(uiReg.queries, id);
|
|
904
|
+
}
|
|
905
|
+
else if (key.startsWith("ui.query:")) {
|
|
906
|
+
remove(uiReg.queries, key.slice("ui.query:".length));
|
|
907
|
+
}
|
|
908
|
+
else if (key.startsWith("ui.action:")) {
|
|
909
|
+
remove(uiReg.actions, key.slice("ui.action:".length));
|
|
910
|
+
}
|
|
911
|
+
else if (key.startsWith(SETUP_CHECK_KEY_PREFIX)) {
|
|
912
|
+
remove(setupChecks, key.slice(SETUP_CHECK_KEY_PREFIX.length));
|
|
913
|
+
}
|
|
914
|
+
else if (key.startsWith("provides:")) {
|
|
915
|
+
remove(provided, key.slice("provides:".length));
|
|
916
|
+
}
|
|
917
|
+
else if (key.startsWith(DEVICE_HOST_KEY_PREFIX)) {
|
|
918
|
+
remove(serviceEventHandlers, key.slice(DEVICE_HOST_KEY_PREFIX.length));
|
|
919
|
+
}
|
|
920
|
+
}
|
|
921
|
+
if (changed) {
|
|
922
|
+
deps.log.warn("extension registrations withdrawn: their permission was revoked", {
|
|
923
|
+
plugin: name,
|
|
924
|
+
keys: [...keys],
|
|
925
|
+
});
|
|
926
|
+
deps.registrationsChanged?.(name);
|
|
927
|
+
}
|
|
928
|
+
void Promise.all(disposals);
|
|
929
|
+
};
|
|
930
|
+
// Registrations made during setup are withdrawn at seal time if already revoked; later
|
|
931
|
+
// revocations withdraw as the lease sees them.
|
|
932
|
+
lease?.onRefused((keys) => {
|
|
933
|
+
if (toolsSealed)
|
|
934
|
+
withdraw(keys);
|
|
935
|
+
});
|
|
713
936
|
const ctx = {
|
|
714
|
-
kv: createKv(deps.redis, name),
|
|
937
|
+
kv: leased(createKv(deps.redis, name), "permissions.kv"),
|
|
715
938
|
lock: {
|
|
716
939
|
// 取到的租约记账:实例撤销时释放仍持有的;插件自己 release 时销账
|
|
717
940
|
async acquire(key, opts) {
|
|
718
|
-
|
|
719
|
-
|
|
941
|
+
await revoked("permissions.lock");
|
|
942
|
+
const held = await lock.acquire(key, opts);
|
|
943
|
+
if (!held)
|
|
720
944
|
return null;
|
|
721
|
-
const settle = ledger.add({ kind: "lease", key, dispose: () =>
|
|
945
|
+
const settle = ledger.add({ kind: "lease", key, dispose: () => held.release() });
|
|
722
946
|
return {
|
|
723
|
-
renew: () =>
|
|
947
|
+
renew: () => held.renew(),
|
|
724
948
|
async release() {
|
|
725
949
|
settle();
|
|
726
|
-
await
|
|
950
|
+
await held.release();
|
|
727
951
|
},
|
|
728
952
|
};
|
|
729
953
|
},
|
|
@@ -738,8 +962,12 @@ identity = { sha256: null }) {
|
|
|
738
962
|
},
|
|
739
963
|
},
|
|
740
964
|
bus: {
|
|
741
|
-
|
|
965
|
+
async publish(topic, payload) {
|
|
966
|
+
await revoked("permissions.bus");
|
|
967
|
+
return bus.publish(topic, payload);
|
|
968
|
+
},
|
|
742
969
|
async subscribe(topic, handler) {
|
|
970
|
+
await revoked("permissions.bus");
|
|
743
971
|
const closedError = () => new Error(`plugin ${name}: ctx is closed; bus.subscribe is not allowed after close`);
|
|
744
972
|
if (closing || ledger.sealed)
|
|
745
973
|
throw closedError();
|
|
@@ -765,7 +993,11 @@ identity = { sha256: null }) {
|
|
|
765
993
|
dispose: () => queue.stopWorker(qname, drainDeadline),
|
|
766
994
|
});
|
|
767
995
|
},
|
|
768
|
-
|
|
996
|
+
// ctx/queue.ts's own add (a free function), behind the revocation check
|
|
997
|
+
add: ((enqueue) => (async (...args) => {
|
|
998
|
+
await revoked("permissions.queue");
|
|
999
|
+
return enqueue(...args);
|
|
1000
|
+
}))(queue.add),
|
|
769
1001
|
},
|
|
770
1002
|
db: guardDb((identity.db ?? deps.db).withSchema(pluginSchemaName(name)), name, effectTransactions),
|
|
771
1003
|
hasEffectQueue: queue.hasDefined,
|
|
@@ -1034,12 +1266,15 @@ identity = { sha256: null }) {
|
|
|
1034
1266
|
sealTools() {
|
|
1035
1267
|
toolsSealed = true;
|
|
1036
1268
|
uiReg.seal();
|
|
1269
|
+
if (lease?.enforced)
|
|
1270
|
+
withdraw(lease.refusedKeys());
|
|
1037
1271
|
},
|
|
1038
1272
|
/** 幂等:重复 / 并发调用共享同一次关闭。 */
|
|
1039
1273
|
close() {
|
|
1040
1274
|
closing ??= (async () => {
|
|
1041
1275
|
if (!lifecycle.signal.aborted)
|
|
1042
1276
|
lifecycle.abort();
|
|
1277
|
+
lease?.close();
|
|
1043
1278
|
await ledger.disposeAll((r, err) => deps.log.warn("plugin registration dispose failed", {
|
|
1044
1279
|
plugin: name,
|
|
1045
1280
|
kind: r.kind,
|
package/dist/ctx/net.d.ts
CHANGED
|
@@ -25,7 +25,7 @@ export type ExtensionNetServices = {
|
|
|
25
25
|
/** What a refused private address tells the reader of an org-bound request. */
|
|
26
26
|
export declare const ORG_PRIVATE_HINT = "ask a super admin to allow this internal endpoint for the organization";
|
|
27
27
|
/** What a refused private address tells the reader of a request made outside an organization. */
|
|
28
|
-
export declare const NO_ORG_PRIVATE_HINT = "a request made outside an organization reaches public addresses only";
|
|
28
|
+
export declare const NO_ORG_PRIVATE_HINT = "a request made outside an organization reaches public addresses only, or a private endpoint a super admin granted to this plugin";
|
|
29
29
|
/**
|
|
30
30
|
* `ctx.net` (plugin safe fetch spec): the kernel's guarded client (`safeFetch`) for URLs a person
|
|
31
31
|
* supplied. Per call:
|
|
@@ -34,6 +34,10 @@ export declare const NO_ORG_PRIVATE_HINT = "a request made outside an organizati
|
|
|
34
34
|
* replica; another org's allowances never apply), public addresses only without an org, and the
|
|
35
35
|
* deployment's egress proxy (`net.httpsProxy` / `net.noProxy`: a proxied https request is
|
|
36
36
|
* resolved by the proxy, which then owns SSRF protection; IP-literal targets are still checked);
|
|
37
|
+
* - without an org, a `net.privateEndpoints` alias granted to this plugin admits its exact origin,
|
|
38
|
+
* path prefix and methods (`private-endpoints.ts`): private addresses allowed, checked and pinned
|
|
39
|
+
* locally, never through the proxy, never the isolation Engine API; an org-bound request never
|
|
40
|
+
* uses an alias;
|
|
37
41
|
* - loopback, link-local and cloud metadata addresses are refused whatever the allowances
|
|
38
42
|
* (loopback allowed only under `net.allowInsecureLoopback`);
|
|
39
43
|
* - redirects are never followed: `redirect: "manual"` returns the 3xx response, otherwise a 3xx
|
package/dist/ctx/net.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { NetDeniedError as SdkNetDeniedError, } from "@capybara-hq/plugin-sdk";
|
|
2
|
+
import { aliasConfigHint, BROKERED_ENDPOINT_PINS } from "../net/private-endpoint-preflight.js";
|
|
3
|
+
import { aliasNetPolicy, matchPrivateEndpoint, } from "../net/private-endpoints.js";
|
|
2
4
|
import { NetDeniedError } from "../net/public-address.js";
|
|
3
5
|
import { safeFetch } from "../net/safe-fetch.js";
|
|
4
6
|
/**
|
|
@@ -10,7 +12,19 @@ export const EXTENSION_NET_SEAMS = Symbol("EXTENSION_NET_SEAMS");
|
|
|
10
12
|
/** What a refused private address tells the reader of an org-bound request. */
|
|
11
13
|
export const ORG_PRIVATE_HINT = "ask a super admin to allow this internal endpoint for the organization";
|
|
12
14
|
/** What a refused private address tells the reader of a request made outside an organization. */
|
|
13
|
-
export const NO_ORG_PRIVATE_HINT = "a request made outside an organization reaches public addresses only";
|
|
15
|
+
export const NO_ORG_PRIVATE_HINT = "a request made outside an organization reaches public addresses only, or a private endpoint a super admin granted to this plugin";
|
|
16
|
+
/** The refusal hint of a request made outside an organization: the alias config that would admit it. */
|
|
17
|
+
function noOrgPrivateHint(url, plugin) {
|
|
18
|
+
let origin;
|
|
19
|
+
try {
|
|
20
|
+
origin = new URL(url).origin;
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
return NO_ORG_PRIVATE_HINT;
|
|
24
|
+
}
|
|
25
|
+
const alias = BROKERED_ENDPOINT_PINS.find((p) => p.plugin === plugin)?.alias ?? plugin;
|
|
26
|
+
return `${NO_ORG_PRIVATE_HINT}. ${aliasConfigHint(alias, origin, plugin)}`;
|
|
27
|
+
}
|
|
14
28
|
/**
|
|
15
29
|
* `ctx.net` (plugin safe fetch spec): the kernel's guarded client (`safeFetch`) for URLs a person
|
|
16
30
|
* supplied. Per call:
|
|
@@ -19,6 +33,10 @@ export const NO_ORG_PRIVATE_HINT = "a request made outside an organization reach
|
|
|
19
33
|
* replica; another org's allowances never apply), public addresses only without an org, and the
|
|
20
34
|
* deployment's egress proxy (`net.httpsProxy` / `net.noProxy`: a proxied https request is
|
|
21
35
|
* resolved by the proxy, which then owns SSRF protection; IP-literal targets are still checked);
|
|
36
|
+
* - without an org, a `net.privateEndpoints` alias granted to this plugin admits its exact origin,
|
|
37
|
+
* path prefix and methods (`private-endpoints.ts`): private addresses allowed, checked and pinned
|
|
38
|
+
* locally, never through the proxy, never the isolation Engine API; an org-bound request never
|
|
39
|
+
* uses an alias;
|
|
22
40
|
* - loopback, link-local and cloud metadata addresses are refused whatever the allowances
|
|
23
41
|
* (loopback allowed only under `net.allowInsecureLoopback`);
|
|
24
42
|
* - redirects are never followed: `redirect: "manual"` returns the 3xx response, otherwise a 3xx
|
|
@@ -31,10 +49,26 @@ export function createExtensionNet(deps) {
|
|
|
31
49
|
return {
|
|
32
50
|
async fetch(url, init, opts) {
|
|
33
51
|
const orgId = opts?.orgId;
|
|
34
|
-
const
|
|
52
|
+
const cfg = deps.config.get();
|
|
53
|
+
const net = cfg.net;
|
|
35
54
|
const exemptions = orgId
|
|
36
55
|
? await deps.allowances.policyFor(orgId)
|
|
37
56
|
: { allowPrivateHosts: [], trustedOrigins: [] };
|
|
57
|
+
let alias;
|
|
58
|
+
try {
|
|
59
|
+
const match = orgId === undefined
|
|
60
|
+
? matchPrivateEndpoint(net.privateEndpoints ?? {}, deps.plugin, url, init?.method ?? "GET", init?.headers)
|
|
61
|
+
: undefined;
|
|
62
|
+
if (match !== undefined) {
|
|
63
|
+
alias = {
|
|
64
|
+
...match,
|
|
65
|
+
...aliasNetPolicy(match, cfg.extensionHost?.isolation?.engineUrl),
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
catch (e) {
|
|
70
|
+
throw refusal(e, orgId);
|
|
71
|
+
}
|
|
38
72
|
const policy = {
|
|
39
73
|
allowInsecureLoopback: net.allowInsecureLoopback,
|
|
40
74
|
allowPrivateHosts: exemptions.allowPrivateHosts,
|
|
@@ -42,7 +76,18 @@ export function createExtensionNet(deps) {
|
|
|
42
76
|
...(net.httpsProxy !== undefined && {
|
|
43
77
|
proxy: { url: net.httpsProxy, noProxy: net.noProxy },
|
|
44
78
|
}),
|
|
45
|
-
extension:
|
|
79
|
+
extension: orgId
|
|
80
|
+
? { privateHint: ORG_PRIVATE_HINT }
|
|
81
|
+
: {
|
|
82
|
+
privateHint: noOrgPrivateHint(url, deps.plugin),
|
|
83
|
+
insecureHint: noOrgPrivateHint(url, deps.plugin),
|
|
84
|
+
},
|
|
85
|
+
...(alias !== undefined && {
|
|
86
|
+
privateEndpoint: {
|
|
87
|
+
origin: alias.origin,
|
|
88
|
+
allowLoopback: alias.allowLoopback,
|
|
89
|
+
},
|
|
90
|
+
}),
|
|
46
91
|
};
|
|
47
92
|
const signal = init?.signal ? AbortSignal.any([deps.signal, init.signal]) : deps.signal;
|
|
48
93
|
try {
|
|
@@ -52,16 +97,21 @@ export function createExtensionNet(deps) {
|
|
|
52
97
|
});
|
|
53
98
|
}
|
|
54
99
|
catch (e) {
|
|
55
|
-
|
|
56
|
-
throw e;
|
|
57
|
-
deps.log.warn("ctx.net.fetch refused a request", {
|
|
58
|
-
plugin: deps.plugin,
|
|
59
|
-
orgId: orgId ?? null,
|
|
60
|
-
host: e.host,
|
|
61
|
-
code: e.code,
|
|
62
|
-
});
|
|
63
|
-
throw new SdkNetDeniedError(e.code, e.host, e.message, e.status);
|
|
100
|
+
throw refusal(e, orgId, alias?.alias);
|
|
64
101
|
}
|
|
65
102
|
},
|
|
66
103
|
};
|
|
104
|
+
/** A kernel refusal logged and turned into the SDK's error; anything else passes through. */
|
|
105
|
+
function refusal(e, orgId, alias) {
|
|
106
|
+
if (!(e instanceof NetDeniedError))
|
|
107
|
+
return e;
|
|
108
|
+
deps.log.warn("ctx.net.fetch refused a request", {
|
|
109
|
+
plugin: deps.plugin,
|
|
110
|
+
orgId: orgId ?? null,
|
|
111
|
+
host: e.host,
|
|
112
|
+
code: e.code,
|
|
113
|
+
...(alias !== undefined && { privateEndpoint: alias }),
|
|
114
|
+
});
|
|
115
|
+
return new SdkNetDeniedError(e.code, e.host, e.message, e.status);
|
|
116
|
+
}
|
|
67
117
|
}
|