@intentic/sandbox-contract 1.365.0 → 1.367.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/contracts/agent.contract.d.ts +9 -0
- package/dist/contracts/agent.contract.d.ts.map +1 -1
- package/dist/contracts/agents.contract.d.ts +2 -0
- package/dist/contracts/agents.contract.d.ts.map +1 -1
- package/dist/contracts/device.contract.d.ts +43 -0
- package/dist/contracts/device.contract.d.ts.map +1 -1
- package/dist/contracts/needs.contract.d.ts +237 -0
- package/dist/contracts/needs.contract.d.ts.map +1 -1
- package/dist/contracts/needs.contract.js +10 -1
- package/dist/contracts/needs.contract.js.map +1 -1
- package/dist/contracts/ports.contract.d.ts +25 -0
- package/dist/contracts/ports.contract.d.ts.map +1 -1
- package/dist/contracts/ports.contract.js +29 -1
- package/dist/contracts/ports.contract.js.map +1 -1
- package/dist/contracts/runner.contract.d.ts +6 -0
- package/dist/contracts/runner.contract.d.ts.map +1 -1
- package/dist/contracts/sessions.contract.d.ts +1 -0
- package/dist/contracts/sessions.contract.d.ts.map +1 -1
- package/dist/contracts/system.contract.d.ts +155 -30
- package/dist/contracts/system.contract.d.ts.map +1 -1
- package/dist/contracts/system.contract.js +9 -0
- package/dist/contracts/system.contract.js.map +1 -1
- package/dist/events/agent-events.d.ts +5 -0
- package/dist/events/agent-events.d.ts.map +1 -1
- package/dist/events/agent-events.js +1 -0
- package/dist/events/agent-events.js.map +1 -1
- package/dist/events/agent-transcript.d.ts +1 -0
- package/dist/events/agent-transcript.d.ts.map +1 -1
- package/dist/events/transcript.d.ts +6 -0
- package/dist/events/transcript.d.ts.map +1 -1
- package/dist/events/transcript.js +4 -0
- package/dist/events/transcript.js.map +1 -1
- package/dist/index.d.ts +429 -30
- package/dist/index.d.ts.map +1 -1
- package/dist/netd/generated/wire.d.ts +8 -0
- package/dist/netd/generated/wire.d.ts.map +1 -1
- package/dist/protocol/raw/raw-json-routes.d.ts +3 -0
- package/dist/protocol/raw/raw-json-routes.d.ts.map +1 -1
- package/dist/schemas/dev-rebuild-log.d.ts +2 -0
- package/dist/schemas/dev-rebuild-log.d.ts.map +1 -1
- package/dist/schemas/dev-rebuild-log.js +7 -1
- package/dist/schemas/dev-rebuild-log.js.map +1 -1
- package/dist/schemas/device-commands.d.ts +1 -1
- package/dist/schemas/device-commands.d.ts.map +1 -1
- package/dist/schemas/device-commands.js +1 -1
- package/dist/schemas/device-commands.js.map +1 -1
- package/dist/schemas/devices.d.ts +249 -0
- package/dist/schemas/devices.d.ts.map +1 -1
- package/dist/schemas/devices.js +6 -0
- package/dist/schemas/devices.js.map +1 -1
- package/dist/schemas/egress.d.ts +238 -0
- package/dist/schemas/egress.d.ts.map +1 -0
- package/dist/schemas/egress.js +192 -0
- package/dist/schemas/egress.js.map +1 -0
- package/dist/schemas/hosts.d.ts +2 -0
- package/dist/schemas/hosts.d.ts.map +1 -1
- package/dist/schemas/hosts.js +2 -0
- package/dist/schemas/hosts.js.map +1 -1
- package/dist/schemas/members.d.ts +4 -0
- package/dist/schemas/members.d.ts.map +1 -1
- package/dist/schemas/members.js +1 -1
- package/dist/schemas/members.js.map +1 -1
- package/dist/schemas/needs.d.ts +8 -0
- package/dist/schemas/needs.d.ts.map +1 -1
- package/dist/schemas/needs.js +8 -1
- package/dist/schemas/needs.js.map +1 -1
- package/dist/schemas/ports.d.ts +21 -0
- package/dist/schemas/ports.d.ts.map +1 -1
- package/dist/schemas/ports.js +12 -0
- package/dist/schemas/ports.js.map +1 -1
- package/dist/state/auth-state.d.ts.map +1 -1
- package/dist/state/auth-state.js +1 -0
- package/dist/state/auth-state.js.map +1 -1
- package/dist/text/transcript-fold.d.ts.map +1 -1
- package/dist/text/transcript-fold.js +1 -0
- package/dist/text/transcript-fold.js.map +1 -1
- package/package.json +5 -5
- package/src/contracts/needs.contract.ts +11 -0
- package/src/contracts/ports.contract.ts +42 -1
- package/src/contracts/system.contract.ts +12 -0
- package/src/events/agent-events.ts +2 -0
- package/src/events/transcript.ts +5 -0
- package/src/netd/generated/netd-wire.json +44 -0
- package/src/netd/generated/wire.ts +36 -1
- package/src/schemas/dev-rebuild-log.test.ts +10 -1
- package/src/schemas/dev-rebuild-log.ts +14 -1
- package/src/schemas/device-commands.ts +1 -0
- package/src/schemas/devices.ts +14 -0
- package/src/schemas/egress-private.test.ts +17 -0
- package/src/schemas/egress.test.ts +109 -0
- package/src/schemas/egress.ts +331 -0
- package/src/schemas/hosts.ts +3 -0
- package/src/schemas/members.ts +7 -5
- package/src/schemas/needs.ts +9 -1
- package/src/schemas/ports.ts +25 -0
- package/src/state/auth-state.ts +3 -0
- package/src/text/transcript-fold.test.ts +7 -0
- package/src/text/transcript-fold.ts +1 -0
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
// egress: what a sandbox may reach on the networks around the machine it runs on, enforced by `ic` on the host.
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { AuthenticationResponseSchema } from "./system.js";
|
|
4
|
+
|
|
5
|
+
// WHY THIS LIVES ON THE HOST. The agent is root in its container, a `vpn` or `exit` card gives the container
|
|
6
|
+
// NET_ADMIN, and the Docker capability makes it privileged, so no rule inside the container can fence it. `ic` puts the
|
|
7
|
+
// rules in the host's network namespace (one nftables table of its own, `inet intentic_egress`), where the sandbox's
|
|
8
|
+
// traffic meets the uplink, and it is the only writer of the policy: the daemon shows it and asks for changes, the
|
|
9
|
+
// machine agent decides whether a change may be carried out, ic carries it out. A sandbox is matched by its own network
|
|
10
|
+
// when ic made that network for it, and by its addresses when something else did (Docker Compose), which ic follows
|
|
11
|
+
// through docker's events so a recreate is fenced within a second.
|
|
12
|
+
|
|
13
|
+
// `open` is today's behaviour, nothing fenced. `internet-only` refuses every private, link-local, shared and
|
|
14
|
+
// multicast range and the machine itself, except the listed `allow` entries; the internet stays reachable. A profile
|
|
15
|
+
// further down this list is tighter; a later one (an allowlist of hostnames) goes after the last.
|
|
16
|
+
export const EgressProfileSchema = z.enum(["open", "internet-only"]);
|
|
17
|
+
export type EgressProfile = z.infer<typeof EgressProfileSchema>;
|
|
18
|
+
export const EGRESS_PROFILE_RANK = { open: 0, "internet-only": 1 } as const satisfies Record<EgressProfile, number>;
|
|
19
|
+
|
|
20
|
+
// What `internet-only` refuses. RFC 1918 and the loopback/unspecified blocks, CGNAT space (Tailscale lives there),
|
|
21
|
+
// link-local (where cloud metadata answers, 169.254.169.254), the documentation, benchmarking and reserved blocks,
|
|
22
|
+
// multicast; for IPv6 the unique-local (fc00::/7), link-local, site-local and multicast prefixes and the IPv4-mapped
|
|
23
|
+
// space, so a mapped address cannot walk around the IPv4 set. The machine's own addresses are refused separately (the
|
|
24
|
+
// input hook), whatever they are.
|
|
25
|
+
export const EGRESS_PRIVATE_V4: readonly string[] = [
|
|
26
|
+
"0.0.0.0/8",
|
|
27
|
+
"10.0.0.0/8",
|
|
28
|
+
"100.64.0.0/10",
|
|
29
|
+
"127.0.0.0/8",
|
|
30
|
+
"169.254.0.0/16",
|
|
31
|
+
"172.16.0.0/12",
|
|
32
|
+
"192.0.0.0/24",
|
|
33
|
+
"192.0.2.0/24",
|
|
34
|
+
"192.168.0.0/16",
|
|
35
|
+
"198.18.0.0/15",
|
|
36
|
+
"198.51.100.0/24",
|
|
37
|
+
"203.0.113.0/24",
|
|
38
|
+
"224.0.0.0/4",
|
|
39
|
+
"240.0.0.0/4",
|
|
40
|
+
];
|
|
41
|
+
export const EGRESS_PRIVATE_V6: readonly string[] = ["::/128", "::1/128", "::ffff:0:0/96", "64:ff9b:1::/48", "fc00::/7", "fe80::/10", "fec0::/10", "ff00::/8"];
|
|
42
|
+
|
|
43
|
+
// THE MACHINE ITSELF, as an `allow` target: whatever addresses the host has (its LAN address, the bridge gateway, the
|
|
44
|
+
// WSL side every distro shares). Kept a word, since those addresses change and only ic can read them.
|
|
45
|
+
export const EGRESS_HOST = "host";
|
|
46
|
+
|
|
47
|
+
const HOSTNAME = /^(?=.{1,253}$)(?!-)[A-Za-z0-9-]{1,63}(?<!-)(\.(?!-)[A-Za-z0-9-]{1,63}(?<!-))*\.?$/u;
|
|
48
|
+
const IPV4 = z.ipv4();
|
|
49
|
+
const CIDRV4 = z.cidrv4();
|
|
50
|
+
const IPV6 = z.ipv6();
|
|
51
|
+
const CIDRV6 = z.cidrv6();
|
|
52
|
+
|
|
53
|
+
export type EgressDestinationKind = "v4" | "v6" | "host" | "name";
|
|
54
|
+
// Which kind a destination is, or undefined when it is none: an address or a prefix of either family, the word
|
|
55
|
+
// `host`, or a hostname ic resolves on the host every time it applies the rules (a NAS named on the LAN's DNS).
|
|
56
|
+
export const egressDestinationKind = (value: string): EgressDestinationKind | undefined => {
|
|
57
|
+
if (value === EGRESS_HOST) {
|
|
58
|
+
return "host";
|
|
59
|
+
}
|
|
60
|
+
if (IPV4.safeParse(value).success || CIDRV4.safeParse(value).success) {
|
|
61
|
+
return "v4";
|
|
62
|
+
}
|
|
63
|
+
if (IPV6.safeParse(value).success || CIDRV6.safeParse(value).success) {
|
|
64
|
+
return "v6";
|
|
65
|
+
}
|
|
66
|
+
// A dotted quad that failed as an address (300.1.1.1) is a typo, never a name.
|
|
67
|
+
if (/^[\d./]+$/u.test(value) || value.includes(":")) {
|
|
68
|
+
return undefined;
|
|
69
|
+
}
|
|
70
|
+
return HOSTNAME.test(value) ? "name" : undefined;
|
|
71
|
+
};
|
|
72
|
+
export const EgressDestinationSchema = z
|
|
73
|
+
.string()
|
|
74
|
+
.trim()
|
|
75
|
+
.min(1)
|
|
76
|
+
.max(253)
|
|
77
|
+
.refine((value) => egressDestinationKind(value) !== undefined, {
|
|
78
|
+
message: "A destination is an address (192.168.1.20), a prefix (192.168.1.0/24, fd00::/8), a hostname (nas.lan) or the word host.",
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
// One port, or an inclusive range spelled `8000-8100`.
|
|
82
|
+
export const EgressPortSchema = z.union([
|
|
83
|
+
z.int().min(1).max(65535),
|
|
84
|
+
z
|
|
85
|
+
.string()
|
|
86
|
+
.regex(/^\d{1,5}-\d{1,5}$/u, "A port range is FROM-TO, like 8000-8100.")
|
|
87
|
+
.refine((range) => {
|
|
88
|
+
const from = Number(range.slice(0, range.indexOf("-")));
|
|
89
|
+
const to = Number(range.slice(range.indexOf("-") + 1));
|
|
90
|
+
return from >= 1 && to <= 65535 && from < to;
|
|
91
|
+
}, "A port range runs upwards inside 1-65535, like 8000-8100."),
|
|
92
|
+
]);
|
|
93
|
+
export type EgressPort = z.infer<typeof EgressPortSchema>;
|
|
94
|
+
|
|
95
|
+
// One way through `internet-only`. `ports` absent means every port, `protocol` absent means TCP and UDP both. `from`
|
|
96
|
+
// names what asked for it (a card's id, `owner`), so a card removed can offer to take its exception with it.
|
|
97
|
+
export const EgressAllowSchema = z.strictObject({
|
|
98
|
+
to: EgressDestinationSchema,
|
|
99
|
+
ports: z.array(EgressPortSchema).min(1).max(32).optional(),
|
|
100
|
+
protocol: z.enum(["tcp", "udp"]).optional(),
|
|
101
|
+
note: z.string().max(200).optional(),
|
|
102
|
+
from: z.string().max(200).optional(),
|
|
103
|
+
});
|
|
104
|
+
export type EgressAllow = z.infer<typeof EgressAllowSchema>;
|
|
105
|
+
|
|
106
|
+
// A sandbox's policy, WHOLE, as ic stores it in the sandbox's record and as a change carries it. `allow` means
|
|
107
|
+
// nothing under `open`, and is kept so turning the fence back on restores the same exceptions.
|
|
108
|
+
export const EgressPolicySchema = z.strictObject({
|
|
109
|
+
profile: EgressProfileSchema,
|
|
110
|
+
allow: z.array(EgressAllowSchema).max(64),
|
|
111
|
+
});
|
|
112
|
+
export type EgressPolicy = z.infer<typeof EgressPolicySchema>;
|
|
113
|
+
export const OPEN_EGRESS: EgressPolicy = { profile: "open", allow: [] };
|
|
114
|
+
|
|
115
|
+
// THE MACHINE'S OWN WORD over every sandbox on it, which a sandbox's policy can only narrow: `/etc/intentic/os.json`'s
|
|
116
|
+
// `egress` on Intentic OS, ic's own `~/.intentic/egress.json` elsewhere. `minimum` lifts every sandbox's profile to at
|
|
117
|
+
// least itself; `neverAllow` is refused before any sandbox's `allow` is read, so no card can open it.
|
|
118
|
+
export const EgressBaselineSchema = z.strictObject({
|
|
119
|
+
minimum: EgressProfileSchema.default("open"),
|
|
120
|
+
neverAllow: z.array(EgressDestinationSchema).max(64).default([]),
|
|
121
|
+
});
|
|
122
|
+
export type EgressBaseline = z.infer<typeof EgressBaselineSchema>;
|
|
123
|
+
|
|
124
|
+
// ---- One spelling of a policy, so two policies that fence the same way compare equal ----
|
|
125
|
+
|
|
126
|
+
// Ports in order of where they start (a range by its first port), duplicates dropped.
|
|
127
|
+
const portStart = (port: EgressPort): number => (Number.isInteger(port) ? Number(port) : Number(String(port).slice(0, String(port).indexOf("-"))));
|
|
128
|
+
const canonicalPorts = (ports: readonly EgressPort[]): EgressPort[] =>
|
|
129
|
+
[...new Map(ports.map((port) => [String(port), port])).values()].toSorted((a, b) => portStart(a) - portStart(b) || String(a).localeCompare(String(b)));
|
|
130
|
+
|
|
131
|
+
// One entry with its keys in one order, so JSON.stringify spells it one way.
|
|
132
|
+
const canonicalAllow = (entry: EgressAllow): EgressAllow => {
|
|
133
|
+
const out: EgressAllow = { to: entry.to.trim().toLowerCase().replace(/\.$/u, "") };
|
|
134
|
+
if (entry.from !== undefined) {
|
|
135
|
+
out.from = entry.from;
|
|
136
|
+
}
|
|
137
|
+
if (entry.note !== undefined) {
|
|
138
|
+
out.note = entry.note;
|
|
139
|
+
}
|
|
140
|
+
if (entry.ports !== undefined) {
|
|
141
|
+
out.ports = canonicalPorts(entry.ports);
|
|
142
|
+
}
|
|
143
|
+
if (entry.protocol !== undefined) {
|
|
144
|
+
out.protocol = entry.protocol;
|
|
145
|
+
}
|
|
146
|
+
return out;
|
|
147
|
+
};
|
|
148
|
+
const byText = <T>(items: readonly T[], text: (item: T) => string): T[] =>
|
|
149
|
+
[...new Map(items.map((item) => [text(item), item])).entries()].toSorted(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0)).map(([, item]) => item);
|
|
150
|
+
|
|
151
|
+
// The policy in its one form: destinations lower-cased, ports deduplicated and in order, entries deduplicated and in
|
|
152
|
+
// order of their text. What `icEgressSetArgs` hands ic, and what the comparisons below read.
|
|
153
|
+
export const canonicalEgressPolicy = (policy: EgressPolicy): EgressPolicy => ({
|
|
154
|
+
allow: byText(policy.allow.map(canonicalAllow), (entry) => JSON.stringify(entry)),
|
|
155
|
+
profile: policy.profile,
|
|
156
|
+
});
|
|
157
|
+
export const canonicalEgressPolicyJson = (policy: EgressPolicy): string => JSON.stringify(canonicalEgressPolicy(policy));
|
|
158
|
+
|
|
159
|
+
// What an exception OPENS, without its labels: two entries reaching the same place are the same way through.
|
|
160
|
+
const reachOf = (entry: EgressAllow): string => JSON.stringify([entry.to, entry.ports ?? null, entry.protocol ?? null]);
|
|
161
|
+
|
|
162
|
+
// WHETHER A CHANGE ONLY TIGHTENS. Tightening needs no proof from any door; anything else needs the owner's passkey,
|
|
163
|
+
// or a door on the machine itself (ic's own CLI, the desktop app). From `open` every policy is tighter. Otherwise the
|
|
164
|
+
// new profile must be at least as tight and every way through it opens must already have been open, compared as
|
|
165
|
+
// written (not as address arithmetic: a narrower prefix typed differently is asked about, never guessed at).
|
|
166
|
+
export const egressOnlyTightens = (from: EgressPolicy, to: EgressPolicy): boolean => {
|
|
167
|
+
if (from.profile === "open") {
|
|
168
|
+
return true;
|
|
169
|
+
}
|
|
170
|
+
if (EGRESS_PROFILE_RANK[to.profile] < EGRESS_PROFILE_RANK[from.profile]) {
|
|
171
|
+
return false;
|
|
172
|
+
}
|
|
173
|
+
const before = new Set(canonicalEgressPolicy(from).allow.map(reachOf));
|
|
174
|
+
return canonicalEgressPolicy(to).allow.every((entry) => before.has(reachOf(entry)));
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
// The revision of the policy ic holds, OPAQUE to everyone but ic: it reports it (EgressStatus.revision), a signed
|
|
178
|
+
// change names it back (`basedOn`), and the machine agent compares the two as strings before carrying the change out.
|
|
179
|
+
// `none` for a sandbox ic holds no policy for.
|
|
180
|
+
export const EGRESS_NO_REVISION = "none";
|
|
181
|
+
|
|
182
|
+
// ---- The owner's passkey over a loosening ----
|
|
183
|
+
|
|
184
|
+
// A passkey's public half as the machine agent pins it: the credential id (base64url) and the key as a JWK with its
|
|
185
|
+
// COSE algorithm (ES256 -7, RS256 -257, EdDSA -8), the daemon's own stored form.
|
|
186
|
+
export const EgressTrustedKeySchema = z.strictObject({
|
|
187
|
+
id: z.string().min(1),
|
|
188
|
+
alg: z.union([z.literal(-7), z.literal(-257), z.literal(-8)]),
|
|
189
|
+
jwk: z.record(z.string(), z.string()),
|
|
190
|
+
// The name the owner gave it in Access → Sign-in, shown wherever the pin is.
|
|
191
|
+
name: z.string().max(200).optional(),
|
|
192
|
+
});
|
|
193
|
+
export type EgressTrustedKey = z.infer<typeof EgressTrustedKeySchema>;
|
|
194
|
+
// The owner's passkeys and where a ceremony with them may run: the editor's rpId, and the exact origins it accepts
|
|
195
|
+
// (`https://<rpId>`, its subdomains the daemon admits, the Android app's `android:apk-key-hash:` origins).
|
|
196
|
+
// Daemon-filled on every `set-egress`; the machine agent pins it on the first one and only ever replaces it under a
|
|
197
|
+
// signature from a key it already pins.
|
|
198
|
+
export const EgressOwnerKeysSchema = z.strictObject({
|
|
199
|
+
rpId: z.string().min(1),
|
|
200
|
+
origins: z.array(z.string().min(1)).min(1).max(16),
|
|
201
|
+
keys: z.array(EgressTrustedKeySchema).max(32),
|
|
202
|
+
});
|
|
203
|
+
export type EgressOwnerKeys = z.infer<typeof EgressOwnerKeysSchema>;
|
|
204
|
+
// The owner keys in one spelling (keys by id, each JWK's members in order, origins in order), whose sha256 a signed
|
|
205
|
+
// change names as `keys`: the editor hashes what it signs over, the machine agent what the daemon handed it.
|
|
206
|
+
export const canonicalEgressOwnerKeysJson = (owner: EgressOwnerKeys): string =>
|
|
207
|
+
JSON.stringify({
|
|
208
|
+
keys: byText(
|
|
209
|
+
owner.keys.map((key) => {
|
|
210
|
+
const out: EgressTrustedKey = {
|
|
211
|
+
alg: key.alg,
|
|
212
|
+
id: key.id,
|
|
213
|
+
jwk: Object.fromEntries(Object.entries(key.jwk).toSorted(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))),
|
|
214
|
+
};
|
|
215
|
+
if (key.name !== undefined) {
|
|
216
|
+
out.name = key.name;
|
|
217
|
+
}
|
|
218
|
+
return out;
|
|
219
|
+
}),
|
|
220
|
+
(key) => key.id,
|
|
221
|
+
),
|
|
222
|
+
origins: [...new Set(owner.origins)].toSorted(),
|
|
223
|
+
rpId: owner.rpId,
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
// What the owner's passkey signs to loosen one sandbox's policy on one machine. `basedOn` is the revision it was
|
|
227
|
+
// written against, so it can be carried out once and never replayed after any other change; `expiresAt` bounds it
|
|
228
|
+
// to minutes; `keys` is the sha256 (hex) of `canonicalEgressOwnerKeysJson` over the owner keys the request carries, so
|
|
229
|
+
// the same signature may also move the pin to the owner's current passkeys. The WebAuthn challenge is the sha256 of
|
|
230
|
+
// the document's text exactly as `EgressProof.document` carries it; the verifier hashes and parses those same bytes,
|
|
231
|
+
// so nothing has to re-spell the document to check it.
|
|
232
|
+
export const EgressChangeDocumentSchema = z.strictObject({
|
|
233
|
+
v: z.literal(1),
|
|
234
|
+
purpose: z.literal("intentic-egress-change"),
|
|
235
|
+
machineId: z.string().min(1),
|
|
236
|
+
environment: z.string().min(1),
|
|
237
|
+
slug: z.string().min(1),
|
|
238
|
+
basedOn: z.string().min(1),
|
|
239
|
+
policy: EgressPolicySchema,
|
|
240
|
+
keys: z.string().regex(/^[0-9a-f]{64}$/u),
|
|
241
|
+
expiresAt: z.number().int().positive(),
|
|
242
|
+
nonce: z.string().min(16).max(64),
|
|
243
|
+
});
|
|
244
|
+
export type EgressChangeDocument = z.infer<typeof EgressChangeDocumentSchema>;
|
|
245
|
+
// How long a signed change stays good; the machine agent refuses one whose `expiresAt` is further out than this.
|
|
246
|
+
export const EGRESS_PROOF_MAX_AGE_MS = 5 * 60_000;
|
|
247
|
+
export const egressChangeDocumentText = (document: EgressChangeDocument): string => JSON.stringify({ ...document, policy: canonicalEgressPolicy(document.policy) });
|
|
248
|
+
|
|
249
|
+
export const EgressProofSchema = z.strictObject({
|
|
250
|
+
// The document text, byte for byte what the challenge hashed.
|
|
251
|
+
document: z.string().min(1).max(32_768),
|
|
252
|
+
assertion: AuthenticationResponseSchema,
|
|
253
|
+
});
|
|
254
|
+
export type EgressProof = z.infer<typeof EgressProofSchema>;
|
|
255
|
+
|
|
256
|
+
// ---- What ic says it holds and enforces ----
|
|
257
|
+
|
|
258
|
+
// `off`: the policy is open, no rules. `enforced`: the rules are in place for every address the sandbox has.
|
|
259
|
+
// `pending`: written, not yet applied (the sandbox is stopped, or ic is between its start and its rules). `failed`:
|
|
260
|
+
// ic could not put the rules in; a sandbox with a policy other than open is stopped rather than run unfenced, and
|
|
261
|
+
// `reason` says why. `unsupported`: this engine cannot take them (no nftables in its kernel), so the policy is held
|
|
262
|
+
// and nothing enforces it.
|
|
263
|
+
export const EgressStateSchema = z.enum(["off", "enforced", "pending", "failed", "unsupported"]);
|
|
264
|
+
export type EgressState = z.infer<typeof EgressStateSchema>;
|
|
265
|
+
|
|
266
|
+
// One destination the fence refused, from the per-sandbox counters ic reads back (an nftables dynamic set, an hour of
|
|
267
|
+
// memory per entry). `port` is absent for a protocol without ports.
|
|
268
|
+
export const EgressBlockedSchema = z.object({
|
|
269
|
+
to: z.string(),
|
|
270
|
+
port: z.number().int().optional(),
|
|
271
|
+
protocol: z.enum(["tcp", "udp", "other"]),
|
|
272
|
+
packets: z.number().int().nonnegative(),
|
|
273
|
+
// When ic first saw this entry's count grow, by the machine's clock (ms); absent when ic has no earlier reading.
|
|
274
|
+
lastSeenAt: z.number().optional(),
|
|
275
|
+
});
|
|
276
|
+
export type EgressBlocked = z.infer<typeof EgressBlockedSchema>;
|
|
277
|
+
|
|
278
|
+
export const EgressStatusSchema = z.object({
|
|
279
|
+
// What ic holds for the sandbox, and its revision (EGRESS_NO_REVISION when nothing is held, read as OPEN_EGRESS).
|
|
280
|
+
policy: EgressPolicySchema,
|
|
281
|
+
revision: z.string(),
|
|
282
|
+
// After the machine's baseline: the profile that is enforced and what the baseline refuses whatever `allow` says.
|
|
283
|
+
effectiveProfile: EgressProfileSchema,
|
|
284
|
+
neverAllow: z.array(z.string()),
|
|
285
|
+
state: EgressStateSchema,
|
|
286
|
+
reason: z.string().optional(),
|
|
287
|
+
// `network`: ic's own network for this sandbox, fenced as a whole from the moment it exists. `address`: a network
|
|
288
|
+
// something else made (Compose), fenced per address as docker reports them.
|
|
289
|
+
match: z.enum(["network", "address"]).optional(),
|
|
290
|
+
// The rules are in place but the sandbox can step around them: privileged on runc is the host's root. Under Kata
|
|
291
|
+
// (`isolation: auto`) it is not advisory.
|
|
292
|
+
advisory: z.boolean().optional(),
|
|
293
|
+
// The sandbox may run commands on this very machine through a device grant (`shell`), which reaches past any
|
|
294
|
+
// fence on the machine; the daemon fills this from its own enrollments, ic does not know it.
|
|
295
|
+
hostShell: z.boolean().optional(),
|
|
296
|
+
appliedAt: z.number().optional(),
|
|
297
|
+
// Hostname entries as ic last resolved them on the host.
|
|
298
|
+
resolved: z.array(z.object({ to: z.string(), addresses: z.array(z.string()) })).optional(),
|
|
299
|
+
blocked: z.array(EgressBlockedSchema).max(100),
|
|
300
|
+
});
|
|
301
|
+
export type EgressStatus = z.infer<typeof EgressStatusSchema>;
|
|
302
|
+
|
|
303
|
+
// Where ic writes the sandbox's own status inside its container (read-only to nothing: it is a report, and the
|
|
304
|
+
// sandbox changing it changes no rule), so the daemon and its agents can say "blocked by the egress policy".
|
|
305
|
+
export const EGRESS_STATUS_FILE = "/run/intentic/egress.json";
|
|
306
|
+
|
|
307
|
+
// ---- ic's verbs, the one spelling outside ic ----
|
|
308
|
+
|
|
309
|
+
// Sets the whole policy (ic stores it and applies it at once when the sandbox runs, or at its next start).
|
|
310
|
+
export const icEgressSetArgs = (slug: string, policy: EgressPolicy): string[] => ["sandbox", "egress", slug, "--policy", canonicalEgressPolicyJson(policy)];
|
|
311
|
+
// Prints the sandbox's EgressStatus as JSON.
|
|
312
|
+
export const icEgressShowArgs = (slug: string): string[] => ["sandbox", "egress", slug, "--json"];
|
|
313
|
+
// Follows docker's events and fences every sandbox start ic did not perform itself; runs until stopped.
|
|
314
|
+
export const icEgressFollowArgs = (): string[] => ["sandbox", "egress", "--follow"];
|
|
315
|
+
|
|
316
|
+
// ---- What the editor reads before it signs (2026-10-27) ----
|
|
317
|
+
|
|
318
|
+
// `GET /system/egress/owner-keys`: the owner keys the daemon will hand the machine with a `set-egress` sent from this
|
|
319
|
+
// same origin, so the editor hashes exactly them into `keys`; the owner's credential ids for the ceremony's
|
|
320
|
+
// `allowCredentials`; whether the caller is the owner (only the owner's passkey can sign a loosening); and the
|
|
321
|
+
// exceptions this sandbox's own cards suggest. `ownerKeys` is absent when no rpId can be named for the caller's origin.
|
|
322
|
+
export const EgressCredentialSchema = z.object({ id: z.string(), transports: z.array(z.string()) });
|
|
323
|
+
export const EgressOwnerKeysReadSchema = z.object({
|
|
324
|
+
ownerKeys: EgressOwnerKeysSchema.optional(),
|
|
325
|
+
credentials: z.array(EgressCredentialSchema),
|
|
326
|
+
owner: z.boolean(),
|
|
327
|
+
// This sandbox's own slug: the row on a machine the suggestions are about.
|
|
328
|
+
slug: z.string(),
|
|
329
|
+
suggestions: z.array(EgressAllowSchema),
|
|
330
|
+
});
|
|
331
|
+
export type EgressOwnerKeysRead = z.infer<typeof EgressOwnerKeysReadSchema>;
|
package/src/schemas/hosts.ts
CHANGED
|
@@ -122,6 +122,8 @@ export const DeviceFeatureSchema = z.enum([
|
|
|
122
122
|
"keyring",
|
|
123
123
|
"sleep",
|
|
124
124
|
"reachable-ways-back",
|
|
125
|
+
// (2026-10-27) The `set-egress` op and the `egress` field on its sandbox rows: an ic with `ic sandbox egress`.
|
|
126
|
+
"egress",
|
|
125
127
|
]);
|
|
126
128
|
export type DeviceFeature = z.infer<typeof DeviceFeatureSchema>;
|
|
127
129
|
export const DEVICE_FEATURE_RESHAPE_LATER: DeviceFeature = "reshape-later";
|
|
@@ -133,6 +135,7 @@ export const DEVICE_FEATURE_PROJECT_DELIVERY: DeviceFeature = "project-delivery"
|
|
|
133
135
|
export const DEVICE_FEATURE_PROGRAMS: DeviceFeature = "programs";
|
|
134
136
|
export const DEVICE_FEATURE_KEYRING: DeviceFeature = "keyring";
|
|
135
137
|
export const DEVICE_FEATURE_SLEEP: DeviceFeature = "sleep";
|
|
138
|
+
export const DEVICE_FEATURE_EGRESS: DeviceFeature = "egress";
|
|
136
139
|
export const DEVICE_FEATURE_REACHABLE_WAYS_BACK: DeviceFeature = "reachable-ways-back";
|
|
137
140
|
// What `ic features --json` answers (_sandbox/ic/src/features.rs, golden/ic-features.json): the optional ops that ic
|
|
138
141
|
// implements, as strings, since a newer ic's word means nothing to an older agent.
|
package/src/schemas/members.ts
CHANGED
|
@@ -225,14 +225,14 @@ export type MembersRoster = z.infer<typeof MembersRosterSchema>;
|
|
|
225
225
|
// `emailSignIn` lets the platform's identity assertion open this sandbox for them (policy/identity-assertion.ts): true
|
|
226
226
|
// allows it, false takes it back, absent keeps what the row already says, so a re-grade from an editor that predates
|
|
227
227
|
// the field never drops it. `credentials` the same way: `all` lifts a reach, a list sets one, absent keeps the row's,
|
|
228
|
-
// so a re-grade that never mentions it can never widen what a person's conversations may spend. A maintainer
|
|
229
|
-
// a list:
|
|
228
|
+
// so a re-grade that never mentions it can never widen what a person's conversations may spend. A maintainer may hold
|
|
229
|
+
// a list too: managing the sandbox and spending all of it are separate answers (docs/architecture/access.md).
|
|
230
230
|
// `agents` and `edit` decide the rest of the access; absent, the role's own meaning stands, so an editor that predates
|
|
231
231
|
// them still grants what it always did. `lands` is written as sent: absent is no, so a re-grade that never mentions it
|
|
232
232
|
// can never hand a home-only person's agent the authority to land. The role sent must be the tier the access makes (`tierOf`): two answers to one
|
|
233
233
|
// question are refused rather than one of them guessed away. `aiAccounts` reads as `credentials` does: `all` lifts it, a
|
|
234
|
-
// list sets it, absent keeps the row's
|
|
235
|
-
//
|
|
234
|
+
// list sets it, absent keeps the row's, a maintainer's included. `tools` and `assistants` read the same way, except that
|
|
235
|
+
// a maintainer is refused a tool ceiling, since the tier runs every tool.
|
|
236
236
|
// `profile` names an access profile instead of answering on the row: the daemon writes that profile's answers out on
|
|
237
237
|
// the row and ignores the access fields sent beside it, and the role sent must still be the tier the profile makes.
|
|
238
238
|
// Absent is answers of the row's own, so a re-grade from an editor that predates profiles unlinks the row, keeping
|
|
@@ -284,7 +284,9 @@ export type MemberSelf = z.infer<typeof MemberSelfSchema>;
|
|
|
284
284
|
// where granting the person what they asked for answers it. One open request per person: a later ask replaces theirs.
|
|
285
285
|
// `want` is what stood in the way, in the terms a grant answers: a tier (`viewer` is a guest asking to see more),
|
|
286
286
|
// running agents (`agents`), or a folder outside their areas (`areas`).
|
|
287
|
-
|
|
287
|
+
// `aiAccounts`: the AI accounts their turns may run on (`aiAccounts` on their row) leave them nothing to run on that they
|
|
288
|
+
// asked for, asked from a model picker with no model of theirs in it.
|
|
289
|
+
export const AccessWantSchema = z.enum(["viewer", "collaborator", "writer", "maintainer", "agents", "areas", "aiAccounts"]);
|
|
288
290
|
export type AccessWant = z.infer<typeof AccessWantSchema>;
|
|
289
291
|
|
|
290
292
|
// POST /members/requests: what the person asks for, and where they were when they asked.
|
package/src/schemas/needs.ts
CHANGED
|
@@ -19,7 +19,7 @@ export type NeedKind = z.infer<typeof NeedKindSchema>;
|
|
|
19
19
|
export const NeedStatusSchema = z
|
|
20
20
|
.enum(["open", "working", "met", "declined", "cancelled"])
|
|
21
21
|
.describe(
|
|
22
|
-
"Where it stands: open (waiting on a person), working (a person said yes and it is being set up), met, declined, or cancelled (the agent withdrew it, or its conversation went away).",
|
|
22
|
+
"Where it stands: open (waiting on a person), working (a person said yes and it is being set up), met (a person's answer, the daemon's own check, or the agent's word where no check can see it), declined, or cancelled (the agent withdrew it, or its conversation went away).",
|
|
23
23
|
);
|
|
24
24
|
export type NeedStatus = z.infer<typeof NeedStatusSchema>;
|
|
25
25
|
|
|
@@ -177,6 +177,10 @@ export const NeedSchema = z.object({
|
|
|
177
177
|
createdAt: z.number().describe("When it was raised, in milliseconds."),
|
|
178
178
|
updatedAt: z.number().describe("When it last moved, in milliseconds."),
|
|
179
179
|
answeredBy: z.string().optional().describe("Who answered it, as the sandbox verified them."),
|
|
180
|
+
byAgent: z
|
|
181
|
+
.boolean()
|
|
182
|
+
.optional()
|
|
183
|
+
.describe("The agent closed it as met on its own word (`needs done`), after a person said in the chat it was fixed and a retry worked."),
|
|
180
184
|
outcome: z.string().optional().describe("How it ended, in the daemon's words, once it has."),
|
|
181
185
|
told: NeedToldSchema.optional().describe("How the agent heard the outcome, once it has."),
|
|
182
186
|
unattended: z.boolean().optional().describe("Raised by a turn nobody was watching, so the card waited for whoever came next."),
|
|
@@ -255,6 +259,10 @@ export const NeedAnswerSchema = z.discriminatedUnion("kind", [
|
|
|
255
259
|
export type NeedAnswer = z.infer<typeof NeedAnswerSchema>;
|
|
256
260
|
|
|
257
261
|
export const NeedIdParamSchema = z.object({ id: z.string().min(1).describe("Which need.") });
|
|
262
|
+
// POST /needs/{id}/done: the agent closing its own need as met, where nothing the daemon checks could see it met.
|
|
263
|
+
export const NeedDoneInputSchema = NeedIdParamSchema.extend({
|
|
264
|
+
how: z.string().trim().min(1).max(280).describe("What showed the agent it works now: the call it retried and what came back."),
|
|
265
|
+
});
|
|
258
266
|
export const NeedAnswerInputSchema = NeedIdParamSchema.extend({ answer: NeedAnswerSchema });
|
|
259
267
|
// POST /needs/{id}/release: a release need's own answer, from the people its gate names, whatever their tier.
|
|
260
268
|
export const NeedReleaseInputSchema = NeedIdParamSchema.extend({
|
package/src/schemas/ports.ts
CHANGED
|
@@ -74,3 +74,28 @@ export const PortForwardResultSchema = z.object({
|
|
|
74
74
|
.describe("Where it can now be reached. Absent on a sandbox with no outside address, where the mapping exists but has no public name."),
|
|
75
75
|
});
|
|
76
76
|
export type PortForwardResult = z.infer<typeof PortForwardResultSchema>;
|
|
77
|
+
|
|
78
|
+
// THE OWNER'S GUARD ON PREVIEWS (2026-10-27, docs/architecture/sandbox.md). Off, a preview is open to anyone with its
|
|
79
|
+
// address, as it always was; `panels` asks a visitor of a panel's preview (`preview-<panel>-<id>`) for this sandbox's
|
|
80
|
+
// pass, which only its members get; `all` asks it of forwarded ports (`port-<slot>-<id>`) too. The outbox is public
|
|
81
|
+
// whatever this says. Ports are left out of `panels` because their names are salted already, and they are where a
|
|
82
|
+
// webhook or a phone app with no browser to sign in calls.
|
|
83
|
+
export const PreviewGuardScopeSchema = z.enum(["off", "panels", "all"]);
|
|
84
|
+
export type PreviewGuardScope = z.infer<typeof PreviewGuardScopeSchema>;
|
|
85
|
+
export const PreviewGuardSchema = z.object({
|
|
86
|
+
scope: PreviewGuardScopeSchema.default("off").describe(
|
|
87
|
+
"Who may open this sandbox's previews from outside: anyone with the address (`off`), only its members for panel previews (`panels`), or only its members for panel previews and forwarded ports alike (`all`). The outbox stays public.",
|
|
88
|
+
),
|
|
89
|
+
});
|
|
90
|
+
export type PreviewGuard = z.infer<typeof PreviewGuardSchema>;
|
|
91
|
+
export const PreviewPassRequestSchema = z.object({
|
|
92
|
+
url: z.string().min(1).max(4096).describe("The preview address to open, at the path to open it on."),
|
|
93
|
+
});
|
|
94
|
+
export const PreviewPassSchema = z.object({
|
|
95
|
+
url: z
|
|
96
|
+
.string()
|
|
97
|
+
.describe(
|
|
98
|
+
"Where to send the browser: the same address through a one-time link that signs this browser in to it, or the address unchanged when nothing guards it.",
|
|
99
|
+
),
|
|
100
|
+
});
|
|
101
|
+
export type PreviewPass = z.infer<typeof PreviewPassSchema>;
|
package/src/state/auth-state.ts
CHANGED
|
@@ -30,6 +30,9 @@ export const AUTH_STATE_FILES: readonly StateFile[] = [
|
|
|
30
30
|
{ path: "privacy-shield.json", portability: "carry" },
|
|
31
31
|
// The execution boundary agents run in (workload/domain/agent-domain-policy.ts).
|
|
32
32
|
{ path: "agent-domain.json", portability: "carry" },
|
|
33
|
+
// Who may open the sandbox's previews from outside (auth/previews/preview-guard.ts); its signing key stays on the history
|
|
34
|
+
// volume and never travels.
|
|
35
|
+
{ path: "preview-guard.json", portability: "carry" },
|
|
33
36
|
|
|
34
37
|
/* ---- credentials and what holds their values ---- */
|
|
35
38
|
|
|
@@ -1322,6 +1322,13 @@ describe("TranscriptFold with a clock", () => {
|
|
|
1322
1322
|
expect(fold.rows[1]?.tools?.[0]).toMatchObject({ input: '{"prompt":"look"}', startedAt: SENT_AT + 2000 });
|
|
1323
1323
|
});
|
|
1324
1324
|
|
|
1325
|
+
it("carries a command's own description onto its card, through the schema a stored record is read back with", () => {
|
|
1326
|
+
const fold = new TranscriptFold(openingOf("look"), ticking());
|
|
1327
|
+
fold.apply({ kind: "tool_call", id: "b1", name: "Bash", category: "execute", status: "in_progress", target: "git status", description: "Show working tree status" });
|
|
1328
|
+
expect(fold.rows[1]?.tools?.[0]).toMatchObject({ target: "git status", description: "Show working tree status" });
|
|
1329
|
+
expect(fold.rows.map((row) => TranscriptRowSchema.parse(row))).toEqual(fold.rows);
|
|
1330
|
+
});
|
|
1331
|
+
|
|
1325
1332
|
it("keeps a daemon-written row's own moment, and never stamps a user's row", () => {
|
|
1326
1333
|
const fold = new TranscriptFold(openingOf("go"), ticking());
|
|
1327
1334
|
fold.note({ role: "notice", text: "kept", openedAt: 7 });
|
|
@@ -70,6 +70,7 @@ const cardOf = (event: Extract<AgentEvent, { kind: "tool_call" }>, at: number |
|
|
|
70
70
|
category: event.category,
|
|
71
71
|
status: event.status,
|
|
72
72
|
...(event.target !== undefined ? { target: event.target } : {}),
|
|
73
|
+
...(event.description !== undefined ? { description: event.description } : {}),
|
|
73
74
|
...(event.locations !== undefined ? { locations: event.locations } : {}),
|
|
74
75
|
...(event.content !== undefined ? { content: event.content } : {}),
|
|
75
76
|
...(event.input !== undefined ? { input: event.input } : {}),
|