@buildanagent/harness 0.0.0-stage → 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/LICENSE +54 -0
- package/LICENSE-APACHE +202 -0
- package/LICENSE-MIT +21 -0
- package/README.md +822 -2
- package/dist/ablation.d.ts +2 -0
- package/dist/ablation.js +3 -0
- package/dist/ablation.js.map +1 -0
- package/dist/completion/check.d.ts +64 -0
- package/dist/completion/check.js +152 -0
- package/dist/completion/check.js.map +1 -0
- package/dist/completion/checks.d.ts +45 -0
- package/dist/completion/checks.js +173 -0
- package/dist/completion/checks.js.map +1 -0
- package/dist/completion/flags.d.ts +25 -0
- package/dist/completion/flags.js +87 -0
- package/dist/completion/flags.js.map +1 -0
- package/dist/completion/index.d.ts +8 -0
- package/dist/completion/index.js +9 -0
- package/dist/completion/index.js.map +1 -0
- package/dist/completion/snapshot.d.ts +33 -0
- package/dist/completion/snapshot.js +83 -0
- package/dist/completion/snapshot.js.map +1 -0
- package/dist/context/cap.d.ts +32 -0
- package/dist/context/cap.js +50 -0
- package/dist/context/cap.js.map +1 -0
- package/dist/context/estimate.d.ts +18 -0
- package/dist/context/estimate.js +20 -0
- package/dist/context/estimate.js.map +1 -0
- package/dist/context/file-spill.d.ts +15 -0
- package/dist/context/file-spill.js +40 -0
- package/dist/context/file-spill.js.map +1 -0
- package/dist/context/index.d.ts +10 -0
- package/dist/context/index.js +10 -0
- package/dist/context/index.js.map +1 -0
- package/dist/context/mask.d.ts +27 -0
- package/dist/context/mask.js +71 -0
- package/dist/context/mask.js.map +1 -0
- package/dist/context/mid-turn.d.ts +40 -0
- package/dist/context/mid-turn.js +82 -0
- package/dist/context/mid-turn.js.map +1 -0
- package/dist/context/policy.d.ts +9 -0
- package/dist/context/policy.js +140 -0
- package/dist/context/policy.js.map +1 -0
- package/dist/context/spill-ledger.d.ts +25 -0
- package/dist/context/spill-ledger.js +54 -0
- package/dist/context/spill-ledger.js.map +1 -0
- package/dist/context/spill.d.ts +10 -0
- package/dist/context/spill.js +18 -0
- package/dist/context/spill.js.map +1 -0
- package/dist/context/summarize.d.ts +53 -0
- package/dist/context/summarize.js +204 -0
- package/dist/context/summarize.js.map +1 -0
- package/dist/context/summary-template.d.ts +29 -0
- package/dist/context/summary-template.js +69 -0
- package/dist/context/summary-template.js.map +1 -0
- package/dist/context/types.d.ts +150 -0
- package/dist/context/types.js +2 -0
- package/dist/context/types.js.map +1 -0
- package/dist/context/write-cap.d.ts +19 -0
- package/dist/context/write-cap.js +41 -0
- package/dist/context/write-cap.js.map +1 -0
- package/dist/create-harness.d.ts +7 -0
- package/dist/create-harness.js +21 -0
- package/dist/create-harness.js.map +1 -0
- package/dist/credentials/addresses.d.ts +14 -0
- package/dist/credentials/addresses.js +144 -0
- package/dist/credentials/addresses.js.map +1 -0
- package/dist/credentials/allowlist.d.ts +54 -0
- package/dist/credentials/allowlist.js +134 -0
- package/dist/credentials/allowlist.js.map +1 -0
- 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 +82 -0
- package/dist/credentials/egress-proxy.js +650 -0
- package/dist/credentials/egress-proxy.js.map +1 -0
- 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 +13 -0
- package/dist/credentials/index.js +14 -0
- package/dist/credentials/index.js.map +1 -0
- package/dist/credentials/scrub.d.ts +23 -0
- package/dist/credentials/scrub.js +115 -0
- package/dist/credentials/scrub.js.map +1 -0
- package/dist/errors.d.ts +60 -0
- package/dist/errors.js +67 -0
- package/dist/errors.js.map +1 -0
- package/dist/extensions/compose.d.ts +27 -0
- package/dist/extensions/compose.js +83 -0
- package/dist/extensions/compose.js.map +1 -0
- package/dist/extensions/context-files-node.d.ts +28 -0
- package/dist/extensions/context-files-node.js +74 -0
- package/dist/extensions/context-files-node.js.map +1 -0
- package/dist/extensions/context-files.d.ts +68 -0
- package/dist/extensions/context-files.js +214 -0
- package/dist/extensions/context-files.js.map +1 -0
- package/dist/extensions/digest.d.ts +6 -0
- package/dist/extensions/digest.js +68 -0
- package/dist/extensions/digest.js.map +1 -0
- package/dist/extensions/index.d.ts +10 -0
- package/dist/extensions/index.js +10 -0
- package/dist/extensions/index.js.map +1 -0
- package/dist/extensions/load.d.ts +42 -0
- package/dist/extensions/load.js +211 -0
- package/dist/extensions/load.js.map +1 -0
- package/dist/extensions/lock.d.ts +8 -0
- package/dist/extensions/lock.js +95 -0
- package/dist/extensions/lock.js.map +1 -0
- package/dist/extensions/node.d.ts +10 -0
- package/dist/extensions/node.js +11 -0
- package/dist/extensions/node.js.map +1 -0
- package/dist/extensions/project-dirs.d.ts +24 -0
- package/dist/extensions/project-dirs.js +97 -0
- package/dist/extensions/project-dirs.js.map +1 -0
- package/dist/extensions/skills-node.d.ts +34 -0
- package/dist/extensions/skills-node.js +123 -0
- package/dist/extensions/skills-node.js.map +1 -0
- package/dist/extensions/skills.d.ts +51 -0
- package/dist/extensions/skills.js +175 -0
- package/dist/extensions/skills.js.map +1 -0
- package/dist/extensions/trust-file.d.ts +3 -0
- package/dist/extensions/trust-file.js +62 -0
- package/dist/extensions/trust-file.js.map +1 -0
- package/dist/extensions/trust-store-node.d.ts +10 -0
- package/dist/extensions/trust-store-node.js +33 -0
- package/dist/extensions/trust-store-node.js.map +1 -0
- package/dist/extensions/types.d.ts +42 -0
- package/dist/extensions/types.js +2 -0
- package/dist/extensions/types.js.map +1 -0
- package/dist/harness.d.ts +156 -0
- package/dist/harness.js +2 -0
- package/dist/harness.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp/connection.d.ts +22 -0
- package/dist/mcp/connection.js +267 -0
- package/dist/mcp/connection.js.map +1 -0
- package/dist/mcp/content.d.ts +27 -0
- package/dist/mcp/content.js +177 -0
- package/dist/mcp/content.js.map +1 -0
- package/dist/mcp/errors.d.ts +19 -0
- package/dist/mcp/errors.js +21 -0
- package/dist/mcp/errors.js.map +1 -0
- package/dist/mcp/index.d.ts +10 -0
- package/dist/mcp/index.js +10 -0
- package/dist/mcp/index.js.map +1 -0
- package/dist/mcp/manager.d.ts +7 -0
- package/dist/mcp/manager.js +173 -0
- package/dist/mcp/manager.js.map +1 -0
- package/dist/mcp/record.d.ts +7 -0
- package/dist/mcp/record.js +20 -0
- package/dist/mcp/record.js.map +1 -0
- package/dist/mcp/stdio.d.ts +39 -0
- package/dist/mcp/stdio.js +382 -0
- package/dist/mcp/stdio.js.map +1 -0
- package/dist/mcp/types.d.ts +172 -0
- package/dist/mcp/types.js +2 -0
- package/dist/mcp/types.js.map +1 -0
- package/dist/memory/index.d.ts +2 -0
- package/dist/memory/index.js +3 -0
- package/dist/memory/index.js.map +1 -0
- package/dist/permissions/default-rules.d.ts +7 -0
- package/dist/permissions/default-rules.js +42 -0
- package/dist/permissions/default-rules.js.map +1 -0
- package/dist/permissions/errors.d.ts +11 -0
- package/dist/permissions/errors.js +14 -0
- package/dist/permissions/errors.js.map +1 -0
- package/dist/permissions/index.d.ts +9 -0
- package/dist/permissions/index.js +9 -0
- package/dist/permissions/index.js.map +1 -0
- package/dist/permissions/match.d.ts +33 -0
- package/dist/permissions/match.js +287 -0
- package/dist/permissions/match.js.map +1 -0
- package/dist/permissions/pipeline.d.ts +9 -0
- package/dist/permissions/pipeline.js +235 -0
- package/dist/permissions/pipeline.js.map +1 -0
- package/dist/permissions/rules.d.ts +22 -0
- package/dist/permissions/rules.js +74 -0
- package/dist/permissions/rules.js.map +1 -0
- package/dist/permissions/shadow.d.ts +5 -0
- package/dist/permissions/shadow.js +22 -0
- package/dist/permissions/shadow.js.map +1 -0
- package/dist/permissions/types.d.ts +104 -0
- package/dist/permissions/types.js +2 -0
- package/dist/permissions/types.js.map +1 -0
- package/dist/sandbox/base.d.ts +45 -0
- package/dist/sandbox/base.js +74 -0
- package/dist/sandbox/base.js.map +1 -0
- package/dist/sandbox/docker/index.d.ts +41 -0
- package/dist/sandbox/docker/index.js +497 -0
- package/dist/sandbox/docker/index.js.map +1 -0
- package/dist/sandbox/errors.d.ts +44 -0
- package/dist/sandbox/errors.js +57 -0
- package/dist/sandbox/errors.js.map +1 -0
- package/dist/sandbox/host-files.d.ts +65 -0
- package/dist/sandbox/host-files.js +258 -0
- package/dist/sandbox/host-files.js.map +1 -0
- package/dist/sandbox/index.d.ts +10 -0
- package/dist/sandbox/index.js +10 -0
- package/dist/sandbox/index.js.map +1 -0
- package/dist/sandbox/none.d.ts +17 -0
- package/dist/sandbox/none.js +108 -0
- package/dist/sandbox/none.js.map +1 -0
- 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.d.ts +61 -0
- package/dist/sandbox/process.js +253 -0
- package/dist/sandbox/process.js.map +1 -0
- package/dist/sandbox/spawn-env.d.ts +20 -0
- package/dist/sandbox/spawn-env.js +128 -0
- package/dist/sandbox/spawn-env.js.map +1 -0
- package/dist/sandbox/srt/index.d.ts +38 -0
- package/dist/sandbox/srt/index.js +283 -0
- package/dist/sandbox/srt/index.js.map +1 -0
- package/dist/sandbox/srt/settings.d.ts +60 -0
- package/dist/sandbox/srt/settings.js +84 -0
- package/dist/sandbox/srt/settings.js.map +1 -0
- package/dist/sandbox/types.d.ts +125 -0
- package/dist/sandbox/types.js +6 -0
- package/dist/sandbox/types.js.map +1 -0
- package/dist/server/answers.d.ts +16 -0
- package/dist/server/answers.js +43 -0
- package/dist/server/answers.js.map +1 -0
- package/dist/server/connection.d.ts +99 -0
- package/dist/server/connection.js +309 -0
- package/dist/server/connection.js.map +1 -0
- package/dist/server/dispatcher.d.ts +86 -0
- package/dist/server/dispatcher.js +800 -0
- package/dist/server/dispatcher.js.map +1 -0
- package/dist/server/index.d.ts +13 -0
- package/dist/server/index.js +12 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server/local-transport.d.ts +44 -0
- package/dist/server/local-transport.js +103 -0
- package/dist/server/local-transport.js.map +1 -0
- package/dist/server/outbox.d.ts +31 -0
- package/dist/server/outbox.js +130 -0
- package/dist/server/outbox.js.map +1 -0
- package/dist/server/params.d.ts +25 -0
- package/dist/server/params.js +112 -0
- package/dist/server/params.js.map +1 -0
- package/dist/server/protocol.schema.json +2448 -0
- package/dist/server/rpc-session.d.ts +43 -0
- package/dist/server/rpc-session.js +167 -0
- package/dist/server/rpc-session.js.map +1 -0
- package/dist/server/stdio-streams.d.ts +67 -0
- package/dist/server/stdio-streams.js +218 -0
- package/dist/server/stdio-streams.js.map +1 -0
- package/dist/server/stdio.d.ts +59 -0
- package/dist/server/stdio.js +189 -0
- package/dist/server/stdio.js.map +1 -0
- package/dist/server/websocket.d.ts +106 -0
- package/dist/server/websocket.js +327 -0
- package/dist/server/websocket.js.map +1 -0
- package/dist/session/approvals.d.ts +81 -0
- package/dist/session/approvals.js +217 -0
- package/dist/session/approvals.js.map +1 -0
- package/dist/session/code-call-log.d.ts +42 -0
- package/dist/session/code-call-log.js +63 -0
- package/dist/session/code-call-log.js.map +1 -0
- package/dist/session/code-call-result.d.ts +19 -0
- package/dist/session/code-call-result.js +95 -0
- package/dist/session/code-call-result.js.map +1 -0
- package/dist/session/code-call.d.ts +49 -0
- package/dist/session/code-call.js +345 -0
- package/dist/session/code-call.js.map +1 -0
- package/dist/session/effect-scope.d.ts +11 -0
- package/dist/session/effect-scope.js +10 -0
- package/dist/session/effect-scope.js.map +1 -0
- package/dist/session/errors.d.ts +19 -0
- package/dist/session/errors.js +27 -0
- package/dist/session/errors.js.map +1 -0
- package/dist/session/file-index.d.ts +8 -0
- package/dist/session/file-index.js +70 -0
- package/dist/session/file-index.js.map +1 -0
- package/dist/session/file-key-store.d.ts +16 -0
- package/dist/session/file-key-store.js +169 -0
- package/dist/session/file-key-store.js.map +1 -0
- package/dist/session/file-lock.d.ts +52 -0
- package/dist/session/file-lock.js +324 -0
- package/dist/session/file-lock.js.map +1 -0
- package/dist/session/index.d.ts +22 -0
- package/dist/session/index.js +20 -0
- package/dist/session/index.js.map +1 -0
- package/dist/session/jsonl-store.d.ts +37 -0
- package/dist/session/jsonl-store.js +386 -0
- package/dist/session/jsonl-store.js.map +1 -0
- package/dist/session/jsonl.d.ts +9 -0
- package/dist/session/jsonl.js +10 -0
- package/dist/session/jsonl.js.map +1 -0
- package/dist/session/lock.d.ts +19 -0
- package/dist/session/lock.js +2 -0
- package/dist/session/lock.js.map +1 -0
- package/dist/session/memory-store.d.ts +12 -0
- package/dist/session/memory-store.js +60 -0
- package/dist/session/memory-store.js.map +1 -0
- package/dist/session/migrate.d.ts +41 -0
- package/dist/session/migrate.js +86 -0
- package/dist/session/migrate.js.map +1 -0
- package/dist/session/pointer.d.ts +15 -0
- package/dist/session/pointer.js +22 -0
- package/dist/session/pointer.js.map +1 -0
- package/dist/session/rebuild.d.ts +53 -0
- package/dist/session/rebuild.js +230 -0
- package/dist/session/rebuild.js.map +1 -0
- package/dist/session/resume.d.ts +26 -0
- package/dist/session/resume.js +128 -0
- package/dist/session/resume.js.map +1 -0
- package/dist/session/retention.d.ts +97 -0
- package/dist/session/retention.js +702 -0
- package/dist/session/retention.js.map +1 -0
- package/dist/session/runner.d.ts +156 -0
- package/dist/session/runner.js +656 -0
- package/dist/session/runner.js.map +1 -0
- package/dist/session/scheduler.d.ts +47 -0
- package/dist/session/scheduler.js +85 -0
- package/dist/session/scheduler.js.map +1 -0
- package/dist/session/secret-key-store.d.ts +47 -0
- package/dist/session/secret-key-store.js +79 -0
- package/dist/session/secret-key-store.js.map +1 -0
- package/dist/session/session.d.ts +106 -0
- package/dist/session/session.js +353 -0
- package/dist/session/session.js.map +1 -0
- package/dist/session/sticky.d.ts +48 -0
- package/dist/session/sticky.js +232 -0
- package/dist/session/sticky.js.map +1 -0
- package/dist/session/store.d.ts +108 -0
- package/dist/session/store.js +163 -0
- package/dist/session/store.js.map +1 -0
- package/dist/telemetry/index.d.ts +2 -0
- package/dist/telemetry/index.js +3 -0
- package/dist/telemetry/index.js.map +1 -0
- package/dist/testing/fake-sandbox.d.ts +52 -0
- package/dist/testing/fake-sandbox.js +370 -0
- package/dist/testing/fake-sandbox.js.map +1 -0
- package/dist/testing/index.d.ts +10 -0
- package/dist/testing/index.js +11 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/testing/key-store-conformance.d.ts +22 -0
- package/dist/testing/key-store-conformance.js +97 -0
- package/dist/testing/key-store-conformance.js.map +1 -0
- package/dist/testing/run-cases.d.ts +21 -0
- package/dist/testing/run-cases.js +20 -0
- package/dist/testing/run-cases.js.map +1 -0
- package/dist/testing/sandbox-conformance.d.ts +64 -0
- package/dist/testing/sandbox-conformance.js +468 -0
- package/dist/testing/sandbox-conformance.js.map +1 -0
- package/dist/testing/scheduler-conformance.d.ts +32 -0
- package/dist/testing/scheduler-conformance.js +72 -0
- package/dist/testing/scheduler-conformance.js.map +1 -0
- package/dist/testing/store-conformance.d.ts +21 -0
- package/dist/testing/store-conformance.js +320 -0
- package/dist/testing/store-conformance.js.map +1 -0
- 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/errors.d.ts +13 -0
- package/dist/tools/errors.js +17 -0
- package/dist/tools/errors.js.map +1 -0
- package/dist/tools/index.d.ts +12 -0
- package/dist/tools/index.js +11 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/registry.d.ts +3 -0
- package/dist/tools/registry.js +234 -0
- package/dist/tools/registry.js.map +1 -0
- package/dist/tools/tool-search.d.ts +30 -0
- package/dist/tools/tool-search.js +118 -0
- package/dist/tools/tool-search.js.map +1 -0
- package/dist/tools/types.d.ts +106 -0
- package/dist/tools/types.js +2 -0
- package/dist/tools/types.js.map +1 -0
- package/llms.txt +469 -0
- package/package.json +118 -3
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { invokeCodeCall } from "./session/code-call.js";
|
|
2
|
+
/** Creates a harness. `H` types the host context of each turn, so `runTurn()` checks it. */
|
|
3
|
+
export function createHarness(options) {
|
|
4
|
+
return {
|
|
5
|
+
...options,
|
|
6
|
+
tenant: options.tenant ?? "local",
|
|
7
|
+
env: {
|
|
8
|
+
cwd: options.env?.cwd ?? "/",
|
|
9
|
+
permissionMode: options.env?.permissionMode ?? "default",
|
|
10
|
+
approvalPolicy: options.env?.approvalPolicy ?? "on-request",
|
|
11
|
+
sandbox: options.env?.sandbox ?? "none",
|
|
12
|
+
},
|
|
13
|
+
harnessVersion: options.harnessVersion ?? "0.0.0",
|
|
14
|
+
ablationHash: options.ablationHash ?? "none",
|
|
15
|
+
// `this`, not a captured harness, so a copy made with a spread runs with its own settings.
|
|
16
|
+
invokeTool(session, call) {
|
|
17
|
+
return invokeCodeCall(this, session, call);
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=create-harness.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-harness.js","sourceRoot":"","sources":["../src/create-harness.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAExD,4FAA4F;AAC5F,MAAM,UAAU,aAAa,CAAc,OAA0B;IACnE,OAAO;QACL,GAAG,OAAO;QACV,MAAM,EAAE,OAAO,CAAC,MAAM,IAAI,OAAO;QACjC,GAAG,EAAE;YACH,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE,GAAG,IAAI,GAAG;YAC5B,cAAc,EAAE,OAAO,CAAC,GAAG,EAAE,cAAc,IAAI,SAAS;YACxD,cAAc,EAAE,OAAO,CAAC,GAAG,EAAE,cAAc,IAAI,YAAY;YAC3D,OAAO,EAAE,OAAO,CAAC,GAAG,EAAE,OAAO,IAAI,MAAM;SACxC;QACD,cAAc,EAAE,OAAO,CAAC,cAAc,IAAI,OAAO;QACjD,YAAY,EAAE,OAAO,CAAC,YAAY,IAAI,MAAM;QAC5C,2FAA2F;QAC3F,UAAU,CAAC,OAAO,EAAE,IAAI;YACtB,OAAO,cAAc,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC;QAC7C,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["/**\n * `createHarness()`: a harness from its options, with the defaults filled in and `invokeTool()` bound to the code-call\n * runner. It is apart from the harness's types because the runner imports them.\n */\nimport type { Harness, HarnessOptions } from \"./harness.js\";\nimport { invokeCodeCall } from \"./session/code-call.js\";\n\n/** Creates a harness. `H` types the host context of each turn, so `runTurn()` checks it. */\nexport function createHarness<H = unknown>(options: HarnessOptions<H>): Harness<H> {\n return {\n ...options,\n tenant: options.tenant ?? \"local\",\n env: {\n cwd: options.env?.cwd ?? \"/\",\n permissionMode: options.env?.permissionMode ?? \"default\",\n approvalPolicy: options.env?.approvalPolicy ?? \"on-request\",\n sandbox: options.env?.sandbox ?? \"none\",\n },\n harnessVersion: options.harnessVersion ?? \"0.0.0\",\n ablationHash: options.ablationHash ?? \"none\",\n // `this`, not a captured harness, so a copy made with a spread runs with its own settings.\n invokeTool(session, call) {\n return invokeCodeCall(this, session, call);\n },\n };\n}\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which network addresses an egress proxy may connect to. It refuses every address that isn't a public one: loopback,
|
|
3
|
+
* link-local (which holds the cloud metadata address 169.254.169.254), private, carrier-grade NAT, unspecified,
|
|
4
|
+
* multicast and reserved ranges, for both IPv4 and IPv6, and an IPv6 address that wraps one of the refused IPv4 ones.
|
|
5
|
+
* Names resolve to addresses in the proxy, and each address is checked here, so a name that points at the host's own
|
|
6
|
+
* network is refused even when its name is allowed. It parses addresses itself and imports no Node module.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Whether `address` is a public one a proxy may connect to. Text that isn't an IPv4 or IPv6 address is not public, so a
|
|
10
|
+
* resolver's odd answer is refused instead of passed on.
|
|
11
|
+
*/
|
|
12
|
+
export declare function isPublicAddress(address: string): boolean;
|
|
13
|
+
/** Whether `text` is an IPv4 or IPv6 address, as a host name that must not be looked up. */
|
|
14
|
+
export declare function isAddressLiteral(text: string): boolean;
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which network addresses an egress proxy may connect to. It refuses every address that isn't a public one: loopback,
|
|
3
|
+
* link-local (which holds the cloud metadata address 169.254.169.254), private, carrier-grade NAT, unspecified,
|
|
4
|
+
* multicast and reserved ranges, for both IPv4 and IPv6, and an IPv6 address that wraps one of the refused IPv4 ones.
|
|
5
|
+
* Names resolve to addresses in the proxy, and each address is checked here, so a name that points at the host's own
|
|
6
|
+
* network is refused even when its name is allowed. It parses addresses itself and imports no Node module.
|
|
7
|
+
*/
|
|
8
|
+
/** The IPv4 ranges a proxy refuses, as `[address, prefix length]`. */
|
|
9
|
+
const IPV4_REFUSED = [
|
|
10
|
+
[0x00000000, 8], // this network
|
|
11
|
+
[0x0a000000, 8], // private
|
|
12
|
+
[0x64400000, 10], // carrier-grade NAT, 100.64.0.0/10
|
|
13
|
+
[0x7f000000, 8], // loopback
|
|
14
|
+
[0xa9fe0000, 16], // link-local, which holds the metadata address
|
|
15
|
+
[0xac100000, 12], // private
|
|
16
|
+
[0xc0000000, 24], // IETF protocol assignments
|
|
17
|
+
[0xc0000200, 24], // documentation
|
|
18
|
+
[0xc0a80000, 16], // private
|
|
19
|
+
[0xc6120000, 15], // benchmarking, 198.18.0.0/15
|
|
20
|
+
[0xc6336400, 24], // documentation
|
|
21
|
+
[0xcb007100, 24], // documentation
|
|
22
|
+
[0xe0000000, 4], // multicast
|
|
23
|
+
[0xf0000000, 4], // reserved, and the broadcast address
|
|
24
|
+
];
|
|
25
|
+
/** The four parts of an IPv4 address as one number, or `undefined` when `text` is not a dotted quad. */
|
|
26
|
+
function parseIpv4(text) {
|
|
27
|
+
const parts = text.split(".");
|
|
28
|
+
if (parts.length !== 4)
|
|
29
|
+
return undefined;
|
|
30
|
+
let value = 0;
|
|
31
|
+
for (const part of parts) {
|
|
32
|
+
if (!/^(0|[1-9][0-9]{0,2})$/.test(part))
|
|
33
|
+
return undefined;
|
|
34
|
+
const octet = Number(part);
|
|
35
|
+
if (octet > 255)
|
|
36
|
+
return undefined;
|
|
37
|
+
value = value * 256 + octet;
|
|
38
|
+
}
|
|
39
|
+
return value;
|
|
40
|
+
}
|
|
41
|
+
/** The 16-bit groups in one side of an IPv6 address, where the last piece may be a dotted IPv4 address. */
|
|
42
|
+
function readGroups(side) {
|
|
43
|
+
if (side === "")
|
|
44
|
+
return [];
|
|
45
|
+
const groups = [];
|
|
46
|
+
const pieces = side.split(":");
|
|
47
|
+
for (const [index, piece] of pieces.entries()) {
|
|
48
|
+
const v4 = index === pieces.length - 1 && piece.includes(".") ? parseIpv4(piece) : undefined;
|
|
49
|
+
if (v4 !== undefined) {
|
|
50
|
+
groups.push(Math.floor(v4 / 65536), v4 % 65536);
|
|
51
|
+
}
|
|
52
|
+
else if (/^[0-9a-fA-F]{1,4}$/.test(piece)) {
|
|
53
|
+
groups.push(Number.parseInt(piece, 16));
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return groups;
|
|
60
|
+
}
|
|
61
|
+
/** The eight 16-bit groups of an IPv6 address, or `undefined` when `text` is not one. */
|
|
62
|
+
function parseIpv6(text) {
|
|
63
|
+
const whole = text.split("%")[0] ?? text;
|
|
64
|
+
const doubles = whole.split("::");
|
|
65
|
+
if (doubles.length > 2)
|
|
66
|
+
return undefined;
|
|
67
|
+
const head = readGroups(doubles[0] ?? "");
|
|
68
|
+
const tail = doubles.length === 2 ? readGroups(doubles[1] ?? "") : [];
|
|
69
|
+
if (head === undefined || tail === undefined)
|
|
70
|
+
return undefined;
|
|
71
|
+
if (doubles.length === 1)
|
|
72
|
+
return head.length === 8 ? head : undefined;
|
|
73
|
+
const missing = 8 - head.length - tail.length;
|
|
74
|
+
return missing >= 1 ? [...head, ...new Array(missing).fill(0), ...tail] : undefined;
|
|
75
|
+
}
|
|
76
|
+
function ipv4Refused(value) {
|
|
77
|
+
return IPV4_REFUSED.some(([base, bits]) => {
|
|
78
|
+
const size = 2 ** (32 - bits);
|
|
79
|
+
return Math.floor(value / size) === Math.floor(base / size);
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
/** The IPv6 prefixes a proxy refuses, as the leading groups and the prefix length in bits. */
|
|
83
|
+
const IPV6_REFUSED = [
|
|
84
|
+
[[0, 0, 0, 0, 0, 0, 0, 0], 128], // ::, unspecified
|
|
85
|
+
[[0, 0, 0, 0, 0, 0, 0, 1], 128], // ::1, loopback
|
|
86
|
+
[[0x64, 0xff9b, 1], 48], // 64:ff9b:1::/48, local-use NAT64
|
|
87
|
+
[[0x100], 64], // 100::/64, discard-only
|
|
88
|
+
[[0x2001, 0], 23], // 2001::/23: Teredo, benchmarking, ORCHID and protocol assignments
|
|
89
|
+
[[0x2001, 0x0db8], 32], // documentation
|
|
90
|
+
[[0x3fff], 20], // 3fff::/20, documentation
|
|
91
|
+
[[0x5f00], 16], // segment routing SIDs
|
|
92
|
+
[[0xfc00], 7], // unique local
|
|
93
|
+
[[0xfe80], 10], // link-local
|
|
94
|
+
[[0xfec0], 10], // site-local, deprecated
|
|
95
|
+
[[0xff00], 8], // multicast
|
|
96
|
+
];
|
|
97
|
+
/** Whether the first `bits` bits of `groups` equal those of `prefix`. */
|
|
98
|
+
function inPrefix(groups, prefix, bits) {
|
|
99
|
+
for (let index = 0; index * 16 < bits; index += 1) {
|
|
100
|
+
const take = Math.min(16, bits - index * 16);
|
|
101
|
+
const mask = (0xffff << (16 - take)) & 0xffff;
|
|
102
|
+
if (((groups[index] ?? 0) & mask) !== ((prefix[index] ?? 0) & mask))
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
return true;
|
|
106
|
+
}
|
|
107
|
+
/** The IPv4 address an IPv6 one carries, as a number: mapped, compatible, translated, NAT64 and 6to4 forms. */
|
|
108
|
+
function wrappedIpv4(groups) {
|
|
109
|
+
const [a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0, h = 0] = groups;
|
|
110
|
+
const zeroHigh = a === 0 && b === 0 && c === 0 && d === 0;
|
|
111
|
+
const low = g * 65536 + h;
|
|
112
|
+
if (zeroHigh && e === 0 && (f === 0xffff || f === 0))
|
|
113
|
+
return low; // ::ffff:a.b.c.d and ::a.b.c.d
|
|
114
|
+
if (zeroHigh && e === 0xffff && f === 0)
|
|
115
|
+
return low; // ::ffff:0:a.b.c.d, IPv4-translated
|
|
116
|
+
if (a === 0x64 && b === 0xff9b && c === 0 && d === 0 && e === 0 && f === 0)
|
|
117
|
+
return low; // 64:ff9b::/96
|
|
118
|
+
return a === 0x2002 ? b * 65536 + c : undefined; // 6to4 wraps the address in its next two groups
|
|
119
|
+
}
|
|
120
|
+
/** Whether an IPv6 address, as eight groups, is one a proxy refuses. */
|
|
121
|
+
function ipv6Refused(groups) {
|
|
122
|
+
const wrapped = wrappedIpv4(groups);
|
|
123
|
+
if (wrapped !== undefined && ipv4Refused(wrapped))
|
|
124
|
+
return true;
|
|
125
|
+
return IPV6_REFUSED.some(([prefix, bits]) => inPrefix(groups, prefix, bits));
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Whether `address` is a public one a proxy may connect to. Text that isn't an IPv4 or IPv6 address is not public, so a
|
|
129
|
+
* resolver's odd answer is refused instead of passed on.
|
|
130
|
+
*/
|
|
131
|
+
export function isPublicAddress(address) {
|
|
132
|
+
const bare = address.startsWith("[") && address.endsWith("]") ? address.slice(1, -1) : address;
|
|
133
|
+
const v4 = parseIpv4(bare);
|
|
134
|
+
if (v4 !== undefined)
|
|
135
|
+
return !ipv4Refused(v4);
|
|
136
|
+
const v6 = parseIpv6(bare);
|
|
137
|
+
return v6 !== undefined && !ipv6Refused(v6);
|
|
138
|
+
}
|
|
139
|
+
/** Whether `text` is an IPv4 or IPv6 address, as a host name that must not be looked up. */
|
|
140
|
+
export function isAddressLiteral(text) {
|
|
141
|
+
const bare = text.startsWith("[") && text.endsWith("]") ? text.slice(1, -1) : text;
|
|
142
|
+
return parseIpv4(bare) !== undefined || parseIpv6(bare) !== undefined;
|
|
143
|
+
}
|
|
144
|
+
//# sourceMappingURL=addresses.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"addresses.js","sourceRoot":"","sources":["../../src/credentials/addresses.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,sEAAsE;AACtE,MAAM,YAAY,GAA2C;IAC3D,CAAC,UAAU,EAAE,CAAC,CAAC,EAAE,eAAe;IAChC,CAAC,UAAU,EAAE,CAAC,CAAC,EAAE,UAAU;IAC3B,CAAC,UAAU,EAAE,EAAE,CAAC,EAAE,mCAAmC;IACrD,CAAC,UAAU,EAAE,CAAC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I,WAAW,CAAC,OAAO,CAAC;QAAE,OAAO,IAAI,CAAC;IAC/D,OAAO,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC;AAC/E,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,eAAe,CAAC,OAAe;IAC7C,MAAM,IAAI,GAAG,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;IAC/F,MAAM,EAAE,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC;IAC3B,IAAI,EAAE,KAAK,SAAS;QAAE,OAAO,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC;IAC9C,MAAM,EAAE,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC;IAC3B,OAAO,EAAE,KAAK,SAAS,IAAI,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC;AAC9C,CAAC;AAED,4FAA4F;AAC5F,MAAM,UAAU,gBAAgB,CAAC,IAAY;IAC3C,MAAM,IAAI,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IACnF,OAAO,SAAS,CAAC,IAAI,CAAC,KAAK,SAAS,IAAI,SAAS,CAAC,IAAI,CAAC,KAAK,SAAS,CAAC;AACxE,CAAC","sourcesContent":["/**\n * Which network addresses an egress proxy may connect to. It refuses every address that isn't a public one: loopback,\n * link-local (which holds the cloud metadata address 169.254.169.254), private, carrier-grade NAT, unspecified,\n * multicast and reserved ranges, for both IPv4 and IPv6, and an IPv6 address that wraps one of the refused IPv4 ones.\n * Names resolve to addresses in the proxy, and each address is checked here, so a name that points at the host's own\n * network is refused even when its name is allowed. It parses addresses itself and imports no Node module.\n */\n\n/** The IPv4 ranges a proxy refuses, as `[address, prefix length]`. */\nconst IPV4_REFUSED: readonly (readonly [number, number])[] = [\n [0x00000000, 8], // this network\n [0x0a000000, 8], // private\n [0x64400000, 10], // carrier-grade NAT, 100.64.0.0/10\n [0x7f000000, 8], // loopback\n [0xa9fe0000, 16], // link-local, which holds the metadata address\n [0xac100000, 12], // private\n [0xc0000000, 24], // IETF protocol assignments\n [0xc0000200, 24], // documentation\n [0xc0a80000, 16], // private\n [0xc6120000, 15], // benchmarking, 198.18.0.0/15\n [0xc6336400, 24], // documentation\n [0xcb007100, 24], // documentation\n [0xe0000000, 4], // multicast\n [0xf0000000, 4], // reserved, and the broadcast address\n];\n\n/** The four parts of an IPv4 address as one number, or `undefined` when `text` is not a dotted quad. */\nfunction parseIpv4(text: string): number | undefined {\n const parts = text.split(\".\");\n if (parts.length !== 4) return undefined;\n let value = 0;\n for (const part of parts) {\n if (!/^(0|[1-9][0-9]{0,2})$/.test(part)) return undefined;\n const octet = Number(part);\n if (octet > 255) return undefined;\n value = value * 256 + octet;\n }\n return value;\n}\n\n/** The 16-bit groups in one side of an IPv6 address, where the last piece may be a dotted IPv4 address. */\nfunction readGroups(side: string): number[] | undefined {\n if (side === \"\") return [];\n const groups: number[] = [];\n const pieces = side.split(\":\");\n for (const [index, piece] of pieces.entries()) {\n const v4 = index === pieces.length - 1 && piece.includes(\".\") ? parseIpv4(piece) : undefined;\n if (v4 !== undefined) {\n groups.push(Math.floor(v4 / 65536), v4 % 65536);\n } else if (/^[0-9a-fA-F]{1,4}$/.test(piece)) {\n groups.push(Number.parseInt(piece, 16));\n } else {\n return undefined;\n }\n }\n return groups;\n}\n\n/** The eight 16-bit groups of an IPv6 address, or `undefined` when `text` is not one. */\nfunction parseIpv6(text: string): number[] | undefined {\n const whole = text.split(\"%\")[0] ?? text;\n const doubles = whole.split(\"::\");\n if (doubles.length > 2) return undefined;\n const head = readGroups(doubles[0] ?? \"\");\n const tail = doubles.length === 2 ? readGroups(doubles[1] ?? \"\") : [];\n if (head === undefined || tail === undefined) return undefined;\n if (doubles.length === 1) return head.length === 8 ? head : undefined;\n const missing = 8 - head.length - tail.length;\n return missing >= 1 ? [...head, ...new Array<number>(missing).fill(0), ...tail] : undefined;\n}\n\nfunction ipv4Refused(value: number): boolean {\n return IPV4_REFUSED.some(([base, bits]) => {\n const size = 2 ** (32 - bits);\n return Math.floor(value / size) === Math.floor(base / size);\n });\n}\n\n/** The IPv6 prefixes a proxy refuses, as the leading groups and the prefix length in bits. */\nconst IPV6_REFUSED: readonly (readonly [readonly number[], number])[] = [\n [[0, 0, 0, 0, 0, 0, 0, 0], 128], // ::, unspecified\n [[0, 0, 0, 0, 0, 0, 0, 1], 128], // ::1, loopback\n [[0x64, 0xff9b, 1], 48], // 64:ff9b:1::/48, local-use NAT64\n [[0x100], 64], // 100::/64, discard-only\n [[0x2001, 0], 23], // 2001::/23: Teredo, benchmarking, ORCHID and protocol assignments\n [[0x2001, 0x0db8], 32], // documentation\n [[0x3fff], 20], // 3fff::/20, documentation\n [[0x5f00], 16], // segment routing SIDs\n [[0xfc00], 7], // unique local\n [[0xfe80], 10], // link-local\n [[0xfec0], 10], // site-local, deprecated\n [[0xff00], 8], // multicast\n];\n\n/** Whether the first `bits` bits of `groups` equal those of `prefix`. */\nfunction inPrefix(groups: readonly number[], prefix: readonly number[], bits: number): boolean {\n for (let index = 0; index * 16 < bits; index += 1) {\n const take = Math.min(16, bits - index * 16);\n const mask = (0xffff << (16 - take)) & 0xffff;\n if (((groups[index] ?? 0) & mask) !== ((prefix[index] ?? 0) & mask)) return false;\n }\n return true;\n}\n\n/** The IPv4 address an IPv6 one carries, as a number: mapped, compatible, translated, NAT64 and 6to4 forms. */\nfunction wrappedIpv4(groups: readonly number[]): number | undefined {\n const [a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0, h = 0] = groups;\n const zeroHigh = a === 0 && b === 0 && c === 0 && d === 0;\n const low = g * 65536 + h;\n if (zeroHigh && e === 0 && (f === 0xffff || f === 0)) return low; // ::ffff:a.b.c.d and ::a.b.c.d\n if (zeroHigh && e === 0xffff && f === 0) return low; // ::ffff:0:a.b.c.d, IPv4-translated\n if (a === 0x64 && b === 0xff9b && c === 0 && d === 0 && e === 0 && f === 0) return low; // 64:ff9b::/96\n return a === 0x2002 ? b * 65536 + c : undefined; // 6to4 wraps the address in its next two groups\n}\n\n/** Whether an IPv6 address, as eight groups, is one a proxy refuses. */\nfunction ipv6Refused(groups: readonly number[]): boolean {\n const wrapped = wrappedIpv4(groups);\n if (wrapped !== undefined && ipv4Refused(wrapped)) return true;\n return IPV6_REFUSED.some(([prefix, bits]) => inPrefix(groups, prefix, bits));\n}\n\n/**\n * Whether `address` is a public one a proxy may connect to. Text that isn't an IPv4 or IPv6 address is not public, so a\n * resolver's odd answer is refused instead of passed on.\n */\nexport function isPublicAddress(address: string): boolean {\n const bare = address.startsWith(\"[\") && address.endsWith(\"]\") ? address.slice(1, -1) : address;\n const v4 = parseIpv4(bare);\n if (v4 !== undefined) return !ipv4Refused(v4);\n const v6 = parseIpv6(bare);\n return v6 !== undefined && !ipv6Refused(v6);\n}\n\n/** Whether `text` is an IPv4 or IPv6 address, as a host name that must not be looked up. */\nexport function isAddressLiteral(text: string): boolean {\n const bare = text.startsWith(\"[\") && text.endsWith(\"]\") ? text.slice(1, -1) : text;\n return parseIpv4(bare) !== undefined || parseIpv6(bare) !== undefined;\n}\n"]}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { type GitRouteFilter } from "./git-route.js";
|
|
2
|
+
/** A host the proxy may reach on one port. A `*.` name matches every name under it, and never the name itself. */
|
|
3
|
+
export interface AllowEntry {
|
|
4
|
+
readonly name: string;
|
|
5
|
+
readonly wildcard: boolean;
|
|
6
|
+
readonly port: number;
|
|
7
|
+
}
|
|
8
|
+
/** One credential route: where a request for `/<route>/…` goes, and how the proxy adds the credential. */
|
|
9
|
+
export interface CredentialRoute {
|
|
10
|
+
/** The first part of the path the sandbox requests, such as `github`. Lower case letters, digits, `-` and `_`. */
|
|
11
|
+
readonly route: string;
|
|
12
|
+
/** The HTTPS host the request is forwarded to, such as `api.github.com`, with `:port` when it isn't 443. */
|
|
13
|
+
readonly host: string;
|
|
14
|
+
/** The methods the route accepts, such as `["GET"]`. A request with another method is refused. */
|
|
15
|
+
readonly methods: readonly string[];
|
|
16
|
+
/** The request header that carries the credential, such as `authorization`. */
|
|
17
|
+
readonly header: string;
|
|
18
|
+
/** The real secret, read at each request so a rotated key is used at once. It never enters the sandbox. */
|
|
19
|
+
readonly secret: () => Promise<string>;
|
|
20
|
+
/**
|
|
21
|
+
* Makes the route a git route: only git's smart HTTP requests for the listed repositories pass, a push only to the
|
|
22
|
+
* listed branches, and the secret goes in HTTP Basic as the password of `username`. Its `header` must be
|
|
23
|
+
* `authorization` and its `methods` `GET` and `POST`. The sandbox's git sends the route's sentinel as its password.
|
|
24
|
+
*/
|
|
25
|
+
readonly git?: GitRouteFilter;
|
|
26
|
+
}
|
|
27
|
+
/** A route with its host and port split, its method and header names normalised, and its sentinel. */
|
|
28
|
+
export interface ParsedRoute {
|
|
29
|
+
readonly route: string;
|
|
30
|
+
readonly hostname: string;
|
|
31
|
+
readonly port: number;
|
|
32
|
+
readonly methods: ReadonlySet<string>;
|
|
33
|
+
readonly header: string;
|
|
34
|
+
readonly secret: () => Promise<string>;
|
|
35
|
+
readonly git?: GitRouteFilter;
|
|
36
|
+
}
|
|
37
|
+
/** Parses the allowlist: each entry is `name`, `*.name`, with `:port` when it isn't 443. */
|
|
38
|
+
export declare function parseAllow(entries: readonly string[]): AllowEntry[];
|
|
39
|
+
/** Whether `host` on `port` is on the allowlist. `host` is lower case, without a trailing dot. */
|
|
40
|
+
export declare function isAllowed(allow: readonly AllowEntry[], host: string, port: number): boolean;
|
|
41
|
+
/**
|
|
42
|
+
* The first git route that shares its host with a way around its filter, and what that way is: an allowlist entry, on
|
|
43
|
+
* any port, that lets a tunnel reach the host, or another route to the same host, which would carry a credential there
|
|
44
|
+
* without the git route's repository and ref checks. Hosts are compared in lower case without their ports.
|
|
45
|
+
*/
|
|
46
|
+
export declare function gitHostOverlap(routes: readonly Pick<CredentialRoute, "host" | "git">[], allow: readonly AllowEntry[]): {
|
|
47
|
+
readonly index: number;
|
|
48
|
+
readonly with: "allow" | "route";
|
|
49
|
+
} | undefined;
|
|
50
|
+
/**
|
|
51
|
+
* Parses and checks the routes against the parsed allowlist. It refuses two routes with one name, and a git route whose
|
|
52
|
+
* host is also on the allowlist or is another route's host, because either would go around its filter.
|
|
53
|
+
*/
|
|
54
|
+
export declare function parseRoutes(routes: readonly CredentialRoute[], allow: readonly AllowEntry[]): ParsedRoute[];
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The egress proxy's configuration, checked once when it starts: the allowlist of names and the credential routes. A
|
|
3
|
+
* bad entry throws, so a typo can't widen what leaves the machine. It is pure and portable.
|
|
4
|
+
*/
|
|
5
|
+
import { HarnessError } from "../errors.js";
|
|
6
|
+
import { isAddressLiteral } from "./addresses.js";
|
|
7
|
+
import { checkGitFilter } from "./git-route.js";
|
|
8
|
+
const HOST_NAME = /^[a-z0-9]([a-z0-9-]*[a-z0-9])?(\.[a-z0-9]([a-z0-9-]*[a-z0-9])?)*$/;
|
|
9
|
+
const ROUTE_NAME = /^[a-z0-9][a-z0-9_-]{0,63}$/;
|
|
10
|
+
const HEADER_NAME = /^[!#$%&'*+.^_`|~0-9a-z-]+$/;
|
|
11
|
+
const METHOD = /^[A-Z]{3,10}$/;
|
|
12
|
+
// Headers the proxy sets or removes itself, so a route can't name one as its credential header.
|
|
13
|
+
const RESERVED_HEADERS = new Set([
|
|
14
|
+
"host",
|
|
15
|
+
"content-length",
|
|
16
|
+
"transfer-encoding",
|
|
17
|
+
"connection",
|
|
18
|
+
"keep-alive",
|
|
19
|
+
"te",
|
|
20
|
+
"trailer",
|
|
21
|
+
"upgrade",
|
|
22
|
+
"proxy-authorization",
|
|
23
|
+
"proxy-authenticate",
|
|
24
|
+
"proxy-connection",
|
|
25
|
+
]);
|
|
26
|
+
function invalid(message) {
|
|
27
|
+
return new HarnessError("invalid_egress_options", message);
|
|
28
|
+
}
|
|
29
|
+
/** The lower-case host name and the port of `text`, which is `name` or `name:port`, or an error. */
|
|
30
|
+
function splitHost(text, what) {
|
|
31
|
+
const [name = "", port, extra] = text.toLowerCase().split(":");
|
|
32
|
+
const portNumber = port === undefined ? 443 : Number(port);
|
|
33
|
+
if (extra !== undefined || !Number.isInteger(portNumber) || portNumber < 1 || portNumber > 65535) {
|
|
34
|
+
throw invalid(`${what} ${JSON.stringify(text)} has a bad port`);
|
|
35
|
+
}
|
|
36
|
+
return { name, port: portNumber };
|
|
37
|
+
}
|
|
38
|
+
/** Parses the allowlist: each entry is `name`, `*.name`, with `:port` when it isn't 443. */
|
|
39
|
+
export function parseAllow(entries) {
|
|
40
|
+
return entries.map((entry) => {
|
|
41
|
+
const wildcard = entry.startsWith("*.");
|
|
42
|
+
const { name, port } = splitHost(wildcard ? entry.slice(2) : entry, "the allowlist entry");
|
|
43
|
+
if (!HOST_NAME.test(name) || isAddressLiteral(name)) {
|
|
44
|
+
throw invalid(`the allowlist entry ${JSON.stringify(entry)} must be a host name, such as example.com or *.example.com`);
|
|
45
|
+
}
|
|
46
|
+
return { name, wildcard, port };
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
/** Whether `host` on `port` is on the allowlist. `host` is lower case, without a trailing dot. */
|
|
50
|
+
export function isAllowed(allow, host, port) {
|
|
51
|
+
return allow.some((entry) => entry.port === port && (entry.wildcard ? host.endsWith(`.${entry.name}`) : host === entry.name));
|
|
52
|
+
}
|
|
53
|
+
/** Whether `name` is on the allowlist on any port, so a tunnel could reach it. */
|
|
54
|
+
const allowedOnAnyPort = (allow, name) => allow.some((entry) => (entry.wildcard ? name.endsWith(`.${entry.name}`) : name === entry.name));
|
|
55
|
+
/**
|
|
56
|
+
* The first git route that shares its host with a way around its filter, and what that way is: an allowlist entry, on
|
|
57
|
+
* any port, that lets a tunnel reach the host, or another route to the same host, which would carry a credential there
|
|
58
|
+
* without the git route's repository and ref checks. Hosts are compared in lower case without their ports.
|
|
59
|
+
*/
|
|
60
|
+
export function gitHostOverlap(routes, allow) {
|
|
61
|
+
const names = routes.map((route) => String(route.host)
|
|
62
|
+
.toLowerCase()
|
|
63
|
+
.replace(/:[0-9]*$/, ""));
|
|
64
|
+
for (const [index, route] of routes.entries()) {
|
|
65
|
+
if (route.git === undefined)
|
|
66
|
+
continue;
|
|
67
|
+
const name = names[index] ?? "";
|
|
68
|
+
if (allowedOnAnyPort(allow, name))
|
|
69
|
+
return { index, with: "allow" };
|
|
70
|
+
if (names.some((other, at) => at !== index && other === name))
|
|
71
|
+
return { index, with: "route" };
|
|
72
|
+
}
|
|
73
|
+
return undefined;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Parses and checks the routes against the parsed allowlist. It refuses two routes with one name, and a git route whose
|
|
77
|
+
* host is also on the allowlist or is another route's host, because either would go around its filter.
|
|
78
|
+
*/
|
|
79
|
+
export function parseRoutes(routes, allow) {
|
|
80
|
+
const seen = new Set();
|
|
81
|
+
const parsed = routes.map((route) => {
|
|
82
|
+
if (!ROUTE_NAME.test(route.route))
|
|
83
|
+
throw invalid(`the route name ${JSON.stringify(route.route)} is not usable`);
|
|
84
|
+
if (seen.has(route.route))
|
|
85
|
+
throw invalid(`two routes are named ${route.route}`);
|
|
86
|
+
seen.add(route.route);
|
|
87
|
+
return parseRoute(route);
|
|
88
|
+
});
|
|
89
|
+
const overlap = gitHostOverlap(routes, allow);
|
|
90
|
+
if (overlap !== undefined) {
|
|
91
|
+
const name = routes[overlap.index]?.route ?? "";
|
|
92
|
+
throw invalid(overlap.with === "allow"
|
|
93
|
+
? `the host of the git route ${name} is also on the allowlist, so a tunnel could go around its filter`
|
|
94
|
+
: `the host of the git route ${name} is another route's host, which could go around its filter`);
|
|
95
|
+
}
|
|
96
|
+
return parsed;
|
|
97
|
+
}
|
|
98
|
+
/** Parses and checks one route's host, methods, header, secret and git filter. */
|
|
99
|
+
function parseRoute(route) {
|
|
100
|
+
const { name, port } = splitHost(route.host, "the route host");
|
|
101
|
+
if (!HOST_NAME.test(name) || isAddressLiteral(name))
|
|
102
|
+
throw invalid(`the route host ${route.host} must be a host name`);
|
|
103
|
+
const methods = route.methods.map((method) => method.toUpperCase());
|
|
104
|
+
if (methods.length === 0 || !methods.every((method) => METHOD.test(method)) || methods.includes("CONNECT")) {
|
|
105
|
+
throw invalid(`the route ${route.route} needs a list of methods, such as ["GET"]`);
|
|
106
|
+
}
|
|
107
|
+
const header = route.header.toLowerCase();
|
|
108
|
+
if (!HEADER_NAME.test(header) || RESERVED_HEADERS.has(header)) {
|
|
109
|
+
throw invalid(`the route ${route.route} can't carry its credential in the header ${route.header}`);
|
|
110
|
+
}
|
|
111
|
+
if (typeof route.secret !== "function")
|
|
112
|
+
throw invalid(`the route ${route.route} needs a secret function`);
|
|
113
|
+
if (route.git !== undefined)
|
|
114
|
+
checkGitRoute(route.git, methods, header);
|
|
115
|
+
return {
|
|
116
|
+
route: route.route,
|
|
117
|
+
hostname: name,
|
|
118
|
+
port,
|
|
119
|
+
methods: new Set(methods),
|
|
120
|
+
header,
|
|
121
|
+
secret: route.secret,
|
|
122
|
+
...(route.git === undefined ? {} : { git: route.git }),
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
/** Throws unless a git route carries its credential in `authorization` and takes exactly `GET` and `POST`. */
|
|
126
|
+
function checkGitRoute(filter, methods, header) {
|
|
127
|
+
checkGitFilter(filter);
|
|
128
|
+
if (header !== "authorization")
|
|
129
|
+
throw invalid("a git route carries its credential in the authorization header");
|
|
130
|
+
if (new Set(methods).size !== 2 || !methods.includes("GET") || !methods.includes("POST")) {
|
|
131
|
+
throw invalid("a git route takes the methods GET and POST");
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
//# sourceMappingURL=allowlist.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"allowlist.js","sourceRoot":"","sources":["../../src/credentials/allowlist.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAE,cAAc,EAAuB,MAAM,gBAAgB,CAAC;AAwCrE,MAAM,SAAS,GAAG,mEAAmE,CAAC;AACtF,MAAM,UAAU,GAAG,4BAA4B,CAAC;AAChD,MAAM,WAAW,GAAG,4BAA4B,CAAC;AACjD,MAAM,MAAM,GAAG,eAAe,CAAC;AAC/B,gGAAgG;AAChG,MAAM,gBAAgB,GAAG,IAAI,GAAG,CAAC;IAC/B,MAAM;IACN,gBAAgB;IAChB,mBAAmB;IACnB,YAAY;IACZ,YAAY;IACZ,IAAI;IACJ,SAAS;IACT,SAAS;IACT,qBAAqB;IACrB,oBAAoB;IACpB,kBAAkB;CACnB,CAAC,CAAC;AAEH,SAAS,OAAO,CAAC,OAAe;IAC9B,OAAO,IAAI,YAAY,CAAC,wBAAwB,EAAE,OAAO,CAAC,CAAC;AAC7D,CAAC;AAED,oGAAoG;AACpG,SAAS,SAAS,CAAC,IAAY,EAAE,IAAY;IAC3C,MAAM,CAAC,IAAI,GAAG,EAAE,EAAE,IAAI,EAAE,KAAK,CAAC,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC/D,MAAM,UAAU,GAAG,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAC3D,IAAI,KAAK,KAAK,SAAS,IAAI,CAAC,MAA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CAAC,GAAG,EAAE,CAAC;KACvD,CAAC;AACJ,CAAC;AAED,8GAA8G;AAC9G,SAAS,aAAa,CAAC,MAAsB,EAAE,OAA0B,EAAE,MAAc;IACvF,cAAc,CAAC,MAAM,CAAC,CAAC;IACvB,IAAI,MAAM,KAAK,eAAe;QAAE,MAAM,OAAO,CAAC,gEAAgE,CAAC,CAAC;IAChH,IAAI,IAAI,GAAG,CAAC,OAAO,CAAC,CAAC,IAAI,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;QACzF,MAAM,OAAO,CAAC,4CAA4C,CAAC,CAAC;IAC9D,CAAC;AACH,CAAC","sourcesContent":["/**\n * The egress proxy's configuration, checked once when it starts: the allowlist of names and the credential routes. A\n * bad entry throws, so a typo can't widen what leaves the machine. It is pure and portable.\n */\nimport { HarnessError } from \"../errors.js\";\nimport { isAddressLiteral } from \"./addresses.js\";\nimport { checkGitFilter, type GitRouteFilter } from \"./git-route.js\";\n\n/** A host the proxy may reach on one port. A `*.` name matches every name under it, and never the name itself. */\nexport interface AllowEntry {\n readonly name: string;\n readonly wildcard: boolean;\n readonly port: number;\n}\n\n/** One credential route: where a request for `/<route>/…` goes, and how the proxy adds the credential. */\nexport interface CredentialRoute {\n /** The first part of the path the sandbox requests, such as `github`. Lower case letters, digits, `-` and `_`. */\n readonly route: string;\n /** The HTTPS host the request is forwarded to, such as `api.github.com`, with `:port` when it isn't 443. */\n readonly host: string;\n /** The methods the route accepts, such as `[\"GET\"]`. A request with another method is refused. */\n readonly methods: readonly string[];\n /** The request header that carries the credential, such as `authorization`. */\n readonly header: string;\n /** The real secret, read at each request so a rotated key is used at once. It never enters the sandbox. */\n readonly secret: () => Promise<string>;\n /**\n * Makes the route a git route: only git's smart HTTP requests for the listed repositories pass, a push only to the\n * listed branches, and the secret goes in HTTP Basic as the password of `username`. Its `header` must be\n * `authorization` and its `methods` `GET` and `POST`. The sandbox's git sends the route's sentinel as its password.\n */\n readonly git?: GitRouteFilter;\n}\n\n/** A route with its host and port split, its method and header names normalised, and its sentinel. */\nexport interface ParsedRoute {\n readonly route: string;\n readonly hostname: string;\n readonly port: number;\n readonly methods: ReadonlySet<string>;\n readonly header: string;\n readonly secret: () => Promise<string>;\n readonly git?: GitRouteFilter;\n}\n\nconst HOST_NAME = /^[a-z0-9]([a-z0-9-]*[a-z0-9])?(\\.[a-z0-9]([a-z0-9-]*[a-z0-9])?)*$/;\nconst ROUTE_NAME = /^[a-z0-9][a-z0-9_-]{0,63}$/;\nconst HEADER_NAME = /^[!#$%&'*+.^_`|~0-9a-z-]+$/;\nconst METHOD = /^[A-Z]{3,10}$/;\n// Headers the proxy sets or removes itself, so a route can't name one as its credential header.\nconst RESERVED_HEADERS = new Set([\n \"host\",\n \"content-length\",\n \"transfer-encoding\",\n \"connection\",\n \"keep-alive\",\n \"te\",\n \"trailer\",\n \"upgrade\",\n \"proxy-authorization\",\n \"proxy-authenticate\",\n \"proxy-connection\",\n]);\n\nfunction invalid(message: string): HarnessError {\n return new HarnessError(\"invalid_egress_options\", message);\n}\n\n/** The lower-case host name and the port of `text`, which is `name` or `name:port`, or an error. */\nfunction splitHost(text: string, what: string): { name: string; port: number } {\n const [name = \"\", port, extra] = text.toLowerCase().split(\":\");\n const portNumber = port === undefined ? 443 : Number(port);\n if (extra !== undefined || !Number.isInteger(portNumber) || portNumber < 1 || portNumber > 65535) {\n throw invalid(`${what} ${JSON.stringify(text)} has a bad port`);\n }\n return { name, port: portNumber };\n}\n\n/** Parses the allowlist: each entry is `name`, `*.name`, with `:port` when it isn't 443. */\nexport function parseAllow(entries: readonly string[]): AllowEntry[] {\n return entries.map((entry) => {\n const wildcard = entry.startsWith(\"*.\");\n const { name, port } = splitHost(wildcard ? entry.slice(2) : entry, \"the allowlist entry\");\n if (!HOST_NAME.test(name) || isAddressLiteral(name)) {\n throw invalid(\n `the allowlist entry ${JSON.stringify(entry)} must be a host name, such as example.com or *.example.com`,\n );\n }\n return { name, wildcard, port };\n });\n}\n\n/** Whether `host` on `port` is on the allowlist. `host` is lower case, without a trailing dot. */\nexport function isAllowed(allow: readonly AllowEntry[], host: string, port: number): boolean {\n return allow.some(\n (entry) => entry.port === port && (entry.wildcard ? host.endsWith(`.${entry.name}`) : host === entry.name),\n );\n}\n\n/** Whether `name` is on the allowlist on any port, so a tunnel could reach it. */\nconst allowedOnAnyPort = (allow: readonly AllowEntry[], name: string): boolean =>\n allow.some((entry) => (entry.wildcard ? name.endsWith(`.${entry.name}`) : name === entry.name));\n\n/**\n * The first git route that shares its host with a way around its filter, and what that way is: an allowlist entry, on\n * any port, that lets a tunnel reach the host, or another route to the same host, which would carry a credential there\n * without the git route's repository and ref checks. Hosts are compared in lower case without their ports.\n */\nexport function gitHostOverlap(\n routes: readonly Pick<CredentialRoute, \"host\" | \"git\">[],\n allow: readonly AllowEntry[],\n): { readonly index: number; readonly with: \"allow\" | \"route\" } | undefined {\n const names = routes.map((route) =>\n String(route.host)\n .toLowerCase()\n .replace(/:[0-9]*$/, \"\"),\n );\n for (const [index, route] of routes.entries()) {\n if (route.git === undefined) continue;\n const name = names[index] ?? \"\";\n if (allowedOnAnyPort(allow, name)) return { index, with: \"allow\" };\n if (names.some((other, at) => at !== index && other === name)) return { index, with: \"route\" };\n }\n return undefined;\n}\n\n/**\n * Parses and checks the routes against the parsed allowlist. It refuses two routes with one name, and a git route whose\n * host is also on the allowlist or is another route's host, because either would go around its filter.\n */\nexport function parseRoutes(routes: readonly CredentialRoute[], allow: readonly AllowEntry[]): ParsedRoute[] {\n const seen = new Set<string>();\n const parsed = routes.map((route) => {\n if (!ROUTE_NAME.test(route.route)) throw invalid(`the route name ${JSON.stringify(route.route)} is not usable`);\n if (seen.has(route.route)) throw invalid(`two routes are named ${route.route}`);\n seen.add(route.route);\n return parseRoute(route);\n });\n const overlap = gitHostOverlap(routes, allow);\n if (overlap !== undefined) {\n const name = routes[overlap.index]?.route ?? \"\";\n throw invalid(\n overlap.with === \"allow\"\n ? `the host of the git route ${name} is also on the allowlist, so a tunnel could go around its filter`\n : `the host of the git route ${name} is another route's host, which could go around its filter`,\n );\n }\n return parsed;\n}\n\n/** Parses and checks one route's host, methods, header, secret and git filter. */\nfunction parseRoute(route: CredentialRoute): ParsedRoute {\n const { name, port } = splitHost(route.host, \"the route host\");\n if (!HOST_NAME.test(name) || isAddressLiteral(name))\n throw invalid(`the route host ${route.host} must be a host name`);\n const methods = route.methods.map((method) => method.toUpperCase());\n if (methods.length === 0 || !methods.every((method) => METHOD.test(method)) || methods.includes(\"CONNECT\")) {\n throw invalid(`the route ${route.route} needs a list of methods, such as [\"GET\"]`);\n }\n const header = route.header.toLowerCase();\n if (!HEADER_NAME.test(header) || RESERVED_HEADERS.has(header)) {\n throw invalid(`the route ${route.route} can't carry its credential in the header ${route.header}`);\n }\n if (typeof route.secret !== \"function\") throw invalid(`the route ${route.route} needs a secret function`);\n if (route.git !== undefined) checkGitRoute(route.git, methods, header);\n return {\n route: route.route,\n hostname: name,\n port,\n methods: new Set(methods),\n header,\n secret: route.secret,\n ...(route.git === undefined ? {} : { git: route.git }),\n };\n}\n\n/** Throws unless a git route carries its credential in `authorization` and takes exactly `GET` and `POST`. */\nfunction checkGitRoute(filter: GitRouteFilter, methods: readonly string[], header: string): void {\n checkGitFilter(filter);\n if (header !== \"authorization\") throw invalid(\"a git route carries its credential in the authorization header\");\n if (new Set(methods).size !== 2 || !methods.includes(\"GET\") || !methods.includes(\"POST\")) {\n throw invalid(\"a git route takes the methods GET and POST\");\n }\n}\n"]}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { type CredentialRoute } from "./allowlist.js";
|
|
2
|
+
/** A route that swaps the sentinel in one request header for a credential, as `startEgressProxy()`'s routes do. */
|
|
3
|
+
export interface HeaderEgressRoute {
|
|
4
|
+
readonly kind: "header";
|
|
5
|
+
/** The first part of the path the sandbox requests, such as `github`. Lower case letters, digits, `-` and `_`. */
|
|
6
|
+
readonly route: string;
|
|
7
|
+
/** The HTTPS host the request is forwarded to, such as `api.github.com`, with `:port` when it isn't 443. */
|
|
8
|
+
readonly host: string;
|
|
9
|
+
/** The methods the route accepts, such as `["GET"]`. */
|
|
10
|
+
readonly methods: readonly string[];
|
|
11
|
+
/** The request header that carries the credential, such as `authorization`. */
|
|
12
|
+
readonly header: string;
|
|
13
|
+
/** The name of the credential the host injects, in upper case, such as `GITHUB_TOKEN`. Never the credential. */
|
|
14
|
+
readonly credential: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* A route for git over HTTPS: git's smart HTTP requests for the listed repositories only, and a push only to the listed
|
|
18
|
+
* branches. A deletion and a tag are always refused, and so is anything the route can't parse.
|
|
19
|
+
*/
|
|
20
|
+
export interface GitEgressRoute {
|
|
21
|
+
readonly kind: "git";
|
|
22
|
+
/** The first part of the path the sandbox's git remote uses, such as `git`. */
|
|
23
|
+
readonly route: string;
|
|
24
|
+
/** The git host, such as `github.com`. */
|
|
25
|
+
readonly host: string;
|
|
26
|
+
/** The repositories the route reaches, as `owner/name`. */
|
|
27
|
+
readonly repositories: readonly string[];
|
|
28
|
+
/** The branches a push may create or update, such as `refs/heads/agent/*`. Leave it out to refuse every push. */
|
|
29
|
+
readonly pushRefs?: readonly string[];
|
|
30
|
+
/** Whether a fetch or clone may read the repositories. Defaults to `false`. */
|
|
31
|
+
readonly fetch?: boolean;
|
|
32
|
+
/** The user name sent with the credential in HTTP Basic. Defaults to `x-access-token`, which GitHub App tokens use. */
|
|
33
|
+
readonly username?: string;
|
|
34
|
+
/** The name of the credential the host injects, in upper case, such as `GITHUB_TOKEN`. Never the credential. */
|
|
35
|
+
readonly credential: string;
|
|
36
|
+
}
|
|
37
|
+
/** One credential route of an `EgressPolicy`. */
|
|
38
|
+
export type EgressRoute = HeaderEgressRoute | GitEgressRoute;
|
|
39
|
+
/** What a sandbox may reach: the hosts it may tunnel to, and the routes that add a credential on its behalf. */
|
|
40
|
+
export interface EgressPolicy {
|
|
41
|
+
/** Exact host names, with `:port` when it isn't 443. A wildcard and an address literal are refused. */
|
|
42
|
+
readonly allow: readonly string[];
|
|
43
|
+
readonly routes: readonly EgressRoute[];
|
|
44
|
+
}
|
|
45
|
+
/** The options of `compileEgressPolicy()`. */
|
|
46
|
+
export interface CompileEgressOptions {
|
|
47
|
+
/** Reads the credential a route names, at each request, on the host. It never runs in the sandbox. */
|
|
48
|
+
readonly secret: (name: string) => Promise<string>;
|
|
49
|
+
}
|
|
50
|
+
/** A compiled policy: the `allow` and `routes` options of `startEgressProxy()`. */
|
|
51
|
+
export interface CompiledEgressPolicy {
|
|
52
|
+
readonly allow: readonly string[];
|
|
53
|
+
readonly routes: readonly CredentialRoute[];
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Checks `policy` and compiles it for `startEgressProxy()`: pass the result's `allow` and `routes` with a `log`.
|
|
57
|
+
* Everything is refused that isn't plainly allowed, with `HarnessError` code `invalid_egress_options`, and the
|
|
58
|
+
* message names the entry's place, never its value:
|
|
59
|
+
*
|
|
60
|
+
* - a field a route kind doesn't have, such as `secret` or `token`, and a credential that is not an upper-case name;
|
|
61
|
+
* - any string in the policy that looks like a credential, such as one starting `ghp_` or `sk-`;
|
|
62
|
+
* - a wildcard or an address literal in `allow` or a route's host;
|
|
63
|
+
* - a git route whose host is also in `allow`, because a tunnel to it would go around the ref filter, and a git route
|
|
64
|
+
* whose host is another route's host, because that route would carry a credential there without the ref filter;
|
|
65
|
+
* - a git route with no repository, a push ref outside `refs/heads/`, or neither a push nor a fetch.
|
|
66
|
+
*
|
|
67
|
+
* The compiled routes read each credential through `options.secret` at every request, so a rotated one is used at once.
|
|
68
|
+
*/
|
|
69
|
+
export declare function compileEgressPolicy(policy: EgressPolicy, options: CompileEgressOptions): CompiledEgressPolicy;
|