@capybara-hq/plugin-sdk 0.1.0-rc.38 → 0.1.0-rc.39
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/device-protocol.d.ts +77 -46
- package/dist/device-protocol.js +206 -83
- package/dist/index.d.ts +3 -2
- package/dist/index.js +3 -2
- package/dist/network-classes.d.ts +98 -0
- package/dist/network-classes.js +291 -0
- package/dist/sandbox-linux-runtime-source.js +460 -28
- package/dist/sandbox-native-runtime-source.js +143 -3
- package/dist/sandbox-operation.d.ts +36 -4
- package/dist/sandbox-operation.js +21 -4
- package/dist/sandbox-runtime-source.js +2 -2
- package/dist/sandbox-write-denies.d.ts +87 -8
- package/dist/sandbox-write-denies.js +249 -10
- package/dist/sandbox.d.ts +11 -22
- package/package.json +1 -1
|
@@ -2,40 +2,41 @@
|
|
|
2
2
|
* The device protocol: the WebSocket frames between the kernel and a `capybara-device` program
|
|
3
3
|
* (a connected machine that serves as a device). Pure types and hand-written guards.
|
|
4
4
|
*
|
|
5
|
-
* Protocol
|
|
6
|
-
* this file. Protocol 2's frames keep a `Legacy` prefix where a
|
|
7
|
-
* (`LegacyDeviceHello`, `parseLegacyDeviceFrame`, ...); protocol
|
|
5
|
+
* Protocol 4 (the scope-bearing operations, `parseDeviceFrame`) is defined in the second half of
|
|
6
|
+
* this file. Protocol 2's frames keep a `Legacy` prefix where a newer name replaced them
|
|
7
|
+
* (`LegacyDeviceHello`, `parseLegacyDeviceFrame`, ...); protocol 4 reuses their value guards, and
|
|
8
8
|
* they go with the legacy device surface.
|
|
9
9
|
*/
|
|
10
10
|
import { type ExecResult, type SandboxActor, type SandboxLimits, type SandboxRoots } from "./sandbox.js";
|
|
11
11
|
import { type SandboxPermissionSupport } from "./sandbox-operation.js";
|
|
12
12
|
/** The protocol version carried in `X-Capybara-Device-Protocol` and the hello frame. */
|
|
13
|
-
export declare const DEVICE_PROTOCOL_VERSION =
|
|
13
|
+
export declare const DEVICE_PROTOCOL_VERSION = 4;
|
|
14
14
|
/**
|
|
15
|
-
* Protocol
|
|
16
|
-
* on the header, a protocol close on the hello)
|
|
15
|
+
* Protocol 3's version, which a deployment speaking {@link DEVICE_PROTOCOL_VERSION} refuses (426
|
|
16
|
+
* on the header, a protocol close on the hello): its owner report and runtime support describe the
|
|
17
|
+
* removed Full access ceiling, so a protocol 3 program must be updated.
|
|
17
18
|
*/
|
|
18
|
-
export declare const LEGACY_DEVICE_PROTOCOL_VERSION =
|
|
19
|
+
export declare const LEGACY_DEVICE_PROTOCOL_VERSION = 3;
|
|
19
20
|
/** The operations the kernel asks a device to run. */
|
|
20
21
|
export type DeviceOp = "create" | "exec" | "readFile" | "writeFile" | "stat" | "killTagged" | "killAll" | "stop" | "policy" | "policyStatus" | "list" | "scan";
|
|
21
22
|
/**
|
|
22
23
|
* Optional capabilities a device announces in its hello. `policyOp`: the device takes the `policy`
|
|
23
24
|
* op; `policyOpId`: it also logs each `policy` op's outcome by its `opId`, answers `policyStatus`
|
|
24
25
|
* and reports recent outcomes in its hello (`recentOps`); `networkReport` means exec results may
|
|
25
|
-
* carry `network`; `
|
|
26
|
-
* the device behaves as an allowlisted sandbox); `projects` means the device serves `list` and
|
|
26
|
+
* carry `network`; `projects` means the device serves `list` and
|
|
27
27
|
* `scan` (the kernel keeps a device's projects itself and asks the device only what it can read).
|
|
28
28
|
* The kernel gates each op on its feature, as it gates `policy` on `policyOp` / `policyOpId`: it
|
|
29
29
|
* never sends `list` or `scan` to a device that did not announce `projects`.
|
|
30
30
|
*/
|
|
31
|
-
export type DeviceFeature = "networkReport" | "policyOp" | "policyOpId" | "
|
|
31
|
+
export type DeviceFeature = "networkReport" | "policyOp" | "policyOpId" | "projects";
|
|
32
32
|
/** The most entries a `list` op may ask for and its result may carry. */
|
|
33
33
|
export declare const MAX_DEVICE_LIST_ENTRIES = 1000;
|
|
34
|
-
/**
|
|
34
|
+
/**
|
|
35
|
+
* What a device knows of its local policy and reports (in the hello or a `policy` op). The owner
|
|
36
|
+
* ceiling travels separately, in the owner report ({@link DeviceOwnerCeiling}).
|
|
37
|
+
*/
|
|
35
38
|
export interface DeviceLocalPolicySummary {
|
|
36
|
-
/**
|
|
37
|
-
mode: "auto" | "sandbox";
|
|
38
|
-
/** The device's sandbox-mode allowlist; meaningful in sandbox mode only. */
|
|
39
|
+
/** The device's sandbox allowlist (the owner's `allowedDomains`). */
|
|
39
40
|
allowedDomains: string[];
|
|
40
41
|
}
|
|
41
42
|
/**
|
|
@@ -47,14 +48,13 @@ export interface DeviceProjectCandidate {
|
|
|
47
48
|
path: string;
|
|
48
49
|
suggestedName: string;
|
|
49
50
|
}
|
|
50
|
-
/**
|
|
51
|
-
* The kernel's current ceiling on a request that reads the device's file system outside a command
|
|
52
|
-
* (`readFile`, `stat`, `list`, `scan`): the device answers in the mode it would run this request in, the owner's
|
|
53
|
-
* choice cut to `mode`, never by a ceiling it saw on an earlier command.
|
|
54
|
-
*/
|
|
55
|
-
export type DeviceRequestCeiling = Pick<SandboxLimits, "mode">;
|
|
56
51
|
/** The most blocked hosts an exec result reports; the parser cuts longer lists. */
|
|
57
52
|
export declare const MAX_NETWORK_BLOCKED_HOSTS = 20;
|
|
53
|
+
/**
|
|
54
|
+
* Why a `policy` op naming hosts to `add` is refused: the deployment may only narrow a local
|
|
55
|
+
* device's sandbox; its owner widens it on the machine.
|
|
56
|
+
*/
|
|
57
|
+
export declare const POLICY_ADD_REFUSED = "The deployment may not add hosts to a device's sandbox allowlist: widening happens only on the machine (capybara-device policy add allowedDomains <host>)";
|
|
58
58
|
/** The longest `opId` a `policy` / `policyStatus` op may carry. */
|
|
59
59
|
export declare const MAX_POLICY_OP_ID_LENGTH = 128;
|
|
60
60
|
/** The most entries a hello's `recentOps` carries; the parser keeps the newest. */
|
|
@@ -176,7 +176,6 @@ export interface DeviceExecGrants {
|
|
|
176
176
|
export type DeviceExecResult = ExecResult;
|
|
177
177
|
export interface DeviceReadFileArgs {
|
|
178
178
|
path: string;
|
|
179
|
-
limits: DeviceRequestCeiling;
|
|
180
179
|
maxBytes: number;
|
|
181
180
|
}
|
|
182
181
|
export type DeviceReadFileResult = {
|
|
@@ -190,7 +189,6 @@ export interface DeviceWriteFileArgs {
|
|
|
190
189
|
export type DeviceWriteFileResult = null;
|
|
191
190
|
export interface DeviceStatArgs {
|
|
192
191
|
path: string;
|
|
193
|
-
limits: DeviceRequestCeiling;
|
|
194
192
|
}
|
|
195
193
|
export type DeviceStatResult = {
|
|
196
194
|
size: number;
|
|
@@ -210,9 +208,10 @@ export interface DeviceStopArgs {
|
|
|
210
208
|
reason: "revoked" | "deleted";
|
|
211
209
|
}
|
|
212
210
|
/**
|
|
213
|
-
* Edits the device's local policy. The kernel may only narrow:
|
|
214
|
-
*
|
|
215
|
-
*
|
|
211
|
+
* Edits the device's local policy. The kernel may only narrow: it removes hosts from the sandbox
|
|
212
|
+
* allowlist and narrows the owner ceiling ({@link DevicePolicyArgs}). Widening happens only on the
|
|
213
|
+
* machine (`capybara-device policy add`, `capybara-device ceiling set`): the frame parser refuses
|
|
214
|
+
* an `add` and the protocol 3 `mode`.
|
|
216
215
|
*/
|
|
217
216
|
export interface LegacyDevicePolicyArgs {
|
|
218
217
|
/**
|
|
@@ -221,12 +220,8 @@ export interface LegacyDevicePolicyArgs {
|
|
|
221
220
|
* `recentOps`.
|
|
222
221
|
*/
|
|
223
222
|
opId: string;
|
|
224
|
-
/** Hosts to add to `allowedDomains`. */
|
|
225
|
-
add?: string[];
|
|
226
223
|
/** Hosts to remove from `allowedDomains`. */
|
|
227
224
|
remove?: string[];
|
|
228
|
-
/** Only `"sandbox"`: the kernel may narrow, never turn auto mode on. */
|
|
229
|
-
mode?: "sandbox";
|
|
230
225
|
/** Who decided, for the device's local audit line. */
|
|
231
226
|
source: {
|
|
232
227
|
approvalId?: string;
|
|
@@ -255,13 +250,12 @@ export interface LegacyDevicePolicyStatus {
|
|
|
255
250
|
}
|
|
256
251
|
/**
|
|
257
252
|
* Lists one directory (absolute `path`, {@link validateSandboxPathShape}): at most `limit` entries
|
|
258
|
-
* (at most {@link MAX_DEVICE_LIST_ENTRIES}), read
|
|
253
|
+
* (at most {@link MAX_DEVICE_LIST_ENTRIES}), read within the operation's scope. See
|
|
259
254
|
* `SandboxProvider.list` for the semantics.
|
|
260
255
|
*/
|
|
261
256
|
export interface DeviceListArgs {
|
|
262
257
|
path: string;
|
|
263
258
|
limit: number;
|
|
264
|
-
limits: DeviceRequestCeiling;
|
|
265
259
|
}
|
|
266
260
|
/**
|
|
267
261
|
* One entry of a listed directory: `name` is never empty, `.` or `..` and holds no `/`. `isDir`
|
|
@@ -284,13 +278,12 @@ export type DeviceListResult = {
|
|
|
284
278
|
} | null;
|
|
285
279
|
/**
|
|
286
280
|
* Looks for project-like directories under `base` (absolute, {@link validateSandboxPathShape}),
|
|
287
|
-
* read
|
|
288
|
-
* file, unreadable, or outside the request's
|
|
281
|
+
* read within the operation's scope. A `base` that does not exist answers `[]`; a `base` that is a
|
|
282
|
+
* file, unreadable, or outside the request's scope is an error. See `SandboxProvider.scan` for the
|
|
289
283
|
* traversal.
|
|
290
284
|
*/
|
|
291
285
|
export interface DeviceScanArgs {
|
|
292
286
|
base: string;
|
|
293
|
-
limits: DeviceRequestCeiling;
|
|
294
287
|
}
|
|
295
288
|
/**
|
|
296
289
|
* `base` itself and the directories at most {@link MAX_DEVICE_SCAN_DEPTH} levels below it that
|
|
@@ -332,24 +325,36 @@ export declare function parseOpResult<Op extends DeviceOp>(op: Op, result: unkno
|
|
|
332
325
|
*/
|
|
333
326
|
export declare function parseLegacyDeviceFrame(raw: string, from: "device" | "kernel"): LegacyDeviceFrame;
|
|
334
327
|
/**
|
|
335
|
-
* The operations the kernel asks a protocol
|
|
328
|
+
* The operations the kernel asks a protocol 4 device to run: every user operation carries its
|
|
336
329
|
* admitted scope; there is no broad kill (`killTagged` / `killAll`).
|
|
337
330
|
*/
|
|
338
331
|
export type DeviceOperation = Exclude<DeviceOp, "killTagged" | "killAll"> | "prepareReadFile" | "prepareWriteFile" | "prepareStat" | "browseStat" | "browseList" | "browseScan" | "backgroundStart" | "backgroundStatus" | "backgroundTail" | "backgroundReadOutput" | "backgroundStop" | "revokeOperation" | "bindInstance";
|
|
332
|
+
/** The sandbox network of a device: the open public internet or an allowlist. */
|
|
333
|
+
export type DeviceNetworkMode = "open" | "allowlist";
|
|
334
|
+
/**
|
|
335
|
+
* The owner ceiling of protocol 4 (approval-only profiles design, "Settings model"): the device
|
|
336
|
+
* sandbox for every profile. `outsideSandbox` is whether a call may be granted escalation outside
|
|
337
|
+
* the sandbox; `network` and `allowedDomains` are the sandbox network.
|
|
338
|
+
*/
|
|
339
339
|
export interface DeviceOwnerCeiling {
|
|
340
|
-
readonly version:
|
|
340
|
+
readonly version: 3;
|
|
341
341
|
readonly sequence: number;
|
|
342
|
-
readonly restrictedProjectReach: "workspace" | "os-user";
|
|
343
342
|
readonly revision: string;
|
|
344
|
-
readonly
|
|
345
|
-
readonly
|
|
343
|
+
readonly outsideSandbox: boolean;
|
|
344
|
+
readonly network: DeviceNetworkMode;
|
|
345
|
+
readonly allowedDomains: readonly string[];
|
|
346
|
+
readonly restrictedProjectReach: "workspace" | "os-user";
|
|
346
347
|
}
|
|
347
348
|
/**
|
|
348
|
-
* The
|
|
349
|
-
*
|
|
349
|
+
* The narrowing of protocol 4: the kernel may switch the network to `allowlist`, remove hosts, turn
|
|
350
|
+
* `outsideSandbox` off or narrow the project reach. Never a widening: widening is decided on the
|
|
351
|
+
* machine by its owner (`capybara-device ceiling set`), never over the wire.
|
|
350
352
|
*/
|
|
351
353
|
export interface DeviceOwnerCeilingNarrowing {
|
|
352
|
-
readonly
|
|
354
|
+
readonly outsideSandbox?: false;
|
|
355
|
+
readonly network?: "allowlist";
|
|
356
|
+
/** Hosts to remove from `allowedDomains`; a host not on the list is ignored. */
|
|
357
|
+
readonly removeAllowedDomains?: readonly string[];
|
|
353
358
|
readonly restrictedProjectReach?: "workspace";
|
|
354
359
|
}
|
|
355
360
|
/** A staged `policy` op: the protocol 2 change plus an optional owner-ceiling narrowing. */
|
|
@@ -372,7 +377,7 @@ export interface DevicePolicyChanged {
|
|
|
372
377
|
ownerCeiling: DeviceOwnerCeiling;
|
|
373
378
|
}
|
|
374
379
|
export interface DeviceHello extends LegacyDeviceHello {
|
|
375
|
-
protocol:
|
|
380
|
+
protocol: 4;
|
|
376
381
|
permissionSupport: SandboxPermissionSupport;
|
|
377
382
|
ownerCeiling: DeviceOwnerCeiling;
|
|
378
383
|
instanceGeneration: string | null;
|
|
@@ -438,13 +443,39 @@ export type DeviceResponse = Exclude<DeviceRes, {
|
|
|
438
443
|
id: string;
|
|
439
444
|
ok: false;
|
|
440
445
|
error: {
|
|
441
|
-
|
|
446
|
+
/**
|
|
447
|
+
* The typed failure: `denied`, `unsupported`, `unknown` and `invalid` carry the SDK's
|
|
448
|
+
* scope denial, unsupported permission, unknown outcome and scope validation errors.
|
|
449
|
+
* `invalid` never proves the operation had no effect (a skewed device may have parsed
|
|
450
|
+
* part of it): it must never join the not-run refusals (`isRefusal`, `failureKindOf`).
|
|
451
|
+
*/
|
|
452
|
+
kind: "gone" | "fs_gone" | "policy" | "error" | "denied" | "unsupported" | "unknown" | "invalid";
|
|
442
453
|
message: string;
|
|
443
454
|
};
|
|
444
455
|
};
|
|
445
456
|
export type DeviceFrame = DeviceHello | KernelReady | KernelRequest | KernelCancel | DeviceResponse | DevicePolicyChanged;
|
|
446
|
-
/**
|
|
457
|
+
/**
|
|
458
|
+
* Strictly parses a runtime permission report, version 2 (the protocol 4 `permissionSupport`, also
|
|
459
|
+
* the shape a cloud provider reports), and returns a frozen copy; throws {@link DeviceProtocolError}.
|
|
460
|
+
* Restricted support is all four claims or `null`; per-operation hosts need the allowlist; an
|
|
461
|
+
* operation boundary without restricted support claims no sandbox network at all. An
|
|
462
|
+
* instance boundary is the whole instance: it claims no restricted per-operation scope, no
|
|
463
|
+
* outside-sandbox escalation and no per-operation hosts (a host joins the device's list instead).
|
|
464
|
+
*/
|
|
465
|
+
export declare function parseSandboxPermissionSupport(value: unknown): SandboxPermissionSupport;
|
|
466
|
+
/**
|
|
467
|
+
* Strictly parses one authenticated owner-ceiling report of protocol 4 and returns a frozen copy;
|
|
468
|
+
* throws {@link DeviceProtocolError}. Unknown fields (the protocol 3 `fullAccess` and
|
|
469
|
+
* `restrictedAllowedDomains` among them) are refused.
|
|
470
|
+
*/
|
|
447
471
|
export declare function parseOwnerCeilingReport(value: unknown): DeviceOwnerCeiling;
|
|
448
|
-
/**
|
|
472
|
+
/**
|
|
473
|
+
* Strictly parses an owner-ceiling narrowing of protocol 4 and returns a frozen copy; throws
|
|
474
|
+
* {@link DeviceProtocolError}. Every field can only narrow: `outsideSandbox` only to `false`,
|
|
475
|
+
* `network` only to `allowlist`, the project reach only to `workspace`, and hosts only removed.
|
|
476
|
+
* There is no way to name a host to add or a list to replace.
|
|
477
|
+
*/
|
|
478
|
+
export declare function parseOwnerCeilingNarrowing(value: unknown): DeviceOwnerCeilingNarrowing;
|
|
479
|
+
/** Strictly parses one protocol 4 frame; throws {@link DeviceProtocolError}. */
|
|
449
480
|
export declare function parseDeviceFrame(raw: string, from: "device" | "kernel", maxFrameBytes?: number): DeviceFrame;
|
|
450
481
|
export declare function parseOperationResult(op: DeviceOperation, result: unknown, request?: BackgroundReadOutputRequest | BindInstanceRequest): unknown;
|