@buildanagent/harness 0.1.0-alpha.28 → 0.1.0-alpha.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/README.md +111 -5
- package/dist/context/file-spill.d.ts +11 -1
- package/dist/context/file-spill.js +23 -8
- package/dist/context/file-spill.js.map +1 -1
- package/dist/context/spill.d.ts +5 -1
- package/dist/context/spill.js +6 -2
- package/dist/context/spill.js.map +1 -1
- package/dist/credentials/allowlist.d.ts +22 -2
- package/dist/credentials/allowlist.js +74 -17
- package/dist/credentials/allowlist.js.map +1 -1
- package/dist/credentials/egress-policy.d.ts +69 -0
- package/dist/credentials/egress-policy.js +170 -0
- package/dist/credentials/egress-policy.js.map +1 -0
- package/dist/credentials/egress-proxy.d.ts +13 -1
- package/dist/credentials/egress-proxy.js +179 -11
- package/dist/credentials/egress-proxy.js.map +1 -1
- package/dist/credentials/git-route.d.ts +68 -0
- package/dist/credentials/git-route.js +288 -0
- package/dist/credentials/git-route.js.map +1 -0
- package/dist/credentials/index.d.ts +5 -1
- package/dist/credentials/index.js +5 -1
- package/dist/credentials/index.js.map +1 -1
- package/dist/credentials/scrub.d.ts +7 -0
- package/dist/credentials/scrub.js +22 -0
- package/dist/credentials/scrub.js.map +1 -1
- package/dist/errors.d.ts +9 -5
- package/dist/errors.js +8 -4
- package/dist/errors.js.map +1 -1
- package/dist/sandbox/base.d.ts +11 -1
- package/dist/sandbox/base.js +14 -0
- package/dist/sandbox/base.js.map +1 -1
- package/dist/sandbox/docker/index.d.ts +8 -2
- package/dist/sandbox/docker/index.js +63 -14
- package/dist/sandbox/docker/index.js.map +1 -1
- package/dist/sandbox/errors.d.ts +30 -2
- package/dist/sandbox/errors.js +36 -1
- package/dist/sandbox/errors.js.map +1 -1
- package/dist/sandbox/host-files.d.ts +2 -0
- package/dist/sandbox/host-files.js +10 -0
- package/dist/sandbox/host-files.js.map +1 -1
- package/dist/sandbox/index.d.ts +6 -4
- package/dist/sandbox/index.js +5 -3
- package/dist/sandbox/index.js.map +1 -1
- package/dist/sandbox/policy.d.ts +49 -0
- package/dist/sandbox/policy.js +149 -0
- package/dist/sandbox/policy.js.map +1 -0
- package/dist/sandbox/process.js +1 -1
- package/dist/sandbox/process.js.map +1 -1
- package/dist/sandbox/srt/index.d.ts +5 -2
- package/dist/sandbox/srt/index.js +27 -8
- package/dist/sandbox/srt/index.js.map +1 -1
- package/dist/sandbox/srt/settings.d.ts +17 -5
- package/dist/sandbox/srt/settings.js +53 -0
- package/dist/sandbox/srt/settings.js.map +1 -1
- package/dist/sandbox/types.d.ts +41 -4
- package/dist/sandbox/types.js.map +1 -1
- package/dist/testing/fake-sandbox.d.ts +21 -3
- package/dist/testing/fake-sandbox.js +157 -8
- package/dist/testing/fake-sandbox.js.map +1 -1
- package/dist/testing/sandbox-conformance.js +108 -1
- package/dist/testing/sandbox-conformance.js.map +1 -1
- package/dist/tools/builtins/bash.d.ts +9 -0
- package/dist/tools/builtins/bash.js +75 -0
- package/dist/tools/builtins/bash.js.map +1 -0
- package/dist/tools/builtins/builtins.d.ts +38 -0
- package/dist/tools/builtins/builtins.js +48 -0
- package/dist/tools/builtins/builtins.js.map +1 -0
- package/dist/tools/builtins/descriptions.d.ts +69 -0
- package/dist/tools/builtins/descriptions.js +94 -0
- package/dist/tools/builtins/descriptions.js.map +1 -0
- package/dist/tools/builtins/fetch.d.ts +12 -0
- package/dist/tools/builtins/fetch.js +157 -0
- package/dist/tools/builtins/fetch.js.map +1 -0
- package/dist/tools/builtins/files.d.ts +27 -0
- package/dist/tools/builtins/files.js +274 -0
- package/dist/tools/builtins/files.js.map +1 -0
- package/dist/tools/builtins/paths.d.ts +30 -0
- package/dist/tools/builtins/paths.js +62 -0
- package/dist/tools/builtins/paths.js.map +1 -0
- package/dist/tools/builtins/results.d.ts +15 -0
- package/dist/tools/builtins/results.js +31 -0
- package/dist/tools/builtins/results.js.map +1 -0
- package/dist/tools/builtins/search.d.ts +18 -0
- package/dist/tools/builtins/search.js +217 -0
- package/dist/tools/builtins/search.js.map +1 -0
- package/dist/tools/index.d.ts +6 -2
- package/dist/tools/index.js +5 -2
- package/dist/tools/index.js.map +1 -1
- package/llms.txt +34 -0
- package/package.json +5 -5
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"git-route.js","sourceRoot":"","sources":["../../src/credentials/git-route.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAuB5C,iHAAiH;AACjH,MAAM,CAAC,MAAM,qBAAqB,GAAG,EAAE,GAAG,IAAI,CAAC;AAC/C,wCAAwC;AACxC,MAAM,CAAC,MAAM,gBAAgB,GAAG,EAAE,CAAC;AAEnC,MAAM,OAAO,GAAG,KAAK,CAAC;AACtB,MAAM,OAAO,GAAG,mBAAmB,CAAC;AACpC,MAAM,eAAe,GAAG,qEAAqE,CAAC;AAC9F,MAAM,GAAG,GAAG,6BAA6B,CAAC;AAC1C,MAAM,OAAO,GAAG,IAAI,MAAM,CAAC,IAAI,GAAG,IAAI,GAAG,UAAU,CAAC,CAAC;AACrD,MAAM,OAAO,GAAG,IAAI,MAAM,CAAC,YAAY,GAAG,GAAG,CAAC,CAAC;AAC/C,MAAM,IAAI,GAAG,MAAM,CAAC;AACpB,MAAM,QAAQ,GAAG,wBAAwB,CAAC;AAE1C,MAAM,OAAO,GAAG,CAAC,OAAe,EAAE,EAAE,CAAC,IAAI,YAAY,CAAC,wBAAwB,EAAE,OAAO,CAAC,CAAC;AAEzF,8GAA8G;AAC9G,MAAM,UAAU,cAAc,CAAC,IAAY;IACzC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,IAAI,CAAC,MAAM,GAAG,IAAI;QAAE,OAAO,KAAK,CAAC;IAClE,MAAM,OAAO,GAAG,CAAC,GAAG,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,UA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,QAAQ,CAAC;AAC7D,CAAC;AAED,qFAAqF;AACrF,MAAM,UAAU,WAAW,CAAC,QAAgB,EAAE,MAAc;IAC1D,MAAM,KAAK,GAAG,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,GAAG,QAAQ,IAAI,MAAM,EAAE,CAAC,CAAC;IAChE,OAAO,SAAS,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,GAAG,KAAK,CAAC,CAAC,EAAE,CAAC;AACxD,CAAC","sourcesContent":["/**\n * The checks of a git route: git's smart HTTP protocol over a credential route, limited to listed repositories and,\n * for a push, to listed branches. It is pure and portable, so the proxy and any other backend can share it. Everything\n * it doesn't understand is refused: an unknown path, a query, a push certificate, a pkt-line it can't read, a command\n * list past its size limit, a deletion, a tag and any ref outside the patterns.\n */\nimport { HarnessError } from \"../errors.js\";\n\n/** What a git route lets through. */\nexport interface GitRouteFilter {\n /** The repositories the route reaches, as `owner/name`. Compared without case, as GitHub does. */\n readonly repositories: readonly string[];\n /**\n * The branches a push may create or update, as `refs/heads/<name>` or a prefix ending in `/*`, such as\n * `refs/heads/agent/*`. Leave it empty to refuse every push. A deletion and a tag are always refused.\n */\n readonly pushRefs: readonly string[];\n /** Whether a fetch or clone may read the repositories. A fetch is not limited by ref. */\n readonly fetch: boolean;\n /** The user name sent with the credential in HTTP Basic, such as `x-access-token` for a GitHub App token. */\n readonly username: string;\n}\n\n/** A git request the route accepts: which service, and whether it is the ref advertisement or the request itself. */\nexport interface GitEndpoint {\n readonly service: \"git-receive-pack\" | \"git-upload-pack\";\n readonly phase: \"advertise\" | \"rpc\";\n}\n\n/** The most bytes of a push's command list, before its flush, that the route reads. A longer list is refused. */\nexport const GIT_MAX_COMMAND_BYTES = 64 * 1024;\n/** The most ref updates in one push. */\nexport const GIT_MAX_COMMANDS = 64;\n\nconst PKT_MAX = 65520;\nconst SEGMENT = /^[A-Za-z0-9_.-]+$/;\nconst REPOSITORY_PATH = /^\\/([^/]+)\\/([^/]+)\\/(info\\/refs|git-receive-pack|git-upload-pack)$/;\nconst OID = \"([0-9a-f]{40}|[0-9a-f]{64})\";\nconst COMMAND = new RegExp(`^${OID} ${OID} (\\\\S+)$`);\nconst SHALLOW = new RegExp(`^shallow ${OID}$`);\nconst ZERO = /^0+$/;\nconst USERNAME = /^[A-Za-z0-9._-]{1,64}$/;\n\nconst invalid = (message: string) => new HarnessError(\"invalid_egress_options\", message);\n\n/** Whether `name` is a ref name git itself would accept, by `git check-ref-format`'s rules, under `refs/`. */\nexport function isValidRefName(name: string): boolean {\n if (!name.startsWith(\"refs/\") || name.length > 1024) return false;\n const control = [...name].some((char) => char.charCodeAt(0) <= 0x20 || char.charCodeAt(0) === 0x7f);\n if (control || /[~^:?*[\\\\]/.test(name) || name.includes(\"..\") || name.includes(\"@{\") || name.includes(\"//\")) {\n return false;\n }\n if (name.endsWith(\"/\") || name.endsWith(\".\")) return false;\n return name.split(\"/\").every((part) => part !== \"\" && !part.startsWith(\".\") && !part.endsWith(\".lock\"));\n}\n\n/** Throws unless `pattern` is a branch, or a branch prefix ending in `/*`, under `refs/heads/`. */\nfunction checkPattern(pattern: unknown, index: number): void {\n const text = typeof pattern === \"string\" ? pattern : \"\";\n const bare = text.endsWith(\"/*\") ? `${text.slice(0, -2)}/x` : text;\n if (!text.startsWith(\"refs/heads/\") || !isValidRefName(bare)) {\n throw invalid(`push ref ${index} must be a branch, or a branch prefix ending in /*, under refs/heads/`);\n }\n}\n\n/** Throws unless every field of a git route's filter is usable. The message names the field, never its value. */\nexport function checkGitFilter(filter: GitRouteFilter): void {\n const { repositories, pushRefs, fetch, username } = filter;\n if (!Array.isArray(repositories) || repositories.length === 0) {\n throw invalid(\"a git route needs at least one repository, as owner/name\");\n }\n repositories.forEach((repository: unknown, index) => {\n const parts = typeof repository === \"string\" ? repository.split(\"/\") : [];\n const usable = parts.length === 2 && parts.every((part) => SEGMENT.test(part) && !/^\\.+$/.test(part));\n if (!usable) throw invalid(`repository ${index} must be owner/name`);\n });\n if (!Array.isArray(pushRefs)) throw invalid(\"a git route's pushRefs must be a list\");\n pushRefs.forEach(checkPattern);\n if (typeof fetch !== \"boolean\") throw invalid(\"a git route's fetch must be true or false\");\n if (pushRefs.length === 0 && !fetch) throw invalid(\"a git route must allow a push, a fetch or both\");\n if (typeof username !== \"string\" || !USERNAME.test(username)) throw invalid(\"a git route's username is not usable\");\n}\n\n/** The repository `owner/name` in lower case, without a trailing `.git`. */\nconst repositoryKey = (owner: string, name: string): string => `${owner}/${name.replace(/\\.git$/i, \"\")}`.toLowerCase();\n\n/**\n * The git endpoint a request is for, or the reason it is refused. `path` is the part after the route's name, and\n * `query` is the search part with its `?`, or empty.\n */\nexport function gitEndpoint(\n filter: GitRouteFilter,\n method: string,\n path: string,\n query: string,\n): GitEndpoint | { readonly refused: string } {\n const match = REPOSITORY_PATH.exec(path);\n const [, owner = \"\", name = \"\", action = \"\"] = match ?? [];\n if (match === null || ![owner, name].every((part) => SEGMENT.test(part) && !/^\\.+$/.test(part))) {\n return { refused: \"git_path_refused\" };\n }\n const listed = filter.repositories.map((repository) => repositoryKey(...(repository.split(\"/\") as [string, string])));\n if (!listed.includes(repositoryKey(owner, name))) return { refused: \"git_repository_refused\" };\n const endpoint = endpointOf(action, method.toUpperCase(), query);\n if (endpoint === undefined) return { refused: \"git_path_refused\" };\n if (endpoint.service === \"git-receive-pack\" && filter.pushRefs.length === 0) return { refused: \"git_push_refused\" };\n if (endpoint.service === \"git-upload-pack\" && !filter.fetch) return { refused: \"git_fetch_refused\" };\n return endpoint;\n}\n\nfunction endpointOf(action: string, method: string, query: string): GitEndpoint | undefined {\n if (action === \"info/refs\") {\n if (method !== \"GET\") return undefined;\n if (query === \"?service=git-receive-pack\") return { service: \"git-receive-pack\", phase: \"advertise\" };\n if (query === \"?service=git-upload-pack\") return { service: \"git-upload-pack\", phase: \"advertise\" };\n return undefined;\n }\n if (method !== \"POST\" || query !== \"\") return undefined;\n return { service: action as GitEndpoint[\"service\"], phase: \"rpc\" };\n}\n\n/** One ref update in a push. */\ninterface PushCommand {\n readonly old: string;\n readonly new: string;\n readonly ref: string;\n}\n\nconst DECODER = new TextDecoder(\"utf-8\", { fatal: true });\nconst LENGTH = /^[0-9a-fA-F]{4}$/;\nconst BAD: { readonly refused: string } = { refused: \"git_bad_pkt_line\" };\nconst FLUSH_LENGTH = 4;\n\n/** The text of one pkt-line's payload without its line feed, or `undefined` when it isn't UTF-8. */\nfunction payloadText(bytes: Uint8Array): string | undefined {\n try {\n return DECODER.decode(bytes).replace(/\\n$/, \"\");\n } catch {\n return undefined;\n }\n}\n\n/** Reads one command line; the first carries the capabilities after a NUL, which are dropped. */\nfunction readCommand(text: string, commands: PushCommand[]): string | undefined {\n if (commands.length === 0 && SHALLOW.test(text)) return undefined;\n if (text.startsWith(\"push-cert\")) return \"git_push_cert\";\n const line = commands.length === 0 ? (text.split(\"\\0\")[0] ?? \"\") : text;\n if (commands.length > 0 && text.includes(\"\\0\")) return \"git_bad_pkt_line\";\n const match = COMMAND.exec(line);\n if (match === null || match[1]?.length !== match[2]?.length) return \"git_bad_pkt_line\";\n commands.push({ old: match[1] ?? \"\", new: match[2] ?? \"\", ref: match[3] ?? \"\" });\n return commands.length > GIT_MAX_COMMANDS ? \"git_too_many_commands\" : undefined;\n}\n\n/**\n * One pkt-line at `at` in `bytes`, which starts at body offset `offset`: a flush, a payload's text, how many bytes from\n * `at` it needs before it can be read, or a refusal. A line that would end past `GIT_MAX_COMMAND_BYTES` is refused from\n * its header, so the reader never holds much more than the limit.\n */\nfunction readPacket(\n bytes: Uint8Array,\n at: number,\n offset: number,\n):\n | { readonly needed: number }\n | { readonly refused: string }\n | \"flush\"\n | { readonly text: string; readonly length: number } {\n if (bytes.length - at < 4) return { needed: 4 };\n const header = String.fromCharCode(...bytes.subarray(at, at + 4));\n if (!LENGTH.test(header)) return BAD;\n const length = Number.parseInt(header, 16);\n if (length === 0) return \"flush\";\n if (length < 5 || length > PKT_MAX) return BAD;\n if (offset + at + length > GIT_MAX_COMMAND_BYTES) return { refused: \"git_too_large\" };\n if (bytes.length - at < length) return { needed: length };\n const text = payloadText(bytes.subarray(at + 4, at + length));\n return text === undefined ? BAD : { text, length };\n}\n\n/** The chunks joined into one array, or the one chunk itself. */\nfunction join(chunks: readonly Uint8Array[]): Uint8Array {\n if (chunks.length === 1) return chunks[0] as Uint8Array;\n const joined = new Uint8Array(chunks.reduce((total, chunk) => total + chunk.length, 0));\n let at = 0;\n for (const chunk of chunks) {\n joined.set(chunk, at);\n at += chunk.length;\n }\n return joined;\n}\n\n/** A push check's verdict so far: `incomplete` until the command list reaches its flush, or the route's verdict. */\nexport type PushCheckVerdict = \"incomplete\" | \"allowed\" | { readonly refused: string };\n\n/**\n * Reads the command list at the start of a push body as the body arrives, in pieces of any size, and gives the route's\n * verdict once it can. The work is linear in the bytes received: pieces are joined only once they hold the next\n * pkt-line's header or the whole line, and a line already read is never read again. A list whose lines end past\n * `GIT_MAX_COMMAND_BYTES` is refused as soon as a header says so, however the body is split.\n */\nexport class PushReader {\n readonly #filter: GitRouteFilter;\n #pending: Uint8Array[] = [];\n #pendingBytes = 0;\n /** The body offset of the first pending byte. Every byte before it belongs to a pkt-line already read. */\n #offset = 0;\n /** How many pending bytes the next pkt-line needs before it can be read. */\n #needed = 4;\n readonly #commands: PushCommand[] = [];\n /** Whether the body so far is exactly one flush, git's probe before a large push. */\n #probe = false;\n #verdict: \"allowed\" | { readonly refused: string } | undefined;\n\n constructor(filter: GitRouteFilter) {\n this.#filter = filter;\n }\n\n /** Reads the next piece of the body and returns the verdict so far. Bytes after a verdict are not read. */\n add(chunk: Uint8Array): PushCheckVerdict {\n if (this.#verdict !== undefined) return this.#verdict;\n if (chunk.length === 0) return \"incomplete\";\n // The probe is a body of one flush and nothing else, so any byte after it is refused.\n if (this.#probe) return this.#settle(BAD);\n this.#pending.push(chunk);\n this.#pendingBytes += chunk.length;\n return this.#pendingBytes < this.#needed ? \"incomplete\" : this.#read();\n }\n\n /** Says the body has ended and returns the final verdict: a list still incomplete is refused. */\n end(): \"allowed\" | { readonly refused: string } {\n return this.#verdict ?? this.#settle(this.#probe ? \"allowed\" : BAD);\n }\n\n #read(): PushCheckVerdict {\n const bytes = join(this.#pending);\n let at = 0;\n for (;;) {\n const packet = readPacket(bytes, at, this.#offset);\n if (packet === \"flush\") return this.#flush(bytes, at);\n if (\"refused\" in packet) return this.#settle(packet);\n if (\"needed\" in packet) {\n this.#pending = at < bytes.length ? [bytes.subarray(at)] : [];\n this.#pendingBytes = bytes.length - at;\n this.#offset += at;\n this.#needed = packet.needed;\n return \"incomplete\";\n }\n const refused = readCommand(packet.text, this.#commands);\n if (refused !== undefined) return this.#settle({ refused });\n at += packet.length;\n }\n }\n\n /** The verdict at a flush at `at`: the end of the command list, git's probe, or a flush with no command before it. */\n #flush(bytes: Uint8Array, at: number): PushCheckVerdict {\n if (this.#commands.length > 0) return this.#settle(commandsVerdict(this.#commands, this.#filter));\n if (this.#offset + at !== 0 || bytes.length > FLUSH_LENGTH) return this.#settle(BAD);\n this.#probe = true;\n this.#pending = [];\n this.#pendingBytes = 0;\n return \"incomplete\";\n }\n\n #settle(verdict: \"allowed\" | { readonly refused: string }): \"allowed\" | { readonly refused: string } {\n this.#verdict = verdict;\n this.#pending = [];\n this.#pendingBytes = 0;\n return verdict;\n }\n}\n\n/** Whether `ref` is matched by one of the patterns: exactly, or under a prefix that ends in `/*`. */\nfunction refAllowed(ref: string, patterns: readonly string[]): boolean {\n return patterns.some((pattern) =>\n pattern.endsWith(\"/*\") ? ref.startsWith(pattern.slice(0, -1)) && ref.length > pattern.length - 1 : ref === pattern,\n );\n}\n\n/** Whether every command creates or updates a ref the patterns allow, or why not. */\nfunction commandsVerdict(\n commands: readonly PushCommand[],\n filter: GitRouteFilter,\n): \"allowed\" | { readonly refused: string } {\n for (const command of commands) {\n if (ZERO.test(command.new)) return { refused: \"git_delete_refused\" };\n if (!isValidRefName(command.ref) || !refAllowed(command.ref, filter.pushRefs))\n return { refused: \"git_ref_refused\" };\n }\n return \"allowed\";\n}\n\n/**\n * The route's verdict on the start of a push body: `incomplete` while the command list hasn't reached its flush,\n * `allowed` once every command creates or updates a ref the patterns allow, or the reason it is refused. A body that is\n * exactly one flush packet, the probe git sends before a large push, is `allowed` once it has ended, because it updates\n * no ref; a byte after that flush is refused. `ended` says the body has no more bytes, so a list still incomplete is\n * refused. A list whose lines end past `GIT_MAX_COMMAND_BYTES` is refused, whether or not its flush has arrived.\n */\nexport function pushVerdict(\n bytes: Uint8Array,\n filter: GitRouteFilter,\n ended: boolean,\n): \"incomplete\" | \"allowed\" | { readonly refused: string } {\n const reader = new PushReader(filter);\n const verdict = reader.add(bytes);\n return verdict === \"incomplete\" && ended ? reader.end() : verdict;\n}\n\n/** Whether an `Authorization` header is HTTP Basic whose password is exactly `sentinel`. */\nexport function basicCarries(header: string | undefined, sentinel: string): boolean {\n const match = /^Basic ([A-Za-z0-9+/]+={0,2})$/i.exec(header ?? \"\");\n if (match === null || sentinel === \"\") return false;\n let decoded: string;\n try {\n decoded = atob(match[1] ?? \"\");\n } catch {\n return false;\n }\n const colon = decoded.indexOf(\":\");\n return colon >= 0 && decoded.slice(colon + 1) === sentinel;\n}\n\n/** The `Authorization` value that carries `secret` as the password of `username`. */\nexport function basicHeader(username: string, secret: string): string {\n const bytes = new TextEncoder().encode(`${username}:${secret}`);\n return `Basic ${btoa(String.fromCharCode(...bytes))}`;\n}\n"]}
|
|
@@ -2,8 +2,12 @@
|
|
|
2
2
|
* `@buildanagent/harness/credentials`: the credential boundary. `startEgressProxy()` is a host-side, default-deny
|
|
3
3
|
* egress proxy that logs each request, injects a host-scoped credential on a local route when the sentinel matches, and
|
|
4
4
|
* gates an in-process fetch under the same allowlist. `scrubSecrets()` removes known secrets from an entry before it is
|
|
5
|
-
* appended.
|
|
5
|
+
* appended. `compileEgressPolicy()` turns an `EgressPolicy`, which names credentials but never holds them, into the
|
|
6
|
+
* proxy's allowlist and routes, and a `git` route limits git over HTTPS to listed repositories and branches. The proxy
|
|
7
|
+
* is Node-only; the policy compiler, the git checks, the scrubber and the address check are portable.
|
|
6
8
|
*/
|
|
7
9
|
export { isAddressLiteral, isPublicAddress } from "./addresses.js";
|
|
10
|
+
export { type CompiledEgressPolicy, type CompileEgressOptions, compileEgressPolicy, type EgressPolicy, type EgressRoute, type GitEgressRoute, type HeaderEgressRoute, } from "./egress-policy.js";
|
|
8
11
|
export { type CredentialRoute, type EgressProxy, type EgressProxyOptions, type EgressRecord, startEgressProxy, } from "./egress-proxy.js";
|
|
12
|
+
export { GIT_MAX_COMMAND_BYTES, GIT_MAX_COMMANDS, type GitRouteFilter, isValidRefName, pushVerdict, } from "./git-route.js";
|
|
9
13
|
export { REDACTED, scrubSecrets } from "./scrub.js";
|
|
@@ -2,9 +2,13 @@
|
|
|
2
2
|
* `@buildanagent/harness/credentials`: the credential boundary. `startEgressProxy()` is a host-side, default-deny
|
|
3
3
|
* egress proxy that logs each request, injects a host-scoped credential on a local route when the sentinel matches, and
|
|
4
4
|
* gates an in-process fetch under the same allowlist. `scrubSecrets()` removes known secrets from an entry before it is
|
|
5
|
-
* appended.
|
|
5
|
+
* appended. `compileEgressPolicy()` turns an `EgressPolicy`, which names credentials but never holds them, into the
|
|
6
|
+
* proxy's allowlist and routes, and a `git` route limits git over HTTPS to listed repositories and branches. The proxy
|
|
7
|
+
* is Node-only; the policy compiler, the git checks, the scrubber and the address check are portable.
|
|
6
8
|
*/
|
|
7
9
|
export { isAddressLiteral, isPublicAddress } from "./addresses.js";
|
|
10
|
+
export { compileEgressPolicy, } from "./egress-policy.js";
|
|
8
11
|
export { startEgressProxy, } from "./egress-proxy.js";
|
|
12
|
+
export { GIT_MAX_COMMAND_BYTES, GIT_MAX_COMMANDS, isValidRefName, pushVerdict, } from "./git-route.js";
|
|
9
13
|
export { REDACTED, scrubSecrets } from "./scrub.js";
|
|
10
14
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/credentials/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/credentials/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACnE,OAAO,EAGL,mBAAmB,GAKpB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAKL,gBAAgB,GACjB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,qBAAqB,EACrB,gBAAgB,EAEhB,cAAc,EACd,WAAW,GACZ,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC","sourcesContent":["/**\n * `@buildanagent/harness/credentials`: the credential boundary. `startEgressProxy()` is a host-side, default-deny\n * egress proxy that logs each request, injects a host-scoped credential on a local route when the sentinel matches, and\n * gates an in-process fetch under the same allowlist. `scrubSecrets()` removes known secrets from an entry before it is\n * appended. `compileEgressPolicy()` turns an `EgressPolicy`, which names credentials but never holds them, into the\n * proxy's allowlist and routes, and a `git` route limits git over HTTPS to listed repositories and branches. The proxy\n * is Node-only; the policy compiler, the git checks, the scrubber and the address check are portable.\n */\nexport { isAddressLiteral, isPublicAddress } from \"./addresses.js\";\nexport {\n type CompiledEgressPolicy,\n type CompileEgressOptions,\n compileEgressPolicy,\n type EgressPolicy,\n type EgressRoute,\n type GitEgressRoute,\n type HeaderEgressRoute,\n} from \"./egress-policy.js\";\nexport {\n type CredentialRoute,\n type EgressProxy,\n type EgressProxyOptions,\n type EgressRecord,\n startEgressProxy,\n} from \"./egress-proxy.js\";\nexport {\n GIT_MAX_COMMAND_BYTES,\n GIT_MAX_COMMANDS,\n type GitRouteFilter,\n isValidRefName,\n pushVerdict,\n} from \"./git-route.js\";\nexport { REDACTED, scrubSecrets } from \"./scrub.js\";\n"]}
|
|
@@ -7,6 +7,13 @@
|
|
|
7
7
|
import type { SessionEntry } from "@buildanagent/protocol";
|
|
8
8
|
/** What replaces a secret. */
|
|
9
9
|
export declare const REDACTED = "[REDACTED]";
|
|
10
|
+
/** `text` with every form of each secret replaced, for a host-side tool that returns text it fetched. */
|
|
11
|
+
export declare function scrubString(text: string, secrets: readonly string[]): string;
|
|
12
|
+
/**
|
|
13
|
+
* `text`, the start of a longer text that was cut, with every form of each secret replaced and any start of one left at
|
|
14
|
+
* its end removed, so a secret that the cut split leaks none of its first characters.
|
|
15
|
+
*/
|
|
16
|
+
export declare function scrubCutString(text: string, secrets: readonly string[]): string;
|
|
10
17
|
/**
|
|
11
18
|
* Returns a copy of `entry` with every secret replaced by `[REDACTED]`, in every string value and every key, at any depth.
|
|
12
19
|
* A secret is also removed when it appears percent-encoded, JSON-escaped or in base64. The entry's `type`, `id`,
|
|
@@ -59,6 +59,28 @@ function scrubText(text, patterns) {
|
|
|
59
59
|
}
|
|
60
60
|
return result;
|
|
61
61
|
}
|
|
62
|
+
/** `text` with every form of each secret replaced, for a host-side tool that returns text it fetched. */
|
|
63
|
+
export function scrubString(text, secrets) {
|
|
64
|
+
return scrubText(text, forms(secrets));
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* `text`, the start of a longer text that was cut, with every form of each secret replaced and any start of one left at
|
|
68
|
+
* its end removed, so a secret that the cut split leaks none of its first characters.
|
|
69
|
+
*/
|
|
70
|
+
export function scrubCutString(text, secrets) {
|
|
71
|
+
const patterns = forms(secrets);
|
|
72
|
+
const scrubbed = scrubText(text, patterns);
|
|
73
|
+
let keep = scrubbed.length;
|
|
74
|
+
for (const pattern of patterns) {
|
|
75
|
+
for (let size = Math.min(pattern.length - 1, scrubbed.length); size > 0; size -= 1) {
|
|
76
|
+
if (scrubbed.endsWith(pattern.slice(0, size))) {
|
|
77
|
+
keep = Math.min(keep, scrubbed.length - size);
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return scrubbed.slice(0, keep);
|
|
83
|
+
}
|
|
62
84
|
function scrubValue(value, patterns) {
|
|
63
85
|
if (typeof value === "string")
|
|
64
86
|
return scrubText(value, patterns);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scrub.js","sourceRoot":"","sources":["../../src/credentials/scrub.ts"],"names":[],"mappings":"AAQA,8BAA8B;AAC9B,MAAM,CAAC,MAAM,QAAQ,GAAG,YAAY,CAAC;AAErC,wHAAwH;AACxH,0DAA0D;AAC1D,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC,CAAC,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,eAAe,CAAC,CAAC,CAAC;AAEtG,oEAAoE;AACpE,SAAS,QAAQ,CAAC,KAAiB;IACjC,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,KAAK,MAAM,IAAI,IAAI,KAAK;QAAE,MAAM,IAAI,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;IAC9D,MAAM,QAAQ,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IACjD,OAAO,CAAC,QAAQ,EAAE,QAAQ,CAAC,UAAU,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,UAAU,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;AACxE,CAAC;AAED,yGAAyG;AACzG,MAAM,gBAAgB,GAAG,CAAC,CAAC;AAE3B;;;;GAIG;AACH,SAAS,WAAW,CAAC,IAAY;IAC/B,MAAM,MAAM,GAAG,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAC9C,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC;IACxC,KAAK,IAAI,MAAM,GAAG,CAAC,EAAE,MAAM,GAAG,CAAC,EAAE,MAAM,IAAI,CAAC,EAAE,CAAC;QAC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AO,CAAC,CAAC;IAChC,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,GAAG,KAAK,EAAE,CAAC;IAC/C,MAAM,GAAG,GAA4B,EAAE,CAAC;IACxC,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACjD,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,SAAS,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC,GAAG,UAAU,CAAC,GAAG,CAAC,GAAG,CAAC;YAC7E,CAAC,CAAC,KAAK;YACP,CAAC,CAAC,UAAU,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;IAClC,CAAC;IACD,OAAO,GAAQ,CAAC;AAClB,CAAC","sourcesContent":["/**\n * `scrubSecrets()`: removes known secrets from a session entry before it is appended, so a credential that reached a\n * tool result, a model message or an error never reaches the log. It is the net under the credential boundary, not the\n * boundary itself: the boundary keeps the secret out of the sandbox, and this catches what a host-side tool wrote\n * anyway. It is pure and portable.\n */\nimport type { SessionEntry } from \"@buildanagent/protocol\";\n\n/** What replaces a secret. */\nexport const REDACTED = \"[REDACTED]\";\n\n// Fields that give an entry its shape and place in the log. A secret is never one of them, and changing one would break\n// the log, so they are left alone at the top of an entry.\nconst STRUCTURAL = new Set([\"type\", \"id\", \"parentId\", \"seq\", \"timestamp\", \"origin\", \"formatVersion\"]);\n\n/** The standard and URL-safe base64 of `bytes`, without padding. */\nfunction base64Of(bytes: Uint8Array): string[] {\n let binary = \"\";\n for (const byte of bytes) binary += String.fromCharCode(byte);\n const standard = btoa(binary).replace(/=+$/, \"\");\n return [standard, standard.replaceAll(\"+\", \"-\").replaceAll(\"/\", \"_\")];\n}\n\n// The fewest base64 characters worth looking for, so a short secret's pieces don't redact ordinary text.\nconst MIN_BASE64_PIECE = 8;\n\n/**\n * The base64 forms of a secret: alone, and as part of longer text. Base64 packs three bytes into four characters, so a\n * secret that follows a prefix such as `user:` encodes differently by its offset in the group. The encodings at all three\n * offsets are kept, trimmed to the groups the secret fills, because the groups at its edges depend on its neighbours.\n */\nfunction base64Forms(text: string): string[] {\n const secret = new TextEncoder().encode(text);\n const found = new Set(base64Of(secret));\n for (let offset = 0; offset < 3; offset += 1) {\n const shifted = new Uint8Array(offset + secret.length);\n shifted.set(secret, offset);\n const groups = Math.floor(shifted.length / 3);\n for (const form of base64Of(shifted)) {\n const piece = form.slice(offset === 0 ? 0 : 4, groups * 4);\n if (piece.length >= MIN_BASE64_PIECE) found.add(piece);\n }\n }\n return [...found];\n}\n\n/**\n * The forms a secret takes when something copies it: as written, percent-encoded, escaped inside JSON, and base64 (which\n * is how a Basic authorization header carries one). Longest first, so a secret that contains another is removed whole.\n */\nfunction forms(secrets: readonly string[]): string[] {\n const found = new Set<string>();\n for (const secret of secrets) {\n if (secret === \"\") continue;\n found.add(secret);\n found.add(encodeURIComponent(secret));\n found.add(JSON.stringify(secret).slice(1, -1));\n for (const form of base64Forms(secret)) found.add(form);\n }\n found.delete(\"\");\n return [...found].sort((a, b) => b.length - a.length);\n}\n\nfunction scrubText(text: string, patterns: readonly string[]): string {\n let result = text;\n for (const pattern of patterns) {\n if (result.includes(pattern)) result = result.replaceAll(pattern, REDACTED);\n }\n return result;\n}\n\nfunction scrubValue(value: unknown, patterns: readonly string[]): unknown {\n if (typeof value === \"string\") return scrubText(value, patterns);\n if (Array.isArray(value)) return value.map((item) => scrubValue(item, patterns));\n if (value !== null && typeof value === \"object\") {\n const out: Record<string, unknown> = {};\n for (const [key, inner] of Object.entries(value)) out[scrubText(key, patterns)] = scrubValue(inner, patterns);\n return out;\n }\n return value;\n}\n\n/**\n * Returns a copy of `entry` with every secret replaced by `[REDACTED]`, in every string value and every key, at any depth.\n * A secret is also removed when it appears percent-encoded, JSON-escaped or in base64. The entry's `type`, `id`,\n * `parentId`, `seq`, `timestamp`, `origin` and `formatVersion` are kept as they are. An empty secret is ignored, and a short one redacts\n * every place it occurs, so pass real credentials. The input is not changed.\n */\nexport function scrubSecrets<T extends SessionEntry>(entry: T, secrets: readonly string[]): T {\n const patterns = forms(secrets);\n if (patterns.length === 0) return { ...entry };\n const out: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(entry)) {\n out[STRUCTURAL.has(key) ? key : scrubText(key, patterns)] = STRUCTURAL.has(key)\n ? value\n : scrubValue(value, patterns);\n }\n return out as T;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"scrub.js","sourceRoot":"","sources":["../../src/credentials/scrub.ts"],"names":[],"mappings":"AAQA,8BAA8B;AAC9B,MAAM,CAAC,MAAM,QAAQ,GAAG,YAAY,CAAC;AAErC,wHAAwH;AACxH,0DAA0D;AAC1D,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC,CAAC,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,eAAe,CAAC,CAAC,CAAC;AAEtG,oEAAoE;AACpE,SAAS,QAAQ,CAAC,KAAiB;IACjC,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,KAAK,MAAM,IAAI,IAAI,KAAK;QAAE,MAAM,IAAI,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;IAC9D,MAAM,QAAQ,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IACjD,OAAO,CAAC,QAAQ,EAAE,QAAQ,CAAC,UAAU,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,UAAU,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;AACxE,CAAC;AAED,yGAAyG;AACzG,MAAM,gBAAgB,GAAG,CAAC,CAAC;AAE3B;;;;GAIG;AACH,SAAS,WAAW,CAAC,IAAY;IAC/B,MAAM,MAAM,GAAG,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,IAA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AC;IAC/C,MAAM,GAAG,GAA4B,EAAE,CAAC;IACxC,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACjD,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,SAAS,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC,GAAG,UAAU,CAAC,GAAG,CAAC,GAAG,CAAC;YAC7E,CAAC,CAAC,KAAK;YACP,CAAC,CAAC,UAAU,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;IAClC,CAAC;IACD,OAAO,GAAQ,CAAC;AAClB,CAAC","sourcesContent":["/**\n * `scrubSecrets()`: removes known secrets from a session entry before it is appended, so a credential that reached a\n * tool result, a model message or an error never reaches the log. It is the net under the credential boundary, not the\n * boundary itself: the boundary keeps the secret out of the sandbox, and this catches what a host-side tool wrote\n * anyway. It is pure and portable.\n */\nimport type { SessionEntry } from \"@buildanagent/protocol\";\n\n/** What replaces a secret. */\nexport const REDACTED = \"[REDACTED]\";\n\n// Fields that give an entry its shape and place in the log. A secret is never one of them, and changing one would break\n// the log, so they are left alone at the top of an entry.\nconst STRUCTURAL = new Set([\"type\", \"id\", \"parentId\", \"seq\", \"timestamp\", \"origin\", \"formatVersion\"]);\n\n/** The standard and URL-safe base64 of `bytes`, without padding. */\nfunction base64Of(bytes: Uint8Array): string[] {\n let binary = \"\";\n for (const byte of bytes) binary += String.fromCharCode(byte);\n const standard = btoa(binary).replace(/=+$/, \"\");\n return [standard, standard.replaceAll(\"+\", \"-\").replaceAll(\"/\", \"_\")];\n}\n\n// The fewest base64 characters worth looking for, so a short secret's pieces don't redact ordinary text.\nconst MIN_BASE64_PIECE = 8;\n\n/**\n * The base64 forms of a secret: alone, and as part of longer text. Base64 packs three bytes into four characters, so a\n * secret that follows a prefix such as `user:` encodes differently by its offset in the group. The encodings at all three\n * offsets are kept, trimmed to the groups the secret fills, because the groups at its edges depend on its neighbours.\n */\nfunction base64Forms(text: string): string[] {\n const secret = new TextEncoder().encode(text);\n const found = new Set(base64Of(secret));\n for (let offset = 0; offset < 3; offset += 1) {\n const shifted = new Uint8Array(offset + secret.length);\n shifted.set(secret, offset);\n const groups = Math.floor(shifted.length / 3);\n for (const form of base64Of(shifted)) {\n const piece = form.slice(offset === 0 ? 0 : 4, groups * 4);\n if (piece.length >= MIN_BASE64_PIECE) found.add(piece);\n }\n }\n return [...found];\n}\n\n/**\n * The forms a secret takes when something copies it: as written, percent-encoded, escaped inside JSON, and base64 (which\n * is how a Basic authorization header carries one). Longest first, so a secret that contains another is removed whole.\n */\nfunction forms(secrets: readonly string[]): string[] {\n const found = new Set<string>();\n for (const secret of secrets) {\n if (secret === \"\") continue;\n found.add(secret);\n found.add(encodeURIComponent(secret));\n found.add(JSON.stringify(secret).slice(1, -1));\n for (const form of base64Forms(secret)) found.add(form);\n }\n found.delete(\"\");\n return [...found].sort((a, b) => b.length - a.length);\n}\n\nfunction scrubText(text: string, patterns: readonly string[]): string {\n let result = text;\n for (const pattern of patterns) {\n if (result.includes(pattern)) result = result.replaceAll(pattern, REDACTED);\n }\n return result;\n}\n\n/** `text` with every form of each secret replaced, for a host-side tool that returns text it fetched. */\nexport function scrubString(text: string, secrets: readonly string[]): string {\n return scrubText(text, forms(secrets));\n}\n\n/**\n * `text`, the start of a longer text that was cut, with every form of each secret replaced and any start of one left at\n * its end removed, so a secret that the cut split leaks none of its first characters.\n */\nexport function scrubCutString(text: string, secrets: readonly string[]): string {\n const patterns = forms(secrets);\n const scrubbed = scrubText(text, patterns);\n let keep = scrubbed.length;\n for (const pattern of patterns) {\n for (let size = Math.min(pattern.length - 1, scrubbed.length); size > 0; size -= 1) {\n if (scrubbed.endsWith(pattern.slice(0, size))) {\n keep = Math.min(keep, scrubbed.length - size);\n break;\n }\n }\n }\n return scrubbed.slice(0, keep);\n}\n\nfunction scrubValue(value: unknown, patterns: readonly string[]): unknown {\n if (typeof value === \"string\") return scrubText(value, patterns);\n if (Array.isArray(value)) return value.map((item) => scrubValue(item, patterns));\n if (value !== null && typeof value === \"object\") {\n const out: Record<string, unknown> = {};\n for (const [key, inner] of Object.entries(value)) out[scrubText(key, patterns)] = scrubValue(inner, patterns);\n return out;\n }\n return value;\n}\n\n/**\n * Returns a copy of `entry` with every secret replaced by `[REDACTED]`, in every string value and every key, at any depth.\n * A secret is also removed when it appears percent-encoded, JSON-escaped or in base64. The entry's `type`, `id`,\n * `parentId`, `seq`, `timestamp`, `origin` and `formatVersion` are kept as they are. An empty secret is ignored, and a short one redacts\n * every place it occurs, so pass real credentials. The input is not changed.\n */\nexport function scrubSecrets<T extends SessionEntry>(entry: T, secrets: readonly string[]): T {\n const patterns = forms(secrets);\n if (patterns.length === 0) return { ...entry };\n const out: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(entry)) {\n out[STRUCTURAL.has(key) ? key : scrubText(key, patterns)] = STRUCTURAL.has(key)\n ? value\n : scrubValue(value, patterns);\n }\n return out as T;\n}\n"]}
|
package/dist/errors.d.ts
CHANGED
|
@@ -1,20 +1,24 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* `HarnessError`: the harness's error for programmer errors and for a sandbox that can't do what it was asked.
|
|
3
|
-
* subclasses keep their own names for the cases callers catch by class: `SandboxUnavailableError
|
|
4
|
-
* `SandboxDeniedError`,
|
|
2
|
+
* `HarnessError`: the harness's error for programmer errors and for a sandbox that can't do what it was asked. Four
|
|
3
|
+
* subclasses keep their own names for the cases callers catch by class: `SandboxUnavailableError`,
|
|
4
|
+
* `SandboxDeniedError`, `SandboxPolicyMismatchError` and `SandboxUnsupportedError`, all in `./sandbox`.
|
|
5
5
|
*/
|
|
6
6
|
/** Why a `HarnessError` was thrown. */
|
|
7
|
-
export type HarnessErrorCode = "sandbox_unavailable" | "sandbox_denied" | "sandbox_disposed" | "sandbox_not_found" | "sandbox_io_failed" | "egress_denied" | "invalid_egress_options" | "unsafe_sandbox_not_acknowledged" | "invalid_sandbox_options" | "invalid_spawn_env" | "duplicate_tool" | "invalid_tool_registration" | "invalid_permission_config" | "invalid_lock_options" | "session_locked" | "session_read_only" | "entry_not_found" | "unsupported_format" | "invalid_turn_options" | "invalid_context_options" | "invalid_dispatcher_options" | "invalid_transport_options" | "spill_unavailable" | "invalid_extension" | "extension_hash_mismatch" | "approval_not_pending" | "approval_unavailable" | "sticky_refused" | "approval_reuse_refused" | "approver_is_requester" | "approval_refused" | "invalid_code_call" | "invalid_key_store" | "key_store_read_only" | "session_conflict" | "entry_too_large" | "invalid_session_entry" | "invalid_session_key" | "invalid_retention" | "session_corrupt" | "invalid_completion_config" | "invalid_mcp_config" | "mcp_connect_failed" | "mcp_tool_list_refused" | "mcp_call_failed";
|
|
7
|
+
export type HarnessErrorCode = "sandbox_unavailable" | "sandbox_denied" | "sandbox_disposed" | "sandbox_not_found" | "sandbox_io_failed" | "sandbox_policy_mismatch" | "sandbox_unsupported" | "egress_denied" | "invalid_egress_options" | "unsafe_sandbox_not_acknowledged" | "invalid_sandbox_options" | "invalid_spawn_env" | "duplicate_tool" | "invalid_tool_registration" | "invalid_tool_options" | "invalid_permission_config" | "invalid_lock_options" | "session_locked" | "session_read_only" | "entry_not_found" | "unsupported_format" | "invalid_turn_options" | "invalid_context_options" | "invalid_dispatcher_options" | "invalid_transport_options" | "spill_unavailable" | "invalid_extension" | "extension_hash_mismatch" | "approval_not_pending" | "approval_unavailable" | "sticky_refused" | "approval_reuse_refused" | "approver_is_requester" | "approval_refused" | "invalid_code_call" | "invalid_key_store" | "key_store_read_only" | "session_conflict" | "entry_too_large" | "invalid_session_entry" | "invalid_session_key" | "invalid_retention" | "session_corrupt" | "invalid_completion_config" | "invalid_mcp_config" | "mcp_connect_failed" | "mcp_tool_list_refused" | "mcp_call_failed";
|
|
8
8
|
/**
|
|
9
9
|
* Thrown for a mistake in how the harness is called, and for a sandbox that is unavailable or refuses a file operation.
|
|
10
10
|
* `sandbox_unavailable`: a backend can't start (`SandboxUnavailableError`). `sandbox_denied`: the policy refused a file
|
|
11
11
|
* read or write (`SandboxDeniedError`). `sandbox_disposed`: the sandbox was disposed before the call.
|
|
12
12
|
* `sandbox_not_found`: a file to read doesn't exist. `sandbox_io_failed`: a file call failed for a reason that is
|
|
13
|
-
* neither a missing file nor a denial. `
|
|
13
|
+
* neither a missing file nor a denial. `sandbox_policy_mismatch`: the policy a backend read back after it provisioned or
|
|
14
|
+
* resumed a sandbox differs from the one requested (`SandboxPolicyMismatchError`). `sandbox_unsupported`: a sandbox was
|
|
15
|
+
* asked to resume, snapshot or pause on a backend that lacks the capability (`SandboxUnsupportedError`).
|
|
16
|
+
* `unsafe_sandbox_not_acknowledged`: `noneSandbox()` was called without `unsafe:
|
|
14
17
|
* true`. `invalid_sandbox_options`: a sandbox option, manifest or command is unusable. `invalid_spawn_env`:
|
|
15
18
|
* `spawnEnv()` was given a name or value that can't be part of a clean environment. `duplicate_tool`: a tool registry
|
|
16
19
|
* already holds a tool or alias by that name (`DuplicateToolError`). `invalid_tool_registration`: a tool registration
|
|
17
20
|
* or a registry option is unusable, such as a name that breaks the canonical rule or an unknown source.
|
|
21
|
+
* `invalid_tool_options`: the built-in tools were given a workspace root or a policy root that is not an absolute path.
|
|
18
22
|
* `invalid_permission_config`: an allow rule makes the host callback unreachable (`PermissionConfigError`).
|
|
19
23
|
* `invalid_lock_options`: a file lock was given a lease, renewal interval or host name it can't use. `session_locked`:
|
|
20
24
|
* another writer holds the session. `session_read_only`: a session opened without a lock was asked to write.
|
package/dist/errors.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* `HarnessError`: the harness's error for programmer errors and for a sandbox that can't do what it was asked.
|
|
3
|
-
* subclasses keep their own names for the cases callers catch by class: `SandboxUnavailableError
|
|
4
|
-
* `SandboxDeniedError`,
|
|
2
|
+
* `HarnessError`: the harness's error for programmer errors and for a sandbox that can't do what it was asked. Four
|
|
3
|
+
* subclasses keep their own names for the cases callers catch by class: `SandboxUnavailableError`,
|
|
4
|
+
* `SandboxDeniedError`, `SandboxPolicyMismatchError` and `SandboxUnsupportedError`, all in `./sandbox`.
|
|
5
5
|
*/
|
|
6
6
|
// A registered symbol, so the guard still works when two copies of the package are bundled.
|
|
7
7
|
const HARNESS_ERROR = Symbol.for("buildanagent.harness.HarnessError");
|
|
@@ -10,11 +10,15 @@ const HARNESS_ERROR = Symbol.for("buildanagent.harness.HarnessError");
|
|
|
10
10
|
* `sandbox_unavailable`: a backend can't start (`SandboxUnavailableError`). `sandbox_denied`: the policy refused a file
|
|
11
11
|
* read or write (`SandboxDeniedError`). `sandbox_disposed`: the sandbox was disposed before the call.
|
|
12
12
|
* `sandbox_not_found`: a file to read doesn't exist. `sandbox_io_failed`: a file call failed for a reason that is
|
|
13
|
-
* neither a missing file nor a denial. `
|
|
13
|
+
* neither a missing file nor a denial. `sandbox_policy_mismatch`: the policy a backend read back after it provisioned or
|
|
14
|
+
* resumed a sandbox differs from the one requested (`SandboxPolicyMismatchError`). `sandbox_unsupported`: a sandbox was
|
|
15
|
+
* asked to resume, snapshot or pause on a backend that lacks the capability (`SandboxUnsupportedError`).
|
|
16
|
+
* `unsafe_sandbox_not_acknowledged`: `noneSandbox()` was called without `unsafe:
|
|
14
17
|
* true`. `invalid_sandbox_options`: a sandbox option, manifest or command is unusable. `invalid_spawn_env`:
|
|
15
18
|
* `spawnEnv()` was given a name or value that can't be part of a clean environment. `duplicate_tool`: a tool registry
|
|
16
19
|
* already holds a tool or alias by that name (`DuplicateToolError`). `invalid_tool_registration`: a tool registration
|
|
17
20
|
* or a registry option is unusable, such as a name that breaks the canonical rule or an unknown source.
|
|
21
|
+
* `invalid_tool_options`: the built-in tools were given a workspace root or a policy root that is not an absolute path.
|
|
18
22
|
* `invalid_permission_config`: an allow rule makes the host callback unreachable (`PermissionConfigError`).
|
|
19
23
|
* `invalid_lock_options`: a file lock was given a lease, renewal interval or host name it can't use. `session_locked`:
|
|
20
24
|
* another writer holds the session. `session_read_only`: a session opened without a lock was asked to write.
|
package/dist/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;GAIG;
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAqDH,4FAA4F;AAC5F,MAAM,aAAa,GAAG,MAAM,CAAC,GAAG,CAAC,mCAAmC,CAAC,CAAC;AAEtE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AACH,MAAM,OAAO,YAAa,SAAQ,KAAK;IACnB,IAAI,GAAW,cAAc,CAAC;IACvC,IAAI,CAAmB;IAEhC,YAAY,IAAsB,EAAE,OAAe,EAAE,OAAsB;QACzE,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACxB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,aAAa,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IAC9D,CAAC;CACF;AAED,iFAAiF;AACjF,MAAM,UAAU,cAAc,CAAC,KAAc;IAC3C,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAK,KAAiC,CAAC,aAAa,CAAC,KAAK,IAAI,CAAC;AACnH,CAAC","sourcesContent":["/**\n * `HarnessError`: the harness's error for programmer errors and for a sandbox that can't do what it was asked. Four\n * subclasses keep their own names for the cases callers catch by class: `SandboxUnavailableError`,\n * `SandboxDeniedError`, `SandboxPolicyMismatchError` and `SandboxUnsupportedError`, all in `./sandbox`.\n */\n\n/** Why a `HarnessError` was thrown. */\nexport type HarnessErrorCode =\n | \"sandbox_unavailable\"\n | \"sandbox_denied\"\n | \"sandbox_disposed\"\n | \"sandbox_not_found\"\n | \"sandbox_io_failed\"\n | \"sandbox_policy_mismatch\"\n | \"sandbox_unsupported\"\n | \"egress_denied\"\n | \"invalid_egress_options\"\n | \"unsafe_sandbox_not_acknowledged\"\n | \"invalid_sandbox_options\"\n | \"invalid_spawn_env\"\n | \"duplicate_tool\"\n | \"invalid_tool_registration\"\n | \"invalid_tool_options\"\n | \"invalid_permission_config\"\n | \"invalid_lock_options\"\n | \"session_locked\"\n | \"session_read_only\"\n | \"entry_not_found\"\n | \"unsupported_format\"\n | \"invalid_turn_options\"\n | \"invalid_context_options\"\n | \"invalid_dispatcher_options\"\n | \"invalid_transport_options\"\n | \"spill_unavailable\"\n | \"invalid_extension\"\n | \"extension_hash_mismatch\"\n | \"approval_not_pending\"\n | \"approval_unavailable\"\n | \"sticky_refused\"\n | \"approval_reuse_refused\"\n | \"approver_is_requester\"\n | \"approval_refused\"\n | \"invalid_code_call\"\n | \"invalid_key_store\"\n | \"key_store_read_only\"\n | \"session_conflict\"\n | \"entry_too_large\"\n | \"invalid_session_entry\"\n | \"invalid_session_key\"\n | \"invalid_retention\"\n | \"session_corrupt\"\n | \"invalid_completion_config\"\n | \"invalid_mcp_config\"\n | \"mcp_connect_failed\"\n | \"mcp_tool_list_refused\"\n | \"mcp_call_failed\";\n\n// A registered symbol, so the guard still works when two copies of the package are bundled.\nconst HARNESS_ERROR = Symbol.for(\"buildanagent.harness.HarnessError\");\n\n/**\n * Thrown for a mistake in how the harness is called, and for a sandbox that is unavailable or refuses a file operation.\n * `sandbox_unavailable`: a backend can't start (`SandboxUnavailableError`). `sandbox_denied`: the policy refused a file\n * read or write (`SandboxDeniedError`). `sandbox_disposed`: the sandbox was disposed before the call.\n * `sandbox_not_found`: a file to read doesn't exist. `sandbox_io_failed`: a file call failed for a reason that is\n * neither a missing file nor a denial. `sandbox_policy_mismatch`: the policy a backend read back after it provisioned or\n * resumed a sandbox differs from the one requested (`SandboxPolicyMismatchError`). `sandbox_unsupported`: a sandbox was\n * asked to resume, snapshot or pause on a backend that lacks the capability (`SandboxUnsupportedError`).\n * `unsafe_sandbox_not_acknowledged`: `noneSandbox()` was called without `unsafe:\n * true`. `invalid_sandbox_options`: a sandbox option, manifest or command is unusable. `invalid_spawn_env`:\n * `spawnEnv()` was given a name or value that can't be part of a clean environment. `duplicate_tool`: a tool registry\n * already holds a tool or alias by that name (`DuplicateToolError`). `invalid_tool_registration`: a tool registration\n * or a registry option is unusable, such as a name that breaks the canonical rule or an unknown source.\n * `invalid_tool_options`: the built-in tools were given a workspace root or a policy root that is not an absolute path.\n * `invalid_permission_config`: an allow rule makes the host callback unreachable (`PermissionConfigError`).\n * `invalid_lock_options`: a file lock was given a lease, renewal interval or host name it can't use. `session_locked`:\n * another writer holds the session. `session_read_only`: a session opened without a lock was asked to write.\n * `entry_not_found`: an entry id is in no file of the session. `unsupported_format`: a session file's format can't be\n * read or migrated, its header names none, or the store can't read it as written. `invalid_turn_options`: a turn's\n * options can't be used, such as a tool allowlist that names a tool the registry lacks, or a hook that changed the\n * model inside a turn.\n * `invalid_context_options`: a context policy's setting can't be used, such as a write cap with no spill store or a mask\n * step of zero. `invalid_dispatcher_options`: a dispatcher's setting can't be used, such as a queue size of zero.\n * `invalid_transport_options`: a transport's setting can't be used, such as a write timeout of zero.\n * `spill_unavailable`: a spill store can't write, such as the file store on a runtime without Node's file\n * system. `invalid_extension`: an extension has no name or version, two share a name, or a project extension's module does not export one. `extension_hash_mismatch`: a project extension's files hash differently from the lock file, or the lock file does not list it. `approval_not_pending`: a resolution names a request that is not waiting.\n * `approval_unavailable`: the harness has no signer, so no approval can be checked. `sticky_refused`: a sticky\n * allowance would cover an interpreter prefix or a secret. `approval_reuse_refused`: the tool's `approvalReuse` forbids\n * a sticky or grouped answer. `approver_is_requester`: the approver is the one who asked. `approval_refused`: a code\n * call's signed request failed its check when it was resolved, so nothing ran and nothing was written.\n * `invalid_code_call`: `Harness.invokeTool()` or a code call's resolution was given something it can't run, such as a\n * tool the registry lacks or a compensation that names no call that ran. `invalid_key_store`: a key\n * file or key secret is unreadable or malformed, or a key file is readable by others. `key_store_read_only`: a key store\n * with no `rotate()` or `prune()` was asked to rotate or prune. `session_conflict`: an append found the log in a state it did\n * not expect (`ConflictError`). `entry_too_large`: an entry is over the store's size bound (`EntryTooLargeError`).\n * `invalid_session_entry`: an entry is not valid or is out of place, such as a first entry that is not a header.\n * `invalid_session_key`: a user or session id the store can't use. `invalid_retention`: a retention period that is not a\n * positive number, or an action other than `archive` and `purge`. `session_corrupt`: a log file has a bad line before\n * its last line. `invalid_completion_config`: `.agents/harness.json` is not JSON, or its `completionChecks` is not a list\n * of commands. `invalid_mcp_config`: an MCP server's configuration can't be used, such as a name outside the allowed\n * characters or two servers with one name. `mcp_connect_failed`: an MCP server did not start, did not finish the\n * handshake in time, or closed before it did (`McpError`). `mcp_tool_list_refused`: an MCP server listed tools the\n * harness refuses, such as two with one name, so none of its tools was registered (`McpError`). `mcp_call_failed`: an\n * MCP tool call ended without a result, because the server closed, timed out, asked for input or answered with an\n * error (`McpError`).\n */\nexport class HarnessError extends Error {\n override readonly name: string = \"HarnessError\";\n readonly code: HarnessErrorCode;\n\n constructor(code: HarnessErrorCode, message: string, options?: ErrorOptions) {\n super(message, options);\n this.code = code;\n Object.defineProperty(this, HARNESS_ERROR, { value: true });\n }\n}\n\n/** True for a `HarnessError`, including one from another copy of the package. */\nexport function isHarnessError(error: unknown): error is HarnessError {\n return typeof error === \"object\" && error !== null && (error as Record<symbol, unknown>)[HARNESS_ERROR] === true;\n}\n"]}
|
package/dist/sandbox/base.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type HostFiles } from "./host-files.js";
|
|
2
|
+
import { APPLY_STOPS } from "./policy.js";
|
|
2
3
|
import { type NodeModules } from "./process.js";
|
|
3
|
-
import type { ExecOptions, ExecResult, Sandbox } from "./types.js";
|
|
4
|
+
import type { ExecOptions, ExecResult, Sandbox, SandboxClient, SandboxPolicy, SandboxStop } from "./types.js";
|
|
4
5
|
/** The state a backend's sandbox is built on. */
|
|
5
6
|
export interface BackendBase {
|
|
6
7
|
readonly modules: NodeModules;
|
|
@@ -12,6 +13,7 @@ export interface BackendBase {
|
|
|
12
13
|
export declare abstract class BackendSandbox implements Sandbox {
|
|
13
14
|
private disposed;
|
|
14
15
|
private disposing;
|
|
16
|
+
private applied;
|
|
15
17
|
private readonly base;
|
|
16
18
|
protected constructor(base: BackendBase);
|
|
17
19
|
/** Throws `sandbox_disposed` once `dispose()` has been called. */
|
|
@@ -26,6 +28,14 @@ export declare abstract class BackendSandbox implements Sandbox {
|
|
|
26
28
|
readonly cwd: string;
|
|
27
29
|
} | ExecResult>;
|
|
28
30
|
abstract exec(command: readonly string[], options: ExecOptions): Promise<ExecResult>;
|
|
31
|
+
/** Reads back the policy this sandbox applies, from what the backend wrote or will pass to each command. */
|
|
32
|
+
abstract readBack(): Promise<SandboxPolicy>;
|
|
33
|
+
/** The stops the applied policy delivers, set by `confirm()` when the sandbox is provisioned. */
|
|
34
|
+
get stops(): readonly SandboxStop[];
|
|
35
|
+
/** Reads the policy back and checks it against `requested`, or disposes the sandbox and throws on a difference. */
|
|
36
|
+
confirm(client: SandboxClient, requested: SandboxPolicy): Promise<void>;
|
|
37
|
+
/** Sets the stops a resumed sandbox's confirmed policy delivers, for `resumeSandbox()`. */
|
|
38
|
+
[APPLY_STOPS](stops: readonly SandboxStop[]): void;
|
|
29
39
|
readFile(path: string): Promise<Uint8Array>;
|
|
30
40
|
writeFile(path: string, data: Uint8Array): Promise<void>;
|
|
31
41
|
/** Stops what is running and cleans up. Every call gets the first call's promise, so a second caller waits too. */
|
package/dist/sandbox/base.js
CHANGED
|
@@ -4,11 +4,13 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { HarnessError } from "../errors.js";
|
|
6
6
|
import { workingDirectory } from "./host-files.js";
|
|
7
|
+
import { APPLY_STOPS, confirmPolicy } from "./policy.js";
|
|
7
8
|
import { checkCommand, checkOptions } from "./process.js";
|
|
8
9
|
/** A sandbox that checks a command the same way, reads and writes files in the host, and disposes once. */
|
|
9
10
|
export class BackendSandbox {
|
|
10
11
|
disposed = false;
|
|
11
12
|
disposing;
|
|
13
|
+
applied = [];
|
|
12
14
|
base;
|
|
13
15
|
constructor(base) {
|
|
14
16
|
this.base = base;
|
|
@@ -40,6 +42,18 @@ export class BackendSandbox {
|
|
|
40
42
|
}
|
|
41
43
|
return located;
|
|
42
44
|
}
|
|
45
|
+
/** The stops the applied policy delivers, set by `confirm()` when the sandbox is provisioned. */
|
|
46
|
+
get stops() {
|
|
47
|
+
return this.applied;
|
|
48
|
+
}
|
|
49
|
+
/** Reads the policy back and checks it against `requested`, or disposes the sandbox and throws on a difference. */
|
|
50
|
+
async confirm(client, requested) {
|
|
51
|
+
this.applied = await confirmPolicy(client, this, requested);
|
|
52
|
+
}
|
|
53
|
+
/** Sets the stops a resumed sandbox's confirmed policy delivers, for `resumeSandbox()`. */
|
|
54
|
+
[APPLY_STOPS](stops) {
|
|
55
|
+
this.applied = stops;
|
|
56
|
+
}
|
|
43
57
|
async readFile(path) {
|
|
44
58
|
this.live();
|
|
45
59
|
return this.base.files.readFile(path);
|
package/dist/sandbox/base.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.js","sourceRoot":"","sources":["../../src/sandbox/base.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAkB,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnE,OAAO,EAAE,YAAY,EAAE,YAAY,EAAoB,MAAM,cAAc,CAAC;AAW5E,2GAA2G;AAC3G,MAAM,OAAgB,cAAc;IAC1B,QAAQ,GAAG,KAAK,CAAC;IACjB,SAAS,CAA4B;IAC5B,IAAI,CAAc;IAEnC,YAAsB,IAAiB;QACrC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;IAED,kEAAkE;IACxD,IAAI;QACZ,IA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IAAI,CAAC,OAAO,GAAG,MAAM,aAAa,CAAC,MAAM,EAAE,IAAI,EAAE,SAAS,CAAC,CAAC;IAC9D,CAAC;IAED,2FAA2F;IAC3F,CAAC,WAAW,CAAC,CAAC,KAA6B;QACzC,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC;IACvB,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,IAAY;QACzB,IAAI,CAAC,IAAI,EAAE,CAAC;QACZ,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IACxC,CAAC;IAED,KAAK,CAAC,SAAS,CAAC,IAAY,EAAE,IAAgB;QAC5C,IAAI,CAAC,IAAI,EAAE,CAAC;QACZ,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAC/C,CAAC;IAED,mHAAmH;IACnH,OAAO;QACL,IAAI,IAAI,CAAC,SAAS,KAAK,SAAS,EAAE,CAAC;YACjC,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;YACrB,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAC;QACnC,CAAC;QACD,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;CAIF","sourcesContent":["/**\n * What the Node-only backends that mount a workspace share: the checks before a command runs, the file calls, and a\n * `dispose()` that every caller waits on. A backend extends it and adds how it starts a command and what it cleans up.\n */\nimport { HarnessError } from \"../errors.js\";\nimport { type HostFiles, workingDirectory } from \"./host-files.js\";\nimport { APPLY_STOPS, confirmPolicy } from \"./policy.js\";\nimport { checkCommand, checkOptions, type NodeModules } from \"./process.js\";\nimport type { ExecOptions, ExecResult, Sandbox, SandboxClient, SandboxPolicy, SandboxStop } from \"./types.js\";\n\n/** The state a backend's sandbox is built on. */\nexport interface BackendBase {\n readonly modules: NodeModules;\n /** The workspace's real root. */\n readonly root: string;\n readonly files: HostFiles;\n}\n\n/** A sandbox that checks a command the same way, reads and writes files in the host, and disposes once. */\nexport abstract class BackendSandbox implements Sandbox {\n private disposed = false;\n private disposing: Promise<void> | undefined;\n private applied: readonly SandboxStop[] = [];\n private readonly base: BackendBase;\n\n protected constructor(base: BackendBase) {\n this.base = base;\n }\n\n /** Throws `sandbox_disposed` once `dispose()` has been called. */\n protected live(): void {\n if (this.disposed) throw new HarnessError(\"sandbox_disposed\", \"the sandbox was disposed\");\n }\n\n /**\n * Checks a command and its options, and finds its working directory. It returns the real working directory to run in,\n * or the result that settles the call without running anything: a denial for a directory outside the workspace, and\n * exit code 127 for a first word with `=`, which `env` would read as an assignment, as `none` answers a program it\n * can't find.\n */\n protected async prepare(\n command: readonly string[],\n options: ExecOptions,\n ): Promise<{ readonly cwd: string } | ExecResult> {\n this.live();\n checkCommand(command);\n checkOptions(options);\n options.signal.throwIfAborted();\n const located = await workingDirectory(this.base.modules, this.base.root, options);\n if (\"denied\" in located) return located;\n // The sandbox or the signal may have changed while the folder was checked.\n this.live();\n options.signal.throwIfAborted();\n if (command[0]?.includes(\"=\")) {\n return { exitCode: 127, stdout: \"\", stderr: `command not found: ${command[0]}\\n` };\n }\n return located;\n }\n\n abstract exec(command: readonly string[], options: ExecOptions): Promise<ExecResult>;\n\n /** Reads back the policy this sandbox applies, from what the backend wrote or will pass to each command. */\n abstract readBack(): Promise<SandboxPolicy>;\n\n /** The stops the applied policy delivers, set by `confirm()` when the sandbox is provisioned. */\n get stops(): readonly SandboxStop[] {\n return this.applied;\n }\n\n /** Reads the policy back and checks it against `requested`, or disposes the sandbox and throws on a difference. */\n async confirm(client: SandboxClient, requested: SandboxPolicy): Promise<void> {\n this.applied = await confirmPolicy(client, this, requested);\n }\n\n /** Sets the stops a resumed sandbox's confirmed policy delivers, for `resumeSandbox()`. */\n [APPLY_STOPS](stops: readonly SandboxStop[]): void {\n this.applied = stops;\n }\n\n async readFile(path: string): Promise<Uint8Array> {\n this.live();\n return this.base.files.readFile(path);\n }\n\n async writeFile(path: string, data: Uint8Array): Promise<void> {\n this.live();\n return this.base.files.writeFile(path, data);\n }\n\n /** Stops what is running and cleans up. Every call gets the first call's promise, so a second caller waits too. */\n dispose(): Promise<void> {\n if (this.disposing === undefined) {\n this.disposed = true;\n this.disposing = this.shutDown();\n }\n return this.disposing;\n }\n\n /** Ends the commands still running and removes what the sandbox made. It runs once. */\n protected abstract shutDown(): Promise<void>;\n}\n"]}
|
|
@@ -19,7 +19,11 @@ export interface DockerSandboxOptions {
|
|
|
19
19
|
readonly extraReadRoots?: readonly string[];
|
|
20
20
|
/** Folders that stay read-only inside a write root, such as the session's own log folder. */
|
|
21
21
|
readonly denyWrite?: readonly string[];
|
|
22
|
-
/**
|
|
22
|
+
/**
|
|
23
|
+
* A Unix socket on the host that a command may use to reach the hosts its policy allows, mounted at
|
|
24
|
+
* `DOCKER_PROXY_SOCKET_PATH`. The proxy on it enforces the allowlist, so start `startEgressProxy()` there with the
|
|
25
|
+
* policy's hosts, such as from `compileEgressPolicy()`; the read-back trusts it to.
|
|
26
|
+
*/
|
|
23
27
|
readonly proxySocket?: string;
|
|
24
28
|
}
|
|
25
29
|
/** Where a command finds the proxy socket, when the caller mounts one. */
|
|
@@ -30,6 +34,8 @@ export declare const DOCKER_PROXY_SOCKET_PATH = "/run/harness/proxy.sock";
|
|
|
30
34
|
* client runs with a clean environment: a `PATH`, a private empty `HOME` and `DOCKER_HOST` when one is set, and never
|
|
31
35
|
* the parent's environment. The policy's roots, `extraReadRoots`, `denyWrite` and `proxySocket` must be absolute, and
|
|
32
36
|
* the workspace must lie inside a root. A command whose first word contains `=` resolves with exit code 127, as under
|
|
33
|
-
* `none`.
|
|
37
|
+
* `none`. Before it returns, `provision()` reads back the policy its mounts and flags apply and throws
|
|
38
|
+
* `SandboxPolicyMismatchError` on a difference. Without `proxySocket` the container reaches no host, so a policy whose
|
|
39
|
+
* `network.allow` names one is refused. The backend lists no capability: it can't resume, snapshot or pause.
|
|
34
40
|
*/
|
|
35
41
|
export declare function dockerSandbox(options: DockerSandboxOptions): SandboxClient;
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
import { HarnessError } from "../../errors.js";
|
|
13
13
|
import { BackendSandbox } from "../base.js";
|
|
14
14
|
import { SandboxUnavailableError } from "../errors.js";
|
|
15
|
-
import { absolutePath, checkPaths, existing, findOnPath, HostFiles, inside, isProtectedPath, PROTECTED_TOP_LEVEL, realOrSelf, workspaceRoot, } from "../host-files.js";
|
|
15
|
+
import { absolutePath, checkPaths, existing, findOnPath, HostFiles, inside, isProtectedPath, PROTECTED_TOP_LEVEL, realOrSelf, spellings, workspaceRoot, } from "../host-files.js";
|
|
16
16
|
import { nodeModules, ProcessRunner } from "../process.js";
|
|
17
17
|
/** Where a command finds the proxy socket, when the caller mounts one. */
|
|
18
18
|
export const DOCKER_PROXY_SOCKET_PATH = "/run/harness/proxy.sock";
|
|
@@ -124,8 +124,8 @@ class DockerSandbox extends BackendSandbox {
|
|
|
124
124
|
const created = this.client(this.runArguments(name, located.cwd, command, options.env), CREATE_TIMEOUT_MS);
|
|
125
125
|
this.track(created);
|
|
126
126
|
const made = await this.untilStopped(name, created, options);
|
|
127
|
-
if ("
|
|
128
|
-
return made.
|
|
127
|
+
if ("expired" in made)
|
|
128
|
+
return made.expired;
|
|
129
129
|
if (made.exitCode !== 0) {
|
|
130
130
|
await this.removeContainer(name);
|
|
131
131
|
return { exitCode: made.exitCode, stdout: "", stderr: made.stderr };
|
|
@@ -181,7 +181,7 @@ class DockerSandbox extends BackendSandbox {
|
|
|
181
181
|
options.signal.addEventListener("abort", onAbort, { once: true });
|
|
182
182
|
if (options.timeoutMs !== undefined) {
|
|
183
183
|
const note = `timed out after ${options.timeoutMs} ms\n`;
|
|
184
|
-
timer = setTimeout(() => finish(() => resolve({
|
|
184
|
+
timer = setTimeout(() => finish(() => resolve({ expired: { exitCode: 124, stdout: "", stderr: note, timedOut: true } }), true), options.timeoutMs);
|
|
185
185
|
}
|
|
186
186
|
created.then((result) => finish(() => resolve(result), false), (error) => finish(() => reject(error), false));
|
|
187
187
|
});
|
|
@@ -206,6 +206,43 @@ class DockerSandbox extends BackendSandbox {
|
|
|
206
206
|
await new Promise((resolve) => setTimeout(resolve, SWEEP_PAUSE_MS));
|
|
207
207
|
}
|
|
208
208
|
}
|
|
209
|
+
/**
|
|
210
|
+
* The policy the mounts and flags apply, which are what every command's container is created with. The network is
|
|
211
|
+
* closed unless the caller mounted a proxy socket, and then the proxy on it enforces the requested allowlist. A
|
|
212
|
+
* read-only mount the request doesn't explain reads back as a read root it didn't ask for.
|
|
213
|
+
*
|
|
214
|
+
* One narrowing is not caught: a write root that the caller's `denyWrite` names exactly is mounted read-only but still
|
|
215
|
+
* reads back as a write root, because the read-back takes the caller's own `denyWrite` as part of the request. So
|
|
216
|
+
* `provision()` accepts it, and nothing in that root is writable inside the container.
|
|
217
|
+
*/
|
|
218
|
+
async readBack() {
|
|
219
|
+
this.live();
|
|
220
|
+
const { mounts, names, flags } = this.state;
|
|
221
|
+
const own = mounts.filter((mount) => mount.to !== DOCKER_PROXY_SOCKET_PATH);
|
|
222
|
+
// A write root that the caller's own denyWrite made read-only is still the root the request asked for.
|
|
223
|
+
const granted = (mount) => !mount.readOnly || (names.implicit.has(mount.from) && names.write.has(mount.from));
|
|
224
|
+
const writable = own.filter(granted).map((mount) => mount.from);
|
|
225
|
+
const inWritable = (path) => writable.some((root) => inside(this.state.modules, root, path));
|
|
226
|
+
const readable = (real) => names.missing.has(real) || inWritable(real) || own.some((m) => m.from === real);
|
|
227
|
+
const unexplained = own
|
|
228
|
+
.filter((mount) => mount.readOnly && !names.readReal.includes(mount.from))
|
|
229
|
+
.map((mount) => mount.from)
|
|
230
|
+
.filter((from) => !names.implicit.has(from) && !inWritable(from));
|
|
231
|
+
const closed = flags.join(" ").includes("--network none");
|
|
232
|
+
const proxied = mounts.length !== own.length;
|
|
233
|
+
return {
|
|
234
|
+
readRoots: [
|
|
235
|
+
...names.requested.readRoots.filter((_, index) => readable(names.readReal[index] ?? "")),
|
|
236
|
+
...unexplained,
|
|
237
|
+
],
|
|
238
|
+
writeRoots: writable.flatMap((path) => names.write.get(path) ?? [path]),
|
|
239
|
+
network: !closed
|
|
240
|
+
? { allow: ["*"], deny: [] }
|
|
241
|
+
: proxied
|
|
242
|
+
? names.requested.network
|
|
243
|
+
: { allow: [], deny: names.requested.network.deny },
|
|
244
|
+
};
|
|
245
|
+
}
|
|
209
246
|
async shutDown() {
|
|
210
247
|
await this.runner.stopAll();
|
|
211
248
|
await Promise.allSettled([...this.pending]);
|
|
@@ -281,19 +318,27 @@ async function planMounts(modules, policy, options) {
|
|
|
281
318
|
const denied = denyWrite.filter(underWrite);
|
|
282
319
|
const protectedPaths = writeRoots.flatMap((root) => PROTECTED_TOP_LEVEL.map((name) => modules.path.join(root, name)));
|
|
283
320
|
const readOnlyRoots = [...readRoots, ...extra].filter((path) => !underWrite(path));
|
|
321
|
+
// One look at which read roots exist feeds both the mounts and the names, so a folder made in between can't make them
|
|
322
|
+
// disagree.
|
|
323
|
+
const present = await existing(modules, readOnlyRoots);
|
|
284
324
|
const base = [
|
|
285
325
|
...writeRoots.map((from) => ({ from, to: from, readOnly: false })),
|
|
286
|
-
...
|
|
326
|
+
...present.map((from) => ({ from, to: from, readOnly: true })),
|
|
287
327
|
];
|
|
288
|
-
const
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
328
|
+
const protectedPresent = await existing(modules, protectedPaths);
|
|
329
|
+
const guarded = [...denied, ...protectedPresent].map((from) => ({ from, to: from, readOnly: true }));
|
|
330
|
+
const names = {
|
|
331
|
+
requested: policy,
|
|
332
|
+
readReal: readRoots,
|
|
333
|
+
write: spellings(writeRoots, policy.writeRoots),
|
|
334
|
+
missing: new Set(readOnlyRoots.filter((path) => !present.includes(path))),
|
|
335
|
+
implicit: new Set([...extra, ...denied, ...protectedPresent]),
|
|
336
|
+
};
|
|
293
337
|
return {
|
|
294
338
|
base: onePerDestination(base),
|
|
295
339
|
mounts: onePerDestination([...base, ...guarded]),
|
|
296
340
|
roots: { read: readRoots, write: writeRoots, denyWrite: denied },
|
|
341
|
+
names,
|
|
297
342
|
};
|
|
298
343
|
}
|
|
299
344
|
/** The `docker run` flags that lock a container down, and limit what it may use. */
|
|
@@ -348,11 +393,13 @@ const firstLine = (text) => text.trim().split("\n")[0] ?? "no output";
|
|
|
348
393
|
* client runs with a clean environment: a `PATH`, a private empty `HOME` and `DOCKER_HOST` when one is set, and never
|
|
349
394
|
* the parent's environment. The policy's roots, `extraReadRoots`, `denyWrite` and `proxySocket` must be absolute, and
|
|
350
395
|
* the workspace must lie inside a root. A command whose first word contains `=` resolves with exit code 127, as under
|
|
351
|
-
* `none`.
|
|
396
|
+
* `none`. Before it returns, `provision()` reads back the policy its mounts and flags apply and throws
|
|
397
|
+
* `SandboxPolicyMismatchError` on a difference. Without `proxySocket` the container reaches no host, so a policy whose
|
|
398
|
+
* `network.allow` names one is refused. The backend lists no capability: it can't resume, snapshot or pause.
|
|
352
399
|
*/
|
|
353
400
|
export function dockerSandbox(options) {
|
|
354
401
|
checkOptionValues(options);
|
|
355
|
-
|
|
402
|
+
const client = {
|
|
356
403
|
tier: "container",
|
|
357
404
|
stops: ["mistakes", "exfiltration"],
|
|
358
405
|
async provision(manifest, policy) {
|
|
@@ -368,8 +415,7 @@ export function dockerSandbox(options) {
|
|
|
368
415
|
checkPaths(modules, options.denyWrite ?? [], "a denyWrite folder");
|
|
369
416
|
const folder = await modules.fs.mkdtemp(modules.path.join(modules.os.tmpdir(), "harness-docker-"));
|
|
370
417
|
try {
|
|
371
|
-
|
|
372
|
-
return sandbox;
|
|
418
|
+
return await startSandbox({ modules, docker, hostPath, root, folder, manifest, policy, options, client });
|
|
373
419
|
}
|
|
374
420
|
catch (error) {
|
|
375
421
|
await modules.fs.rm(folder, { recursive: true, force: true });
|
|
@@ -377,6 +423,7 @@ export function dockerSandbox(options) {
|
|
|
377
423
|
}
|
|
378
424
|
},
|
|
379
425
|
};
|
|
426
|
+
return client;
|
|
380
427
|
}
|
|
381
428
|
async function startSandbox(input) {
|
|
382
429
|
const { modules, options } = input;
|
|
@@ -416,8 +463,10 @@ async function startSandbox(input) {
|
|
|
416
463
|
clientEnv,
|
|
417
464
|
folder: input.folder,
|
|
418
465
|
label: `harness.sandbox=harness-${modules.path.basename(input.folder).slice("harness-docker-".length)}`,
|
|
466
|
+
names: plan.names,
|
|
419
467
|
});
|
|
420
468
|
await probe(sandbox, options.image);
|
|
469
|
+
await sandbox.confirm(input.client, input.policy);
|
|
421
470
|
for (const folder of plan.roots.denyWrite)
|
|
422
471
|
await modules.fs.mkdir(folder, { recursive: true });
|
|
423
472
|
const encoder = new TextEncoder();
|