@brud/kernel 0.0.1 → 0.0.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 +0 -0
- package/README.md +0 -0
- package/dist/index.d.ts +0 -0
- package/dist/index.js +0 -0
- package/dist/serviceModules/events.d.ts +0 -0
- package/dist/serviceModules/events.js +0 -0
- package/dist/serviceModules/exposedApiRegistry.d.ts +0 -0
- package/dist/serviceModules/exposedApiRegistry.js +0 -0
- package/dist/serviceModules/identityRegistry.d.ts +0 -0
- package/dist/serviceModules/identityRegistry.js +0 -0
- package/dist/serviceModules/interception.d.ts +0 -0
- package/dist/serviceModules/interception.js +0 -0
- package/dist/serviceModules/parser.d.ts +0 -0
- package/dist/serviceModules/parser.js +0 -0
- package/dist/serviceModules/router.d.ts +0 -0
- package/dist/serviceModules/router.js +0 -0
- package/dist/serviceModules/wasmCage.d.ts +0 -0
- package/dist/serviceModules/wasmCage.js +0 -0
- package/dist/services/Events/contracts/IEventsService.d.ts +0 -0
- package/dist/services/Events/contracts/IEventsService.js +0 -0
- package/dist/services/Events/contracts/errors.d.ts +0 -0
- package/dist/services/Events/contracts/errors.js +0 -0
- package/dist/services/Events/contracts/index.d.ts +0 -0
- package/dist/services/Events/contracts/index.js +0 -0
- package/dist/services/Events/contracts/tokens.d.ts +0 -0
- package/dist/services/Events/contracts/tokens.js +0 -0
- package/dist/services/Events/descriptor/EventsDescriptor.d.ts +0 -0
- package/dist/services/Events/descriptor/EventsDescriptor.js +0 -0
- package/dist/services/Events/descriptor/tokens.d.ts +0 -0
- package/dist/services/Events/descriptor/tokens.js +0 -0
- package/dist/services/Events/index.d.ts +0 -0
- package/dist/services/Events/index.js +0 -0
- package/dist/services/Events/orchestrator/EventsService.d.ts +0 -0
- package/dist/services/Events/orchestrator/EventsService.js +0 -0
- package/dist/services/Events/orchestrator/index.d.ts +0 -0
- package/dist/services/Events/orchestrator/index.js +0 -0
- package/dist/services/Events/orchestrator/limits.d.ts +0 -0
- package/dist/services/Events/orchestrator/limits.js +0 -0
- package/dist/services/Events/serviceModule.d.ts +0 -0
- package/dist/services/Events/serviceModule.js +0 -0
- package/dist/services/ExposedApiRegistry/contracts/IExposedApiRegistry.d.ts +13 -1
- package/dist/services/ExposedApiRegistry/contracts/IExposedApiRegistry.js +0 -0
- package/dist/services/ExposedApiRegistry/contracts/errors.d.ts +0 -0
- package/dist/services/ExposedApiRegistry/contracts/errors.js +0 -0
- package/dist/services/ExposedApiRegistry/contracts/index.d.ts +1 -1
- package/dist/services/ExposedApiRegistry/contracts/index.js +0 -0
- package/dist/services/ExposedApiRegistry/contracts/policy.d.ts +0 -0
- package/dist/services/ExposedApiRegistry/contracts/policy.js +0 -0
- package/dist/services/ExposedApiRegistry/contracts/registrant.d.ts +0 -0
- package/dist/services/ExposedApiRegistry/contracts/registrant.js +0 -0
- package/dist/services/ExposedApiRegistry/contracts/types.d.ts +21 -0
- package/dist/services/ExposedApiRegistry/contracts/types.js +0 -0
- package/dist/services/ExposedApiRegistry/descriptor/ExposedApiRegistryDescriptor.d.ts +2 -2
- package/dist/services/ExposedApiRegistry/descriptor/ExposedApiRegistryDescriptor.js +2 -2
- package/dist/services/ExposedApiRegistry/descriptor/tokens.d.ts +0 -0
- package/dist/services/ExposedApiRegistry/descriptor/tokens.js +0 -0
- package/dist/services/ExposedApiRegistry/index.d.ts +0 -0
- package/dist/services/ExposedApiRegistry/index.js +0 -0
- package/dist/services/ExposedApiRegistry/orchestrator/ExposedApiRegistryService.d.ts +9 -2
- package/dist/services/ExposedApiRegistry/orchestrator/ExposedApiRegistryService.js +50 -5
- package/dist/services/ExposedApiRegistry/orchestrator/index.d.ts +0 -0
- package/dist/services/ExposedApiRegistry/orchestrator/index.js +0 -0
- package/dist/services/ExposedApiRegistry/serviceModule.d.ts +0 -0
- package/dist/services/ExposedApiRegistry/serviceModule.js +0 -0
- package/dist/services/ExposedApiRegistry/storage/protection.d.ts +0 -0
- package/dist/services/ExposedApiRegistry/storage/protection.js +0 -0
- package/dist/services/ExposedApiRegistry/storage/scopeRecord.d.ts +0 -0
- package/dist/services/ExposedApiRegistry/storage/scopeRecord.js +0 -0
- package/dist/services/IdentityRegistry/contracts/errors.d.ts +0 -0
- package/dist/services/IdentityRegistry/contracts/errors.js +0 -0
- package/dist/services/IdentityRegistry/contracts/index.d.ts +0 -0
- package/dist/services/IdentityRegistry/contracts/index.js +0 -0
- package/dist/services/IdentityRegistry/contracts/types.d.ts +0 -0
- package/dist/services/IdentityRegistry/contracts/types.js +0 -0
- package/dist/services/IdentityRegistry/descriptor/descriptor.d.ts +0 -0
- package/dist/services/IdentityRegistry/descriptor/descriptor.js +0 -0
- package/dist/services/IdentityRegistry/descriptor/tokens.d.ts +0 -0
- package/dist/services/IdentityRegistry/descriptor/tokens.js +0 -0
- package/dist/services/IdentityRegistry/index.d.ts +0 -0
- package/dist/services/IdentityRegistry/index.js +0 -0
- package/dist/services/IdentityRegistry/orchestrator/IdentityRegistryService.d.ts +0 -0
- package/dist/services/IdentityRegistry/orchestrator/IdentityRegistryService.js +0 -0
- package/dist/services/IdentityRegistry/serviceModule.d.ts +0 -0
- package/dist/services/IdentityRegistry/serviceModule.js +0 -0
- package/dist/services/IdentityRegistry/storage/registryDocument.d.ts +0 -0
- package/dist/services/IdentityRegistry/storage/registryDocument.js +0 -0
- package/dist/services/Interception/contracts/IInterceptionService.d.ts +91 -1
- package/dist/services/Interception/contracts/IInterceptionService.js +12 -1
- package/dist/services/Interception/contracts/errors.d.ts +0 -0
- package/dist/services/Interception/contracts/errors.js +0 -0
- package/dist/services/Interception/contracts/index.d.ts +0 -0
- package/dist/services/Interception/contracts/index.js +0 -0
- package/dist/services/Interception/contracts/tokens.d.ts +0 -0
- package/dist/services/Interception/contracts/tokens.js +0 -0
- package/dist/services/Interception/descriptor/InterceptionDescriptor.d.ts +1 -1
- package/dist/services/Interception/descriptor/InterceptionDescriptor.js +2 -1
- package/dist/services/Interception/descriptor/tokens.d.ts +0 -0
- package/dist/services/Interception/descriptor/tokens.js +0 -0
- package/dist/services/Interception/index.d.ts +0 -0
- package/dist/services/Interception/index.js +0 -0
- package/dist/services/Interception/orchestrator/InterceptionService.d.ts +9 -1
- package/dist/services/Interception/orchestrator/InterceptionService.js +167 -4
- package/dist/services/Interception/orchestrator/index.d.ts +0 -0
- package/dist/services/Interception/orchestrator/index.js +0 -0
- package/dist/services/Interception/serviceModule.d.ts +0 -0
- package/dist/services/Interception/serviceModule.js +0 -0
- package/dist/services/Parser/contracts/IParserService.d.ts +0 -0
- package/dist/services/Parser/contracts/IParserService.js +0 -0
- package/dist/services/Parser/contracts/errors.d.ts +0 -0
- package/dist/services/Parser/contracts/errors.js +0 -0
- package/dist/services/Parser/contracts/index.d.ts +0 -0
- package/dist/services/Parser/contracts/index.js +0 -0
- package/dist/services/Parser/contracts/types.d.ts +0 -0
- package/dist/services/Parser/contracts/types.js +0 -0
- package/dist/services/Parser/descriptor/ParserDescriptor.d.ts +0 -0
- package/dist/services/Parser/descriptor/ParserDescriptor.js +0 -0
- package/dist/services/Parser/descriptor/tokens.d.ts +0 -0
- package/dist/services/Parser/descriptor/tokens.js +0 -0
- package/dist/services/Parser/index.d.ts +0 -0
- package/dist/services/Parser/index.js +0 -0
- package/dist/services/Parser/orchestrator/ParserService.d.ts +0 -0
- package/dist/services/Parser/orchestrator/ParserService.js +0 -0
- package/dist/services/Parser/orchestrator/index.d.ts +0 -0
- package/dist/services/Parser/orchestrator/index.js +0 -0
- package/dist/services/Parser/parser/indexSynthesis.d.ts +0 -0
- package/dist/services/Parser/parser/indexSynthesis.js +0 -0
- package/dist/services/Parser/parser/parameters.d.ts +0 -0
- package/dist/services/Parser/parser/parameters.js +0 -0
- package/dist/services/Parser/parser/scanner.d.ts +0 -0
- package/dist/services/Parser/parser/scanner.js +0 -0
- package/dist/services/Parser/parser/syntax.d.ts +0 -0
- package/dist/services/Parser/parser/syntax.js +0 -0
- package/dist/services/Parser/serviceModule.d.ts +0 -0
- package/dist/services/Parser/serviceModule.js +0 -0
- package/dist/services/Router/bootOptions.d.ts +0 -0
- package/dist/services/Router/bootOptions.js +0 -0
- package/dist/services/Router/contracts/IRouterService.d.ts +1 -1
- package/dist/services/Router/contracts/IRouterService.js +0 -0
- package/dist/services/Router/contracts/caller.d.ts +0 -0
- package/dist/services/Router/contracts/caller.js +0 -0
- package/dist/services/Router/contracts/errors.d.ts +12 -1
- package/dist/services/Router/contracts/errors.js +15 -0
- package/dist/services/Router/contracts/index.d.ts +2 -2
- package/dist/services/Router/contracts/index.js +1 -1
- package/dist/services/Router/contracts/kind.d.ts +0 -0
- package/dist/services/Router/contracts/kind.js +0 -0
- package/dist/services/Router/contracts/registrant.d.ts +0 -0
- package/dist/services/Router/contracts/registrant.js +0 -0
- package/dist/services/Router/contracts/types.d.ts +28 -8
- package/dist/services/Router/contracts/types.js +0 -0
- package/dist/services/Router/descriptor/RouterDescriptor.d.ts +0 -0
- package/dist/services/Router/descriptor/RouterDescriptor.js +1 -1
- package/dist/services/Router/descriptor/tokens.d.ts +0 -0
- package/dist/services/Router/descriptor/tokens.js +0 -0
- package/dist/services/Router/index.d.ts +0 -0
- package/dist/services/Router/index.js +0 -0
- package/dist/services/Router/orchestrator/RouterService.d.ts +22 -3
- package/dist/services/Router/orchestrator/RouterService.js +131 -6
- package/dist/services/Router/orchestrator/index.d.ts +0 -0
- package/dist/services/Router/orchestrator/index.js +0 -0
- package/dist/services/Router/serviceModule.d.ts +0 -0
- package/dist/services/Router/serviceModule.js +0 -0
- package/dist/services/WasmCage/index.d.ts +0 -0
- package/dist/services/WasmCage/index.js +0 -0
- package/dist/services/WasmCage/scripts/prepin.d.ts +0 -0
- package/dist/services/WasmCage/scripts/prepin.js +0 -0
- package/dist/services/WasmCage/serviceModule.d.ts +0 -0
- package/dist/services/WasmCage/serviceModule.js +0 -0
- package/dist/services/WasmCage/src/caged.d.ts +19 -2
- package/dist/services/WasmCage/src/caged.js +85 -6
- package/dist/services/WasmCage/src/descriptor.d.ts +0 -0
- package/dist/services/WasmCage/src/descriptor.js +0 -0
- package/dist/services/WasmCage/src/native.d.ts +0 -0
- package/dist/services/WasmCage/src/native.js +0 -0
- package/dist/services/WasmCage/src/nativeDigests.d.ts +0 -0
- package/dist/services/WasmCage/src/nativeDigests.js +5 -5
- package/dist/services/WasmCage/src/package.d.ts +0 -0
- package/dist/services/WasmCage/src/package.js +0 -0
- package/dist/services/shared/canonicalJson.d.ts +0 -0
- package/dist/services/shared/canonicalJson.js +0 -0
- package/dist/services/shared/documentStore.d.ts +0 -0
- package/dist/services/shared/documentStore.js +0 -0
- package/dist/src/bootstrap/bootKernelInternal.d.ts +4 -3
- package/dist/src/bootstrap/bootKernelInternal.js +284 -71
- package/dist/src/bootstrap/bootTypes.d.ts +25 -1
- package/dist/src/bootstrap/bootTypes.js +0 -0
- package/dist/src/bootstrap/config/index.d.ts +0 -0
- package/dist/src/bootstrap/config/index.js +0 -0
- package/dist/src/bootstrap/config/integrity.d.ts +11 -0
- package/dist/src/bootstrap/config/integrity.js +13 -0
- package/dist/src/bootstrap/config/parse.d.ts +0 -0
- package/dist/src/bootstrap/config/parse.js +0 -0
- package/dist/src/bootstrap/config/pathWriteGuard.d.ts +0 -0
- package/dist/src/bootstrap/config/pathWriteGuard.js +0 -0
- package/dist/src/bootstrap/config/types.d.ts +1 -1
- package/dist/src/bootstrap/config/types.js +0 -0
- package/dist/src/bootstrap/hardcore.d.ts +0 -0
- package/dist/src/bootstrap/hardcore.js +0 -0
- package/dist/src/bootstrap/hardcoreServices.d.ts +0 -0
- package/dist/src/bootstrap/hardcoreServices.js +14 -14
- package/dist/src/bootstrap/index.d.ts +6 -1
- package/dist/src/bootstrap/index.js +2 -0
- package/dist/src/bootstrap/loaded.d.ts +30 -0
- package/dist/src/bootstrap/loaded.js +45 -0
- package/dist/src/bootstrap/packageRequirements.d.ts +0 -0
- package/dist/src/bootstrap/packageRequirements.js +0 -0
- package/dist/src/bootstrap/reload.d.ts +44 -0
- package/dist/src/bootstrap/reload.js +45 -0
- package/dist/src/bootstrap/seal.d.ts +32 -0
- package/dist/src/bootstrap/seal.js +101 -0
- package/dist/src/contracts/accessBroker.d.ts +0 -0
- package/dist/src/contracts/accessBroker.js +0 -0
- package/dist/src/contracts/brudOperation.d.ts +0 -0
- package/dist/src/contracts/brudOperation.js +0 -0
- package/dist/src/contracts/callChain.d.ts +0 -0
- package/dist/src/contracts/callChain.js +0 -0
- package/dist/src/contracts/capability.d.ts +0 -0
- package/dist/src/contracts/capability.js +0 -0
- package/dist/src/contracts/capabilitySet.d.ts +23 -0
- package/dist/src/contracts/capabilitySet.js +72 -0
- package/dist/src/contracts/container.d.ts +0 -0
- package/dist/src/contracts/container.js +0 -0
- package/dist/src/contracts/context.d.ts +0 -0
- package/dist/src/contracts/context.js +0 -0
- package/dist/src/contracts/contextContract.d.ts +11 -8
- package/dist/src/contracts/contextContract.js +21 -32
- package/dist/src/contracts/dispatchView.d.ts +3 -3
- package/dist/src/contracts/dispatchView.js +0 -0
- package/dist/src/contracts/handler.d.ts +0 -7
- package/dist/src/contracts/handler.js +0 -0
- package/dist/src/contracts/index.d.ts +2 -1
- package/dist/src/contracts/index.js +1 -0
- package/dist/src/contracts/kernel.d.ts +0 -0
- package/dist/src/contracts/kernel.js +0 -0
- package/dist/src/contracts/lifecycle.d.ts +0 -0
- package/dist/src/contracts/lifecycle.js +0 -0
- package/dist/src/contracts/manifest.d.ts +35 -0
- package/dist/src/contracts/manifest.js +62 -23
- package/dist/src/contracts/pipeline.d.ts +0 -0
- package/dist/src/contracts/pipeline.js +0 -0
- package/dist/src/contracts/policy.d.ts +0 -0
- package/dist/src/contracts/policy.js +0 -0
- package/dist/src/contracts/registry.d.ts +0 -0
- package/dist/src/contracts/registry.js +0 -0
- package/dist/src/contracts/serviceDescriptor.d.ts +0 -0
- package/dist/src/contracts/serviceDescriptor.js +0 -0
- package/dist/src/contracts/serviceToken.d.ts +0 -0
- package/dist/src/contracts/serviceToken.js +0 -0
- package/dist/src/engine/BrudKernel.d.ts +2 -0
- package/dist/src/engine/BrudKernel.js +35 -6
- package/dist/src/engine/ExecutionPipeline.d.ts +0 -0
- package/dist/src/engine/ExecutionPipeline.js +0 -0
- package/dist/src/engine/KernelAccessBroker.d.ts +0 -0
- package/dist/src/engine/KernelAccessBroker.js +0 -0
- package/dist/src/engine/KernelRegistry.d.ts +0 -0
- package/dist/src/engine/KernelRegistry.js +0 -0
- package/dist/src/engine/OperationRegistry.d.ts +0 -0
- package/dist/src/engine/OperationRegistry.js +0 -0
- package/dist/src/engine/ServiceContainer.d.ts +0 -0
- package/dist/src/engine/ServiceContainer.js +0 -0
- package/dist/src/engine/callChain.d.ts +0 -0
- package/dist/src/engine/callChain.js +5 -10
- package/dist/src/engine/dag.d.ts +0 -0
- package/dist/src/engine/dag.js +0 -0
- package/dist/src/engine/errors.d.ts +0 -0
- package/dist/src/engine/errors.js +0 -0
- package/dist/src/engine/index.d.ts +0 -0
- package/dist/src/engine/index.js +0 -0
- package/dist/src/engine/state.d.ts +0 -0
- package/dist/src/engine/state.js +0 -0
- package/dist/src/validation/jsonSchema/compile.d.ts +0 -0
- package/dist/src/validation/jsonSchema/compile.js +0 -0
- package/dist/src/validation/jsonSchema/index.d.ts +0 -0
- package/dist/src/validation/jsonSchema/index.js +0 -0
- package/dist/src/validation/jsonSchema/jsonValue.d.ts +0 -0
- package/dist/src/validation/jsonSchema/jsonValue.js +0 -0
- package/dist/src/validation/jsonSchema/pattern.d.ts +0 -0
- package/dist/src/validation/jsonSchema/pattern.js +0 -0
- package/dist/src/validation/jsonSchema/types.d.ts +0 -0
- package/dist/src/validation/jsonSchema/types.js +0 -0
- package/package.json +1 -1
- package/services/WasmCage/native/brud-wasm-cage.darwin-arm64.node +0 -0
- package/services/WasmCage/native/brud-wasm-cage.darwin-x64.node +0 -0
- package/services/WasmCage/native/brud-wasm-cage.linux-arm64-gnu.node +0 -0
- package/services/WasmCage/native/brud-wasm-cage.linux-x64-gnu.node +0 -0
- package/services/WasmCage/native/brud-wasm-cage.win32-x64-msvc.node +0 -0
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { evaluateExposedApiPolicy, parseExposedApiPolicy, } from '../../ExposedApiRegistry/contracts/policy.js';
|
|
1
2
|
import { isValidRouterKind } from '../contracts/kind.js';
|
|
2
|
-
import { RouterDisposedError, RouterInvalidKindError, RouterKindCollisionError, RouterRegistrationClosedError, } from '../contracts/errors.js';
|
|
3
|
+
import { RouterDisposedError, RouterInvalidDeclarationError, RouterInvalidKindError, RouterKindCollisionError, RouterRegistrationClosedError, } from '../contracts/errors.js';
|
|
3
4
|
/**
|
|
4
5
|
* Level-1 Brud kind Router.
|
|
5
6
|
*
|
|
@@ -9,11 +10,15 @@ import { RouterDisposedError, RouterInvalidKindError, RouterKindCollisionError,
|
|
|
9
10
|
* guard for alternate compositions.
|
|
10
11
|
*
|
|
11
12
|
* Dispatch resolves every target through the access broker with the token the
|
|
12
|
-
* owning service supplied, so access policies still apply and
|
|
13
|
-
*
|
|
13
|
+
* owning service supplied, so access policies still apply and only the
|
|
14
|
+
* owning service can be a routing target.
|
|
14
15
|
*/
|
|
15
16
|
export class RouterService {
|
|
16
17
|
registrations = new Map();
|
|
18
|
+
/** The parsed permission of every declared operation, by kind then operation. Frozen at registration. */
|
|
19
|
+
permissions = new Map();
|
|
20
|
+
/** The one permission of every kind whose owner defines its operation names. */
|
|
21
|
+
openKinds = new Map();
|
|
17
22
|
authority;
|
|
18
23
|
dependencies;
|
|
19
24
|
parser;
|
|
@@ -40,7 +45,7 @@ export class RouterService {
|
|
|
40
45
|
identity: context.caller.identity,
|
|
41
46
|
callerClass: context.caller.callerClass,
|
|
42
47
|
official: context.caller.official,
|
|
43
|
-
capabilities:
|
|
48
|
+
capabilities: context.caller.capabilities,
|
|
44
49
|
origin: context.origin,
|
|
45
50
|
});
|
|
46
51
|
}
|
|
@@ -72,7 +77,8 @@ export class RouterService {
|
|
|
72
77
|
exposure: declaration.exposure,
|
|
73
78
|
...(declaration.version === undefined ? {} : { version: Number(declaration.version) }),
|
|
74
79
|
...(declaration.description === undefined ? {} : { description: declaration.description }),
|
|
75
|
-
|
|
80
|
+
operations: declaration.operations,
|
|
81
|
+
...(declaration.permission === undefined ? {} : { permission: declaration.permission }),
|
|
76
82
|
}, owner);
|
|
77
83
|
}
|
|
78
84
|
register(registration, owner) {
|
|
@@ -92,7 +98,60 @@ export class RouterService {
|
|
|
92
98
|
if (typeof registration.exposure !== 'string' || registration.exposure.length === 0) {
|
|
93
99
|
throw new RouterInvalidKindError(registration.kind);
|
|
94
100
|
}
|
|
101
|
+
const compiled = this.compilePermissions(registration);
|
|
95
102
|
this.registrations.set(registration.kind, Object.freeze({ ...registration, ...(owner === undefined ? {} : { owner }) }));
|
|
103
|
+
if (compiled instanceof Map) {
|
|
104
|
+
this.permissions.set(registration.kind, compiled);
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
this.openKinds.set(registration.kind, compiled);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Builds the operation registry for one kind: every operation must be
|
|
112
|
+
* declared and carry a valid permission, its own or the kind's. Refuses the
|
|
113
|
+
* declaration, and so the boot, otherwise.
|
|
114
|
+
*/
|
|
115
|
+
compilePermissions(registration) {
|
|
116
|
+
const refuse = (reason) => {
|
|
117
|
+
throw new RouterInvalidDeclarationError(registration.kind, reason);
|
|
118
|
+
};
|
|
119
|
+
const operations = registration.operations;
|
|
120
|
+
if (operations === 'open') {
|
|
121
|
+
if (registration.permission === undefined) {
|
|
122
|
+
return refuse('an open operation vocabulary needs a kind-level permission');
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
else if (typeof operations !== 'object' || operations === null || Array.isArray(operations) || Object.keys(operations).length === 0) {
|
|
126
|
+
return refuse('it must declare every operation it serves');
|
|
127
|
+
}
|
|
128
|
+
const parse = (value, where) => {
|
|
129
|
+
let policy;
|
|
130
|
+
try {
|
|
131
|
+
policy = parseExposedApiPolicy(value);
|
|
132
|
+
}
|
|
133
|
+
catch (error) {
|
|
134
|
+
return refuse(`${where} permission is invalid (${describe(error)})`);
|
|
135
|
+
}
|
|
136
|
+
if (policy.parentCallerClasses !== undefined) {
|
|
137
|
+
return refuse(`${where} permission cannot use parentCallerClasses: the Router does not know the caller's parent`);
|
|
138
|
+
}
|
|
139
|
+
return policy;
|
|
140
|
+
};
|
|
141
|
+
const fallback = registration.permission === undefined ? undefined : parse(registration.permission, 'the kind');
|
|
142
|
+
if (registration.operations === 'open') {
|
|
143
|
+
return fallback;
|
|
144
|
+
}
|
|
145
|
+
const compiled = new Map();
|
|
146
|
+
for (const [name, operation] of Object.entries(registration.operations)) {
|
|
147
|
+
const own = operation.permission === undefined ? undefined : parse(operation.permission, `operation "${name}"`);
|
|
148
|
+
const effective = own ?? fallback;
|
|
149
|
+
if (effective === undefined) {
|
|
150
|
+
return refuse(`operation "${name}" has no permission and the kind declares none`);
|
|
151
|
+
}
|
|
152
|
+
compiled.set(name, effective);
|
|
153
|
+
}
|
|
154
|
+
return compiled;
|
|
96
155
|
}
|
|
97
156
|
closeRegistration() {
|
|
98
157
|
this.closed = true;
|
|
@@ -112,7 +171,13 @@ export class RouterService {
|
|
|
112
171
|
return Object.freeze(Array.from(this.registrations.values(), (registration) => Object.freeze({
|
|
113
172
|
kind: registration.kind,
|
|
114
173
|
...(registration.description === undefined ? {} : { description: registration.description }),
|
|
115
|
-
...(registration.operations ===
|
|
174
|
+
...(registration.operations === 'open' ? { open: true } : { operations: Object.freeze(Object.fromEntries(Object.entries(registration.operations).map(([name, operation]) => [
|
|
175
|
+
name,
|
|
176
|
+
Object.freeze({
|
|
177
|
+
...(operation.description === undefined ? {} : { description: operation.description }),
|
|
178
|
+
...(operation.input === undefined ? {} : { input: operation.input }),
|
|
179
|
+
}),
|
|
180
|
+
]))) }),
|
|
116
181
|
})));
|
|
117
182
|
}
|
|
118
183
|
async route(rawInput, options = {}, caller) {
|
|
@@ -169,6 +234,23 @@ export class RouterService {
|
|
|
169
234
|
}
|
|
170
235
|
continue;
|
|
171
236
|
}
|
|
237
|
+
const refusal = this.refuseBeforeOwner(registration.kind, operation, routeCaller);
|
|
238
|
+
if (refusal !== undefined) {
|
|
239
|
+
failed += 1;
|
|
240
|
+
outcomes.push({
|
|
241
|
+
operationIndex: operation.index,
|
|
242
|
+
sequence,
|
|
243
|
+
kind: operation.kind,
|
|
244
|
+
name: operation.name,
|
|
245
|
+
status: refusal.status,
|
|
246
|
+
error: refusal.error,
|
|
247
|
+
});
|
|
248
|
+
if (stopOnFailure) {
|
|
249
|
+
appendRemaining(outcomes, operations, sequence + 1, 'skipped');
|
|
250
|
+
break;
|
|
251
|
+
}
|
|
252
|
+
continue;
|
|
253
|
+
}
|
|
172
254
|
let result;
|
|
173
255
|
try {
|
|
174
256
|
// The access broker is the only resolution path: the registered token
|
|
@@ -239,6 +321,49 @@ export class RouterService {
|
|
|
239
321
|
failed,
|
|
240
322
|
};
|
|
241
323
|
}
|
|
324
|
+
/**
|
|
325
|
+
* The operation registry check, run before the owner is resolved: the
|
|
326
|
+
* operation must be declared for its kind, and the caller must hold the
|
|
327
|
+
* operation's permission. The reason a permission is denied goes to the
|
|
328
|
+
* observation stream, never to the caller.
|
|
329
|
+
*/
|
|
330
|
+
refuseBeforeOwner(kind, operation, caller) {
|
|
331
|
+
const policy = this.openKinds.get(kind) ?? this.permissions.get(kind)?.get(operation.name);
|
|
332
|
+
if (policy === undefined) {
|
|
333
|
+
this.observeRefusal('operation-not-declared', kind, operation.name, caller, undefined);
|
|
334
|
+
return {
|
|
335
|
+
status: 'operation_not_declared',
|
|
336
|
+
error: `OPERATION_NOT_DECLARED: kind "${kind}" does not declare operation "${operation.name}"`,
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
const decision = evaluateExposedApiPolicy(policy, 'any', {
|
|
340
|
+
origin: caller.origin,
|
|
341
|
+
caller: {
|
|
342
|
+
callerClass: caller.callerClass,
|
|
343
|
+
identity: caller.identity,
|
|
344
|
+
official: caller.official,
|
|
345
|
+
capabilities: caller.capabilities,
|
|
346
|
+
},
|
|
347
|
+
});
|
|
348
|
+
if (decision.allowed) {
|
|
349
|
+
return undefined;
|
|
350
|
+
}
|
|
351
|
+
this.observeRefusal('permission-denied', kind, operation.name, caller, decision.reason);
|
|
352
|
+
return {
|
|
353
|
+
status: 'permission_denied',
|
|
354
|
+
error: `PERMISSION_DENIED: the caller may not call operation "${operation.name}" of kind "${kind}"`,
|
|
355
|
+
};
|
|
356
|
+
}
|
|
357
|
+
observeRefusal(event, kind, name, caller, reason) {
|
|
358
|
+
this.authority?.observe('router', event, {
|
|
359
|
+
kind,
|
|
360
|
+
operation: name,
|
|
361
|
+
...(reason === undefined ? {} : { reason }),
|
|
362
|
+
callerIdentity: caller.identity,
|
|
363
|
+
callerClass: caller.callerClass,
|
|
364
|
+
origin: caller.origin,
|
|
365
|
+
});
|
|
366
|
+
}
|
|
242
367
|
resolveParser() {
|
|
243
368
|
this.parser ??= this.dependencies.getParser();
|
|
244
369
|
return this.parser;
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -11,7 +11,10 @@ import type { ParticipantManifest, ServiceDescriptor } from '../../../src/contra
|
|
|
11
11
|
* - `brud_alloc(len: i32) -> i32` — returns a pointer to `len` writable bytes;
|
|
12
12
|
* - `brud_invoke(ptr: i32, len: i32) -> i64` — a call on one of its exposures;
|
|
13
13
|
* - `brud_intercept(ptr: i32, len: i32) -> i64` — an interception verdict
|
|
14
|
-
* (only when the manifest declares `interceptions`
|
|
14
|
+
* (only when the manifest declares an `interceptions` entry with the input
|
|
15
|
+
* stage, which is the default);
|
|
16
|
+
* - `brud_intercept_result(ptr: i32, len: i32) -> i64` — an output-stage verdict
|
|
17
|
+
* (only when an `interceptions` entry declares the output stage);
|
|
15
18
|
* - optionally `brud_start(ptr: i32, len: i32) -> i64` — called once when the
|
|
16
19
|
* participant starts running, with `{ kind: 'start', token }`; it answers
|
|
17
20
|
* `{ ok: true }` or `{ ok: false, error }` (a failure fails the start).
|
|
@@ -40,6 +43,9 @@ import type { ParticipantManifest, ServiceDescriptor } from '../../../src/contra
|
|
|
40
43
|
* Response: `{ ok: true, value }` or `{ ok: false, error: { code, message } }`.
|
|
41
44
|
* - `brud_intercept` request: the {@link InterceptedCall} as JSON. Response:
|
|
42
45
|
* an {@link InterceptionVerdict}.
|
|
46
|
+
* - `brud_intercept_result` request: the {@link InterceptedResult} as JSON.
|
|
47
|
+
* Response: `{ verdict: 'none' }` or `{ verdict: 'append', content }`; a guest
|
|
48
|
+
* can only add content, never change or remove the result.
|
|
43
49
|
*
|
|
44
50
|
* ## Security properties
|
|
45
51
|
*
|
|
@@ -91,8 +97,19 @@ export declare class CagedGuestError extends Error {
|
|
|
91
97
|
readonly code: "WASM_CAGE_GUEST_FAILED";
|
|
92
98
|
/** The guest-reported error code, when the guest reported one. */
|
|
93
99
|
readonly guestCode: string | undefined;
|
|
94
|
-
|
|
100
|
+
/** A stable reason when the cage itself stopped the guest at a limit; `undefined` for any other failure. */
|
|
101
|
+
readonly reason: CagedLimitReason | undefined;
|
|
102
|
+
/** The engine's full text, backtrace included. Never part of `message`. */
|
|
103
|
+
readonly detail: string | undefined;
|
|
104
|
+
constructor(message: string, guestCode?: string, options?: ErrorOptions & {
|
|
105
|
+
reason?: CagedLimitReason;
|
|
106
|
+
detail?: string;
|
|
107
|
+
});
|
|
95
108
|
}
|
|
109
|
+
/** Why the cage stopped a guest at one of its limits. */
|
|
110
|
+
export type CagedLimitReason = 'CAGE_FUEL_LIMIT' | 'CAGE_MEMORY_LIMIT';
|
|
111
|
+
/** Names the limit the engine's text reports, or `undefined` when it reports none. */
|
|
112
|
+
export declare function limitReason(text: string): CagedLimitReason | undefined;
|
|
96
113
|
/**
|
|
97
114
|
* Builds the descriptor of a caged participant: a participant whose code runs
|
|
98
115
|
* inside the WASM cage and which may be a giver (exposures and interception
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { withPlainCapabilities } from '../../../src/contracts/capabilitySet.js';
|
|
1
2
|
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
2
3
|
import { createServiceToken } from '../../../src/contracts/index.js';
|
|
3
4
|
import { compileJsonSchema } from '../../../src/validation/jsonSchema/index.js';
|
|
@@ -15,10 +16,16 @@ export class CagedGuestError extends Error {
|
|
|
15
16
|
code = 'WASM_CAGE_GUEST_FAILED';
|
|
16
17
|
/** The guest-reported error code, when the guest reported one. */
|
|
17
18
|
guestCode;
|
|
19
|
+
/** A stable reason when the cage itself stopped the guest at a limit; `undefined` for any other failure. */
|
|
20
|
+
reason;
|
|
21
|
+
/** The engine's full text, backtrace included. Never part of `message`. */
|
|
22
|
+
detail;
|
|
18
23
|
constructor(message, guestCode, options) {
|
|
19
24
|
super(message, options);
|
|
20
25
|
this.name = 'CagedGuestError';
|
|
21
26
|
this.guestCode = guestCode;
|
|
27
|
+
this.reason = options?.reason;
|
|
28
|
+
this.detail = options?.detail;
|
|
22
29
|
}
|
|
23
30
|
}
|
|
24
31
|
let engine;
|
|
@@ -43,10 +50,41 @@ function deepFreeze(value) {
|
|
|
43
50
|
}
|
|
44
51
|
return value;
|
|
45
52
|
}
|
|
53
|
+
const BACKTRACE_HEADER = /^\s*error while executing at wasm backtrace:\s*$/u;
|
|
54
|
+
/** One backtrace frame. The engine appends the cause to the last frame, so it is captured. */
|
|
55
|
+
const BACKTRACE_FRAME = /^\s*\d+:\s+0x[0-9a-f]+\s+-\s.*?<wasm function \d+>(?::\s*(.*))?$/u;
|
|
56
|
+
/** Names the limit the engine's text reports, or `undefined` when it reports none. */
|
|
57
|
+
export function limitReason(text) {
|
|
58
|
+
if (/all fuel consumed/iu.test(text)) {
|
|
59
|
+
return 'CAGE_FUEL_LIMIT';
|
|
60
|
+
}
|
|
61
|
+
return /growing memory|failed to grow memory|out of memory|memory (?:limit|minimum size|maximum size)|exceeds? .*memory/iu.test(text) ? 'CAGE_MEMORY_LIMIT' : undefined;
|
|
62
|
+
}
|
|
63
|
+
/** The engine's text without its backtrace frames: the part a caller can act on. */
|
|
64
|
+
function withoutBacktrace(text) {
|
|
65
|
+
return text.split('\n').flatMap((line) => {
|
|
66
|
+
if (BACKTRACE_HEADER.test(line)) {
|
|
67
|
+
return [];
|
|
68
|
+
}
|
|
69
|
+
const frame = BACKTRACE_FRAME.exec(line);
|
|
70
|
+
return frame === null ? [line] : (frame[1] === undefined || frame[1] === '' ? [] : [frame[1]]);
|
|
71
|
+
}).join('\n').trim();
|
|
72
|
+
}
|
|
73
|
+
const LIMIT_TEXT = {
|
|
74
|
+
CAGE_FUEL_LIMIT: 'used all of its fuel (limits.fuel)',
|
|
75
|
+
CAGE_MEMORY_LIMIT: 'passed its memory limit (limits.maxMemoryBytes)',
|
|
76
|
+
};
|
|
46
77
|
function guestFailure(exportName, error) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
78
|
+
if (error instanceof CagedGuestError) {
|
|
79
|
+
return error;
|
|
80
|
+
}
|
|
81
|
+
const detail = error.message;
|
|
82
|
+
const reason = limitReason(detail);
|
|
83
|
+
const summary = reason === undefined ? withoutBacktrace(detail) : LIMIT_TEXT[reason];
|
|
84
|
+
const message = reason === undefined
|
|
85
|
+
? `caged guest "${exportName}" failed${summary === '' ? '' : `: ${summary}`}`
|
|
86
|
+
: `caged guest "${exportName}" ${summary}`;
|
|
87
|
+
return new CagedGuestError(message, undefined, { cause: error, detail, ...(reason === undefined ? {} : { reason }) });
|
|
50
88
|
}
|
|
51
89
|
function step(exportName, run) {
|
|
52
90
|
try {
|
|
@@ -144,6 +182,13 @@ function plainCaller(caller) {
|
|
|
144
182
|
origin: caller.origin,
|
|
145
183
|
};
|
|
146
184
|
}
|
|
185
|
+
function isOutputVerdict(value) {
|
|
186
|
+
if (value === null || typeof value !== 'object') {
|
|
187
|
+
return false;
|
|
188
|
+
}
|
|
189
|
+
const verdict = value;
|
|
190
|
+
return verdict.verdict === 'none' || (verdict.verdict === 'append' && verdict.content !== undefined);
|
|
191
|
+
}
|
|
147
192
|
function isVerdict(value) {
|
|
148
193
|
if (value === null || typeof value !== 'object') {
|
|
149
194
|
return false;
|
|
@@ -303,7 +348,9 @@ export function createCagedParticipant(options) {
|
|
|
303
348
|
};
|
|
304
349
|
const routed = (request, signal) => serveRoutedCall(registry, request, signal);
|
|
305
350
|
const run = createScheduler(guest, routed, deadlineMs);
|
|
306
|
-
const invoke = (exposure, method,
|
|
351
|
+
const invoke = (exposure, method, rawArgs, caller) => {
|
|
352
|
+
// Capability views are carried as sorted arrays: the guest sees plain JSON.
|
|
353
|
+
const args = withPlainCapabilities(rawArgs);
|
|
307
354
|
const validation = argsSchema.validate(args);
|
|
308
355
|
if (!validation.valid) {
|
|
309
356
|
throw new CagedGuestError(`caged call "${exposure}.${method}": arguments are not plain values`);
|
|
@@ -329,6 +376,25 @@ export function createCagedParticipant(options) {
|
|
|
329
376
|
const message = typeof response?.error?.message === 'string' ? response.error.message : 'guest refused the call';
|
|
330
377
|
throw new CagedGuestError(`caged call "${exposure}.${method}" failed: ${message}`, code);
|
|
331
378
|
};
|
|
379
|
+
// The output stage, for a point this participant owns: interceptors may append to the
|
|
380
|
+
// result; the caller then receives the envelope. Without one the result is as it was.
|
|
381
|
+
const finish = (raw) => {
|
|
382
|
+
const value = settle(raw);
|
|
383
|
+
if (!points.has(name)) {
|
|
384
|
+
return value;
|
|
385
|
+
}
|
|
386
|
+
if (evaluator === null) {
|
|
387
|
+
throw new InterceptionBlockedError(exposure, 'interception unavailable');
|
|
388
|
+
}
|
|
389
|
+
const staged = evaluator.evaluateResult(exposure, method, callArgs, value, { caller });
|
|
390
|
+
if (!staged.applied) {
|
|
391
|
+
return value;
|
|
392
|
+
}
|
|
393
|
+
if (!staged.allowed) {
|
|
394
|
+
throw new InterceptionBlockedError(exposure, staged.reason);
|
|
395
|
+
}
|
|
396
|
+
return staged.envelope;
|
|
397
|
+
};
|
|
332
398
|
const outcome = run('brud_invoke', {
|
|
333
399
|
kind: 'invoke',
|
|
334
400
|
exposure,
|
|
@@ -336,7 +402,7 @@ export function createCagedParticipant(options) {
|
|
|
336
402
|
args: callArgs,
|
|
337
403
|
caller: plainCaller(caller),
|
|
338
404
|
}, true);
|
|
339
|
-
return outcome instanceof Promise ? outcome.then(
|
|
405
|
+
return outcome instanceof Promise ? outcome.then(finish) : finish(outcome);
|
|
340
406
|
};
|
|
341
407
|
const bindings = {};
|
|
342
408
|
for (const declaration of manifest.exposures ?? []) {
|
|
@@ -363,7 +429,20 @@ export function createCagedParticipant(options) {
|
|
|
363
429
|
}
|
|
364
430
|
},
|
|
365
431
|
};
|
|
366
|
-
|
|
432
|
+
const declaresStage = (stage) => (manifest.interceptions ?? []).some((entry) => (entry.stages ?? ['input']).includes(stage));
|
|
433
|
+
if (declaresStage('output')) {
|
|
434
|
+
Object.defineProperty(instance, 'interceptResult', {
|
|
435
|
+
value: (call) => {
|
|
436
|
+
const verdict = run('brud_intercept_result', call, false);
|
|
437
|
+
if (!isOutputVerdict(verdict)) {
|
|
438
|
+
throw new CagedGuestError('invalid output verdict');
|
|
439
|
+
}
|
|
440
|
+
return deepFreeze(verdict);
|
|
441
|
+
},
|
|
442
|
+
enumerable: false,
|
|
443
|
+
});
|
|
444
|
+
}
|
|
445
|
+
if (declaresStage('input')) {
|
|
367
446
|
Object.defineProperty(instance, 'intercept', {
|
|
368
447
|
value: (call) => {
|
|
369
448
|
const verdict = run('brud_intercept', call, false);
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -7,9 +7,9 @@
|
|
|
7
7
|
* binary whose digest is not listed here.
|
|
8
8
|
*/
|
|
9
9
|
export const WASM_CAGE_NATIVE_DIGESTS = Object.freeze([
|
|
10
|
-
['darwin-arm64', '
|
|
11
|
-
['darwin-x64', '
|
|
12
|
-
['linux-arm64-gnu', '
|
|
13
|
-
['linux-x64-gnu', '
|
|
14
|
-
['win32-x64-msvc', '
|
|
10
|
+
['darwin-arm64', '47af7e64c8481e42cd7b73bd89ac3f69da182591b64a1b656a33725cb5e64cad'],
|
|
11
|
+
['darwin-x64', 'c833ad031943aa522720805a418edb36add03da0f79bf4421aa908d7644f324a'],
|
|
12
|
+
['linux-arm64-gnu', '5c420e2cf34c26dbd15951d8e9d4c0444f89ac8c3e789637d0a75661699ed25c'],
|
|
13
|
+
['linux-x64-gnu', '7c7d46dfe4b3c72c2612b9742bb474d97f05670332f175055a33d37e61ef5ffa'],
|
|
14
|
+
['win32-x64-msvc', '5be0f4f1b82ab17284afa78b0248d300a8a1589ae288dacbfe2f628d9bed85e2'],
|
|
15
15
|
]);
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { type ReloadableKernel } from './reload.js';
|
|
2
2
|
import type { BootKernelOptions, ComposeKernelOptions } from './bootTypes.js';
|
|
3
3
|
/**
|
|
4
4
|
* Reads, validates, composes, and boots a kernel from `brud.config.json`.
|
|
@@ -6,7 +6,7 @@ import type { BootKernelOptions, ComposeKernelOptions } from './bootTypes.js';
|
|
|
6
6
|
* @param configPath - Path to the config file.
|
|
7
7
|
* @param options - Generic options bag and logger.
|
|
8
8
|
*/
|
|
9
|
-
export declare function bootKernel(configPath: string, options: BootKernelOptions): Promise<
|
|
9
|
+
export declare function bootKernel(configPath: string, options: BootKernelOptions): Promise<ReloadableKernel>;
|
|
10
10
|
/**
|
|
11
11
|
* Builds a kernel whose config is composed lazily on the first `boot()`.
|
|
12
12
|
*
|
|
@@ -15,4 +15,5 @@ export declare function bootKernel(configPath: string, options: BootKernelOption
|
|
|
15
15
|
* instances in the ESM cache instead of loading a second copy through
|
|
16
16
|
* `require`.
|
|
17
17
|
*/
|
|
18
|
-
export declare function createDeferredKernel(configPath: string, options: ComposeKernelOptions):
|
|
18
|
+
export declare function createDeferredKernel(configPath: string, options: ComposeKernelOptions): ReloadableKernel;
|
|
19
|
+
export declare function resolveModuleId(declaredPath: string, configPath: string): string;
|