@parcha/agentrun-computer 0.0.0-stage → 0.1.0-beta.33
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/NOTICE +8 -0
- package/README.md +2411 -2
- package/box/Dockerfile +69 -0
- package/box/agentrun-archil +168 -0
- package/box/build-daytona.py +26 -0
- package/box/build-e2b.mjs +32 -0
- package/box/build-modal.py +17 -0
- package/dist/actions.d.ts +18 -0
- package/dist/actions.js +139 -0
- package/dist/browser.d.ts +151 -0
- package/dist/browser.js +305 -0
- package/dist/browserbase.d.ts +139 -0
- package/dist/browserbase.js +408 -0
- package/dist/child.d.ts +40 -0
- package/dist/child.js +127 -0
- package/dist/client.d.ts +22 -0
- package/dist/client.js +136 -0
- package/dist/computerd-linux-amd64 +0 -0
- package/dist/computerd-linux-arm64 +0 -0
- package/dist/conformance/archil.d.ts +68 -0
- package/dist/conformance/archil.js +152 -0
- package/dist/conformance/browserbase.d.ts +35 -0
- package/dist/conformance/browserbase.js +45 -0
- package/dist/conformance/cases/apps.d.ts +2 -0
- package/dist/conformance/cases/apps.js +155 -0
- package/dist/conformance/cases/browser.d.ts +4 -0
- package/dist/conformance/cases/browser.js +105 -0
- package/dist/conformance/cases/drift.d.ts +2 -0
- package/dist/conformance/cases/drift.js +64 -0
- package/dist/conformance/cases/exec.d.ts +2 -0
- package/dist/conformance/cases/exec.js +125 -0
- package/dist/conformance/cases/files.d.ts +2 -0
- package/dist/conformance/cases/files.js +294 -0
- package/dist/conformance/cases/health.d.ts +2 -0
- package/dist/conformance/cases/health.js +71 -0
- package/dist/conformance/cases/index.d.ts +9 -0
- package/dist/conformance/cases/index.js +37 -0
- package/dist/conformance/cases/input.d.ts +12 -0
- package/dist/conformance/cases/input.js +109 -0
- package/dist/conformance/cases/isolation.d.ts +21 -0
- package/dist/conformance/cases/isolation.js +98 -0
- package/dist/conformance/cases/lifetime.d.ts +2 -0
- package/dist/conformance/cases/lifetime.js +64 -0
- package/dist/conformance/cases/mount.d.ts +2 -0
- package/dist/conformance/cases/mount.js +252 -0
- package/dist/conformance/cases/process.d.ts +2 -0
- package/dist/conformance/cases/process.js +240 -0
- package/dist/conformance/cases/provider.d.ts +2 -0
- package/dist/conformance/cases/provider.js +302 -0
- package/dist/conformance/cases/screen.d.ts +9 -0
- package/dist/conformance/cases/screen.js +230 -0
- package/dist/conformance/cases/settings.d.ts +57 -0
- package/dist/conformance/cases/settings.js +142 -0
- package/dist/conformance/cases/touch.d.ts +2 -0
- package/dist/conformance/cases/touch.js +117 -0
- package/dist/conformance/cases/util.d.ts +7 -0
- package/dist/conformance/cases/util.js +8 -0
- package/dist/conformance/cdp.d.ts +13 -0
- package/dist/conformance/cdp.js +88 -0
- package/dist/conformance/cli.d.ts +29 -0
- package/dist/conformance/cli.js +231 -0
- package/dist/conformance/daytona-sweep.d.ts +18 -0
- package/dist/conformance/daytona-sweep.js +126 -0
- package/dist/conformance/daytona.d.ts +83 -0
- package/dist/conformance/daytona.js +107 -0
- package/dist/conformance/docker.d.ts +38 -0
- package/dist/conformance/docker.js +70 -0
- package/dist/conformance/drift-daemon.d.ts +8 -0
- package/dist/conformance/drift-daemon.js +41 -0
- package/dist/conformance/e2b-diagnose.d.ts +16 -0
- package/dist/conformance/e2b-diagnose.js +61 -0
- package/dist/conformance/e2b-sweep.d.ts +18 -0
- package/dist/conformance/e2b-sweep.js +132 -0
- package/dist/conformance/e2b.d.ts +74 -0
- package/dist/conformance/e2b.js +111 -0
- package/dist/conformance/fixture.d.ts +65 -0
- package/dist/conformance/fixture.js +98 -0
- package/dist/conformance/index.d.ts +8 -0
- package/dist/conformance/index.js +8 -0
- package/dist/conformance/kernel.d.ts +31 -0
- package/dist/conformance/kernel.js +40 -0
- package/dist/conformance/kind.d.ts +23 -0
- package/dist/conformance/kind.js +58 -0
- package/dist/conformance/modal-sweep.d.ts +22 -0
- package/dist/conformance/modal-sweep.js +213 -0
- package/dist/conformance/modal.d.ts +69 -0
- package/dist/conformance/modal.js +76 -0
- package/dist/conformance/orgo.d.ts +41 -0
- package/dist/conformance/orgo.js +69 -0
- package/dist/conformance/phone-harness.d.ts +61 -0
- package/dist/conformance/phone-harness.js +241 -0
- package/dist/conformance/png.d.ts +16 -0
- package/dist/conformance/png.js +132 -0
- package/dist/conformance/report.d.ts +2 -0
- package/dist/conformance/report.js +86 -0
- package/dist/conformance/runner.d.ts +11 -0
- package/dist/conformance/runner.js +585 -0
- package/dist/conformance/tar.d.ts +13 -0
- package/dist/conformance/tar.js +105 -0
- package/dist/conformance/types.d.ts +257 -0
- package/dist/conformance/types.js +24 -0
- package/dist/daemon-copy.d.ts +40 -0
- package/dist/daemon-copy.js +259 -0
- package/dist/daytona.d.ts +180 -0
- package/dist/daytona.js +1498 -0
- package/dist/desktop.d.ts +24 -0
- package/dist/desktop.js +68 -0
- package/dist/docker/egress-main.d.ts +1 -0
- package/dist/docker/egress-main.js +68 -0
- package/dist/docker/egress-proxy.d.ts +53 -0
- package/dist/docker/egress-proxy.js +450 -0
- package/dist/docker/egress-table.d.ts +39 -0
- package/dist/docker/egress-table.js +197 -0
- package/dist/docker/egress.d.ts +109 -0
- package/dist/docker/egress.js +318 -0
- package/dist/docker/image.d.ts +49 -0
- package/dist/docker/image.js +302 -0
- package/dist/docker/stage.d.ts +21 -0
- package/dist/docker/stage.js +290 -0
- package/dist/docker/volume.d.ts +24 -0
- package/dist/docker/volume.js +67 -0
- package/dist/docker.d.ts +156 -0
- package/dist/docker.js +1277 -0
- package/dist/drift.d.ts +200 -0
- package/dist/drift.js +416 -0
- package/dist/e2b.d.ts +337 -0
- package/dist/e2b.js +1516 -0
- package/dist/entry.d.ts +2 -0
- package/dist/entry.js +24 -0
- package/dist/files.d.ts +50 -0
- package/dist/files.js +208 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.js +26 -0
- package/dist/isolation.d.ts +29 -0
- package/dist/isolation.js +71 -0
- package/dist/janitor.d.ts +50 -0
- package/dist/janitor.js +135 -0
- package/dist/kernel.d.ts +113 -0
- package/dist/kernel.js +358 -0
- package/dist/kinds.d.ts +79 -0
- package/dist/kinds.js +133 -0
- package/dist/labels.d.ts +23 -0
- package/dist/labels.js +50 -0
- package/dist/modal.d.ts +302 -0
- package/dist/modal.js +1374 -0
- package/dist/mount-archil.d.ts +164 -0
- package/dist/mount-archil.js +471 -0
- package/dist/mount.d.ts +57 -0
- package/dist/mount.js +104 -0
- package/dist/orgo-channel.d.ts +96 -0
- package/dist/orgo-channel.js +391 -0
- package/dist/orgo.d.ts +139 -0
- package/dist/orgo.js +1006 -0
- package/dist/phone-harness.d.ts +185 -0
- package/dist/phone-harness.js +1420 -0
- package/dist/processes.d.ts +24 -0
- package/dist/processes.js +40 -0
- package/dist/protocol.d.ts +729 -0
- package/dist/protocol.js +54 -0
- package/dist/provider.d.ts +245 -0
- package/dist/provider.js +37 -0
- package/dist/providers.d.ts +68 -0
- package/dist/providers.js +25 -0
- package/dist/result.d.ts +15 -0
- package/dist/result.js +2 -0
- package/dist/screen-watch.d.ts +150 -0
- package/dist/screen-watch.js +490 -0
- package/dist/test-connection.d.ts +17 -0
- package/dist/test-connection.js +26 -0
- package/dist/wait.d.ts +23 -0
- package/dist/wait.js +65 -0
- package/package.json +62 -4
package/dist/drift.d.ts
ADDED
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import { type EgressCode } from "./docker/egress.js";
|
|
2
|
+
import { type DockerVolume } from "./docker/volume.js";
|
|
3
|
+
import { type MountReadBack } from "./mount.js";
|
|
4
|
+
import type { ComputerKind, Group, HelloResult } from "./protocol.js";
|
|
5
|
+
import type { ComputerSpec, NetworkPolicy, NetworkSpec } from "./provider.js";
|
|
6
|
+
/** Where the daemon is mounted in each computer, read-only. */
|
|
7
|
+
export declare const DAEMON_IN_COMPUTER = "/opt/agentrun/computerd";
|
|
8
|
+
/** With the Docker provider's volume option, where the daemon's staged directory is mounted read-only: its computerd is
|
|
9
|
+
* DAEMON_IN_COMPUTER (src/docker/stage.ts). */
|
|
10
|
+
export declare const DAEMON_DIR_IN_COMPUTER = "/opt/agentrun";
|
|
11
|
+
export declare const COMPUTER_LABEL = "agentrun.computer";
|
|
12
|
+
export declare const DEADLINE_LABEL = "agentrun.computer.deadline";
|
|
13
|
+
/** Serve's box sizes, when the spec names none. */
|
|
14
|
+
export declare const DEFAULT_CPUS = 2;
|
|
15
|
+
export declare const DEFAULT_MEMORY_MB = 4096;
|
|
16
|
+
export declare const DEFAULT_PIDS = 1024;
|
|
17
|
+
/** CPUs are a CFS quota of each 100 ms, as serve gives them: Docker refuses a --cpus above its own CPU count. */
|
|
18
|
+
export declare const CPU_PERIOD_US = 100000;
|
|
19
|
+
/** The computer's home and default workdir: a tmpfs its user owns. The run's folder, when bound, is at WORKSPACE. */
|
|
20
|
+
export declare const WORK = "/work";
|
|
21
|
+
/** Where init's socket lives (the daemon's DefaultSocket's directory): a tmpfs the computer's user owns, mode 0700. */
|
|
22
|
+
export declare const SOCKET_DIR = "/run/agentrun";
|
|
23
|
+
/**
|
|
24
|
+
* The --tmpfs options of each tmpfs a computer gets, owned by its uid:gid. A tmpfs's pages count against the
|
|
25
|
+
* computer's memory, so /work holds half of it: a full /work is ENOSPC before the memory limit could OOM-kill a
|
|
26
|
+
* process. /run/agentrun holds only init's socket.
|
|
27
|
+
*/
|
|
28
|
+
export declare function tmpfsOf(user: string, memoryMb: number): Record<string, string>;
|
|
29
|
+
/** The parts of `docker inspect` a computer is checked by; HostConfig and Config are checked whole. */
|
|
30
|
+
export interface DockerInspect {
|
|
31
|
+
Id?: string;
|
|
32
|
+
Name?: string;
|
|
33
|
+
State?: {
|
|
34
|
+
Running?: boolean;
|
|
35
|
+
Status?: string;
|
|
36
|
+
ExitCode?: number;
|
|
37
|
+
Error?: string;
|
|
38
|
+
};
|
|
39
|
+
AppArmorProfile?: string;
|
|
40
|
+
ProcessLabel?: string;
|
|
41
|
+
Config?: {
|
|
42
|
+
User?: string;
|
|
43
|
+
Image?: string;
|
|
44
|
+
WorkingDir?: string;
|
|
45
|
+
Env?: string[] | null;
|
|
46
|
+
Entrypoint?: string[] | null;
|
|
47
|
+
Cmd?: string[] | null;
|
|
48
|
+
Labels?: Record<string, string> | null;
|
|
49
|
+
[field: string]: unknown;
|
|
50
|
+
};
|
|
51
|
+
HostConfig?: {
|
|
52
|
+
NetworkMode?: string;
|
|
53
|
+
CapDrop?: string[] | null;
|
|
54
|
+
CapAdd?: string[] | null;
|
|
55
|
+
Privileged?: boolean;
|
|
56
|
+
SecurityOpt?: string[] | null;
|
|
57
|
+
PidsLimit?: number | null;
|
|
58
|
+
Memory?: number;
|
|
59
|
+
MemorySwap?: number;
|
|
60
|
+
CpuPeriod?: number;
|
|
61
|
+
CpuQuota?: number;
|
|
62
|
+
Tmpfs?: Record<string, string> | null;
|
|
63
|
+
Mounts?: Array<Record<string, unknown>> | null;
|
|
64
|
+
MaskedPaths?: string[] | null;
|
|
65
|
+
ReadonlyPaths?: string[] | null;
|
|
66
|
+
[field: string]: unknown;
|
|
67
|
+
};
|
|
68
|
+
Mounts?: Array<{
|
|
69
|
+
Type?: string;
|
|
70
|
+
Name?: string;
|
|
71
|
+
Source?: string;
|
|
72
|
+
Destination?: string;
|
|
73
|
+
RW?: boolean;
|
|
74
|
+
Propagation?: string;
|
|
75
|
+
}> | null;
|
|
76
|
+
NetworkSettings?: {
|
|
77
|
+
Networks?: Record<string, unknown> | null;
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
/** What `docker info` reports of the host's enforcement, as the provider reads it. */
|
|
81
|
+
export interface DockerInfo {
|
|
82
|
+
Architecture?: string;
|
|
83
|
+
SecurityOptions?: string[] | null;
|
|
84
|
+
MemoryLimit?: boolean;
|
|
85
|
+
SwapLimit?: boolean;
|
|
86
|
+
PidsLimit?: boolean;
|
|
87
|
+
CPUCfsQuota?: boolean;
|
|
88
|
+
CPUCfsPeriod?: boolean;
|
|
89
|
+
ServerVersion?: string;
|
|
90
|
+
}
|
|
91
|
+
/** A Docker host as the provider reads it: its architecture in Go's names, its security modules, and what it lacks. */
|
|
92
|
+
export interface DockerHost {
|
|
93
|
+
arch: string;
|
|
94
|
+
/** The Docker Engine's major version (docker info's ServerVersion), when it reads as one. */
|
|
95
|
+
engine?: number;
|
|
96
|
+
apparmor: boolean;
|
|
97
|
+
selinux: boolean;
|
|
98
|
+
/** Each enforcement the host lacks, in words; a computer is refused on a host with any. */
|
|
99
|
+
problems: string[];
|
|
100
|
+
/**
|
|
101
|
+
* Present when the host remaps user ids (docker info's name=userns: userns-remap; name=rootless: rootless Docker): a
|
|
102
|
+
* computer's uid is then another uid on the host. No problem for a computer, but a bind of the run folder is refused.
|
|
103
|
+
*/
|
|
104
|
+
remap?: "userns" | "rootless";
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* The host's enforcement, from docker info. A computer's sizes are cgroup limits, so a host that does not enforce one
|
|
108
|
+
* makes it configuration only; seccomp is required, since a computer's only syscall filter is Docker's default
|
|
109
|
+
* profile. AppArmor and SELinux are read, not required: a host has the one its distribution ships or neither, and a
|
|
110
|
+
* computer must then carry the profile or label Docker gives every container (the drift check).
|
|
111
|
+
*/
|
|
112
|
+
export declare function hostOf(info: DockerInfo | null | undefined): DockerHost;
|
|
113
|
+
/** What the daemon must report: the provider's version, kind and groups, and the host's architecture. */
|
|
114
|
+
export interface HelloExpected {
|
|
115
|
+
version: string;
|
|
116
|
+
kind: ComputerKind;
|
|
117
|
+
groups: Group[];
|
|
118
|
+
/** Go's name (amd64, arm64); not checked when absent. */
|
|
119
|
+
arch?: string;
|
|
120
|
+
}
|
|
121
|
+
export interface DriftExpected extends HelloExpected {
|
|
122
|
+
/** The daemon file on the host the computer binds, as it was mounted: for DockerProvider, its copy of the daemon. */
|
|
123
|
+
daemonPath: string;
|
|
124
|
+
/** The deadline label's value, as it was set. */
|
|
125
|
+
deadline: string;
|
|
126
|
+
/** The uid:gid the computer was asked to run as. */
|
|
127
|
+
user: string;
|
|
128
|
+
/** Whether the host's Docker gives every container an AppArmor profile, or an SELinux label (hostOf). */
|
|
129
|
+
apparmor: boolean;
|
|
130
|
+
selinux: boolean;
|
|
131
|
+
/** For a computer with an allowlist: its proxy container's inspect (none when it is gone), and where the proxy's code
|
|
132
|
+
* is on the host, as it was bound. */
|
|
133
|
+
proxy?: DockerInspect | null;
|
|
134
|
+
egressCode?: EgressCode;
|
|
135
|
+
/** For a computer with an allowlist: the Docker host's own addresses its proxy must refuse (its --local holds each). */
|
|
136
|
+
hostAddresses?: readonly string[];
|
|
137
|
+
/** The provider's volume option: the daemon and the run's folder are then that volume's subpaths, not binds. */
|
|
138
|
+
volume?: DockerVolume;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* How create mounts a path of this host at `target`: a bind of it, or, with the provider's volume option, the volume's
|
|
142
|
+
* subpath, as HostConfig.Mounts records it (Docker keeps `volume-nocopy` and the subpath under VolumeOptions). Undefined
|
|
143
|
+
* for a path outside the volume, which create never mounts.
|
|
144
|
+
*/
|
|
145
|
+
export declare function mountAsked(path: string, target: string, readonly: boolean, volume: DockerVolume | undefined): Record<string, unknown> | undefined;
|
|
146
|
+
/** Whether a computer's inspect shows any part of an allowlist: the egress volume at its path, or init's relay. */
|
|
147
|
+
export declare function egressShaped(inspected: DockerInspect | null | undefined): boolean;
|
|
148
|
+
/**
|
|
149
|
+
* The network a computer is on, read back from inspect: `none` is network mode none on no network but Docker's own
|
|
150
|
+
* `none`, `open` is the default bridge alone. An allowlist is network mode none with the computer's egress volume
|
|
151
|
+
* mounted read-only at EGRESS_MOUNT and init relaying to its socket, and the list read back from `proxy`, the
|
|
152
|
+
* computer's proxy container's inspect (egressOf: none when it is gone), which must refuse each of `local`, the Docker
|
|
153
|
+
* host's own addresses. Anything else is reported in words, never as a policy it might widen to.
|
|
154
|
+
*/
|
|
155
|
+
export declare function networkOf(inspected: DockerInspect | null | undefined, proxy?: DockerInspect | null, code?: EgressCode, local?: readonly string[]): NetworkPolicy;
|
|
156
|
+
/** Whether a policy read back is the one declared: the same string, or an allowlist with the same entries, normalized. */
|
|
157
|
+
export declare function samePolicy(declared: NetworkSpec, read: NetworkPolicy): boolean;
|
|
158
|
+
/**
|
|
159
|
+
* What `computerd probe` reports from inside a computer: the uid:gid its programs run as, the kernel, reached (the
|
|
160
|
+
* targets that answered: bytes came back) and accepted (those that accepted a connection and sent nothing back). One
|
|
161
|
+
* rule for every provider that probes (README, "Network none, read from inside"): only an answer refuses network none.
|
|
162
|
+
*/
|
|
163
|
+
export interface ProbeReport {
|
|
164
|
+
uid: number;
|
|
165
|
+
gid: number;
|
|
166
|
+
kernel: string;
|
|
167
|
+
/** The live interfaces (up or addressed) of the probe's network namespace; absent from a daemon too old to report them. */
|
|
168
|
+
interfaces?: string[];
|
|
169
|
+
/** The quiet ones (down, no address), and those of them the probe could bring up as its user. */
|
|
170
|
+
quiet?: string[];
|
|
171
|
+
raised?: string[];
|
|
172
|
+
reached: string[];
|
|
173
|
+
accepted: string[];
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* The probe's JSON line from exec.run's stdout (base64), or what is wrong with it in words. The accepted list is
|
|
177
|
+
* required: a report without it cannot tell a target that only accepted from one refused, so it is no read-back of
|
|
178
|
+
* network none.
|
|
179
|
+
*/
|
|
180
|
+
export declare function probeReportOf(stdout: string): ProbeReport | {
|
|
181
|
+
not: string;
|
|
182
|
+
};
|
|
183
|
+
/** Network none's drift by the probe: a target that answered, in words; none when nothing answered. */
|
|
184
|
+
export declare function probeNetworkDrift(probe: ProbeReport): string[];
|
|
185
|
+
/**
|
|
186
|
+
* What the probe recorded that does not refuse the computer: under network none, the targets that accepted a connection
|
|
187
|
+
* and sent nothing back. A firewall that accepts first and decides after looks so from inside; only an answer is drift.
|
|
188
|
+
*/
|
|
189
|
+
export declare function probeNotes(probe: ProbeReport, network: NetworkSpec | NetworkPolicy): string[];
|
|
190
|
+
/**
|
|
191
|
+
* What is mounted at /workspace, read back from inspect: a read-write bind is the run's folder; nothing is undefined;
|
|
192
|
+
* anything else (read-only, a volume, two mounts) is reported in words, never as a bind it might be.
|
|
193
|
+
*/
|
|
194
|
+
export declare function mountOf(inspected: DockerInspect | null | undefined, volume?: DockerVolume): MountReadBack | undefined;
|
|
195
|
+
/** Every way hello differs from what the provider expects. */
|
|
196
|
+
export declare function helloDrift(hello: HelloResult | null | undefined, expected: HelloExpected): string[];
|
|
197
|
+
/** Every way a created computer differs from its spec, from inspect and hello. */
|
|
198
|
+
export declare function drift(spec: ComputerSpec, inspected: DockerInspect | null | undefined, hello: HelloResult | null | undefined, expected: DriftExpected): string[];
|
|
199
|
+
/** Every way a computer's docker inspect differs from its spec: the fields create asks for, and the closed check. */
|
|
200
|
+
export declare function inspectDrift(spec: ComputerSpec, inspected: DockerInspect | null | undefined, expected: DriftExpected): string[];
|
package/dist/drift.js
ADDED
|
@@ -0,0 +1,416 @@
|
|
|
1
|
+
// The drift check for a Docker computer: what the computer reports of itself after create, from docker inspect and the
|
|
2
|
+
// daemon's hello, against what was declared. Pure: no Docker call. Each mismatch is one sentence; none is an empty list.
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { EGRESS_MOUNT, EGRESS_SOCKET, egressNameOf, egressOf, policyWords, RELAY_FLAG, sameAllow } from "./docker/egress.js";
|
|
5
|
+
import { engineOf, subpathOf } from "./docker/volume.js";
|
|
6
|
+
import { WORKSPACE } from "./mount.js";
|
|
7
|
+
/** Where the daemon is mounted in each computer, read-only. */
|
|
8
|
+
export const DAEMON_IN_COMPUTER = "/opt/agentrun/computerd";
|
|
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 (src/docker/stage.ts). */
|
|
11
|
+
export const DAEMON_DIR_IN_COMPUTER = "/opt/agentrun";
|
|
12
|
+
export const COMPUTER_LABEL = "agentrun.computer";
|
|
13
|
+
export const DEADLINE_LABEL = "agentrun.computer.deadline";
|
|
14
|
+
/** Serve's box sizes, when the spec names none. */
|
|
15
|
+
export const DEFAULT_CPUS = 2;
|
|
16
|
+
export const DEFAULT_MEMORY_MB = 4096;
|
|
17
|
+
export const DEFAULT_PIDS = 1024;
|
|
18
|
+
/** CPUs are a CFS quota of each 100 ms, as serve gives them: Docker refuses a --cpus above its own CPU count. */
|
|
19
|
+
export const CPU_PERIOD_US = 100_000;
|
|
20
|
+
/** The computer's home and default workdir: a tmpfs its user owns. The run's folder, when bound, is at WORKSPACE. */
|
|
21
|
+
export const WORK = "/work";
|
|
22
|
+
/** Where init's socket lives (the daemon's DefaultSocket's directory): a tmpfs the computer's user owns, mode 0700. */
|
|
23
|
+
export const SOCKET_DIR = "/run/agentrun";
|
|
24
|
+
/**
|
|
25
|
+
* The --tmpfs options of each tmpfs a computer gets, owned by its uid:gid. A tmpfs's pages count against the
|
|
26
|
+
* computer's memory, so /work holds half of it: a full /work is ENOSPC before the memory limit could OOM-kill a
|
|
27
|
+
* process. /run/agentrun holds only init's socket.
|
|
28
|
+
*/
|
|
29
|
+
export function tmpfsOf(user, memoryMb) {
|
|
30
|
+
const [uid, gid] = user.split(":");
|
|
31
|
+
return {
|
|
32
|
+
[WORK]: `rw,nosuid,nodev,exec,uid=${uid},gid=${gid},mode=0700,size=${Math.floor(memoryMb / 2)}m`,
|
|
33
|
+
[SOCKET_DIR]: `rw,noexec,nosuid,nodev,uid=${uid},gid=${gid},mode=0700,size=1m`,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
/** docker info names the kernel's architecture; hello names Go's. */
|
|
37
|
+
const GO_ARCH = { x86_64: "amd64", aarch64: "arm64" };
|
|
38
|
+
/**
|
|
39
|
+
* The host's enforcement, from docker info. A computer's sizes are cgroup limits, so a host that does not enforce one
|
|
40
|
+
* makes it configuration only; seccomp is required, since a computer's only syscall filter is Docker's default
|
|
41
|
+
* profile. AppArmor and SELinux are read, not required: a host has the one its distribution ships or neither, and a
|
|
42
|
+
* computer must then carry the profile or label Docker gives every container (the drift check).
|
|
43
|
+
*/
|
|
44
|
+
export function hostOf(info) {
|
|
45
|
+
const problems = [];
|
|
46
|
+
const lacks = (flag, what, so) => {
|
|
47
|
+
if (flag !== true)
|
|
48
|
+
problems.push(`this Docker host does not enforce ${what}, so ${so}`);
|
|
49
|
+
};
|
|
50
|
+
lacks(info?.MemoryLimit, "memory limits", "a computer's memory size is only configuration");
|
|
51
|
+
lacks(info?.SwapLimit, "swap limits", "a computer could swap past its memory size");
|
|
52
|
+
lacks(info?.PidsLimit, "pids limits", "a computer's pids limit is only configuration");
|
|
53
|
+
lacks(info?.CPUCfsQuota, "CPU quotas", "a computer's cpus are only configuration");
|
|
54
|
+
lacks(info?.CPUCfsPeriod, "CPU periods", "a computer's cpus are only configuration");
|
|
55
|
+
const options = Array.isArray(info?.SecurityOptions) ? info.SecurityOptions.filter((option) => typeof option === "string") : [];
|
|
56
|
+
const named = (name) => options.find((option) => option.split(",").includes(`name=${name}`));
|
|
57
|
+
const seccomp = named("seccomp");
|
|
58
|
+
if (seccomp === undefined)
|
|
59
|
+
problems.push("this Docker host has no seccomp, so a computer could make any system call");
|
|
60
|
+
else if (seccomp.split(",").includes("profile=unconfined")) {
|
|
61
|
+
problems.push("this Docker host's default seccomp profile is unconfined, so a computer could make any system call");
|
|
62
|
+
}
|
|
63
|
+
const machine = typeof info?.Architecture === "string" ? info.Architecture : "";
|
|
64
|
+
const remap = named("userns") !== undefined ? "userns" : named("rootless") !== undefined ? "rootless" : undefined;
|
|
65
|
+
const engine = engineOf(info?.ServerVersion);
|
|
66
|
+
return { arch: GO_ARCH[machine] ?? machine, apparmor: named("apparmor") !== undefined, selinux: named("selinux") !== undefined, problems, ...(remap ? { remap } : {}), ...(engine === undefined ? {} : { engine }) };
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* How create mounts a path of this host at `target`: a bind of it, or, with the provider's volume option, the volume's
|
|
70
|
+
* subpath, as HostConfig.Mounts records it (Docker keeps `volume-nocopy` and the subpath under VolumeOptions). Undefined
|
|
71
|
+
* for a path outside the volume, which create never mounts.
|
|
72
|
+
*/
|
|
73
|
+
export function mountAsked(path, target, readonly, volume) {
|
|
74
|
+
if (volume === undefined)
|
|
75
|
+
return { Type: "bind", Source: path, Target: target, ...(readonly ? { ReadOnly: true } : {}) };
|
|
76
|
+
const subpath = subpathOf(volume, path);
|
|
77
|
+
if (subpath === undefined)
|
|
78
|
+
return undefined;
|
|
79
|
+
return { Type: "volume", Source: volume.name, Target: target, ...(readonly ? { ReadOnly: true } : {}), VolumeOptions: { NoCopy: true, Subpath: subpath } };
|
|
80
|
+
}
|
|
81
|
+
const show = (value) => (value === undefined ? "nothing" : JSON.stringify(value));
|
|
82
|
+
const text = (value) => (typeof value === "string" ? value : show(value));
|
|
83
|
+
const sameList = (a, b) => Array.isArray(a) && a.length === b.length && a.every((item, i) => item === b[i]);
|
|
84
|
+
/** Docker's default for a field it reports: nothing, an empty string, list or map, zero or false. A map with any key,
|
|
85
|
+
* even to an empty value (a VOLUME's {}), is not. */
|
|
86
|
+
const blank = (value) => value === undefined || value === null || value === "" || value === 0 || value === false || (typeof value === "object" && Object.keys(value).length === 0);
|
|
87
|
+
/** Docker's masked and read-only paths in every release since 20.10; a newer one masks more. */
|
|
88
|
+
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"];
|
|
89
|
+
const READONLY_PATHS = ["/proc/bus", "/proc/fs", "/proc/irq", "/proc/sys", "/proc/sysrq-trigger"];
|
|
90
|
+
const holds = (value, paths) => Array.isArray(value) && paths.every((path) => value.includes(path));
|
|
91
|
+
/**
|
|
92
|
+
* The closed check of HostConfig. A field named here is checked in drift() for what create asked for, is checked
|
|
93
|
+
* here for a default other than blank, or is irrelevant (its value widens nothing the box bounds). Every other field,
|
|
94
|
+
* one Docker adds later included, must be blank.
|
|
95
|
+
*/
|
|
96
|
+
const HOST_ASKED = new Set(["NetworkMode", "CapDrop", "CapAdd", "Privileged", "SecurityOpt", "PidsLimit", "Memory", "MemorySwap", "CpuPeriod", "CpuQuota", "Tmpfs", "Mounts", "IpcMode", "CgroupnsMode", "MaskedPaths", "ReadonlyPaths", "Runtime"]);
|
|
97
|
+
const HOST_DEFAULTS = {
|
|
98
|
+
RestartPolicy: [
|
|
99
|
+
(v) => {
|
|
100
|
+
const { Name, MaximumRetryCount, ...rest } = (v ?? {});
|
|
101
|
+
return (blank(Name) || Name === "no") && blank(MaximumRetryCount) && Object.values(rest).every(blank);
|
|
102
|
+
},
|
|
103
|
+
'no restart ("no")',
|
|
104
|
+
],
|
|
105
|
+
Isolation: [(v) => blank(v) || v === "default", "Docker's default"],
|
|
106
|
+
MemorySwappiness: [(v) => blank(v) || v === -1, "the kernel's (null)"],
|
|
107
|
+
};
|
|
108
|
+
/** Values the host or Docker chooses that a computer cannot widen itself by: logs, the console, /dev/shm (charged to the
|
|
109
|
+
* computer's memory), rlimits (inside the cgroup's limits) and the file create's cid would go to. */
|
|
110
|
+
const HOST_IRRELEVANT = new Set(["ContainerIDFile", "LogConfig", "ConsoleSize", "ShmSize", "Ulimits"]);
|
|
111
|
+
/** The closed check of Config, the same way: the image's own settings that run only inside the computer are irrelevant. */
|
|
112
|
+
const CONFIG_ASKED = new Set(["User", "Image", "WorkingDir", "Env", "Entrypoint", "Cmd", "Labels"]);
|
|
113
|
+
const CONFIG_IRRELEVANT = new Set([
|
|
114
|
+
"Hostname", "Domainname", "AttachStdin", "AttachStdout", "AttachStderr", "Tty", "OpenStdin", "StdinOnce", "ExposedPorts", "Healthcheck",
|
|
115
|
+
"ArgsEscaped", "OnBuild", "StopSignal", "StopTimeout", "Shell", "MacAddress", "NetworkDisabled",
|
|
116
|
+
]);
|
|
117
|
+
/** A mount's options as a set, so their order is no drift. */
|
|
118
|
+
const optionSet = (options) => (typeof options === "string" ? options.split(",").sort().join(",") : undefined);
|
|
119
|
+
/** Whether a computer's inspect shows any part of an allowlist: the egress volume at its path, or init's relay. */
|
|
120
|
+
export function egressShaped(inspected) {
|
|
121
|
+
const cmd = inspected?.Config?.Cmd;
|
|
122
|
+
return (inspected?.Mounts ?? []).some((mount) => mount.Destination === EGRESS_MOUNT) || (Array.isArray(cmd) && cmd.includes(RELAY_FLAG));
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* The network a computer is on, read back from inspect: `none` is network mode none on no network but Docker's own
|
|
126
|
+
* `none`, `open` is the default bridge alone. An allowlist is network mode none with the computer's egress volume
|
|
127
|
+
* mounted read-only at EGRESS_MOUNT and init relaying to its socket, and the list read back from `proxy`, the
|
|
128
|
+
* computer's proxy container's inspect (egressOf: none when it is gone), which must refuse each of `local`, the Docker
|
|
129
|
+
* host's own addresses. Anything else is reported in words, never as a policy it might widen to.
|
|
130
|
+
*/
|
|
131
|
+
export function networkOf(inspected, proxy, code, local) {
|
|
132
|
+
const mode = inspected?.HostConfig?.NetworkMode;
|
|
133
|
+
const networks = Object.keys(inspected?.NetworkSettings?.Networks ?? {}).sort();
|
|
134
|
+
const none = mode === "none" && networks.every((name) => name === "none");
|
|
135
|
+
const where = `network mode ${mode ?? "unknown"} on networks ${networks.join(", ") || "none"}`;
|
|
136
|
+
if (!egressShaped(inspected)) {
|
|
137
|
+
if (none)
|
|
138
|
+
return "none";
|
|
139
|
+
if (mode === "bridge" && sameList(networks, ["bridge"]))
|
|
140
|
+
return "open";
|
|
141
|
+
return { other: where };
|
|
142
|
+
}
|
|
143
|
+
if (!none)
|
|
144
|
+
return { other: `${where}, with an egress volume or relay, which this provider never makes` };
|
|
145
|
+
const name = (inspected?.Name ?? "").replace(/^\//, "");
|
|
146
|
+
const at = (inspected?.Mounts ?? []).filter((mount) => mount.Destination === EGRESS_MOUNT);
|
|
147
|
+
const cmd = inspected?.Config?.Cmd;
|
|
148
|
+
const relay = Array.isArray(cmd) ? cmd.indexOf(RELAY_FLAG) : -1;
|
|
149
|
+
if (at.length === 0)
|
|
150
|
+
return { other: `init's relay points at ${show(Array.isArray(cmd) ? cmd[relay + 1] : undefined)} but no egress volume is mounted at ${EGRESS_MOUNT}` };
|
|
151
|
+
if (relay < 0)
|
|
152
|
+
return { other: `an egress volume at ${EGRESS_MOUNT} but no relay in init's command` };
|
|
153
|
+
if (cmd?.[relay + 1] !== EGRESS_SOCKET)
|
|
154
|
+
return { other: `init relays to ${show(cmd?.[relay + 1])}, not ${EGRESS_SOCKET}` };
|
|
155
|
+
const [only] = at;
|
|
156
|
+
if (at.length !== 1 || only?.Type !== "volume" || only.Name !== egressNameOf(name) || only.RW !== false) {
|
|
157
|
+
return { other: `the egress volume at ${EGRESS_MOUNT} is ${at.map(mountWords).join(", ")}, not ${egressNameOf(name)} read-only` };
|
|
158
|
+
}
|
|
159
|
+
return egressOf(proxy, { name, user: inspected?.Config?.User, deadline: inspected?.Config?.Labels?.[DEADLINE_LABEL], running: inspected?.State?.Running === true }, code, local);
|
|
160
|
+
}
|
|
161
|
+
/** Whether a policy read back is the one declared: the same string, or an allowlist with the same entries, normalized. */
|
|
162
|
+
export function samePolicy(declared, read) {
|
|
163
|
+
if (typeof declared === "string" || typeof read === "string")
|
|
164
|
+
return declared === read;
|
|
165
|
+
return "allow" in declared && "allow" in read && sameAllow(declared.allow, read.allow);
|
|
166
|
+
}
|
|
167
|
+
const isAddresses = (value) => Array.isArray(value) && value.every((one) => typeof one === "string");
|
|
168
|
+
const isId = (value) => typeof value === "number" && Number.isSafeInteger(value);
|
|
169
|
+
/**
|
|
170
|
+
* The probe's JSON line from exec.run's stdout (base64), or what is wrong with it in words. The accepted list is
|
|
171
|
+
* required: a report without it cannot tell a target that only accepted from one refused, so it is no read-back of
|
|
172
|
+
* network none.
|
|
173
|
+
*/
|
|
174
|
+
export function probeReportOf(stdout) {
|
|
175
|
+
const text = Buffer.from(stdout, "base64").toString("utf8");
|
|
176
|
+
const notReport = { not: `wrote what is not its report: ${text.slice(0, 200)}` };
|
|
177
|
+
let value;
|
|
178
|
+
try {
|
|
179
|
+
value = JSON.parse(text);
|
|
180
|
+
}
|
|
181
|
+
catch {
|
|
182
|
+
return notReport;
|
|
183
|
+
}
|
|
184
|
+
if (!(isId(value?.uid) && isId(value?.gid) && typeof value?.kernel === "string" && isAddresses(value?.reached)))
|
|
185
|
+
return notReport;
|
|
186
|
+
if (!isAddresses(value.accepted)) {
|
|
187
|
+
return { not: `wrote a report with no accepted list, so a target that only accepted cannot be told from one refused: ${text.slice(0, 200)}` };
|
|
188
|
+
}
|
|
189
|
+
return {
|
|
190
|
+
uid: value.uid,
|
|
191
|
+
gid: value.gid,
|
|
192
|
+
kernel: value.kernel,
|
|
193
|
+
...(isAddresses(value.interfaces) ? { interfaces: value.interfaces } : {}),
|
|
194
|
+
...(isAddresses(value.quiet) ? { quiet: value.quiet } : {}),
|
|
195
|
+
...(isAddresses(value.raised) ? { raised: value.raised } : {}),
|
|
196
|
+
reached: value.reached,
|
|
197
|
+
accepted: value.accepted,
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
/** Network none's drift by the probe: a target that answered, in words; none when nothing answered. */
|
|
201
|
+
export function probeNetworkDrift(probe) {
|
|
202
|
+
return probe.reached.length > 0 ? [`network: declared none, read back an answer from ${probe.reached.join(", ")}`] : [];
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* What the probe recorded that does not refuse the computer: under network none, the targets that accepted a connection
|
|
206
|
+
* and sent nothing back. A firewall that accepts first and decides after looks so from inside; only an answer is drift.
|
|
207
|
+
*/
|
|
208
|
+
export function probeNotes(probe, network) {
|
|
209
|
+
return network === "none" && probe.accepted.length > 0 ? [`network: none; accepted with no answer (no bytes came back): ${probe.accepted.join(", ")}`] : [];
|
|
210
|
+
}
|
|
211
|
+
/** One mount as a person reads it: "a read-write bind of /runs/r1". */
|
|
212
|
+
const mountWords = (mount) => `a ${mount.RW === true ? "read-write" : "read-only"} ${mount.Type ?? "mount"} of ${mount.Source ?? mount.Name ?? "nothing"}`;
|
|
213
|
+
/**
|
|
214
|
+
* What is mounted at /workspace, read back from inspect: a read-write bind is the run's folder; nothing is undefined;
|
|
215
|
+
* anything else (read-only, a volume, two mounts) is reported in words, never as a bind it might be.
|
|
216
|
+
*/
|
|
217
|
+
export function mountOf(inspected, volume) {
|
|
218
|
+
const at = (inspected?.Mounts ?? []).filter((mount) => mount.Destination === WORKSPACE);
|
|
219
|
+
const [only] = at;
|
|
220
|
+
if (only === undefined)
|
|
221
|
+
return undefined;
|
|
222
|
+
if (volume === undefined && at.length === 1 && only.Type === "bind" && only.RW === true && typeof only.Source === "string")
|
|
223
|
+
return { kind: "bind", path: only.Source };
|
|
224
|
+
// With the provider's volume option, the folder is the volume's subpath, read read-write from HostConfig.Mounts, and
|
|
225
|
+
// reported as the path below the root create was given.
|
|
226
|
+
if (volume !== undefined && at.length === 1 && only.Type === "volume" && only.Name === volume.name && only.RW === true) {
|
|
227
|
+
const asked = (inspected?.HostConfig?.Mounts ?? []).filter((mount) => mount.Target === WORKSPACE);
|
|
228
|
+
const subpath = asked[0]?.VolumeOptions?.Subpath;
|
|
229
|
+
if (asked.length === 1 && asked[0]?.Type === "volume" && asked[0].Source === volume.name && typeof subpath === "string" && subpath !== "" && !subpath.split("/").includes("..")) {
|
|
230
|
+
return { kind: "bind", path: join(volume.root, subpath) };
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
return { other: `${at.map(mountWords).join(", ")} at ${WORKSPACE}` };
|
|
234
|
+
}
|
|
235
|
+
/** Every way hello differs from what the provider expects. */
|
|
236
|
+
export function helloDrift(hello, expected) {
|
|
237
|
+
const found = [];
|
|
238
|
+
if (hello?.version !== expected.version)
|
|
239
|
+
found.push(`hello: the daemon reports version ${text(hello?.version)}, expected ${expected.version}`);
|
|
240
|
+
if (hello?.os !== "linux")
|
|
241
|
+
found.push(`hello: the daemon reports os ${text(hello?.os)}, expected linux`);
|
|
242
|
+
if (expected.arch !== undefined && hello?.arch !== expected.arch) {
|
|
243
|
+
found.push(`hello: the daemon reports arch ${text(hello?.arch)}, expected the host's ${expected.arch}`);
|
|
244
|
+
}
|
|
245
|
+
if (hello?.kind !== expected.kind)
|
|
246
|
+
found.push(`hello: the daemon reports kind ${text(hello?.kind)}, expected ${expected.kind}`);
|
|
247
|
+
const offered = hello?.groups;
|
|
248
|
+
if (!Array.isArray(offered)) {
|
|
249
|
+
found.push(`hello: the daemon reports groups ${show(offered)}, not a list; expected ${expected.groups.join(", ")}`);
|
|
250
|
+
return found;
|
|
251
|
+
}
|
|
252
|
+
const missing = expected.groups.filter((group) => !offered.includes(group));
|
|
253
|
+
if (missing.length > 0)
|
|
254
|
+
found.push(`hello: the daemon's groups lack ${missing.join(", ")}, which the provider declares`);
|
|
255
|
+
const extra = offered.filter((group) => !expected.groups.includes(group));
|
|
256
|
+
if (extra.length > 0)
|
|
257
|
+
found.push(`hello: the daemon offers groups ${extra.map(text).join(", ")}, which the provider does not declare`);
|
|
258
|
+
return found;
|
|
259
|
+
}
|
|
260
|
+
/** Every way a created computer differs from its spec, from inspect and hello. */
|
|
261
|
+
export function drift(spec, inspected, hello, expected) {
|
|
262
|
+
return [...inspectDrift(spec, inspected, expected), ...helloDrift(hello, expected)];
|
|
263
|
+
}
|
|
264
|
+
/** Every way a computer's docker inspect differs from its spec: the fields create asks for, and the closed check. */
|
|
265
|
+
export function inspectDrift(spec, inspected, expected) {
|
|
266
|
+
const found = [];
|
|
267
|
+
const mismatch = (field, declared, actual) => found.push(`${field}: declared ${show(declared)}, read back ${show(actual)}`);
|
|
268
|
+
const host = inspected?.HostConfig ?? {};
|
|
269
|
+
const config = inspected?.Config ?? {};
|
|
270
|
+
const network = networkOf(inspected, expected.proxy, expected.egressCode, expected.hostAddresses);
|
|
271
|
+
if (!samePolicy(spec.network, network))
|
|
272
|
+
found.push(`network: declared ${policyWords(spec.network)}, read back ${policyWords(network)}`);
|
|
273
|
+
const allowed = typeof spec.network === "object" && spec.network !== null && "allow" in spec.network;
|
|
274
|
+
const volume = egressNameOf((inspected?.Name ?? "").replace(/^\//, ""));
|
|
275
|
+
if (!sameList(host.CapDrop, ["ALL"]))
|
|
276
|
+
mismatch("CapDrop", ["ALL"], host.CapDrop);
|
|
277
|
+
if ((host.CapAdd ?? []).length > 0)
|
|
278
|
+
mismatch("CapAdd", [], host.CapAdd);
|
|
279
|
+
if (host.Privileged !== false)
|
|
280
|
+
mismatch("Privileged", false, host.Privileged);
|
|
281
|
+
if (!sameList(host.SecurityOpt, ["no-new-privileges"]))
|
|
282
|
+
mismatch("SecurityOpt", ["no-new-privileges"], host.SecurityOpt);
|
|
283
|
+
if (host.IpcMode !== "private")
|
|
284
|
+
mismatch("IpcMode", "private", host.IpcMode);
|
|
285
|
+
if (host.CgroupnsMode !== "private")
|
|
286
|
+
mismatch("CgroupnsMode", "private", host.CgroupnsMode);
|
|
287
|
+
if (host.Runtime !== "runc")
|
|
288
|
+
mismatch("Runtime", "runc", host.Runtime);
|
|
289
|
+
if (!holds(host.MaskedPaths, MASKED_PATHS))
|
|
290
|
+
found.push(`MaskedPaths: must hold Docker's ${show(MASKED_PATHS)}, read back ${show(host.MaskedPaths)}`);
|
|
291
|
+
if (!holds(host.ReadonlyPaths, READONLY_PATHS))
|
|
292
|
+
found.push(`ReadonlyPaths: must hold Docker's ${show(READONLY_PATHS)}, read back ${show(host.ReadonlyPaths)}`);
|
|
293
|
+
const pids = spec.pids ?? DEFAULT_PIDS;
|
|
294
|
+
if (host.PidsLimit !== pids)
|
|
295
|
+
mismatch("PidsLimit", pids, host.PidsLimit);
|
|
296
|
+
const memoryMb = spec.memoryMb ?? DEFAULT_MEMORY_MB;
|
|
297
|
+
const bytes = memoryMb * 1024 * 1024;
|
|
298
|
+
if (host.Memory !== bytes)
|
|
299
|
+
mismatch("Memory", bytes, host.Memory);
|
|
300
|
+
if (host.MemorySwap !== bytes)
|
|
301
|
+
mismatch("MemorySwap", bytes, host.MemorySwap);
|
|
302
|
+
if (host.CpuPeriod !== CPU_PERIOD_US)
|
|
303
|
+
mismatch("CpuPeriod", CPU_PERIOD_US, host.CpuPeriod);
|
|
304
|
+
const quota = Math.round((spec.cpus ?? DEFAULT_CPUS) * CPU_PERIOD_US);
|
|
305
|
+
if (host.CpuQuota !== quota)
|
|
306
|
+
mismatch("CpuQuota", quota, host.CpuQuota);
|
|
307
|
+
const tmpfs = host.Tmpfs ?? {};
|
|
308
|
+
const tmpfsAsked = tmpfsOf(expected.user, memoryMb);
|
|
309
|
+
for (const [path, options] of Object.entries(tmpfsAsked)) {
|
|
310
|
+
if (optionSet(tmpfs[path]) !== optionSet(options))
|
|
311
|
+
mismatch(`tmpfs ${path}`, options, tmpfs[path]);
|
|
312
|
+
}
|
|
313
|
+
for (const [path, options] of Object.entries(tmpfs)) {
|
|
314
|
+
if (!(path in tmpfsAsked))
|
|
315
|
+
found.push(`tmpfs ${path}: none declared but /work and /run/agentrun, read back ${show(options)}`);
|
|
316
|
+
}
|
|
317
|
+
// A Docker computer takes a bind alone; check() refuses any other kind, so one here is drift, named by its kind only.
|
|
318
|
+
if (spec.mount !== undefined && spec.mount.kind !== "bind")
|
|
319
|
+
found.push(`mount: declared a mount of kind ${String(spec.mount.kind)}, which a Docker computer never makes`);
|
|
320
|
+
const bound = spec.mount?.kind === "bind" ? spec.mount.path : undefined;
|
|
321
|
+
// In create's order: the daemon read-only, then the run's folder read-write at /workspace when one was asked for, then
|
|
322
|
+
// the egress volume read-only for an allowlist.
|
|
323
|
+
// With the provider's volume option the daemon and the folder are the volume's subpaths (mountAsked).
|
|
324
|
+
const shared = expected.volume;
|
|
325
|
+
// The daemon's file is bound at DAEMON_IN_COMPUTER; with the volume option its staged directory is at /opt/agentrun.
|
|
326
|
+
const daemonAt = shared === undefined ? DAEMON_IN_COMPUTER : DAEMON_DIR_IN_COMPUTER;
|
|
327
|
+
const daemonAsked = mountAsked(expected.daemonPath, daemonAt, true, shared);
|
|
328
|
+
const folderAsked = bound === undefined ? undefined : mountAsked(bound, WORKSPACE, false, shared);
|
|
329
|
+
if (daemonAsked === undefined)
|
|
330
|
+
found.push(`daemon mount: ${expected.daemonPath} is not below the volume root ${shared?.root}, so create never mounts it`);
|
|
331
|
+
if (bound !== undefined && folderAsked === undefined)
|
|
332
|
+
found.push(`workspace mount: ${bound} is not below the volume root ${shared?.root}, so create never mounts it`);
|
|
333
|
+
const asked = [
|
|
334
|
+
...(daemonAsked === undefined ? [] : [daemonAsked]),
|
|
335
|
+
...(folderAsked === undefined ? [] : [folderAsked]),
|
|
336
|
+
...(allowed ? [{ Type: "volume", Source: volume, Target: EGRESS_MOUNT, ReadOnly: true }] : []),
|
|
337
|
+
];
|
|
338
|
+
const hostMounts = host.Mounts ?? [];
|
|
339
|
+
// An object (VolumeOptions) is the same when it holds the same fields; any other value, exactly.
|
|
340
|
+
const same = (value, want) => typeof want === "object" && want !== null
|
|
341
|
+
? 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)
|
|
342
|
+
: value === want;
|
|
343
|
+
const sameMount = (made, want) => made !== undefined &&
|
|
344
|
+
Object.entries(made).every(([key, value]) => (key in want ? same(value, want[key]) : blank(value))) &&
|
|
345
|
+
Object.keys(want).every((key) => made[key] !== undefined);
|
|
346
|
+
if (hostMounts.length !== asked.length || !asked.every((want, i) => sameMount(hostMounts[i], want)))
|
|
347
|
+
mismatch("HostConfig.Mounts", asked, host.Mounts);
|
|
348
|
+
for (const [field, value] of Object.entries(host)) {
|
|
349
|
+
if (HOST_ASKED.has(field) || HOST_IRRELEVANT.has(field))
|
|
350
|
+
continue;
|
|
351
|
+
const rule = HOST_DEFAULTS[field];
|
|
352
|
+
if (rule ? !rule[0](value) : !blank(value))
|
|
353
|
+
found.push(`${field}: must be ${rule ? rule[1] : "Docker's default (empty)"}, read back ${show(value)}`);
|
|
354
|
+
}
|
|
355
|
+
if (config.User !== expected.user)
|
|
356
|
+
mismatch("User", expected.user, config.User);
|
|
357
|
+
if (config.Image !== spec.image)
|
|
358
|
+
mismatch("Image", spec.image, config.Image);
|
|
359
|
+
const workdir = spec.workdir ?? WORK;
|
|
360
|
+
if (config.WorkingDir !== workdir)
|
|
361
|
+
mismatch("WorkingDir", workdir, config.WorkingDir);
|
|
362
|
+
const homes = (Array.isArray(config.Env) ? config.Env : []).filter((entry) => typeof entry === "string" && entry.startsWith("HOME="));
|
|
363
|
+
if (!sameList(homes, [`HOME=${WORK}`]))
|
|
364
|
+
mismatch("Env HOME", [`HOME=${WORK}`], homes);
|
|
365
|
+
for (const [field, value] of Object.entries(config)) {
|
|
366
|
+
if (!CONFIG_ASKED.has(field) && !CONFIG_IRRELEVANT.has(field) && !blank(value))
|
|
367
|
+
found.push(`${field}: must be Docker's default (empty), read back ${show(value)}`);
|
|
368
|
+
}
|
|
369
|
+
const apparmor = expected.apparmor ? "docker-default" : "";
|
|
370
|
+
if ((inspected?.AppArmorProfile ?? "") !== apparmor)
|
|
371
|
+
mismatch("AppArmorProfile", apparmor, inspected?.AppArmorProfile);
|
|
372
|
+
const label = inspected?.ProcessLabel ?? "";
|
|
373
|
+
if (expected.selinux ? !/^[^:]*:[^:]*:container_t:/.test(label) : label !== "") {
|
|
374
|
+
mismatch("ProcessLabel", expected.selinux ? "the container_t type" : "", inspected?.ProcessLabel);
|
|
375
|
+
}
|
|
376
|
+
const mounts = inspected?.Mounts ?? [];
|
|
377
|
+
const daemon = mounts.filter((mount) => mount.Destination === daemonAt);
|
|
378
|
+
const [only] = daemon;
|
|
379
|
+
// A bind shows its source; the volume's subpath shows as the volume (its subpath is HostConfig.Mounts', checked above).
|
|
380
|
+
const fits = (mount, path, rw) => mount !== undefined &&
|
|
381
|
+
mount.RW === rw &&
|
|
382
|
+
(shared === undefined ? mount.Type === "bind" && mount.Source === path && ["", "rprivate", undefined].includes(mount.Propagation) : mount.Type === "volume" && mount.Name === shared.name);
|
|
383
|
+
const how = (path, rw, at) => `declared ${path} ${shared === undefined ? "bound" : `mounted from the volume ${shared.name}`} ${rw ? "read-write" : "read-only"} at ${at}`;
|
|
384
|
+
if (daemon.length !== 1 || !fits(only, expected.daemonPath, false)) {
|
|
385
|
+
found.push(`daemon mount: ${how(expected.daemonPath, false, daemonAt)}, read back ${show(daemon)}`);
|
|
386
|
+
}
|
|
387
|
+
if (bound !== undefined) {
|
|
388
|
+
const workspace = mounts.filter((mount) => mount.Destination === WORKSPACE);
|
|
389
|
+
const [one] = workspace;
|
|
390
|
+
if (workspace.length !== 1 || !fits(one, bound, true)) {
|
|
391
|
+
found.push(`workspace mount: ${how(bound, true, WORKSPACE)}, read back ${show(workspace)}`);
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
// The egress volume itself, its name, type and mode, is the network's read-back above.
|
|
395
|
+
const declared = ["the daemon's", ...(bound === undefined ? [] : ["the run folder's"]), ...(allowed ? ["the egress volume's"] : [])].join(" and ");
|
|
396
|
+
for (const mount of mounts) {
|
|
397
|
+
if (mount.Destination === daemonAt || (bound !== undefined && mount.Destination === WORKSPACE) || (allowed && mount.Destination === EGRESS_MOUNT))
|
|
398
|
+
continue;
|
|
399
|
+
found.push(`${mount.Type ?? "unknown"} mount: none declared but ${declared}, read back ${show(mount)}`);
|
|
400
|
+
}
|
|
401
|
+
if (!sameList(config.Entrypoint, [DAEMON_IN_COMPUTER]))
|
|
402
|
+
mismatch("Entrypoint", [DAEMON_IN_COMPUTER], config.Entrypoint);
|
|
403
|
+
const cmd = ["init", "--deadline", expected.deadline, ...(allowed ? [RELAY_FLAG, EGRESS_SOCKET] : [])];
|
|
404
|
+
if (!sameList(config.Cmd, cmd))
|
|
405
|
+
mismatch("Cmd", cmd, config.Cmd);
|
|
406
|
+
const labels = config.Labels ?? {};
|
|
407
|
+
if (labels[COMPUTER_LABEL] !== "1")
|
|
408
|
+
mismatch(`label ${COMPUTER_LABEL}`, "1", labels[COMPUTER_LABEL]);
|
|
409
|
+
if (labels[DEADLINE_LABEL] !== expected.deadline)
|
|
410
|
+
mismatch(`label ${DEADLINE_LABEL}`, expected.deadline, labels[DEADLINE_LABEL]);
|
|
411
|
+
for (const [key, value] of Object.entries(spec.labels ?? {})) {
|
|
412
|
+
if (labels[key] !== value)
|
|
413
|
+
mismatch(`label ${key}`, value, labels[key]);
|
|
414
|
+
}
|
|
415
|
+
return found;
|
|
416
|
+
}
|