@capybara-hq/testing 0.1.0-rc.28 → 0.1.0-rc.29
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/index.d.ts
CHANGED
|
@@ -24,5 +24,5 @@ export { cardRecorded, cookieRequest, createAgent, createConversation, createLoc
|
|
|
24
24
|
export { FAKE_PNG_BASE64, isPngBase64, pdfBase64, pdfSampleWord, redPngBase64, solidPngBase64, } from "./media-samples.js";
|
|
25
25
|
export { type ConformanceTarget, checkDeclaredParameters, describeModelProviderConformance, MEDIA_SAMPLES, thinkingReplayParams, } from "./model-conformance.js";
|
|
26
26
|
export { type NativeFixtureEntry, runSandboxNativeConformance, type SandboxNativeFixture, } from "./sandbox-native-conformance.js";
|
|
27
|
-
export { runSandboxPermissionConformance, type SandboxPermissionEndpoint, type SandboxPermissionFixture, type SandboxPermissionGrant, } from "./sandbox-permission-conformance.js";
|
|
27
|
+
export { runSandboxPermissionConformance, type SandboxPermissionConformancePart, type SandboxPermissionEndpoint, type SandboxPermissionFixture, type SandboxPermissionGrant, type SandboxPermissionOpenNetwork, type SandboxPermissionTarget, } from "./sandbox-permission-conformance.js";
|
|
28
28
|
export { openSse, type SseClient, type SseMessage } from "./sse.js";
|
|
@@ -10,7 +10,7 @@ export interface SandboxPermissionEndpoint {
|
|
|
10
10
|
readonly name: string;
|
|
11
11
|
/**
|
|
12
12
|
* The endpoint's numeric address (an IP literal) for raw socket clients: the pointer race and
|
|
13
|
-
* the ungranted, network-none and
|
|
13
|
+
* the ungranted, network-none and escalated controls connect here. The granted endpoint's address and
|
|
14
14
|
* at least one ungranted address are IPv4 (the race program builds IPv4 socket addresses).
|
|
15
15
|
*/
|
|
16
16
|
readonly address: string;
|
|
@@ -18,6 +18,61 @@ export interface SandboxPermissionEndpoint {
|
|
|
18
18
|
/** Accepted connections so far, observed by the endpoint itself. */
|
|
19
19
|
receipts(): Promise<number>;
|
|
20
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* A destination a sandboxed client asks for by URL (`http://<host>:<port>/`) through the proxy the
|
|
23
|
+
* operation's environment names, when it has one.
|
|
24
|
+
*/
|
|
25
|
+
export interface SandboxPermissionTarget {
|
|
26
|
+
/** A short label for messages (letters, digits, `-`). */
|
|
27
|
+
readonly label: string;
|
|
28
|
+
/** A host name or an IP literal (an IPv6 literal without brackets). */
|
|
29
|
+
readonly host: string;
|
|
30
|
+
readonly port: number;
|
|
31
|
+
/**
|
|
32
|
+
* The numeric address the target is served at, for a raw connect that bypasses the proxy (a
|
|
33
|
+
* proxied provider must refuse it). Omit where it is not known (a public name on the internet).
|
|
34
|
+
*/
|
|
35
|
+
readonly address?: string;
|
|
36
|
+
/** Accepted connections so far, observed by the target itself; omit where none can be counted. */
|
|
37
|
+
receipts?(): Promise<number>;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* The open public network (approval-only profiles design, "Open network"). Every target here is
|
|
41
|
+
* asked for under the `open-public` network, once per profile.
|
|
42
|
+
*/
|
|
43
|
+
export interface SandboxPermissionOpenNetwork {
|
|
44
|
+
/**
|
|
45
|
+
* Set only where no public target can be reached here at all (offline): without it the harness
|
|
46
|
+
* fails when every reachable list (`reachable`, `fakeIp.reachable`) is empty or unavailable.
|
|
47
|
+
*/
|
|
48
|
+
readonly allowNoPositive?: true;
|
|
49
|
+
/**
|
|
50
|
+
* Public targets the open network reaches, by name and by literal. `{ unavailable }` where no
|
|
51
|
+
* public target can be reached from here (no internet and no stand-in), with the reason; every
|
|
52
|
+
* refusal still runs.
|
|
53
|
+
*/
|
|
54
|
+
readonly reachable: readonly SandboxPermissionTarget[] | {
|
|
55
|
+
readonly unavailable: string;
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* Destinations in the closed classes (private, CGNAT, ULA, link-local and metadata, loopback and
|
|
59
|
+
* the host's own addresses, NAT64, benchmark), as IP literals in several spellings and as names
|
|
60
|
+
* resolving there (a DNS rebinding name). Each must be refused; those with receipts see nothing.
|
|
61
|
+
*/
|
|
62
|
+
readonly closed: readonly SandboxPermissionTarget[];
|
|
63
|
+
/**
|
|
64
|
+
* Names the device's resolver answers with a fake-IP address (198.18.0.0/15) while encrypted DNS
|
|
65
|
+
* knows the real one: `reachable` resolve to public addresses, `closed` to closed classes or not
|
|
66
|
+
* at all. `{ unavailable }` with the reason where no fake-IP resolver stands in front of the
|
|
67
|
+
* device here.
|
|
68
|
+
*/
|
|
69
|
+
readonly fakeIp?: {
|
|
70
|
+
readonly reachable: readonly SandboxPermissionTarget[];
|
|
71
|
+
readonly closed: readonly SandboxPermissionTarget[];
|
|
72
|
+
} | {
|
|
73
|
+
readonly unavailable: string;
|
|
74
|
+
};
|
|
75
|
+
}
|
|
21
76
|
/** The scope one fresh operation receives; the fixture adds the IDs and revisions. */
|
|
22
77
|
export interface SandboxPermissionGrant {
|
|
23
78
|
readonly profile: PermissionProfile;
|
|
@@ -31,7 +86,10 @@ export interface SandboxPermissionGrant {
|
|
|
31
86
|
* and read-only; it never runs through a restricted operation and never grants anything.
|
|
32
87
|
*/
|
|
33
88
|
export interface SandboxPermissionFixture {
|
|
34
|
-
/**
|
|
89
|
+
/**
|
|
90
|
+
* The project root granted (writable) to restricted operations. On an instance-boundary provider
|
|
91
|
+
* both `root` and `sibling` lie in the instance, whose whole filesystem is the scope.
|
|
92
|
+
*/
|
|
35
93
|
readonly root: string;
|
|
36
94
|
/** A directory outside every restricted grant, on the same filesystem. */
|
|
37
95
|
readonly sibling: string;
|
|
@@ -53,21 +111,79 @@ export interface SandboxPermissionFixture {
|
|
|
53
111
|
*/
|
|
54
112
|
readonly access: "direct" | "proxy";
|
|
55
113
|
/**
|
|
56
|
-
*
|
|
57
|
-
* changing the host (macOS: no hosts-file entry, and the runtime's proxy
|
|
58
|
-
* resolves to loopback, by design). The by-name positives are then skipped
|
|
59
|
-
* must see no connection at all; every negative still
|
|
60
|
-
* then the provider's own test's evidence (state it next
|
|
114
|
+
* `{ unavailable }` with the reason where the fixture cannot make the allowlisted name lead to
|
|
115
|
+
* `granted` without changing the host (macOS: no hosts-file entry, and the runtime's proxy
|
|
116
|
+
* refuses a name that resolves to loopback, by design). The by-name positives are then skipped
|
|
117
|
+
* (and reported unavailable) and `granted` must see no connection at all; every negative still
|
|
118
|
+
* runs. The positive allowlist reach is then the provider's own test's evidence (state it next
|
|
119
|
+
* to the fixture). Default "available".
|
|
61
120
|
*/
|
|
62
|
-
readonly namedReach?: "available" |
|
|
121
|
+
readonly namedReach?: "available" | {
|
|
122
|
+
readonly unavailable: string;
|
|
123
|
+
};
|
|
124
|
+
/**
|
|
125
|
+
* Names on every allowlist the device applies (the scope's, the owner's and the org's) that
|
|
126
|
+
* resolve into a closed address class: an allowlist grant never reaches a closed class, so
|
|
127
|
+
* each must be refused and see no connection. Required for a provider with restricted support
|
|
128
|
+
* and for an instance boundary (there at least one target whose `address` is a cloud metadata
|
|
129
|
+
* address); `{ unavailable }` with the reason only where no name can resolve into a closed
|
|
130
|
+
* class through the provider's own allowlist path (a stand-in proxy), reported unavailable.
|
|
131
|
+
*/
|
|
132
|
+
readonly closedGranted?: readonly SandboxPermissionTarget[] | {
|
|
133
|
+
readonly unavailable: string;
|
|
134
|
+
};
|
|
135
|
+
};
|
|
136
|
+
/**
|
|
137
|
+
* The open public network's targets. Required when the provider reports
|
|
138
|
+
* `network.openPublic`: the harness then proves the open network under every profile.
|
|
139
|
+
*/
|
|
140
|
+
readonly openNetwork?: SandboxPermissionOpenNetwork;
|
|
141
|
+
/**
|
|
142
|
+
* Variables present in the environment of the device program (or the provider process) that runs
|
|
143
|
+
* the operations: at least one secret-looking (`AWS_SECRET_ACCESS_KEY`) and at least one
|
|
144
|
+
* innocent-looking name (no `SECRET`, `TOKEN`, `KEY`, `PASS`, `CREDENTIAL` or `CAPYBARA_` in it),
|
|
145
|
+
* so a denylist cannot pass for a minimal environment. No sandboxed command under any profile may
|
|
146
|
+
* see one of their values, and on an operation boundary its variable names must all be in the
|
|
147
|
+
* minimal set (approval-only profiles design, "Fixed denies and the minimal environment"):
|
|
148
|
+
* `PATH`, `LANG`, `HOME`, `TMPDIR` / `TMP` / `TEMP`, the proxy variables (any name containing
|
|
149
|
+
* `PROXY`), what the shell itself sets (`PWD`, `OLDPWD`, `SHLVL`, `_`), and `allowed`: the tool
|
|
150
|
+
* homes and runtime variables this provider adds (state each). With `escalatedControl` (and
|
|
151
|
+
* outside-sandbox support), an escalated call must see every planted variable whose name does
|
|
152
|
+
* not start with `CAPYBARA_` and none that does: the planted values are real, and the device's
|
|
153
|
+
* own variables stay out even there. Required for a provider with restricted support.
|
|
154
|
+
*/
|
|
155
|
+
readonly deviceEnvironment?: {
|
|
156
|
+
readonly variables: Readonly<Record<string, string>>;
|
|
157
|
+
readonly escalatedControl: boolean;
|
|
158
|
+
readonly allowed?: readonly string[];
|
|
159
|
+
};
|
|
160
|
+
/**
|
|
161
|
+
* Turns the owner's outside-sandbox setting off and returns a function that restores it. The
|
|
162
|
+
* harness proves that the escalated pair runs only while the setting allows it. Required when
|
|
163
|
+
* the provider reports `outsideSandbox`.
|
|
164
|
+
*/
|
|
165
|
+
withoutOutsideSandbox?(): Promise<() => Promise<void>>;
|
|
166
|
+
/**
|
|
167
|
+
* The device user's home, where the protected home locations (shell startup files and the rest of
|
|
168
|
+
* `SANDBOX_MANDATORY_WRITE_DENIES`) resolve for operations started from now on. When present,
|
|
169
|
+
* the harness links `.zprofile` there through a chain of symbolic links into the granted root
|
|
170
|
+
* (seeded with `seed`, which may write under this path) and proves that no hop of the chain and
|
|
171
|
+
* not the target can be written, retargeted or moved away; `remove` deletes the entry it
|
|
172
|
+
* seeded under the home afterwards. `{ unavailable }` with the reason where the provider has no
|
|
173
|
+
* owner home to protect (reported unavailable); required for a provider with restricted support.
|
|
174
|
+
*/
|
|
175
|
+
readonly home?: {
|
|
176
|
+
readonly path: string;
|
|
177
|
+
remove(path: string): Promise<void>;
|
|
178
|
+
} | {
|
|
179
|
+
readonly unavailable: string;
|
|
63
180
|
};
|
|
64
181
|
/**
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
* otherwise probe a restricted operation on the environment network. Default: "supported".
|
|
182
|
+
* For an instance-boundary provider (`boundary: "instance"`: the container or microVM is the
|
|
183
|
+
* sandbox): its outer network, which the harness proves instead of per-operation networks.
|
|
184
|
+
* "open" needs {@link openNetwork}; "allowlist" allows exactly the granted endpoint's name.
|
|
69
185
|
*/
|
|
70
|
-
readonly
|
|
186
|
+
readonly instanceNetwork?: "open" | "allowlist";
|
|
71
187
|
/**
|
|
72
188
|
* How restricted commands meet the mandatory write denies in other spellings of a protected
|
|
73
189
|
* name. "nfkc" (default): every spelling whose NFKC case fold is protected is refused, as the
|
|
@@ -79,10 +195,12 @@ export interface SandboxPermissionFixture {
|
|
|
79
195
|
*/
|
|
80
196
|
readonly foldedNames?: "nfkc" | "filesystem";
|
|
81
197
|
/**
|
|
82
|
-
* Whether restricted none/allowlist operations may listen on loopback. "allowed" (default):
|
|
83
|
-
* loopback only, every wildcard address refused,
|
|
84
|
-
*
|
|
85
|
-
* included
|
|
198
|
+
* Whether restricted none/allowlist operations may listen on loopback. "allowed" (default, Linux):
|
|
199
|
+
* loopback only, every wildcard address refused, a UNIX socket inside the root works,
|
|
200
|
+
* `SO_REUSEPORT` is refused, no sandboxed client connects to a loopback listener (the command's
|
|
201
|
+
* own included), and a client outside the sandbox (an escalated call) reaches the command's
|
|
202
|
+
* listener. "refused" (macOS): the runtime refuses every listener, loopback and UNIX sockets
|
|
203
|
+
* inside the root included (the macOS worker runs its runtime with local binding off).
|
|
86
204
|
*/
|
|
87
205
|
readonly restrictedLoopbackListen?: "allowed" | "refused";
|
|
88
206
|
/**
|
|
@@ -119,23 +237,68 @@ export interface SandboxPermissionFixture {
|
|
|
119
237
|
dispose(): Promise<void>;
|
|
120
238
|
}
|
|
121
239
|
/**
|
|
122
|
-
*
|
|
123
|
-
*
|
|
124
|
-
*
|
|
125
|
-
*
|
|
126
|
-
*
|
|
127
|
-
*
|
|
128
|
-
*
|
|
240
|
+
* A part of the operation-boundary conformance, for runs that split it (each part needs a fresh
|
|
241
|
+
* fixture; the setup, positive controls and the scope contract run in every part):
|
|
242
|
+
* - `filesystem`: mandatory denies, reserved names, protected link chains, git work, sibling and
|
|
243
|
+
* protected-path denials, every profile sandboxed with the minimal environment;
|
|
244
|
+
* - `network`: allowlist, closed classes, loopback listeners, the open network, UNIX sockets;
|
|
245
|
+
* - `processes`: escalated-pair controls, overlaps, swaps and pointer races, the supervisor,
|
|
246
|
+
* cancellation and narrowed scopes.
|
|
247
|
+
*/
|
|
248
|
+
export type SandboxPermissionConformancePart = "filesystem" | "network" | "processes";
|
|
249
|
+
/**
|
|
250
|
+
* The approval-only checks of the operation-boundary conformance, for a focused rerun or a harness
|
|
251
|
+
* self-test (`checks`: only these, after the setup, positive controls and the scope contract):
|
|
252
|
+
* `outside-switch` (processes), `environment`, `reserved-names` and `link-chain` (filesystem),
|
|
253
|
+
* `closed-granted`, `loopback`, `open-network` and `foreign-unix` (network).
|
|
254
|
+
*/
|
|
255
|
+
export type SandboxPermissionConformanceCheck = "outside-switch" | "environment" | "reserved-names" | "link-chain" | "closed-granted" | "loopback" | "open-network" | "foreign-unix";
|
|
256
|
+
export interface SandboxPermissionConformanceOptions {
|
|
257
|
+
/** Only these parts (each needs a fresh fixture); never empty. Default: every part. */
|
|
258
|
+
readonly parts?: readonly SandboxPermissionConformancePart[];
|
|
259
|
+
/** Only these approval-only checks (see {@link SandboxPermissionConformanceCheck}); never empty. */
|
|
260
|
+
readonly checks?: readonly SandboxPermissionConformanceCheck[];
|
|
261
|
+
}
|
|
262
|
+
/** What a run could not prove here, each with the fixture's reason (annotate or log them). */
|
|
263
|
+
export interface SandboxPermissionConformanceReport {
|
|
264
|
+
readonly unavailable: readonly {
|
|
265
|
+
readonly item: string;
|
|
266
|
+
readonly reason: string;
|
|
267
|
+
}[];
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Proves an actual provider's permission boundary on one shared device (approval-only profiles
|
|
271
|
+
* design). The sandbox is the device's and the same under every profile: a profile only chooses
|
|
272
|
+
* who approves a crossing, so every profile's ordinary call is sandboxed, and only the escalated
|
|
273
|
+
* pair (the device filesystem with the environment network, legal only together) runs outside it,
|
|
274
|
+
* and only with outside-sandbox support while the owner allows it.
|
|
275
|
+
*
|
|
276
|
+
* An operation-boundary provider (a local device) is proved with positive controls; sibling,
|
|
277
|
+
* symlink, protected-path, mandatory-deny, reserved-name, protected-link-chain and network
|
|
278
|
+
* denials; every profile sandboxed with the minimal environment; the open network (closed classes
|
|
279
|
+
* refused by resolved address, rebinding and fake-IP names included) and the allowlist (closed
|
|
280
|
+
* classes refused even for granted names); loopback listeners (Linux: loopback only, no sandboxed
|
|
281
|
+
* connect to any, its own included, no `SO_REUSEPORT`; macOS: none at all); escalated-pair
|
|
282
|
+
* controls outside the sandbox; both overlap orders; component/root swaps and mutable syscall
|
|
283
|
+
* pointers during access; exact cancellation; a supervisor closed to same-uid outsiders (when the
|
|
284
|
+
* fixture can run one) and fresh narrowed scopes. Pathname UNIX services outside the roots stay
|
|
285
|
+
* unreachable under every sandbox network, and so does one another process made inside a write
|
|
286
|
+
* root (only the operation's own sockets are reachable). A provider that reports restricted unsupported must
|
|
129
287
|
* refuse restricted operations (fail closed); nothing here substitutes a fixture flag for support.
|
|
130
288
|
*
|
|
289
|
+
* An instance-boundary provider (a cloud device: the container or microVM is the sandbox) is
|
|
290
|
+
* proved with every profile running alike in the instance (its whole filesystem the scope),
|
|
291
|
+
* nothing outside it, the outer network (open or allowlist) for every operation, and exact
|
|
292
|
+
* cancellation.
|
|
293
|
+
*
|
|
131
294
|
* Not covered, by design (known limitations, not passes): metadata reads outside the roots (stat,
|
|
132
295
|
* readlink, xattrs, statfs), and the world-readable `/proc/<pid>` entries of other processes of the
|
|
133
296
|
* same uid, such as `cmdline`, `stat` and `status`. A restricted operation can therefore read the
|
|
134
|
-
* command line of a concurrent
|
|
297
|
+
* command line of a concurrent escalated command on the device: Landlock cannot scope `/proc` to the
|
|
135
298
|
* operation's own process tree (see the Linux launcher's known limitations). Providers keep secrets
|
|
136
299
|
* out of command lines; ptrace-guarded entries (`environ`, `mem`, `maps`, `fd`) stay closed.
|
|
137
300
|
*/
|
|
138
|
-
export declare function runSandboxPermissionConformance(fixture: SandboxPermissionFixture): Promise<
|
|
301
|
+
export declare function runSandboxPermissionConformance(fixture: SandboxPermissionFixture, options?: SandboxPermissionConformanceOptions): Promise<SandboxPermissionConformanceReport>;
|
|
139
302
|
/**
|
|
140
303
|
* Polls a trusted read until `path` exists, racing the operation that should create it: if that
|
|
141
304
|
* operation settles first (refused, failed or exited without the file), this throws at once with
|