@parcha/agentrun-computer 0.1.0-beta.34 → 0.1.0-beta.35
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/README.md +144 -26
- package/dist/browser.d.ts +12 -13
- package/dist/browser.js +16 -14
- package/dist/browserbase.d.ts +3 -5
- package/dist/browserbase.js +16 -13
- package/dist/chrome.js +1 -1
- package/dist/computerd-linux-amd64 +0 -0
- package/dist/computerd-linux-arm64 +0 -0
- package/dist/conformance/browserbase.js +1 -1
- package/dist/conformance/cases/provider.js +78 -3
- package/dist/conformance/daytona.js +2 -1
- package/dist/conformance/e2b.js +2 -1
- package/dist/conformance/fixture.js +24 -2
- package/dist/conformance/kernel.js +1 -1
- package/dist/conformance/kind.js +2 -1
- package/dist/conformance/{local.d.ts → local-chrome.d.ts} +7 -7
- package/dist/conformance/{local.js → local-chrome.js} +11 -11
- package/dist/conformance/orgo.d.ts +11 -5
- package/dist/conformance/orgo.js +37 -8
- package/dist/conformance/phone-harness.js +2 -1
- package/dist/conformance/report.js +3 -2
- package/dist/conformance/runner.js +25 -7
- package/dist/conformance/types.d.ts +21 -8
- package/dist/conformance/types.js +10 -0
- package/dist/conformance/windows-fixture.d.ts +1 -0
- package/dist/conformance/windows-fixture.js +37 -0
- package/dist/daytona.d.ts +3 -34
- package/dist/daytona.js +34 -61
- package/dist/descriptor.d.ts +94 -0
- package/dist/descriptor.js +81 -0
- package/dist/descriptors/browserbase.d.ts +24 -0
- package/dist/descriptors/browserbase.js +18 -0
- package/dist/descriptors/daytona.d.ts +62 -0
- package/dist/descriptors/daytona.js +49 -0
- package/dist/descriptors/docker.d.ts +12 -0
- package/dist/descriptors/docker.js +17 -0
- package/dist/descriptors/e2b.d.ts +22 -0
- package/dist/descriptors/e2b.js +19 -0
- package/dist/descriptors/index.d.ts +229 -0
- package/dist/descriptors/index.js +19 -0
- package/dist/descriptors/kernel.d.ts +20 -0
- package/dist/descriptors/kernel.js +15 -0
- package/dist/descriptors/local-chrome.d.ts +17 -0
- package/dist/descriptors/local-chrome.js +21 -0
- package/dist/descriptors/modal.d.ts +50 -0
- package/dist/descriptors/modal.js +38 -0
- package/dist/descriptors/orgo.d.ts +88 -0
- package/dist/descriptors/orgo.js +44 -0
- package/dist/descriptors/phone-harness.d.ts +28 -0
- package/dist/descriptors/phone-harness.js +20 -0
- package/dist/descriptors/shared.d.ts +7 -0
- package/dist/descriptors/shared.js +6 -0
- package/dist/desktop.d.ts +4 -4
- package/dist/desktop.js +4 -4
- package/dist/docker/egress.d.ts +1 -1
- package/dist/docker/image.js +17 -15
- package/dist/docker/inspect.d.ts +147 -0
- package/dist/docker/inspect.js +335 -0
- package/dist/docker.d.ts +6 -6
- package/dist/docker.js +46 -42
- package/dist/drift.d.ts +3 -145
- package/dist/drift.js +5 -334
- package/dist/e2b.d.ts +2 -8
- package/dist/e2b.js +16 -22
- package/dist/index.d.ts +8 -11
- package/dist/index.js +13 -11
- package/dist/isolation.js +2 -2
- package/dist/janitor.d.ts +18 -1
- package/dist/janitor.js +67 -19
- package/dist/kernel.d.ts +3 -5
- package/dist/kernel.js +19 -16
- package/dist/kinds.d.ts +54 -34
- package/dist/kinds.js +19 -117
- package/dist/labels.d.ts +12 -0
- package/dist/labels.js +39 -1
- package/dist/{local.d.ts → local-chrome.d.ts} +5 -8
- package/dist/{local.js → local-chrome.js} +19 -16
- package/dist/local-supervisor.d.ts +3 -3
- package/dist/local-supervisor.js +3 -3
- package/dist/modal.d.ts +3 -22
- package/dist/modal.js +15 -31
- package/dist/mount-archil.js +4 -4
- package/dist/orgo-channel.js +16 -13
- package/dist/orgo-desktop.d.ts +153 -0
- package/dist/orgo-desktop.js +1614 -0
- package/dist/orgo-names.d.ts +52 -0
- package/dist/orgo-names.js +84 -0
- package/dist/orgo.d.ts +18 -15
- package/dist/orgo.js +46 -107
- package/dist/phone-harness.d.ts +4 -10
- package/dist/phone-harness.js +45 -46
- package/dist/provider.d.ts +91 -10
- package/dist/provider.js +42 -0
- package/dist/providers.d.ts +23 -24
- package/dist/providers.js +14 -17
- package/dist/result.d.ts +11 -1
- package/dist/result.js +11 -0
- package/dist/test-connection.js +2 -2
- package/package.json +42 -2
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
// A Docker computer read back: docker info's host, and docker inspect's computer against what create asked for. Pure:
|
|
2
|
+
// no Docker call. Each mismatch is one sentence; none is an empty list. The checks every provider shares (hello, the
|
|
3
|
+
// probe's report) are ../drift.ts's.
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { COMPUTER_LABEL, DAEMON_IN_COMPUTER, DEADLINE_LABEL, DEFAULT_CPUS, DEFAULT_MEMORY_MB, DEFAULT_PIDS, helloDrift, SOCKET_DIR, show, WORK } from "../drift.js";
|
|
6
|
+
import { WORKSPACE } from "../mount.js";
|
|
7
|
+
import { EGRESS_MOUNT, EGRESS_SOCKET, egressNameOf, egressOf, policyWords, RELAY_FLAG, sameAllow } from "./egress.js";
|
|
8
|
+
import { engineOf, subpathOf } from "./volume.js";
|
|
9
|
+
/** With the Docker provider's volume option, where the daemon's staged directory is mounted read-only: its computerd is
|
|
10
|
+
* DAEMON_IN_COMPUTER (stage.ts). */
|
|
11
|
+
export const DAEMON_DIR_IN_COMPUTER = "/opt/agentrun";
|
|
12
|
+
/** CPUs are a CFS quota of each 100 ms, as serve gives them: Docker refuses a --cpus above its own CPU count. */
|
|
13
|
+
export const CPU_PERIOD_US = 100_000;
|
|
14
|
+
/**
|
|
15
|
+
* The --tmpfs options of each tmpfs a computer gets, owned by its uid:gid. A tmpfs's pages count against the
|
|
16
|
+
* computer's memory, so /work holds half of it: a full /work is ENOSPC before the memory limit could OOM-kill a
|
|
17
|
+
* process. /run/agentrun holds only init's socket.
|
|
18
|
+
*/
|
|
19
|
+
export function tmpfsOf(user, memoryMb) {
|
|
20
|
+
const [uid, gid] = user.split(":");
|
|
21
|
+
return {
|
|
22
|
+
[WORK]: `rw,nosuid,nodev,exec,uid=${uid},gid=${gid},mode=0700,size=${Math.floor(memoryMb / 2)}m`,
|
|
23
|
+
[SOCKET_DIR]: `rw,noexec,nosuid,nodev,uid=${uid},gid=${gid},mode=0700,size=1m`,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
/** docker info names the kernel's architecture; hello names Go's. */
|
|
27
|
+
const GO_ARCH = { x86_64: "amd64", aarch64: "arm64" };
|
|
28
|
+
/**
|
|
29
|
+
* The host's enforcement, from docker info. A computer's sizes are cgroup limits, so a host that does not enforce one
|
|
30
|
+
* makes it configuration only; seccomp is required, since a computer's only syscall filter is Docker's default
|
|
31
|
+
* profile. AppArmor and SELinux are read, not required: a host has the one its distribution ships or neither, and a
|
|
32
|
+
* computer must then carry the profile or label Docker gives every container (the drift check).
|
|
33
|
+
*/
|
|
34
|
+
export function hostOf(info) {
|
|
35
|
+
const problems = [];
|
|
36
|
+
const lacks = (flag, what, so) => {
|
|
37
|
+
if (flag !== true)
|
|
38
|
+
problems.push(`this Docker host does not enforce ${what}, so ${so}`);
|
|
39
|
+
};
|
|
40
|
+
lacks(info?.MemoryLimit, "memory limits", "a computer's memory size is only configuration");
|
|
41
|
+
lacks(info?.SwapLimit, "swap limits", "a computer could swap past its memory size");
|
|
42
|
+
lacks(info?.PidsLimit, "pids limits", "a computer's pids limit is only configuration");
|
|
43
|
+
lacks(info?.CPUCfsQuota, "CPU quotas", "a computer's cpus are only configuration");
|
|
44
|
+
lacks(info?.CPUCfsPeriod, "CPU periods", "a computer's cpus are only configuration");
|
|
45
|
+
const options = Array.isArray(info?.SecurityOptions) ? info.SecurityOptions.filter((option) => typeof option === "string") : [];
|
|
46
|
+
const named = (name) => options.find((option) => option.split(",").includes(`name=${name}`));
|
|
47
|
+
const seccomp = named("seccomp");
|
|
48
|
+
if (seccomp === undefined)
|
|
49
|
+
problems.push("this Docker host has no seccomp, so a computer could make any system call");
|
|
50
|
+
else if (seccomp.split(",").includes("profile=unconfined")) {
|
|
51
|
+
problems.push("this Docker host's default seccomp profile is unconfined, so a computer could make any system call");
|
|
52
|
+
}
|
|
53
|
+
const machine = typeof info?.Architecture === "string" ? info.Architecture : "";
|
|
54
|
+
const remap = named("userns") !== undefined ? "userns" : named("rootless") !== undefined ? "rootless" : undefined;
|
|
55
|
+
const engine = engineOf(info?.ServerVersion);
|
|
56
|
+
return { arch: GO_ARCH[machine] ?? machine, apparmor: named("apparmor") !== undefined, selinux: named("selinux") !== undefined, problems, ...(remap ? { remap } : {}), ...(engine === undefined ? {} : { engine }) };
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* How create mounts a path of this host at `target`: a bind of it, or, with the provider's volume option, the volume's
|
|
60
|
+
* subpath, as HostConfig.Mounts records it (Docker keeps `volume-nocopy` and the subpath under VolumeOptions). Undefined
|
|
61
|
+
* for a path outside the volume, which create never mounts.
|
|
62
|
+
*/
|
|
63
|
+
export function mountAsked(path, target, readonly, volume) {
|
|
64
|
+
if (volume === undefined)
|
|
65
|
+
return { Type: "bind", Source: path, Target: target, ...(readonly ? { ReadOnly: true } : {}) };
|
|
66
|
+
const subpath = subpathOf(volume, path);
|
|
67
|
+
if (subpath === undefined)
|
|
68
|
+
return undefined;
|
|
69
|
+
return { Type: "volume", Source: volume.name, Target: target, ...(readonly ? { ReadOnly: true } : {}), VolumeOptions: { NoCopy: true, Subpath: subpath } };
|
|
70
|
+
}
|
|
71
|
+
const sameList = (a, b) => Array.isArray(a) && a.length === b.length && a.every((item, i) => item === b[i]);
|
|
72
|
+
/** Docker's default for a field it reports: nothing, an empty string, list or map, zero or false. A map with any key,
|
|
73
|
+
* even to an empty value (a VOLUME's {}), is not. */
|
|
74
|
+
const blank = (value) => value === undefined || value === null || value === "" || value === 0 || value === false || (typeof value === "object" && Object.keys(value).length === 0);
|
|
75
|
+
/** Docker's masked and read-only paths in every release since 20.10; a newer one masks more. */
|
|
76
|
+
const MASKED_PATHS = ["/proc/acpi", "/proc/asound", "/proc/kcore", "/proc/keys", "/proc/latency_stats", "/proc/sched_debug", "/proc/scsi", "/proc/timer_list", "/proc/timer_stats", "/sys/firmware"];
|
|
77
|
+
const READONLY_PATHS = ["/proc/bus", "/proc/fs", "/proc/irq", "/proc/sys", "/proc/sysrq-trigger"];
|
|
78
|
+
const holds = (value, paths) => Array.isArray(value) && paths.every((path) => value.includes(path));
|
|
79
|
+
/**
|
|
80
|
+
* The closed check of HostConfig. A field named here is checked in drift() for what create asked for, is checked
|
|
81
|
+
* here for a default other than blank, or is irrelevant (its value widens nothing the box bounds). Every other field,
|
|
82
|
+
* one Docker adds later included, must be blank.
|
|
83
|
+
*/
|
|
84
|
+
const HOST_ASKED = new Set(["NetworkMode", "CapDrop", "CapAdd", "Privileged", "SecurityOpt", "PidsLimit", "Memory", "MemorySwap", "CpuPeriod", "CpuQuota", "Tmpfs", "Mounts", "IpcMode", "CgroupnsMode", "MaskedPaths", "ReadonlyPaths", "Runtime"]);
|
|
85
|
+
const HOST_DEFAULTS = {
|
|
86
|
+
RestartPolicy: [
|
|
87
|
+
(v) => {
|
|
88
|
+
const { Name, MaximumRetryCount, ...rest } = (v ?? {});
|
|
89
|
+
return (blank(Name) || Name === "no") && blank(MaximumRetryCount) && Object.values(rest).every(blank);
|
|
90
|
+
},
|
|
91
|
+
'no restart ("no")',
|
|
92
|
+
],
|
|
93
|
+
Isolation: [(v) => blank(v) || v === "default", "Docker's default"],
|
|
94
|
+
MemorySwappiness: [(v) => blank(v) || v === -1, "the kernel's (null)"],
|
|
95
|
+
};
|
|
96
|
+
/** Values the host or Docker chooses that a computer cannot widen itself by: logs, the console, /dev/shm (charged to the
|
|
97
|
+
* computer's memory), rlimits (inside the cgroup's limits) and the file create's cid would go to. */
|
|
98
|
+
const HOST_IRRELEVANT = new Set(["ContainerIDFile", "LogConfig", "ConsoleSize", "ShmSize", "Ulimits"]);
|
|
99
|
+
/** The closed check of Config, the same way: the image's own settings that run only inside the computer are irrelevant. */
|
|
100
|
+
const CONFIG_ASKED = new Set(["User", "Image", "WorkingDir", "Env", "Entrypoint", "Cmd", "Labels"]);
|
|
101
|
+
const CONFIG_IRRELEVANT = new Set([
|
|
102
|
+
"Hostname", "Domainname", "AttachStdin", "AttachStdout", "AttachStderr", "Tty", "OpenStdin", "StdinOnce", "ExposedPorts", "Healthcheck",
|
|
103
|
+
"ArgsEscaped", "OnBuild", "StopSignal", "StopTimeout", "Shell", "MacAddress", "NetworkDisabled",
|
|
104
|
+
]);
|
|
105
|
+
/** A mount's options as a set, so their order is no drift. */
|
|
106
|
+
const optionSet = (options) => (typeof options === "string" ? options.split(",").sort().join(",") : undefined);
|
|
107
|
+
/** Whether a computer's inspect shows any part of an allowlist: the egress volume at its path, or init's relay. */
|
|
108
|
+
export function egressShaped(inspected) {
|
|
109
|
+
const cmd = inspected?.Config?.Cmd;
|
|
110
|
+
return (inspected?.Mounts ?? []).some((mount) => mount.Destination === EGRESS_MOUNT) || (Array.isArray(cmd) && cmd.includes(RELAY_FLAG));
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* The network a computer is on, read back from inspect: `none` is network mode none on no network but Docker's own
|
|
114
|
+
* `none`, `open` is the default bridge alone. An allowlist is network mode none with the computer's egress volume
|
|
115
|
+
* mounted read-only at EGRESS_MOUNT and init relaying to its socket, and the list read back from `proxy`, the
|
|
116
|
+
* computer's proxy container's inspect (egressOf: none when it is gone), which must refuse each of `local`, the Docker
|
|
117
|
+
* host's own addresses. Anything else is reported in words, never as a policy it might widen to.
|
|
118
|
+
*/
|
|
119
|
+
export function networkOf(inspected, proxy, code, local) {
|
|
120
|
+
const mode = inspected?.HostConfig?.NetworkMode;
|
|
121
|
+
const networks = Object.keys(inspected?.NetworkSettings?.Networks ?? {}).sort();
|
|
122
|
+
const none = mode === "none" && networks.every((name) => name === "none");
|
|
123
|
+
const where = `network mode ${mode ?? "unknown"} on networks ${networks.join(", ") || "none"}`;
|
|
124
|
+
if (!egressShaped(inspected)) {
|
|
125
|
+
if (none)
|
|
126
|
+
return "none";
|
|
127
|
+
if (mode === "bridge" && sameList(networks, ["bridge"]))
|
|
128
|
+
return "open";
|
|
129
|
+
return { other: where };
|
|
130
|
+
}
|
|
131
|
+
if (!none)
|
|
132
|
+
return { other: `${where}, with an egress volume or relay, which this provider never makes` };
|
|
133
|
+
const name = (inspected?.Name ?? "").replace(/^\//, "");
|
|
134
|
+
const at = (inspected?.Mounts ?? []).filter((mount) => mount.Destination === EGRESS_MOUNT);
|
|
135
|
+
const cmd = inspected?.Config?.Cmd;
|
|
136
|
+
const relay = Array.isArray(cmd) ? cmd.indexOf(RELAY_FLAG) : -1;
|
|
137
|
+
if (at.length === 0)
|
|
138
|
+
return { other: `init's relay points at ${show(Array.isArray(cmd) ? cmd[relay + 1] : undefined)} but no egress volume is mounted at ${EGRESS_MOUNT}` };
|
|
139
|
+
if (relay < 0)
|
|
140
|
+
return { other: `an egress volume at ${EGRESS_MOUNT} but no relay in init's command` };
|
|
141
|
+
if (cmd?.[relay + 1] !== EGRESS_SOCKET)
|
|
142
|
+
return { other: `init relays to ${show(cmd?.[relay + 1])}, not ${EGRESS_SOCKET}` };
|
|
143
|
+
const [only] = at;
|
|
144
|
+
if (at.length !== 1 || only?.Type !== "volume" || only.Name !== egressNameOf(name) || only.RW !== false) {
|
|
145
|
+
return { other: `the egress volume at ${EGRESS_MOUNT} is ${at.map(mountWords).join(", ")}, not ${egressNameOf(name)} read-only` };
|
|
146
|
+
}
|
|
147
|
+
return egressOf(proxy, { name, user: inspected?.Config?.User, deadline: inspected?.Config?.Labels?.[DEADLINE_LABEL], running: inspected?.State?.Running === true }, code, local);
|
|
148
|
+
}
|
|
149
|
+
/** Whether a policy read back is the one declared: the same string, or an allowlist with the same entries, normalized. */
|
|
150
|
+
export function samePolicy(declared, read) {
|
|
151
|
+
if (typeof declared === "string" || typeof read === "string")
|
|
152
|
+
return declared === read;
|
|
153
|
+
return "allow" in declared && "allow" in read && sameAllow(declared.allow, read.allow);
|
|
154
|
+
}
|
|
155
|
+
/** One mount as a person reads it: "a read-write bind of /runs/r1". */
|
|
156
|
+
const mountWords = (mount) => `a ${mount.RW === true ? "read-write" : "read-only"} ${mount.Type ?? "mount"} of ${mount.Source ?? mount.Name ?? "nothing"}`;
|
|
157
|
+
/**
|
|
158
|
+
* What is mounted at /workspace, read back from inspect: a read-write bind is the run's folder; nothing is undefined;
|
|
159
|
+
* anything else (read-only, a volume, two mounts) is reported in words, never as a bind it might be.
|
|
160
|
+
*/
|
|
161
|
+
export function mountOf(inspected, volume) {
|
|
162
|
+
const at = (inspected?.Mounts ?? []).filter((mount) => mount.Destination === WORKSPACE);
|
|
163
|
+
const [only] = at;
|
|
164
|
+
if (only === undefined)
|
|
165
|
+
return undefined;
|
|
166
|
+
if (volume === undefined && at.length === 1 && only.Type === "bind" && only.RW === true && typeof only.Source === "string")
|
|
167
|
+
return { kind: "bind", path: only.Source };
|
|
168
|
+
// With the provider's volume option, the folder is the volume's subpath, read read-write from HostConfig.Mounts, and
|
|
169
|
+
// reported as the path below the root create was given.
|
|
170
|
+
if (volume !== undefined && at.length === 1 && only.Type === "volume" && only.Name === volume.name && only.RW === true) {
|
|
171
|
+
const asked = (inspected?.HostConfig?.Mounts ?? []).filter((mount) => mount.Target === WORKSPACE);
|
|
172
|
+
const subpath = asked[0]?.VolumeOptions?.Subpath;
|
|
173
|
+
if (asked.length === 1 && asked[0]?.Type === "volume" && asked[0].Source === volume.name && typeof subpath === "string" && subpath !== "" && !subpath.split("/").includes("..")) {
|
|
174
|
+
return { kind: "bind", path: join(volume.root, subpath) };
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
return { other: `${at.map(mountWords).join(", ")} at ${WORKSPACE}` };
|
|
178
|
+
}
|
|
179
|
+
/** Every way a created computer differs from its spec, from inspect and hello. */
|
|
180
|
+
export function drift(spec, inspected, hello, expected) {
|
|
181
|
+
return [...inspectDrift(spec, inspected, expected), ...helloDrift(hello, expected)];
|
|
182
|
+
}
|
|
183
|
+
/** Every way a computer's docker inspect differs from its spec: the fields create asks for, and the closed check. */
|
|
184
|
+
export function inspectDrift(spec, inspected, expected) {
|
|
185
|
+
const found = [];
|
|
186
|
+
const mismatch = (field, declared, actual) => found.push(`${field}: declared ${show(declared)}, read back ${show(actual)}`);
|
|
187
|
+
const host = inspected?.HostConfig ?? {};
|
|
188
|
+
const config = inspected?.Config ?? {};
|
|
189
|
+
const network = networkOf(inspected, expected.proxy, expected.egressCode, expected.hostAddresses);
|
|
190
|
+
if (!samePolicy(spec.network, network))
|
|
191
|
+
found.push(`network: declared ${policyWords(spec.network)}, read back ${policyWords(network)}`);
|
|
192
|
+
const allowed = typeof spec.network === "object" && spec.network !== null && "allow" in spec.network;
|
|
193
|
+
const volume = egressNameOf((inspected?.Name ?? "").replace(/^\//, ""));
|
|
194
|
+
if (!sameList(host.CapDrop, ["ALL"]))
|
|
195
|
+
mismatch("CapDrop", ["ALL"], host.CapDrop);
|
|
196
|
+
if ((host.CapAdd ?? []).length > 0)
|
|
197
|
+
mismatch("CapAdd", [], host.CapAdd);
|
|
198
|
+
if (host.Privileged !== false)
|
|
199
|
+
mismatch("Privileged", false, host.Privileged);
|
|
200
|
+
if (!sameList(host.SecurityOpt, ["no-new-privileges"]))
|
|
201
|
+
mismatch("SecurityOpt", ["no-new-privileges"], host.SecurityOpt);
|
|
202
|
+
if (host.IpcMode !== "private")
|
|
203
|
+
mismatch("IpcMode", "private", host.IpcMode);
|
|
204
|
+
if (host.CgroupnsMode !== "private")
|
|
205
|
+
mismatch("CgroupnsMode", "private", host.CgroupnsMode);
|
|
206
|
+
if (host.Runtime !== "runc")
|
|
207
|
+
mismatch("Runtime", "runc", host.Runtime);
|
|
208
|
+
if (!holds(host.MaskedPaths, MASKED_PATHS))
|
|
209
|
+
found.push(`MaskedPaths: must hold Docker's ${show(MASKED_PATHS)}, read back ${show(host.MaskedPaths)}`);
|
|
210
|
+
if (!holds(host.ReadonlyPaths, READONLY_PATHS))
|
|
211
|
+
found.push(`ReadonlyPaths: must hold Docker's ${show(READONLY_PATHS)}, read back ${show(host.ReadonlyPaths)}`);
|
|
212
|
+
const pids = spec.pids ?? DEFAULT_PIDS;
|
|
213
|
+
if (host.PidsLimit !== pids)
|
|
214
|
+
mismatch("PidsLimit", pids, host.PidsLimit);
|
|
215
|
+
const memoryMb = spec.memoryMb ?? DEFAULT_MEMORY_MB;
|
|
216
|
+
const bytes = memoryMb * 1024 * 1024;
|
|
217
|
+
if (host.Memory !== bytes)
|
|
218
|
+
mismatch("Memory", bytes, host.Memory);
|
|
219
|
+
if (host.MemorySwap !== bytes)
|
|
220
|
+
mismatch("MemorySwap", bytes, host.MemorySwap);
|
|
221
|
+
if (host.CpuPeriod !== CPU_PERIOD_US)
|
|
222
|
+
mismatch("CpuPeriod", CPU_PERIOD_US, host.CpuPeriod);
|
|
223
|
+
const quota = Math.round((spec.cpus ?? DEFAULT_CPUS) * CPU_PERIOD_US);
|
|
224
|
+
if (host.CpuQuota !== quota)
|
|
225
|
+
mismatch("CpuQuota", quota, host.CpuQuota);
|
|
226
|
+
const tmpfs = host.Tmpfs ?? {};
|
|
227
|
+
const tmpfsAsked = tmpfsOf(expected.user, memoryMb);
|
|
228
|
+
for (const [path, options] of Object.entries(tmpfsAsked)) {
|
|
229
|
+
if (optionSet(tmpfs[path]) !== optionSet(options))
|
|
230
|
+
mismatch(`tmpfs ${path}`, options, tmpfs[path]);
|
|
231
|
+
}
|
|
232
|
+
for (const [path, options] of Object.entries(tmpfs)) {
|
|
233
|
+
if (!(path in tmpfsAsked))
|
|
234
|
+
found.push(`tmpfs ${path}: none declared but /work and /run/agentrun, read back ${show(options)}`);
|
|
235
|
+
}
|
|
236
|
+
// A Docker computer takes a bind alone; check() refuses any other kind, so one here is drift, named by its kind only.
|
|
237
|
+
if (spec.mount !== undefined && spec.mount.kind !== "bind")
|
|
238
|
+
found.push(`mount: declared a mount of kind ${String(spec.mount.kind)}, which a Docker computer never makes`);
|
|
239
|
+
const bound = spec.mount?.kind === "bind" ? spec.mount.path : undefined;
|
|
240
|
+
// In create's order: the daemon read-only, then the run's folder read-write at /workspace when one was asked for, then
|
|
241
|
+
// the egress volume read-only for an allowlist.
|
|
242
|
+
// With the provider's volume option the daemon and the folder are the volume's subpaths (mountAsked).
|
|
243
|
+
const shared = expected.volume;
|
|
244
|
+
// The daemon's file is bound at DAEMON_IN_COMPUTER; with the volume option its staged directory is at /opt/agentrun.
|
|
245
|
+
const daemonAt = shared === undefined ? DAEMON_IN_COMPUTER : DAEMON_DIR_IN_COMPUTER;
|
|
246
|
+
const daemonAsked = mountAsked(expected.daemonPath, daemonAt, true, shared);
|
|
247
|
+
const folderAsked = bound === undefined ? undefined : mountAsked(bound, WORKSPACE, false, shared);
|
|
248
|
+
if (daemonAsked === undefined)
|
|
249
|
+
found.push(`daemon mount: ${expected.daemonPath} is not below the volume root ${shared?.root}, so create never mounts it`);
|
|
250
|
+
if (bound !== undefined && folderAsked === undefined)
|
|
251
|
+
found.push(`workspace mount: ${bound} is not below the volume root ${shared?.root}, so create never mounts it`);
|
|
252
|
+
const asked = [
|
|
253
|
+
...(daemonAsked === undefined ? [] : [daemonAsked]),
|
|
254
|
+
...(folderAsked === undefined ? [] : [folderAsked]),
|
|
255
|
+
...(allowed ? [{ Type: "volume", Source: volume, Target: EGRESS_MOUNT, ReadOnly: true }] : []),
|
|
256
|
+
];
|
|
257
|
+
const hostMounts = host.Mounts ?? [];
|
|
258
|
+
// An object (VolumeOptions) is the same when it holds the same fields; any other value, exactly.
|
|
259
|
+
const same = (value, want) => typeof want === "object" && want !== null
|
|
260
|
+
? typeof value === "object" && value !== null && Object.entries(value).every(([key, item]) => (key in want ? same(item, want[key]) : blank(item))) && Object.keys(want).every((key) => key in value)
|
|
261
|
+
: value === want;
|
|
262
|
+
const sameMount = (made, want) => made !== undefined &&
|
|
263
|
+
Object.entries(made).every(([key, value]) => (key in want ? same(value, want[key]) : blank(value))) &&
|
|
264
|
+
Object.keys(want).every((key) => made[key] !== undefined);
|
|
265
|
+
if (hostMounts.length !== asked.length || !asked.every((want, i) => sameMount(hostMounts[i], want)))
|
|
266
|
+
mismatch("HostConfig.Mounts", asked, host.Mounts);
|
|
267
|
+
for (const [field, value] of Object.entries(host)) {
|
|
268
|
+
if (HOST_ASKED.has(field) || HOST_IRRELEVANT.has(field))
|
|
269
|
+
continue;
|
|
270
|
+
const rule = HOST_DEFAULTS[field];
|
|
271
|
+
if (rule ? !rule[0](value) : !blank(value))
|
|
272
|
+
found.push(`${field}: must be ${rule ? rule[1] : "Docker's default (empty)"}, read back ${show(value)}`);
|
|
273
|
+
}
|
|
274
|
+
if (config.User !== expected.user)
|
|
275
|
+
mismatch("User", expected.user, config.User);
|
|
276
|
+
if (config.Image !== spec.image)
|
|
277
|
+
mismatch("Image", spec.image, config.Image);
|
|
278
|
+
const workdir = spec.workdir ?? WORK;
|
|
279
|
+
if (config.WorkingDir !== workdir)
|
|
280
|
+
mismatch("WorkingDir", workdir, config.WorkingDir);
|
|
281
|
+
const homes = (Array.isArray(config.Env) ? config.Env : []).filter((entry) => typeof entry === "string" && entry.startsWith("HOME="));
|
|
282
|
+
if (!sameList(homes, [`HOME=${WORK}`]))
|
|
283
|
+
mismatch("Env HOME", [`HOME=${WORK}`], homes);
|
|
284
|
+
for (const [field, value] of Object.entries(config)) {
|
|
285
|
+
if (!CONFIG_ASKED.has(field) && !CONFIG_IRRELEVANT.has(field) && !blank(value))
|
|
286
|
+
found.push(`${field}: must be Docker's default (empty), read back ${show(value)}`);
|
|
287
|
+
}
|
|
288
|
+
const apparmor = expected.apparmor ? "docker-default" : "";
|
|
289
|
+
if ((inspected?.AppArmorProfile ?? "") !== apparmor)
|
|
290
|
+
mismatch("AppArmorProfile", apparmor, inspected?.AppArmorProfile);
|
|
291
|
+
const label = inspected?.ProcessLabel ?? "";
|
|
292
|
+
if (expected.selinux ? !/^[^:]*:[^:]*:container_t:/.test(label) : label !== "") {
|
|
293
|
+
mismatch("ProcessLabel", expected.selinux ? "the container_t type" : "", inspected?.ProcessLabel);
|
|
294
|
+
}
|
|
295
|
+
const mounts = inspected?.Mounts ?? [];
|
|
296
|
+
const daemon = mounts.filter((mount) => mount.Destination === daemonAt);
|
|
297
|
+
const [only] = daemon;
|
|
298
|
+
// A bind shows its source; the volume's subpath shows as the volume (its subpath is HostConfig.Mounts', checked above).
|
|
299
|
+
const fits = (mount, path, rw) => mount !== undefined &&
|
|
300
|
+
mount.RW === rw &&
|
|
301
|
+
(shared === undefined ? mount.Type === "bind" && mount.Source === path && ["", "rprivate", undefined].includes(mount.Propagation) : mount.Type === "volume" && mount.Name === shared.name);
|
|
302
|
+
const how = (path, rw, at) => `declared ${path} ${shared === undefined ? "bound" : `mounted from the volume ${shared.name}`} ${rw ? "read-write" : "read-only"} at ${at}`;
|
|
303
|
+
if (daemon.length !== 1 || !fits(only, expected.daemonPath, false)) {
|
|
304
|
+
found.push(`daemon mount: ${how(expected.daemonPath, false, daemonAt)}, read back ${show(daemon)}`);
|
|
305
|
+
}
|
|
306
|
+
if (bound !== undefined) {
|
|
307
|
+
const workspace = mounts.filter((mount) => mount.Destination === WORKSPACE);
|
|
308
|
+
const [one] = workspace;
|
|
309
|
+
if (workspace.length !== 1 || !fits(one, bound, true)) {
|
|
310
|
+
found.push(`workspace mount: ${how(bound, true, WORKSPACE)}, read back ${show(workspace)}`);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
// The egress volume itself, its name, type and mode, is the network's read-back above.
|
|
314
|
+
const declared = ["the daemon's", ...(bound === undefined ? [] : ["the run folder's"]), ...(allowed ? ["the egress volume's"] : [])].join(" and ");
|
|
315
|
+
for (const mount of mounts) {
|
|
316
|
+
if (mount.Destination === daemonAt || (bound !== undefined && mount.Destination === WORKSPACE) || (allowed && mount.Destination === EGRESS_MOUNT))
|
|
317
|
+
continue;
|
|
318
|
+
found.push(`${mount.Type ?? "unknown"} mount: none declared but ${declared}, read back ${show(mount)}`);
|
|
319
|
+
}
|
|
320
|
+
if (!sameList(config.Entrypoint, [DAEMON_IN_COMPUTER]))
|
|
321
|
+
mismatch("Entrypoint", [DAEMON_IN_COMPUTER], config.Entrypoint);
|
|
322
|
+
const cmd = ["init", "--deadline", expected.deadline, ...(allowed ? [RELAY_FLAG, EGRESS_SOCKET] : [])];
|
|
323
|
+
if (!sameList(config.Cmd, cmd))
|
|
324
|
+
mismatch("Cmd", cmd, config.Cmd);
|
|
325
|
+
const labels = config.Labels ?? {};
|
|
326
|
+
if (labels[COMPUTER_LABEL] !== "1")
|
|
327
|
+
mismatch(`label ${COMPUTER_LABEL}`, "1", labels[COMPUTER_LABEL]);
|
|
328
|
+
if (labels[DEADLINE_LABEL] !== expected.deadline)
|
|
329
|
+
mismatch(`label ${DEADLINE_LABEL}`, expected.deadline, labels[DEADLINE_LABEL]);
|
|
330
|
+
for (const [key, value] of Object.entries(spec.labels ?? {})) {
|
|
331
|
+
if (labels[key] !== value)
|
|
332
|
+
mismatch(`label ${key}`, value, labels[key]);
|
|
333
|
+
}
|
|
334
|
+
return found;
|
|
335
|
+
}
|
package/dist/docker.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { type DesktopOptions } from "./desktop.js";
|
|
2
|
-
import { type DockerHost } from "./
|
|
2
|
+
import { type DockerHost } from "./docker/inspect.js";
|
|
3
3
|
import { type EnsureImageOptions, type ImageSource } from "./docker/image.js";
|
|
4
4
|
import type { KindCapabilities } from "./kinds.js";
|
|
5
5
|
import { type MountKind } from "./mount.js";
|
|
6
|
-
import { type AttachedComputer, type CallContext, type ComputerCapabilities, type ComputerConnection, type ComputerInfo, type ComputerProvider, type ComputerRef, type ComputerSpec, type
|
|
6
|
+
import { type AttachedComputer, type CallContext, type ComputerCapabilities, type ComputerConnection, type ComputerInfo, type ComputerProvider, type ComputerRef, type ComputerSpec, type NetworkPolicy, type NetworkSpec, type Refusal, type ReleaseHow } from "./provider.js";
|
|
7
7
|
import { type Result } from "./result.js";
|
|
8
8
|
import { type ScreenWatch, type ScreenWatchHandlers, type WatchOptions } from "./screen-watch.js";
|
|
9
9
|
/**
|
|
@@ -70,9 +70,7 @@ export interface DockerProviderOptions {
|
|
|
70
70
|
}
|
|
71
71
|
/** The mount kinds a Docker computer takes, as capabilities().mount declares them: a bind of a folder on this host. */
|
|
72
72
|
export declare const MOUNT: readonly MountKind[];
|
|
73
|
-
/** The
|
|
74
|
-
export declare const NETWORK: readonly NetworkForm[];
|
|
75
|
-
/** The machine kind and groups of each configuration: a linux computer, and one made with the desktop option. */
|
|
73
|
+
/** The machine kind and groups of each configuration (its descriptor's): a linux computer, and a desktop. */
|
|
76
74
|
export declare const CAPABILITIES: readonly KindCapabilities[];
|
|
77
75
|
/** What create() takes: the provider's options, the daemon optional. */
|
|
78
76
|
export interface DockerCreateOptions extends Partial<DockerProviderOptions> {
|
|
@@ -111,6 +109,8 @@ export declare class DockerProvider implements ComputerProvider {
|
|
|
111
109
|
* Docker has none; one inspect when it has. Concurrent calls in one process share one build (ensureImage).
|
|
112
110
|
*/
|
|
113
111
|
image(options?: CallContext & Pick<EnsureImageOptions, "timeoutMs" | "onWait">): Promise<Result<string>>;
|
|
112
|
+
/** The provider contract's prepareImage (its descriptor declares it): image(), its recipe built or its image pulled. */
|
|
113
|
+
prepareImage(context?: CallContext & Pick<EnsureImageOptions, "onWait">): Promise<Result<string>>;
|
|
114
114
|
/** The spec's refusals, and the host's once create, attach or host() has read it: its problems, a bind or an
|
|
115
115
|
* allowlist on a host that remaps user ids, and an allowlist on a Docker host this provider does not run on. */
|
|
116
116
|
check(spec: ComputerSpec): Refusal[];
|
|
@@ -154,5 +154,5 @@ export declare class DockerProvider implements ComputerProvider {
|
|
|
154
154
|
* egress volume, found the same way: a container or volume of the proxy's name without that label is never touched.
|
|
155
155
|
* Each is ok when already gone.
|
|
156
156
|
*/
|
|
157
|
-
release(ref: ComputerRef, how:
|
|
157
|
+
release(ref: ComputerRef, how: ReleaseHow): Promise<Result<void>>;
|
|
158
158
|
}
|