@capybara-hq/kernel 0.1.0-rc.54 → 0.1.0-rc.56
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/admin.schemas.d.ts +11 -1
- package/dist/catalog/catalog.module.js +1 -1
- package/dist/catalog/marketplaces.service.d.ts +1 -1
- package/dist/catalog/requests.service.d.ts +5 -5
- package/dist/catalog/requests.service.js +9 -9
- package/dist/channels/cards.d.ts +4 -3
- package/dist/channels/cards.js +25 -16
- package/dist/channels/phrases.d.ts +15 -4
- package/dist/channels/phrases.js +15 -1
- package/dist/config/load.d.ts +26 -7
- package/dist/config/load.js +60 -9
- package/dist/config/permission-migration.d.ts +17 -9
- package/dist/config/permission-migration.js +60 -9
- package/dist/config/schema.d.ts +11 -1
- package/dist/config/schema.js +37 -11
- package/dist/conversations/events.d.ts +247 -5
- package/dist/conversations/events.js +127 -16
- package/dist/conversations/permission-profiles.controller.d.ts +12 -2
- package/dist/conversations/permission-profiles.service.d.ts +12 -2
- package/dist/conversations/permission-profiles.service.js +11 -4
- package/dist/db/kernel-schema.d.ts +8 -2
- package/dist/devices/device-projects.service.d.ts +1 -1
- package/dist/devices/device-projects.service.js +6 -6
- package/dist/devices/devices.controller.d.ts +10 -8
- package/dist/devices/devices.controller.js +14 -18
- package/dist/devices/devices.schemas.d.ts +5 -5
- package/dist/devices/devices.schemas.js +5 -5
- package/dist/devices/devices.service.d.ts +188 -175
- package/dist/devices/devices.service.js +284 -292
- package/dist/devices/dto.d.ts +43 -23
- package/dist/devices/dto.js +45 -49
- package/dist/devices/project-rules.d.ts +0 -10
- package/dist/devices/project-rules.js +0 -5
- package/dist/errors.d.ts +24 -19
- package/dist/errors.js +24 -19
- package/dist/evals/reconstruct.d.ts +12 -3
- package/dist/evals/reconstruct.js +10 -6
- package/dist/evals/recorded-permission-context.d.ts +6 -4
- package/dist/evals/recorded-permission-context.js +15 -9
- package/dist/evals/run-replay.d.ts +6 -1
- package/dist/evals/run-replay.js +7 -2
- package/dist/evals/worker.js +3 -1
- package/dist/identity/settings.d.ts +45 -18
- package/dist/identity/settings.js +151 -51
- package/dist/infra/config/kernel-config.service.d.ts +1 -1
- package/dist/infra/config/kernel-config.service.js +17 -5
- package/dist/local-devices/device-auth.controller.d.ts +1 -1
- package/dist/local-devices/device-auth.controller.js +1 -1
- package/dist/local-devices/device-auth.d.ts +4 -4
- package/dist/local-devices/device-auth.js +1 -1
- package/dist/local-devices/device-policy.service.d.ts +18 -9
- package/dist/local-devices/device-policy.service.js +21 -61
- package/dist/local-devices/device-routes.d.ts +3 -1
- package/dist/local-devices/device-routes.js +15 -4
- package/dist/local-devices/instance-bindings.js +5 -2
- package/dist/local-devices/local-device-gateway.d.ts +2 -2
- package/dist/local-devices/local-device-gateway.js +3 -3
- package/dist/local-devices/local-device-provider.d.ts +4 -4
- package/dist/local-devices/local-device-provider.js +23 -9
- package/dist/local-devices/local-devices.module.d.ts +1 -1
- package/dist/local-devices/local-devices.module.js +1 -1
- package/dist/local-devices/machines.d.ts +40 -16
- package/dist/local-devices/machines.js +89 -61
- package/dist/local-devices/owner-report.d.ts +16 -14
- package/dist/local-devices/owner-report.js +24 -30
- package/dist/local-devices/owner-reports.js +26 -8
- package/dist/local-devices/policy-summary.d.ts +25 -44
- package/dist/local-devices/policy-summary.js +26 -71
- package/dist/local-devices/relay.d.ts +6 -6
- package/dist/local-devices/relay.js +10 -8
- package/dist/net/public-address.d.ts +1 -1
- package/dist/net/public-address.js +5 -2
- package/dist/orgs/device-network-setting.d.ts +82 -0
- package/dist/orgs/device-network-setting.js +142 -0
- package/dist/orgs/settings.service.d.ts +103 -66
- package/dist/orgs/settings.service.js +201 -137
- package/dist/overrides.d.ts +5 -1
- package/dist/overrides.js +2 -0
- package/dist/platform/exclusions.js +1 -1
- package/dist/platform/operation.js +1 -1
- package/dist/platform/ops/admin.ops.js +20 -11
- package/dist/platform/ops/devices.ops.js +70 -5
- package/dist/platform/ops/org-settings.ops.js +10 -6
- package/dist/platform/ops/orgs.ops.js +2 -1
- package/dist/runtime/context/permission-profile.d.ts +17 -8
- package/dist/runtime/context/permission-profile.js +126 -45
- package/dist/runtime/permission-context.service.d.ts +1 -1
- package/dist/runtime/permission-context.service.js +5 -3
- package/dist/runtime/project/knowledge.d.ts +5 -4
- package/dist/runtime/project/knowledge.js +2 -1
- package/dist/runtime/project/knowledge.service.js +16 -13
- package/dist/sandbox/cloud-permission-snapshot.js +22 -3
- package/dist/sandbox/device-sandbox-settings.d.ts +230 -0
- package/dist/sandbox/device-sandbox-settings.js +470 -0
- package/dist/sandbox/device-sandbox.d.ts +187 -0
- package/dist/sandbox/device-sandbox.js +236 -0
- package/dist/sandbox/held-operations.js +15 -7
- package/dist/sandbox/modes.d.ts +49 -24
- package/dist/sandbox/modes.js +27 -19
- package/dist/sandbox/operation-authority-types.d.ts +6 -5
- package/dist/sandbox/operation-authority-types.js +7 -8
- package/dist/sandbox/operation-authority.d.ts +23 -9
- package/dist/sandbox/operation-authority.js +179 -97
- package/dist/sandbox/permission-auto-grants.d.ts +42 -0
- package/dist/sandbox/permission-auto-grants.js +145 -0
- package/dist/sandbox/permission-call-grants.d.ts +12 -4
- package/dist/sandbox/permission-call-grants.js +84 -35
- package/dist/sandbox/permission-call-grants.module.js +10 -3
- package/dist/sandbox/permission-call-types.d.ts +39 -5
- package/dist/sandbox/permission-ceiling-writes.d.ts +29 -3
- package/dist/sandbox/permission-ceiling-writes.js +38 -4
- package/dist/sandbox/permission-config-publication.d.ts +44 -2
- package/dist/sandbox/permission-config-publication.js +230 -59
- package/dist/sandbox/permission-context-types.d.ts +2 -2
- package/dist/sandbox/permission-facts.d.ts +144 -15
- package/dist/sandbox/permission-facts.js +258 -70
- package/dist/sandbox/permission-runtime-reports.d.ts +5 -4
- package/dist/sandbox/permission-runtime-reports.js +19 -29
- package/dist/sandbox/review/classifier.d.ts +8 -0
- package/dist/sandbox/review/classifier.js +10 -0
- package/dist/sandbox/review/permission-candidate.d.ts +69 -5
- package/dist/sandbox/review/permission-candidate.js +153 -30
- package/dist/sandbox/review/review.service.d.ts +19 -3
- package/dist/sandbox/review/review.service.js +59 -11
- package/dist/sandbox/review/rules.js +23 -3
- package/dist/sandbox/sandbox.service.d.ts +29 -11
- package/dist/sandbox/sandbox.service.js +51 -26
- package/dist/skills/invoke.js +3 -2
- package/dist/tools/approvals.service.d.ts +26 -116
- package/dist/tools/approvals.service.js +42 -346
- package/dist/tools/builtins/sandbox/bash.d.ts +16 -3
- package/dist/tools/builtins/sandbox/bash.js +80 -28
- package/dist/tools/builtins/sandbox/common.d.ts +39 -14
- package/dist/tools/builtins/sandbox/common.js +47 -24
- package/dist/tools/builtins/sandbox/deliver.js +7 -4
- package/dist/tools/builtins/skill-load.d.ts +2 -2
- package/dist/tools/builtins/skill-load.js +4 -3
- package/dist/tools/device-op-resolver.d.ts +4 -10
- package/dist/tools/device-op-resolver.js +8 -19
- package/dist/tools/network-asks.d.ts +52 -15
- package/dist/tools/network-asks.js +55 -25
- package/dist/tools/pipeline.d.ts +26 -14
- package/dist/tools/pipeline.js +144 -61
- package/dist/tools/registry.d.ts +6 -0
- package/dist/tools/tools.module.js +1 -1
- package/dist/ui/views.d.ts +3 -1
- package/dist/ui/views.js +2 -1
- package/package.json +4 -4
- package/src/migrations/0165_device_network_columns.sql +50 -0
- package/src/migrations/0166_permission_grant_full_access.sql +17 -0
- package/src/migrations/0167_device_network_backfill.sql +32 -0
- package/src/migrations/0168_binding_installed_connection.sql +6 -0
- package/dist/orgs/cloud-network-setting.d.ts +0 -33
- package/dist/orgs/cloud-network-setting.js +0 -47
- package/dist/sandbox/platform-full-access.d.ts +0 -110
- package/dist/sandbox/platform-full-access.js +0 -198
|
@@ -4,7 +4,6 @@ const KNOWN_FEATURES = [
|
|
|
4
4
|
"networkReport",
|
|
5
5
|
"policyOp",
|
|
6
6
|
"policyOpId",
|
|
7
|
-
"mode",
|
|
8
7
|
"projects",
|
|
9
8
|
];
|
|
10
9
|
/**
|
|
@@ -25,44 +24,11 @@ export function localPolicyOf(v) {
|
|
|
25
24
|
if (typeof v !== "object" || v === null || Array.isArray(v))
|
|
26
25
|
return null;
|
|
27
26
|
const o = v;
|
|
28
|
-
if (o.mode !== "auto" && o.mode !== "sandbox")
|
|
29
|
-
return null;
|
|
30
27
|
if (!Array.isArray(o.allowedDomains))
|
|
31
28
|
return null;
|
|
32
29
|
if (!o.allowedDomains.every((d) => typeof d === "string"))
|
|
33
30
|
return null;
|
|
34
|
-
return {
|
|
35
|
-
}
|
|
36
|
-
/** The isolation of a summary recorded before auto mode, if `v` is one (no `mode` field). */
|
|
37
|
-
export function legacyIsolationOf(v) {
|
|
38
|
-
if (typeof v !== "object" || v === null || Array.isArray(v))
|
|
39
|
-
return null;
|
|
40
|
-
const o = v;
|
|
41
|
-
if (o.mode !== undefined)
|
|
42
|
-
return null;
|
|
43
|
-
return o.isolation === "none" || o.isolation === "sandbox" ? o.isolation : null;
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* The legacy part of a summary a program reported (a pre-auto-mode payload the frame parser drops):
|
|
47
|
-
* its isolation alone, kept so an unsandboxed old program is still recognized. Null for a summary
|
|
48
|
-
* in the current shape, a malformed one, or a program whose summary is unreadable.
|
|
49
|
-
*/
|
|
50
|
-
export function legacyPolicyOf(v) {
|
|
51
|
-
const isolation = legacyIsolationOf(v);
|
|
52
|
-
return isolation === null ? null : { isolation };
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* The mode a local device runs at, from its reported features and stored policy (auto mode spec
|
|
56
|
-
* §4.2), failing closed: a program that applies modes but sent no readable summary is sandbox; an
|
|
57
|
-
* older program (no `mode` feature) is auto only when its legacy summary was unsandboxed.
|
|
58
|
-
*/
|
|
59
|
-
export function localModeOf(features, localPolicy) {
|
|
60
|
-
const summary = localPolicyOf(localPolicy);
|
|
61
|
-
if (summary !== null)
|
|
62
|
-
return summary.mode;
|
|
63
|
-
if (deviceFeaturesOf(features).includes("mode"))
|
|
64
|
-
return "sandbox";
|
|
65
|
-
return legacyIsolationOf(localPolicy) === "none" ? "auto" : "sandbox";
|
|
31
|
+
return { allowedDomains: [...o.allowedDomains] };
|
|
66
32
|
}
|
|
67
33
|
/** The {@link LocalPolicyDiff} from `prev` to `next`; null when nothing the owner sets changed. */
|
|
68
34
|
export function localPolicyDiff(prev, next) {
|
|
@@ -72,10 +38,7 @@ export function localPolicyDiff(prev, next) {
|
|
|
72
38
|
add: [...after].filter((h) => !before.has(h)).sort(),
|
|
73
39
|
remove: [...before].filter((h) => !after.has(h)).sort(),
|
|
74
40
|
};
|
|
75
|
-
|
|
76
|
-
d.mode = { from: prev.mode, to: next.mode };
|
|
77
|
-
const changed = d.add.length > 0 || d.remove.length > 0 || d.mode !== undefined;
|
|
78
|
-
return changed ? d : null;
|
|
41
|
+
return d.add.length > 0 || d.remove.length > 0 ? d : null;
|
|
79
42
|
}
|
|
80
43
|
/** The pending ops stored on a machine row (malformed entries dropped). */
|
|
81
44
|
export function pendingPolicyOpsOf(v) {
|
|
@@ -108,15 +71,9 @@ export function pendingPolicyOpsOf(v) {
|
|
|
108
71
|
: undefined;
|
|
109
72
|
out.push({
|
|
110
73
|
id: o.id,
|
|
111
|
-
add: hosts(o.add),
|
|
112
74
|
remove: hosts(o.remove),
|
|
113
|
-
...(o.mode === "sandbox" && { mode: "sandbox" }),
|
|
114
75
|
...ownerNarrowingOf(o.ownerCeiling),
|
|
115
|
-
source: {
|
|
116
|
-
accountId: src.accountId,
|
|
117
|
-
via: src.via,
|
|
118
|
-
approvalId: typeof src.approvalId === "string" ? src.approvalId : null,
|
|
119
|
-
},
|
|
76
|
+
source: { accountId: src.accountId, via: src.via },
|
|
120
77
|
...(typeof o.actorTokenId === "string" && { actorTokenId: o.actorTokenId }),
|
|
121
78
|
status: o.status,
|
|
122
79
|
sentAt: o.sentAt,
|
|
@@ -128,16 +85,11 @@ export function pendingPolicyOpsOf(v) {
|
|
|
128
85
|
return out;
|
|
129
86
|
}
|
|
130
87
|
/**
|
|
131
|
-
* Whether the change of `op` is in `policy`: its hosts
|
|
132
|
-
*
|
|
133
|
-
* written from one that was not.
|
|
88
|
+
* Whether the change of `op` is in `policy`: its hosts removed. Tells an op the machine logged only
|
|
89
|
+
* as `started` (it stopped between the log and the answer) that was written from one that was not.
|
|
134
90
|
*/
|
|
135
91
|
export function opVisibleIn(op, policy) {
|
|
136
|
-
|
|
137
|
-
return false;
|
|
138
|
-
if (op.remove.some((h) => policy.allowedDomains.includes(h)))
|
|
139
|
-
return false;
|
|
140
|
-
return op.mode === undefined || policy.mode === op.mode;
|
|
92
|
+
return !op.remove.some((h) => policy.allowedDomains.includes(h));
|
|
141
93
|
}
|
|
142
94
|
/** A stored op's owner narrowing: kept only while it narrows (anything wider is dropped). */
|
|
143
95
|
function ownerNarrowingOf(v) {
|
|
@@ -145,7 +97,8 @@ function ownerNarrowingOf(v) {
|
|
|
145
97
|
return {};
|
|
146
98
|
const o = v;
|
|
147
99
|
const narrowing = {
|
|
148
|
-
...(o.
|
|
100
|
+
...(o.outsideSandbox === false && { outsideSandbox: false }),
|
|
101
|
+
...(o.network === "allowlist" && { network: "allowlist" }),
|
|
149
102
|
...(o.restrictedProjectReach === "workspace" && {
|
|
150
103
|
restrictedProjectReach: "workspace",
|
|
151
104
|
}),
|
|
@@ -159,11 +112,14 @@ function ownerNarrowingOf(v) {
|
|
|
159
112
|
* an op's.
|
|
160
113
|
*/
|
|
161
114
|
export function opExplainsOwnerChange(op, before, after) {
|
|
162
|
-
const
|
|
115
|
+
const outsideChanged = before.outsideSandbox !== after.outsideSandbox;
|
|
163
116
|
const reachChanged = before.restrictedProjectReach !== after.restrictedProjectReach;
|
|
164
|
-
|
|
117
|
+
const networkChanged = (before.network ?? after.network) !== (after.network ?? before.network);
|
|
118
|
+
if (!outsideChanged && !reachChanged && !networkChanged)
|
|
165
119
|
return false;
|
|
166
|
-
if (
|
|
120
|
+
if (outsideChanged && (op.ownerCeiling?.outsideSandbox !== false || after.outsideSandbox))
|
|
121
|
+
return false;
|
|
122
|
+
if (networkChanged && (op.ownerCeiling?.network !== "allowlist" || after.network !== "allowlist"))
|
|
167
123
|
return false;
|
|
168
124
|
if (reachChanged &&
|
|
169
125
|
(op.ownerCeiling?.restrictedProjectReach !== "workspace" ||
|
|
@@ -173,26 +129,25 @@ export function opExplainsOwnerChange(op, before, after) {
|
|
|
173
129
|
}
|
|
174
130
|
/**
|
|
175
131
|
* Whether `diff` is what the platform's `op` did (its answer, or the machine's own report of it
|
|
176
|
-
* before the answer was recorded): hosts within the op's
|
|
177
|
-
*
|
|
132
|
+
* before the answer was recorded): hosts within the op's. The device page then lists the change
|
|
133
|
+
* once, as the platform's.
|
|
178
134
|
*/
|
|
179
135
|
export function opExplains(op, diff) {
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
if (!diff.remove.every((h) => op.remove.includes(h)))
|
|
136
|
+
// the platform never adds a host: a diff with an addition is the owner's own
|
|
137
|
+
if (diff.add.length > 0)
|
|
183
138
|
return false;
|
|
184
|
-
|
|
185
|
-
return false;
|
|
186
|
-
return true;
|
|
139
|
+
return diff.remove.every((h) => op.remove.includes(h));
|
|
187
140
|
}
|
|
188
|
-
/**
|
|
141
|
+
/**
|
|
142
|
+
* Revoke only authority removed from a starting grant; explicit additions are not owner baseline.
|
|
143
|
+
* The summary carries the sandbox allowlist only: the owner ceiling (outside the sandbox, the
|
|
144
|
+
* reach) is revoked by the owner report's writer (`ownerReportRevokes`).
|
|
145
|
+
*/
|
|
189
146
|
export function ownerPolicyRevokes(next, scope, method, grantedHosts) {
|
|
190
147
|
if (!next)
|
|
191
148
|
return true;
|
|
192
|
-
if (!("profile" in scope))
|
|
193
|
-
return
|
|
194
|
-
if (isFullExecutionScope(scope))
|
|
195
|
-
return next.mode !== "auto";
|
|
149
|
+
if (!("profile" in scope) || isFullExecutionScope(scope))
|
|
150
|
+
return false;
|
|
196
151
|
if (!isExecutionMethod(method) || scope.network.kind !== "allowlist")
|
|
197
152
|
return false;
|
|
198
153
|
return scope.network.hosts.some((host) => !next.allowedDomains.some((pattern) => coversHost(pattern, host)) &&
|
|
@@ -14,7 +14,7 @@ export declare const POLICY_REFUSAL_PREFIX = "Refused by the machine's local pol
|
|
|
14
14
|
/** The text a machine's `error` result reaches the model with (ruling R28). */
|
|
15
15
|
export declare const ON_MACHINE_PREFIX = "On the connected machine: ";
|
|
16
16
|
/**
|
|
17
|
-
* The text of a staged (protocol
|
|
17
|
+
* The text of a staged (protocol 4) request refused because the machine's connection changed.
|
|
18
18
|
* Only an output read has an offset to retry from; every other operation is simply retried.
|
|
19
19
|
*/
|
|
20
20
|
export declare const connectionChangedMessage: (op: string) => string;
|
|
@@ -95,7 +95,7 @@ export declare class LocalDeviceRelay {
|
|
|
95
95
|
holderLive(deviceId: string): Promise<boolean>;
|
|
96
96
|
/**
|
|
97
97
|
* The negotiated transport of the device's connection for the platform's own controls (policy
|
|
98
|
-
* ops): every connection speaks protocol
|
|
98
|
+
* ops): every connection speaks protocol 4, so this is {@link connection} (a missing or unready
|
|
99
99
|
* one throws its typed error).
|
|
100
100
|
*/
|
|
101
101
|
stagedTransport(deviceId: string): Promise<{
|
|
@@ -115,9 +115,9 @@ export declare class LocalDeviceRelay {
|
|
|
115
115
|
* Queues `stop` for the machine without waiting for an answer (ruling R14). The caller checks
|
|
116
116
|
* {@link holderLive} first; the frame waits on the list for the grace like any request. It is
|
|
117
117
|
* fenced to the machine `machineId` ({@link STOP_MACHINE}): a holder hands it only to that
|
|
118
|
-
* machine's connection (on a staged connection as a protocol
|
|
118
|
+
* machine's connection (on a staged connection as a protocol 4 `stop`, across a socket blip
|
|
119
119
|
* too), never to a newer machine of the device. Only `stop` is ever queued this way: a broad
|
|
120
|
-
* kill (`killAll` / `killTagged`) has no frame on protocol
|
|
120
|
+
* kill (`killAll` / `killTagged`) has no frame on protocol 4.
|
|
121
121
|
*/
|
|
122
122
|
send(deviceId: string, op: "stop", args: DeviceStopArgs, deadlineMs: number, machineId: string): Promise<void>;
|
|
123
123
|
/**
|
|
@@ -132,8 +132,8 @@ export declare class LocalDeviceRelay {
|
|
|
132
132
|
*/
|
|
133
133
|
call<Op extends DeviceOp>(deviceId: string, op: Op, args: unknown, opts: DeviceCallOptions): Promise<DeviceOpResults[Op]>;
|
|
134
134
|
/**
|
|
135
|
-
* Runs a protocol
|
|
136
|
-
* returns its validated result; the request is checked against the protocol
|
|
135
|
+
* Runs a protocol 4 operation on the device's machine over its current staged connection and
|
|
136
|
+
* returns its validated result; the request is checked against the protocol 4 codec first.
|
|
137
137
|
*/
|
|
138
138
|
callV3(deviceId: string, op: DeviceOperation, args: Record<string, unknown>, opts: DeviceCallOptions): Promise<unknown>;
|
|
139
139
|
private callWithCodec;
|
|
@@ -8,7 +8,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
8
8
|
return function (target, key) { decorator(target, key, paramIndex); }
|
|
9
9
|
};
|
|
10
10
|
import { randomUUID } from "node:crypto";
|
|
11
|
-
import { DeviceProtocolError, FileSystemGoneError, parseDeviceFrame, parseLegacyDeviceFrame, parseOperationResult, parseOpResult, SandboxGoneError, SandboxOperationOutcomeUnknownError, SandboxPermissionUnsupportedError, SandboxScopeDeniedError, ToolError, } from "@capybara-hq/plugin-sdk";
|
|
11
|
+
import { DeviceProtocolError, FileSystemGoneError, parseDeviceFrame, parseLegacyDeviceFrame, parseOperationResult, parseOpResult, SandboxGoneError, SandboxOperationOutcomeUnknownError, SandboxPermissionUnsupportedError, SandboxScopeDeniedError, SandboxScopeValidationError, ToolError, } from "@capybara-hq/plugin-sdk";
|
|
12
12
|
import { Inject, Injectable } from "@nestjs/common";
|
|
13
13
|
import { machineRevoked } from "../devices/errors.js";
|
|
14
14
|
import { ApiError } from "../errors.js";
|
|
@@ -27,7 +27,7 @@ export const POLICY_REFUSAL_PREFIX = "Refused by the machine's local policy: ";
|
|
|
27
27
|
/** The text a machine's `error` result reaches the model with (ruling R28). */
|
|
28
28
|
export const ON_MACHINE_PREFIX = "On the connected machine: ";
|
|
29
29
|
/**
|
|
30
|
-
* The text of a staged (protocol
|
|
30
|
+
* The text of a staged (protocol 4) request refused because the machine's connection changed.
|
|
31
31
|
* Only an output read has an offset to retry from; every other operation is simply retried.
|
|
32
32
|
*/
|
|
33
33
|
export const connectionChangedMessage = (op) => op === "backgroundReadOutput"
|
|
@@ -45,7 +45,7 @@ const heldOperation = (op) => op === "backgroundStart" ||
|
|
|
45
45
|
/^(?:exec|readFile|writeFile|stat|list|scan|prepare(?:ReadFile|WriteFile|Stat)|browse(?:Stat|List|Scan))$/.test(op);
|
|
46
46
|
/**
|
|
47
47
|
* Whether a staged operation's result is fenced to the connection its request was sent on.
|
|
48
|
-
* Protocol
|
|
48
|
+
* Protocol 4 (spec B5) fences every request to its connection, so an old capacity is never used on
|
|
49
49
|
* a replacement socket. For results, only an output read is fenced: its range was sized for the
|
|
50
50
|
* old connection's capacity and an in-flight read that meets a reconnect fails so the reader
|
|
51
51
|
* retries from the same offset. Every other operation keeps protocol 2's grace semantics: the
|
|
@@ -162,7 +162,7 @@ let LocalDeviceRelay = class LocalDeviceRelay {
|
|
|
162
162
|
}
|
|
163
163
|
/**
|
|
164
164
|
* The negotiated transport of the device's connection for the platform's own controls (policy
|
|
165
|
-
* ops): every connection speaks protocol
|
|
165
|
+
* ops): every connection speaks protocol 4, so this is {@link connection} (a missing or unready
|
|
166
166
|
* one throws its typed error).
|
|
167
167
|
*/
|
|
168
168
|
async stagedTransport(deviceId) {
|
|
@@ -185,9 +185,9 @@ let LocalDeviceRelay = class LocalDeviceRelay {
|
|
|
185
185
|
* Queues `stop` for the machine without waiting for an answer (ruling R14). The caller checks
|
|
186
186
|
* {@link holderLive} first; the frame waits on the list for the grace like any request. It is
|
|
187
187
|
* fenced to the machine `machineId` ({@link STOP_MACHINE}): a holder hands it only to that
|
|
188
|
-
* machine's connection (on a staged connection as a protocol
|
|
188
|
+
* machine's connection (on a staged connection as a protocol 4 `stop`, across a socket blip
|
|
189
189
|
* too), never to a newer machine of the device. Only `stop` is ever queued this way: a broad
|
|
190
|
-
* kill (`killAll` / `killTagged`) has no frame on protocol
|
|
190
|
+
* kill (`killAll` / `killTagged`) has no frame on protocol 4.
|
|
191
191
|
*/
|
|
192
192
|
async send(deviceId, op, args, deadlineMs, machineId) {
|
|
193
193
|
const id = randomUUID();
|
|
@@ -211,8 +211,8 @@ let LocalDeviceRelay = class LocalDeviceRelay {
|
|
|
211
211
|
return this.callWithCodec(deviceId, op, args, opts, false);
|
|
212
212
|
}
|
|
213
213
|
/**
|
|
214
|
-
* Runs a protocol
|
|
215
|
-
* returns its validated result; the request is checked against the protocol
|
|
214
|
+
* Runs a protocol 4 operation on the device's machine over its current staged connection and
|
|
215
|
+
* returns its validated result; the request is checked against the protocol 4 codec first.
|
|
216
216
|
*/
|
|
217
217
|
async callV3(deviceId, op, args, opts) {
|
|
218
218
|
parseDeviceFrame(JSON.stringify({ type: "req", id: "validation", op, args, deadlineMs: opts.deadlineMs }), "kernel");
|
|
@@ -509,6 +509,8 @@ let LocalDeviceRelay = class LocalDeviceRelay {
|
|
|
509
509
|
throw new SandboxPermissionUnsupportedError(message);
|
|
510
510
|
case "unknown":
|
|
511
511
|
throw new SandboxOperationOutcomeUnknownError(message);
|
|
512
|
+
case "invalid":
|
|
513
|
+
throw new SandboxScopeValidationError(message);
|
|
512
514
|
case "gone":
|
|
513
515
|
throw new SandboxGoneError(message);
|
|
514
516
|
case "fs_gone":
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
export declare function isForbiddenAddress(ip: string): boolean;
|
|
3
3
|
/**
|
|
4
4
|
* Link-local (incl. cloud metadata 169.254.169.254), another cloud metadata endpoint
|
|
5
|
-
* (`100.100.100.200`, `fd00:ec2::254`) or unparseable: forbidden whatever the exemptions.
|
|
5
|
+
* (`100.100.100.200`, `168.63.129.16`, `fd00:ec2::254`) or unparseable: forbidden whatever the exemptions.
|
|
6
6
|
*/
|
|
7
7
|
export declare function isLinkLocalAddress(ip: string): boolean;
|
|
8
8
|
/** Loopback (`127.0.0.0/8`, `::1`) or unspecified (`0.0.0.0/8`, `::`), embedded forms included. */
|
|
@@ -16,7 +16,8 @@ import { BlockList, isIP } from "node:net";
|
|
|
16
16
|
* a host behind a SIIT translator could otherwise reach a private IPv4 address.
|
|
17
17
|
*
|
|
18
18
|
* Link-local addresses (`169.254.0.0/16`, including cloud metadata, and `fe80::/10`) and the cloud
|
|
19
|
-
* metadata endpoints outside link-local (AWS IPv6 `fd00:ec2::254`, Alibaba Cloud `100.100.100.200
|
|
19
|
+
* metadata endpoints outside link-local (AWS IPv6 `fd00:ec2::254`, Alibaba Cloud `100.100.100.200`,
|
|
20
|
+
* Azure WireServer `168.63.129.16`)
|
|
20
21
|
* stay forbidden whatever the exemptions: no internal mirror lives there.
|
|
21
22
|
*
|
|
22
23
|
* Extension requests (`ctx.net`, {@link NetPolicy.extension}) also refuse loopback and unspecified
|
|
@@ -27,6 +28,7 @@ const BLOCKED_V4 = [
|
|
|
27
28
|
["10.0.0.0", 8],
|
|
28
29
|
["100.64.0.0", 10], // CGNAT
|
|
29
30
|
["127.0.0.0", 8],
|
|
31
|
+
["168.63.129.16", 32], // Azure WireServer (metadata, outside link-local)
|
|
30
32
|
["169.254.0.0", 16], // link-local, including cloud metadata 169.254.169.254
|
|
31
33
|
["172.16.0.0", 12],
|
|
32
34
|
["192.0.0.0", 24],
|
|
@@ -60,6 +62,7 @@ const neverAllowed = new BlockList();
|
|
|
60
62
|
neverAllowed.addSubnet("169.254.0.0", 16, "ipv4");
|
|
61
63
|
neverAllowed.addSubnet("fe80::", 10, "ipv6");
|
|
62
64
|
neverAllowed.addAddress("100.100.100.200", "ipv4"); // Alibaba Cloud metadata (inside CGNAT)
|
|
65
|
+
neverAllowed.addAddress("168.63.129.16", "ipv4"); // Azure WireServer
|
|
63
66
|
neverAllowed.addAddress("fd00:ec2::254", "ipv6"); // AWS IMDS over IPv6 (inside ULA)
|
|
64
67
|
/** Loopback and unspecified: never allowed for extension requests (see the file header). */
|
|
65
68
|
const loopbackOrUnspecified = new BlockList();
|
|
@@ -133,7 +136,7 @@ export function isForbiddenAddress(ip) {
|
|
|
133
136
|
}
|
|
134
137
|
/**
|
|
135
138
|
* Link-local (incl. cloud metadata 169.254.169.254), another cloud metadata endpoint
|
|
136
|
-
* (`100.100.100.200`, `fd00:ec2::254`) or unparseable: forbidden whatever the exemptions.
|
|
139
|
+
* (`100.100.100.200`, `168.63.129.16`, `fd00:ec2::254`) or unparseable: forbidden whatever the exemptions.
|
|
137
140
|
*/
|
|
138
141
|
export function isLinkLocalAddress(ip) {
|
|
139
142
|
return inTable(ip, neverAllowed);
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/** The org device network allowlist's host limit. */
|
|
3
|
+
export declare const ORG_SANDBOX_ALLOW_HOSTS_MAX = 200;
|
|
4
|
+
/**
|
|
5
|
+
* The org's device sandbox network (approval-only profiles design, "Settings model"), for local and
|
|
6
|
+
* cloud devices alike, with its hosts stored as a delta over the platform's
|
|
7
|
+
* `sandbox.limits.allowHosts`, never a copy of it, so platform changes keep reaching the org:
|
|
8
|
+
* - `default`: the network a device of the org gets when its owner chooses none (`open` or
|
|
9
|
+
* `allowlist`); absent follows the platform's `devices.network.default`.
|
|
10
|
+
* - `ceiling`: the widest network a device of the org may choose; absent follows the platform's
|
|
11
|
+
* `devices.network.ceiling`. Never above the platform's ceiling (`org.network_not_allowed`); a
|
|
12
|
+
* default above the ceiling is refused.
|
|
13
|
+
* - `base`: `platform` (the default: start from the platform's list) or `none` (only the org's own
|
|
14
|
+
* hosts).
|
|
15
|
+
* - `extraHosts`: hosts the org adds (ignored outside the platform list under `orgHosts: within`).
|
|
16
|
+
* - `excludedHosts`: platform entries the org drops (exact entries; any host is accepted, since the
|
|
17
|
+
* platform may drop an entry later).
|
|
18
|
+
* The effective hosts are `orgEffectiveHosts` in `sandbox/modes.ts`.
|
|
19
|
+
*/
|
|
20
|
+
export declare const DeviceNetworkSettingSchema: z.ZodObject<{
|
|
21
|
+
default: z.ZodOptional<z.ZodEnum<{
|
|
22
|
+
allowlist: "allowlist";
|
|
23
|
+
open: "open";
|
|
24
|
+
}>>;
|
|
25
|
+
ceiling: z.ZodOptional<z.ZodEnum<{
|
|
26
|
+
allowlist: "allowlist";
|
|
27
|
+
open: "open";
|
|
28
|
+
}>>;
|
|
29
|
+
base: z.ZodOptional<z.ZodEnum<{
|
|
30
|
+
none: "none";
|
|
31
|
+
platform: "platform";
|
|
32
|
+
}>>;
|
|
33
|
+
extraHosts: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
34
|
+
excludedHosts: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
35
|
+
}, z.core.$strict>;
|
|
36
|
+
export type DeviceNetworkSetting = z.infer<typeof DeviceNetworkSettingSchema>;
|
|
37
|
+
/** What an invalid stored `deviceNetwork` reads as: the allowlist with no host (never wider). */
|
|
38
|
+
export declare const invalidDeviceNetwork: () => DeviceNetworkSetting;
|
|
39
|
+
/**
|
|
40
|
+
* The org network shape before the approval-only profiles design (`cloudNetwork`), read only to
|
|
41
|
+
* convert it ({@link convertLegacyCloudNetwork}) and to keep it in step for replicas of the
|
|
42
|
+
* previous version until the permission configuration publication converts it.
|
|
43
|
+
*/
|
|
44
|
+
export declare const LegacyCloudNetworkSchema: z.ZodObject<{
|
|
45
|
+
mode: z.ZodOptional<z.ZodEnum<{
|
|
46
|
+
allowlist: "allowlist";
|
|
47
|
+
open: "open";
|
|
48
|
+
}>>;
|
|
49
|
+
base: z.ZodOptional<z.ZodEnum<{
|
|
50
|
+
none: "none";
|
|
51
|
+
platform: "platform";
|
|
52
|
+
}>>;
|
|
53
|
+
extraHosts: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
54
|
+
excludedHosts: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
55
|
+
}, z.core.$strict>;
|
|
56
|
+
export type LegacyCloudNetwork = z.infer<typeof LegacyCloudNetworkSchema>;
|
|
57
|
+
/**
|
|
58
|
+
* The stored-key conversion of an org's old `cloudNetwork` (design, "Migration"): `mode:
|
|
59
|
+
* "allowlist"` becomes `ceiling: "allowlist"`, keeping `base`, `extraHosts` and `excludedHosts`;
|
|
60
|
+
* `mode: "open"` or absent becomes absent. An invalid old value converts to
|
|
61
|
+
* {@link invalidDeviceNetwork}, as it read before (never wider). `undefined` stays `undefined`.
|
|
62
|
+
*/
|
|
63
|
+
export declare function convertLegacyCloudNetwork(raw: unknown): DeviceNetworkSetting | undefined;
|
|
64
|
+
/**
|
|
65
|
+
* The old `cloudNetwork` that says no more than `n`, written next to `deviceNetwork` while the old
|
|
66
|
+
* key is still stored (replicas of the previous version read it): `mode: "allowlist"` when either
|
|
67
|
+
* the default or the ceiling is the allowlist (never wider for an old reader). `undefined` when `n`
|
|
68
|
+
* says nothing the old shape holds.
|
|
69
|
+
*/
|
|
70
|
+
export declare function legacyCloudNetworkOf(n: DeviceNetworkSetting | undefined): LegacyCloudNetwork | undefined;
|
|
71
|
+
/**
|
|
72
|
+
* `n` with the ceiling (and an open default) narrowed to the allowlist: what an old `fullAccess:
|
|
73
|
+
* "off"` adds, since it kept every device of the org on the allowlist (never wider).
|
|
74
|
+
*/
|
|
75
|
+
export declare const withAllowlistCeiling: (n: DeviceNetworkSetting | undefined) => DeviceNetworkSetting;
|
|
76
|
+
/**
|
|
77
|
+
* A delta never wider than either `a` or `b` (absent: follow the platform), for two stored values
|
|
78
|
+
* that disagree (fail closed): the narrower default and ceiling, base `none` when either is, only
|
|
79
|
+
* the extra hosts both hold (each covering the other's exactly), and every exclusion of either.
|
|
80
|
+
* It may be narrower than both; it is only read while an old replica's write diverges.
|
|
81
|
+
*/
|
|
82
|
+
export declare function narrowerDeviceNetwork(a: DeviceNetworkSetting | undefined, b: DeviceNetworkSetting | undefined): DeviceNetworkSetting | undefined;
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { validateAllowHost } from "@capybara-hq/plugin-sdk";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
/** The org device network allowlist's host limit. */
|
|
4
|
+
export const ORG_SANDBOX_ALLOW_HOSTS_MAX = 200;
|
|
5
|
+
/** One host list of the org's device network: at most {@link ORG_SANDBOX_ALLOW_HOSTS_MAX} valid, unique hosts. */
|
|
6
|
+
const orgHostList = (name) => z
|
|
7
|
+
.array(z.string())
|
|
8
|
+
.max(ORG_SANDBOX_ALLOW_HOSTS_MAX)
|
|
9
|
+
.superRefine((hosts, ctx) => {
|
|
10
|
+
hosts.forEach((h, i) => {
|
|
11
|
+
for (const message of validateAllowHost(h)) {
|
|
12
|
+
ctx.addIssue({ code: "custom", path: [i], message: `${h}: ${message}` });
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
if (new Set(hosts).size !== hosts.length) {
|
|
16
|
+
ctx.addIssue({ code: "custom", message: `${name} must not contain duplicates` });
|
|
17
|
+
}
|
|
18
|
+
})
|
|
19
|
+
.optional();
|
|
20
|
+
const Mode = z.enum(["open", "allowlist"]);
|
|
21
|
+
/**
|
|
22
|
+
* The org's device sandbox network (approval-only profiles design, "Settings model"), for local and
|
|
23
|
+
* cloud devices alike, with its hosts stored as a delta over the platform's
|
|
24
|
+
* `sandbox.limits.allowHosts`, never a copy of it, so platform changes keep reaching the org:
|
|
25
|
+
* - `default`: the network a device of the org gets when its owner chooses none (`open` or
|
|
26
|
+
* `allowlist`); absent follows the platform's `devices.network.default`.
|
|
27
|
+
* - `ceiling`: the widest network a device of the org may choose; absent follows the platform's
|
|
28
|
+
* `devices.network.ceiling`. Never above the platform's ceiling (`org.network_not_allowed`); a
|
|
29
|
+
* default above the ceiling is refused.
|
|
30
|
+
* - `base`: `platform` (the default: start from the platform's list) or `none` (only the org's own
|
|
31
|
+
* hosts).
|
|
32
|
+
* - `extraHosts`: hosts the org adds (ignored outside the platform list under `orgHosts: within`).
|
|
33
|
+
* - `excludedHosts`: platform entries the org drops (exact entries; any host is accepted, since the
|
|
34
|
+
* platform may drop an entry later).
|
|
35
|
+
* The effective hosts are `orgEffectiveHosts` in `sandbox/modes.ts`.
|
|
36
|
+
*/
|
|
37
|
+
export const DeviceNetworkSettingSchema = z
|
|
38
|
+
.object({
|
|
39
|
+
default: Mode.optional(),
|
|
40
|
+
ceiling: Mode.optional(),
|
|
41
|
+
base: z.enum(["platform", "none"]).optional(),
|
|
42
|
+
extraHosts: orgHostList("extraHosts"),
|
|
43
|
+
excludedHosts: orgHostList("excludedHosts"),
|
|
44
|
+
})
|
|
45
|
+
.strict()
|
|
46
|
+
.superRefine((n, ctx) => {
|
|
47
|
+
if (n.default === "open" && n.ceiling === "allowlist")
|
|
48
|
+
ctx.addIssue({
|
|
49
|
+
code: "custom",
|
|
50
|
+
path: ["default"],
|
|
51
|
+
message: "default open is above ceiling allowlist; choose a default no wider than the ceiling",
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
/** What an invalid stored `deviceNetwork` reads as: the allowlist with no host (never wider). */
|
|
55
|
+
export const invalidDeviceNetwork = () => ({
|
|
56
|
+
default: "allowlist",
|
|
57
|
+
ceiling: "allowlist",
|
|
58
|
+
base: "none",
|
|
59
|
+
});
|
|
60
|
+
/**
|
|
61
|
+
* The org network shape before the approval-only profiles design (`cloudNetwork`), read only to
|
|
62
|
+
* convert it ({@link convertLegacyCloudNetwork}) and to keep it in step for replicas of the
|
|
63
|
+
* previous version until the permission configuration publication converts it.
|
|
64
|
+
*/
|
|
65
|
+
export const LegacyCloudNetworkSchema = z
|
|
66
|
+
.object({
|
|
67
|
+
mode: Mode.optional(),
|
|
68
|
+
base: z.enum(["platform", "none"]).optional(),
|
|
69
|
+
extraHosts: orgHostList("extraHosts"),
|
|
70
|
+
excludedHosts: orgHostList("excludedHosts"),
|
|
71
|
+
})
|
|
72
|
+
.strict();
|
|
73
|
+
/** Drops absent fields; an object with none left is `undefined` (follow the platform). */
|
|
74
|
+
function compact(n) {
|
|
75
|
+
const out = Object.fromEntries(Object.entries(n).filter(([, v]) => v !== undefined));
|
|
76
|
+
return Object.keys(out).length === 0 ? undefined : out;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* The stored-key conversion of an org's old `cloudNetwork` (design, "Migration"): `mode:
|
|
80
|
+
* "allowlist"` becomes `ceiling: "allowlist"`, keeping `base`, `extraHosts` and `excludedHosts`;
|
|
81
|
+
* `mode: "open"` or absent becomes absent. An invalid old value converts to
|
|
82
|
+
* {@link invalidDeviceNetwork}, as it read before (never wider). `undefined` stays `undefined`.
|
|
83
|
+
*/
|
|
84
|
+
export function convertLegacyCloudNetwork(raw) {
|
|
85
|
+
if (raw === undefined)
|
|
86
|
+
return undefined;
|
|
87
|
+
const parsed = LegacyCloudNetworkSchema.safeParse(raw);
|
|
88
|
+
if (!parsed.success)
|
|
89
|
+
return invalidDeviceNetwork();
|
|
90
|
+
const { mode, ...hosts } = parsed.data;
|
|
91
|
+
return compact({ ...(mode === "allowlist" && { ceiling: "allowlist" }), ...hosts });
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* The old `cloudNetwork` that says no more than `n`, written next to `deviceNetwork` while the old
|
|
95
|
+
* key is still stored (replicas of the previous version read it): `mode: "allowlist"` when either
|
|
96
|
+
* the default or the ceiling is the allowlist (never wider for an old reader). `undefined` when `n`
|
|
97
|
+
* says nothing the old shape holds.
|
|
98
|
+
*/
|
|
99
|
+
export function legacyCloudNetworkOf(n) {
|
|
100
|
+
if (n === undefined)
|
|
101
|
+
return undefined;
|
|
102
|
+
const { default: def, ceiling, ...hosts } = n;
|
|
103
|
+
const out = {
|
|
104
|
+
...((def === "allowlist" || ceiling === "allowlist") && { mode: "allowlist" }),
|
|
105
|
+
...hosts,
|
|
106
|
+
};
|
|
107
|
+
return Object.keys(out).length === 0 ? undefined : out;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* `n` with the ceiling (and an open default) narrowed to the allowlist: what an old `fullAccess:
|
|
111
|
+
* "off"` adds, since it kept every device of the org on the allowlist (never wider).
|
|
112
|
+
*/
|
|
113
|
+
export const withAllowlistCeiling = (n) => ({
|
|
114
|
+
...n,
|
|
115
|
+
...(n?.default !== undefined && { default: "allowlist" }),
|
|
116
|
+
ceiling: "allowlist",
|
|
117
|
+
});
|
|
118
|
+
const narrowerMode = (a, b) => a === "allowlist" || b === "allowlist" ? "allowlist" : (a ?? b);
|
|
119
|
+
/**
|
|
120
|
+
* A delta never wider than either `a` or `b` (absent: follow the platform), for two stored values
|
|
121
|
+
* that disagree (fail closed): the narrower default and ceiling, base `none` when either is, only
|
|
122
|
+
* the extra hosts both hold (each covering the other's exactly), and every exclusion of either.
|
|
123
|
+
* It may be narrower than both; it is only read while an old replica's write diverges.
|
|
124
|
+
*/
|
|
125
|
+
export function narrowerDeviceNetwork(a, b) {
|
|
126
|
+
if (a === undefined && b === undefined)
|
|
127
|
+
return undefined;
|
|
128
|
+
const ceiling = narrowerMode(a?.ceiling, b?.ceiling);
|
|
129
|
+
let def = narrowerMode(a?.default, b?.default);
|
|
130
|
+
if (ceiling === "allowlist" && def === "open")
|
|
131
|
+
def = "allowlist";
|
|
132
|
+
const extraA = new Set(a?.extraHosts ?? []);
|
|
133
|
+
const extra = (b?.extraHosts ?? []).filter((h) => extraA.has(h));
|
|
134
|
+
const excluded = [...new Set([...(a?.excludedHosts ?? []), ...(b?.excludedHosts ?? [])])];
|
|
135
|
+
return compact({
|
|
136
|
+
default: def,
|
|
137
|
+
ceiling,
|
|
138
|
+
base: a?.base === "none" || b?.base === "none" ? "none" : (a?.base ?? b?.base),
|
|
139
|
+
extraHosts: extra.length > 0 ? extra : undefined,
|
|
140
|
+
excludedHosts: excluded.length > 0 ? excluded : undefined,
|
|
141
|
+
});
|
|
142
|
+
}
|