@hmharness/sandbox 0.23.29 → 0.23.31
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/broker.d.ts +21 -2
- package/dist/broker.js +83 -0
- package/package.json +1 -1
package/dist/broker.d.ts
CHANGED
|
@@ -35,7 +35,7 @@ export interface CapabilityToken {
|
|
|
35
35
|
readonly scope: string;
|
|
36
36
|
readonly resource: string;
|
|
37
37
|
readonly operation: CapabilityOperation;
|
|
38
|
-
readonly constraints?: Record<string, string | number | boolean>;
|
|
38
|
+
readonly constraints?: Record<string, string | number | boolean | string[]>;
|
|
39
39
|
/** epoch ms - every token expires, always */
|
|
40
40
|
readonly expiry: number;
|
|
41
41
|
/** who granted and why - the audit answer to 'qui bono' */
|
|
@@ -59,7 +59,8 @@ export interface GrantInput {
|
|
|
59
59
|
scope: string;
|
|
60
60
|
resource: string;
|
|
61
61
|
operation: CapabilityOperation;
|
|
62
|
-
constraints
|
|
62
|
+
/** Sandbox 2.0: constraints may carry an egress allowlist (string[]) */
|
|
63
|
+
constraints?: Record<string, string | number | boolean | string[]>;
|
|
63
64
|
/** how long the token lives, ms (default 1h; cap 24h) */
|
|
64
65
|
ttlMs?: number;
|
|
65
66
|
provenance: string;
|
|
@@ -102,3 +103,21 @@ export declare class CapabilityBroker {
|
|
|
102
103
|
auditTrail(): readonly AuditEntry[];
|
|
103
104
|
private decide;
|
|
104
105
|
}
|
|
106
|
+
export declare class SecretBroker {
|
|
107
|
+
private readonly broker;
|
|
108
|
+
private readonly secrets;
|
|
109
|
+
constructor(broker: CapabilityBroker);
|
|
110
|
+
/** store a secret; returns the opaque reference to use everywhere else */
|
|
111
|
+
set(name: string, value: string): string;
|
|
112
|
+
/** resolve a reference to its value - only under a live secret grant */
|
|
113
|
+
resolve(subject: string, ref: string): {
|
|
114
|
+
ok: true;
|
|
115
|
+
value: string;
|
|
116
|
+
} | {
|
|
117
|
+
ok: false;
|
|
118
|
+
reason: string;
|
|
119
|
+
};
|
|
120
|
+
/** replace known secret values in any text with their references */
|
|
121
|
+
redact(text: string): string;
|
|
122
|
+
list(): string[];
|
|
123
|
+
}
|
package/dist/broker.js
CHANGED
|
@@ -26,6 +26,8 @@ const MAX_TTL_MS = 24 * 60 * 60 * 1000;
|
|
|
26
26
|
const DEFAULT_TTL_MS = 60 * 60 * 1000;
|
|
27
27
|
/** classes the worker tier can never hold - the RLM rule, mechanical */
|
|
28
28
|
const WORKER_FORBIDDEN = ['network', 'secret', 'process', 'device'];
|
|
29
|
+
/** a scope that names an actual path (drive letter, UNC or posix-root) */
|
|
30
|
+
const PATH_SCOPE = /^([A-Za-z]:[\\/]|\\\\|\/)/;
|
|
29
31
|
export class CapabilityBroker {
|
|
30
32
|
tokens = new Map();
|
|
31
33
|
audits = [];
|
|
@@ -73,6 +75,38 @@ export class CapabilityBroker {
|
|
|
73
75
|
if (!match) {
|
|
74
76
|
return this.decide(req, false, `no live ${req.class}/${op} grant for subject '${req.subject}' (deny-by-default)`, tier);
|
|
75
77
|
}
|
|
78
|
+
// Sandbox 2.0 constraint enforcement (per-class, on the LIVE token):
|
|
79
|
+
// - network connect: constraints.allowedHosts (when present) is the
|
|
80
|
+
// egress allowlist - a host outside it denies with the host named
|
|
81
|
+
// - filesystem: the token's scope roots the allowed subtree; a resource
|
|
82
|
+
// outside the root denies (mount policy - 'host' scope is explicit
|
|
83
|
+
// and auditable, never a silent fallback)
|
|
84
|
+
if (req.class === 'network' && op === 'connect') {
|
|
85
|
+
const allowed = match.constraints?.['allowedHosts'];
|
|
86
|
+
if (Array.isArray(allowed)) {
|
|
87
|
+
const host = String(req.resource ?? '');
|
|
88
|
+
// '*.example.org' admits any subdomain; a bare host admits only itself
|
|
89
|
+
const ok = allowed.some((a) => {
|
|
90
|
+
const entry = String(a);
|
|
91
|
+
if (entry.startsWith('*.'))
|
|
92
|
+
return host.endsWith(entry.slice(1));
|
|
93
|
+
return host === entry;
|
|
94
|
+
});
|
|
95
|
+
if (!ok) {
|
|
96
|
+
return this.decide(req, false, `egress denied: '${host || '(no host)'}' not in grant ${match.id}'s allowlist [${allowed.join(', ')}]`, tier);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
if (req.class === 'filesystem' && req.resource && PATH_SCOPE.test(match.scope)) {
|
|
101
|
+
// mount policy applies to PATH-shaped scopes (a label scope like
|
|
102
|
+
// 'workspace-root' is a semantic tag, not a root - it cannot confine)
|
|
103
|
+
const root = match.scope.replace(/\/+$/, '');
|
|
104
|
+
const res = String(req.resource).replace(/\\/g, '/').replace(/\/+$/, '');
|
|
105
|
+
const rooted = res === root || res.startsWith(root + '/');
|
|
106
|
+
if (!rooted) {
|
|
107
|
+
return this.decide(req, false, `mount policy: '${req.resource}' is outside grant ${match.id}'s scope root '${match.scope}'`, tier);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
76
110
|
return this.decide(req, true, `grant ${match.id} (scope ${match.scope}, provenance: ${match.provenance})`, tier, match);
|
|
77
111
|
}
|
|
78
112
|
/** The pack's ladder, composing recommendedIsolation plus broker rules. */
|
|
@@ -119,3 +153,52 @@ export class CapabilityBroker {
|
|
|
119
153
|
return { allowed, reason, tier, ...(token !== undefined ? { token } : {}) };
|
|
120
154
|
}
|
|
121
155
|
}
|
|
156
|
+
/* ---------------- SecretBroker (Sandbox 2.0: secrets never ride payloads) ----------------
|
|
157
|
+
*
|
|
158
|
+
* The audit rule: secret 不传给 LSP/RLM/subagent. The broker holds the
|
|
159
|
+
* values; callers (and logs, and the LLM context) only ever see opaque
|
|
160
|
+
* REFERENCES. resolve() checks the CapabilityBroker for a live 'secret'
|
|
161
|
+
* grant on the subject FIRST - no grant, no value, deny-by-default like
|
|
162
|
+
* everything else; redact() turns any string's secret values into
|
|
163
|
+
* ${ref} tokens so audit trails and transcripts stay clean even when a
|
|
164
|
+
* value leaks into an output by accident.
|
|
165
|
+
*/
|
|
166
|
+
export class SecretBroker {
|
|
167
|
+
broker;
|
|
168
|
+
secrets = new Map();
|
|
169
|
+
constructor(broker) {
|
|
170
|
+
this.broker = broker;
|
|
171
|
+
}
|
|
172
|
+
/** store a secret; returns the opaque reference to use everywhere else */
|
|
173
|
+
set(name, value) {
|
|
174
|
+
const ref = `secret:${name}`;
|
|
175
|
+
this.secrets.set(name, value);
|
|
176
|
+
return ref;
|
|
177
|
+
}
|
|
178
|
+
/** resolve a reference to its value - only under a live secret grant */
|
|
179
|
+
resolve(subject, ref) {
|
|
180
|
+
const m = /^secret:(.+)$/.exec(ref);
|
|
181
|
+
if (!m)
|
|
182
|
+
return { ok: false, reason: `not a secret reference: '${ref.slice(0, 24)}'` };
|
|
183
|
+
const name = m[1];
|
|
184
|
+
const decision = this.broker.check({ subject, class: 'secret', resource: name, operation: 'read' }, { riskLevel: 'high' });
|
|
185
|
+
if (!decision.allowed)
|
|
186
|
+
return { ok: false, reason: decision.reason };
|
|
187
|
+
const value = this.secrets.get(name);
|
|
188
|
+
if (value === undefined)
|
|
189
|
+
return { ok: false, reason: `no such secret '${name}'` };
|
|
190
|
+
return { ok: true, value };
|
|
191
|
+
}
|
|
192
|
+
/** replace known secret values in any text with their references */
|
|
193
|
+
redact(text) {
|
|
194
|
+
let out = text;
|
|
195
|
+
for (const [name, value] of this.secrets) {
|
|
196
|
+
if (value.length > 0)
|
|
197
|
+
out = out.split(value).join(`secret:${name}`);
|
|
198
|
+
}
|
|
199
|
+
return out;
|
|
200
|
+
}
|
|
201
|
+
list() {
|
|
202
|
+
return [...this.secrets.keys()];
|
|
203
|
+
}
|
|
204
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hmharness/sandbox",
|
|
3
|
-
"version": "0.23.
|
|
3
|
+
"version": "0.23.31",
|
|
4
4
|
"description": "hmharness sandbox runtime (V2 blueprint M3): isolated workspaces with create/exec/read/write/snapshot/restore/diff/destroy, tiered permissions (READ_ONLY / WORKSPACE_WRITE / FULL_ACCESS), git-backed snapshots. Runtime owns agent turns; the sandbox owns workspace/process state (ADR-0001).",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|