Skip to content

Commit 7f7448e

Browse files
authored
feat(gateway): identity-conditional forced sandboxing for operator roles (#129926)
One shared agent could not give different people different execution isolation: sandbox selection saw only the agent's mode and the session key, never who created the session. Teams that share an agent had to choose between sandboxing everyone or no one. Add a closed, optional role axis sandbox?: "inherit" | "required" (default "inherit", so existing deployments are unchanged). The Gateway resolves it from the authenticated session creator and stamps it write-once onto genuinely new session entries; the agents layer reads that immutable fact and forces a sandbox even when the agent config says mode: "off". Anchoring on the creator keeps a session's isolation stable for its lifetime: a maintainer replying inside a guest session cannot un-sandbox it, and a caller whose role requires a sandbox is refused inside an unstamped session rather than silently inheriting host execution. Reset, rewind, rollover and fast-path all carry the requirement forward so a session cannot be reset out of its sandbox. Because exec injects the agent's managed GitHub identity only for gateway-host execution and blanks GH_TOKEN/GITHUB_TOKEN otherwise, a forced-sandbox session also loses access to the shared agent's credentials — the property that makes one shared agent safe for untrusted guests. Session entries are JSON; no SQLite schema, schema-version, or protocol change. Docs also correct the sandbox backend list, which omitted the first-class podman backend.
1 parent 8a3f540 commit 7f7448e

58 files changed

Lines changed: 1140 additions & 85 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"core": 2355,
3-
"channel": 3584,
4-
"plugin": 3957
2+
"core": 2353,
3+
"channel": 3596,
4+
"plugin": 3982
55
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
ce06876d3bb5dfce16f3d321623a792baa41c01f06e3972887b0555460ca7873 config-baseline.json
2-
b969d726e663afc6ad8d9a2ceabf8c5d26c61402d711d10f969fab5bab1c3d76 config-baseline.core.json
3-
3300f931abce160c1d6768af1a358683b8f77af479e8b728aeefd38039a61507 config-baseline.channel.json
4-
91f13b695cfae24bff25c09ff8d091f357c13bf01b220c0640216aa5081e4db2 config-baseline.plugin.json
1+
0e5dc75714d23fda74b4723a760c5ad6fbef688b8509d1ec27c9ecc8d1ab4cbb config-baseline.json
2+
a69e64bd65e0f0376d41ea00368975fc03ee1f436b7b62f0377d978ae3ef730b config-baseline.core.json
3+
2cb50df6362fe4a1d0e96659028240330e36e20fdf921ca733a7eb187b6f5dc8 config-baseline.channel.json
4+
fb222f3d84def06d427a7f43e132ae8e1ed2e0ce62b6c1bc4459ff23770d1843 config-baseline.plugin.json

‎docs/cli/sandbox.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ Sandbox settings live in `~/.openclaw/openclaw.json` under `agents.defaults.sand
103103
"defaults": {
104104
"sandbox": {
105105
"mode": "all", // off, non-main, all
106-
"backend": "docker", // docker, ssh, openshell (plugin-provided)
106+
"backend": "docker", // docker, podman, ssh; openshell is plugin-provided
107107
"scope": "agent", // session, agent, shared
108108
"docker": {
109109
"image": "openclaw-sandbox:bookworm-slim",

‎docs/gateway/configuration-reference.md‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -717,13 +717,14 @@ Gateway or node host and check `openclaw nodes pending` again.
717717
definitions: {
718718
maintainer: {
719719
sessions: { others: "write" }, // none | view | suggest | write
720-
agents: "*",
720+
agents: ["roboclaw"],
721721
scopes: ["operator.read", "operator.write", "operator.approvals"],
722722
},
723723
guest: {
724724
sessions: { others: "view" },
725-
agents: ["guest-agent"],
725+
agents: ["roboclaw"],
726726
scopes: ["operator.read", "operator.write"],
727+
sandbox: "required", // inherit (default) | required
727728
},
728729
},
729730
},
@@ -817,7 +818,7 @@ Gateway or node host and check `openclaw nodes pending` again.
817818
- `gateway.auth.mode: "trusted-proxy"`: delegate browser/user auth to an identity-aware reverse proxy and trust identity headers from `gateway.trustedProxies` (see [Trusted Proxy Auth](/gateway/trusted-proxy-auth)). This mode expects a **non-loopback** proxy source by default; same-host loopback reverse proxies require explicit `gateway.auth.trustedProxy.allowLoopback = true`. Internal same-host callers can use `gateway.auth.password` as a local direct fallback; `gateway.auth.token` remains mutually exclusive with trusted-proxy mode.
818819
- `gateway.auth.allowTailscale`: when `true`, Tailscale Serve identity headers can satisfy Control UI/WebSocket auth (verified via `tailscale whois`). HTTP API endpoints do **not** use that Tailscale header auth; they follow the gateway's normal HTTP auth mode instead. This tokenless flow assumes the gateway host is trusted. Defaults to `true` when `tailscale.mode = "serve"`.
819820
- `gateway.auth.identityScopes`: maps a verified trusted-proxy user or Tailscale WhoIs login to connection-only operator scopes. Email keys match case-insensitively; other identities match exactly. For trusted-proxy Control UI connections, `x-openclaw-scopes` caps device enrollment or upgrade requests and the final device-plus-identity session scopes. Grants do not create or modify pairing records. Token, password, and no-auth connections have no verified identity and receive no grant.
820-
- `gateway.roles`: optional named operator roles for authenticated user profiles on team Gateways. Every definition specifies `sessions.others` (`none`, `view`, `suggest`, or `write`), allowed session-creation and agent-run `agents` (`"*"` or an array of agent IDs), and a closed `scopes` ceiling that also applies to identity-authenticated HTTP requests and signed Control UI plugin grants. The administrator-scoped `users.setRole` Gateway method assigns or clears a profile's role and immediately disconnects its active clients so they reconnect with current authority. Identity-authenticated operator sessions do not receive reusable, person-unbound device/bootstrap tokens while roles are configured, and identity-less device-token or bootstrap-token operator authentication is rejected; reconnect through trusted-proxy or other supported verified identity instead. `default` is required, must name a configured definition, and applies to unassigned profiles. `sessions.others: "none"` also denies Gateway-wide `usage.cost`; audit diagnostics and other `operator.write` control-plane capabilities remain shared-domain surfaces, not hostile-tenant isolation. Omitting `roles` leaves existing solo and shared-secret deployments unchanged. See [Operator scopes](/gateway/operator-scopes#named-operator-roles).
821+
- `gateway.roles`: optional named operator roles for authenticated user profiles on team Gateways. Every definition specifies `sessions.others` (`none`, `view`, `suggest`, or `write`), allowed session-creation and agent-run `agents` (`"*"` or an array of agent IDs), and a closed `scopes` ceiling that also applies to identity-authenticated HTTP requests and signed Control UI plugin grants. Optional `sandbox` is `"inherit"` by default or `"required"` to sandbox sessions created under that role even when the agent's sandbox mode is `"off"`. This requirement is recorded once from the authenticated creator, cannot be changed through role updates or session mutation, and does not affect existing sessions. A sandbox-required person cannot start a host-execution session, including through an invitation; unavailable sandbox backends fail closed, and elevated or host-target overrides cannot escape. The administrator-scoped `users.setRole` Gateway method assigns or clears a profile's role and immediately disconnects its active clients so they reconnect with current authority. Identity-authenticated operator sessions do not receive reusable, person-unbound device/bootstrap tokens while roles are configured, and identity-less device-token or bootstrap-token operator authentication is rejected; reconnect through trusted-proxy or other supported verified identity instead. `default` is required, must name a configured definition, and applies to unassigned profiles. `sessions.others: "none"` also denies Gateway-wide `usage.cost`; audit diagnostics and other `operator.write` control-plane capabilities remain shared-domain surfaces, not hostile-tenant isolation. Omitting `roles` leaves existing solo and shared-secret deployments unchanged. See [Operator scopes](/gateway/operator-scopes#named-operator-roles).
821822
- `gateway.auth.rateLimit`: optional failed-auth limiter. Applies per client IP and per auth scope (shared-secret and device-token are tracked independently). Blocked attempts return `429` + `Retry-After`.
822823
- On the async Tailscale Serve Control UI path, failed attempts for the same `{scope, clientIp}` are serialized before the failure write. Concurrent bad attempts from the same client can therefore trip the limiter on the second request instead of both racing through as plain mismatches.
823824
- `gateway.auth.rateLimit.exemptLoopback` defaults to `true`; set `false` when you intentionally want localhost traffic rate-limited too (for test setups or strict proxy deployments).

‎docs/gateway/operator-scopes.md‎

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ already holds `operator.admin`.
4646
## Named operator roles
4747

4848
Team Gateways can bind authenticated user profiles to named operator roles.
49-
Each role combines exactly three closed policies: access to other people's
50-
sessions, agents available for session creation and agent runs, and a maximum
51-
set of operator scopes.
49+
Each role combines four closed policies: access to other people's sessions,
50+
agents available for session creation and agent runs, a maximum set of operator
51+
scopes, and whether newly created sessions require sandboxing.
5252

5353
```json5
5454
{
@@ -58,13 +58,14 @@ set of operator scopes.
5858
definitions: {
5959
maintainer: {
6060
sessions: { others: "write" },
61-
agents: "*",
61+
agents: ["roboclaw"],
6262
scopes: ["operator.read", "operator.write", "operator.approvals"],
6363
},
6464
guest: {
6565
sessions: { others: "view" },
66-
agents: ["guest-agent"],
66+
agents: ["roboclaw"],
6767
scopes: ["operator.read", "operator.write"],
68+
sandbox: "required",
6869
},
6970
},
7071
},
@@ -108,6 +109,24 @@ holding `operator.admin` retain their administrative session access.
108109
Set `agents: "*"` to allow session creation and agent runs on every agent, list
109110
agent IDs to allow only those agents, or use an empty array to disallow both.
110111
The allowlist also applies when a run targets an already-existing session.
112+
113+
The optional `sandbox` policy defaults to `"inherit"`, which keeps the agent's
114+
configured sandbox mode. Set `sandbox: "required"` to sandbox every new session
115+
created by an authenticated person with that role, even when the agent's
116+
sandbox mode is `"off"`. The example lets maintainers use host execution on
117+
`roboclaw` while guest-created sessions on the same agent remain sandboxed.
118+
119+
The Gateway records the creator's sandbox requirement once when the session is
120+
created. Existing sessions are unaffected, and role changes, session sharing,
121+
maintainer participation, and `sessions.patch` cannot remove or replace the
122+
requirement. A person whose role requires sandboxing cannot start a run in an
123+
existing host-execution session, even when explicitly invited. Required sessions
124+
fail if their sandbox backend is unavailable or provisioning fails; they never
125+
fall back to the Gateway or a node. `/elevated`, `exec` host overrides, and
126+
configured host targets cannot bypass this restriction. The agent's managed
127+
GitHub identity is not injected into sandboxed execution: `GH_CONFIG_DIR` is
128+
absent, and `GH_TOKEN` and `GITHUB_TOKEN` are blanked.
129+
111130
The role's `scopes` list intersects scopes granted through connection auth,
112131
identity grants, pairing, scope upgrades, and authenticated trusted-proxy HTTP
113132
requests. It cannot grant scopes the connection did not already receive.

‎docs/gateway/sandbox-vs-tool-policy-vs-elevated.md‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ status: active
77

88
OpenClaw has three related but different controls:
99

10-
1. **Sandbox** (`agents.defaults.sandbox.*` / `agents.entries.*.sandbox.*`) decides **where tools run** (sandbox backend vs host).
10+
1. **Sandbox** (`agents.defaults.sandbox.*`, `agents.entries.*.sandbox.*`, or a required creator-role policy) decides **where tools run** (sandbox backend vs host).
1111
2. **Tool policy** (`tools.*`, `tools.sandbox.tools.*`, `agents.entries.*.tools.*`) decides **which tools are available/allowed**.
12-
3. **Elevated** (`tools.elevated.*`, `agents.entries.*.tools.elevated.*`) is an **exec-only escape hatch** to run outside the sandbox when you are sandboxed (`gateway` by default, or `node` when the exec target is configured to `node`).
12+
3. **Elevated** (`tools.elevated.*`, `agents.entries.*.tools.elevated.*`) is an **exec-only escape hatch** from ordinary sandboxing (`gateway` by default, or `node` when the exec target is configured to `node`). It cannot bypass a creator role's required sandbox.
1313

1414
## Quick debug
1515

@@ -33,12 +33,17 @@ It prints:
3333

3434
Sandboxing is controlled by `agents.defaults.sandbox.mode`:
3535

36-
- `"off"`: everything runs on the host.
36+
- `"off"`: sessions run on the host unless their creator's operator role requires sandboxing.
3737
- `"non-main"`: only non-main sessions are sandboxed (common "surprise" for groups/channels).
3838
- `"all"`: everything is sandboxed.
3939

4040
`agents.defaults.sandbox.workspaceAccess` controls what the sandbox can see: `"none"`, `"ro"`, or `"rw"`.
4141

42+
An operator role with `sandbox: "required"` overrides agent mode, cannot be
43+
escaped through elevated execution or host overrides, and fails closed when its
44+
sandbox cannot be provisioned. See
45+
[Named operator roles](/gateway/operator-scopes#named-operator-roles).
46+
4247
See [Sandboxing](/gateway/sandboxing) for the full matrix (scope, workspace mounts, images).
4348

4449
### Bind mounts (security quick check)
@@ -117,7 +122,7 @@ For sandboxed MCP servers, the sandbox tool policy is a second allow gate. If `m
117122

118123
Elevated does **not** grant extra tools; it only affects `exec`.
119124

120-
- If you are sandboxed, `/elevated on` (or `exec` with `elevated: true`) runs outside the sandbox (approvals may still apply).
125+
- If you are ordinarily sandboxed, `/elevated on` (or `exec` with `elevated: true`) runs outside the sandbox (approvals may still apply). Creator-role-required sandboxes reject elevated execution.
121126
- Use `/elevated full` to skip exec approvals for the session.
122127
- If you are already running direct, elevated is effectively a no-op (still gated).
123128
- Elevated is **not** skill-scoped and does **not** override tool allow/deny.
@@ -137,7 +142,7 @@ See [Elevated Mode](/tools/elevated).
137142

138143
Fix-it keys (pick one):
139144

140-
- Disable sandbox: `agents.defaults.sandbox.mode=off` (or per-agent `agents.entries.*.sandbox.mode=off`)
145+
- Disable ordinary sandboxing: `agents.defaults.sandbox.mode=off` (or per-agent `agents.entries.*.sandbox.mode=off`); this does not override a creator role's required sandbox.
141146
- Allow the tool inside sandbox:
142147
- remove it from `tools.sandbox.tools.deny` (or per-agent `agents.entries.*.tools.sandbox.tools.deny`)
143148
- or add it to `tools.sandbox.tools.allow` (or per-agent allow)

‎docs/gateway/sandboxing.md‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ read_when: "You want a dedicated explanation of sandboxing or need to tune agent
66
status: active
77
---
88

9-
OpenClaw can run tool execution inside a sandbox backend to reduce blast radius. Sandboxing is off by default and controlled by `agents.defaults.sandbox` (global) or `agents.entries.*.sandbox` (per-agent). The Gateway process always stays on the host; only tool execution moves into the sandbox when enabled.
9+
OpenClaw can run tool execution inside a sandbox backend to reduce blast radius. Sandboxing is off by default and controlled by `agents.defaults.sandbox` (global), `agents.entries.*.sandbox` (per-agent), or a required creator-role sandbox policy. The Gateway process always stays on the host; only tool execution moves into the sandbox when enabled.
1010

1111
<Note>
1212
This is not a perfect security boundary, but it materially limits filesystem and process access when the model does something dumb.
@@ -20,7 +20,7 @@ This is not a perfect security boundary, but it materially limits filesystem and
2020
Not sandboxed:
2121

2222
- The Gateway process itself.
23-
- Any tool explicitly allowed to run outside the sandbox via `tools.elevated`. Elevated exec bypasses sandboxing and runs on the configured escape path (`gateway` by default, or `node` when the exec target is `node`). If sandboxing is off, `tools.elevated` changes nothing since exec already runs on the host. See [Elevated Mode](/tools/elevated).
23+
- Any tool explicitly allowed to run outside an ordinary sandbox via `tools.elevated`. Elevated exec uses the configured escape path (`gateway` by default, or `node` when the exec target is `node`), but cannot escape a session whose creator role requires sandboxing. If sandboxing is off, `tools.elevated` changes nothing since exec already runs on the host. See [Elevated Mode](/tools/elevated).
2424

2525
## Modes, scope, and backend
2626

@@ -34,10 +34,17 @@ Three independent settings control sandbox behavior:
3434

3535
**Mode** controls when sandboxing applies:
3636

37-
- `off`: no sandboxing.
37+
- `off`: no agent-wide sandboxing; sessions whose creator role requires a sandbox still run sandboxed.
3838
- `non-main`: sandbox every session except the agent's main session. The main session key is always `agent:<agentId>:main` (or `global` when `session.scope` is `"global"`); it is not configurable. Group/channel sessions use their own keys, so they always count as non-main and get sandboxed.
3939
- `all`: every session runs in a sandbox.
4040

41+
Set a named operator role's `sandbox` policy to `"required"` to sandbox that
42+
role's newly created sessions regardless of agent mode. The creator requirement
43+
is immutable for the session; unavailable backends fail closed, and elevated
44+
execution or Gateway/node host overrides cannot bypass it. The default
45+
`"inherit"` preserves existing agent-mode behavior. See
46+
[Named operator roles](/gateway/operator-scopes#named-operator-roles).
47+
4148
**Scope** controls how many containers/environments are created:
4249

4350
- `agent`: one container per agent.

‎docs/tools/elevated.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ read_when:
66
title: "Elevated mode"
77
---
88

9-
When an agent runs inside a sandbox, its `exec` commands are confined to the sandbox environment. **Elevated mode** lets the agent break out and run commands outside the sandbox instead, with configurable approval gates.
9+
When an agent runs inside a sandbox, its `exec` commands are confined to the sandbox environment. **Elevated mode** lets the agent break out of ordinary agent-configured sandboxing and run commands outside the sandbox instead, with configurable approval gates. Sessions whose creator role requires sandboxing cannot use elevated mode to escape.
1010

1111
<Info>
1212
Elevated mode only changes behavior when the agent is **sandboxed**. For unsandboxed agents, exec already runs on the host.
@@ -102,6 +102,7 @@ Allowlist entry formats:
102102
## What elevated does not control
103103

104104
- **Tool policy**: if `exec` is denied by tool policy, elevated cannot override it.
105+
- **Required role sandboxing**: if the authenticated session creator's operator role required a sandbox, elevated mode cannot run commands on the Gateway or a node.
105106
- **Host selection policy**: elevated does not turn `auto` into a free cross-host override. It uses the configured/session exec target rules, choosing `node` only when the target is already `node`.
106107
- **Separate from `/exec`**: the `/exec` directive adjusts per-session exec defaults (host, security, ask, node) for authorized senders and does not require elevated mode.
107108

‎src/agents/bash-tools.exec-run.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,8 @@ export function createExecTool(
237237
: elevatedDefaults?.defaultLevel === "on"
238238
? "ask"
239239
: "off";
240-
const effectiveDefaultMode = elevatedAllowed ? elevatedDefaultMode : "off";
240+
const effectiveDefaultMode =
241+
elevatedAllowed && !defaults?.sandboxRequired ? elevatedDefaultMode : "off";
241242
const elevatedMode =
242243
typeof params.elevated === "boolean"
243244
? params.elevated
@@ -291,6 +292,7 @@ export function createExecTool(
291292
requestedTarget,
292293
elevatedRequested,
293294
sandboxAvailable: Boolean(defaults?.sandbox),
295+
sandboxRequired: defaults?.sandboxRequired,
294296
});
295297
const host: ExecHost = target.effectiveHost;
296298

‎src/agents/bash-tools.exec-runtime.ts‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,9 +255,23 @@ export function resolveExecTarget(params: {
255255
requestedTarget?: ExecTarget | null;
256256
elevatedRequested: boolean;
257257
sandboxAvailable: boolean;
258+
sandboxRequired?: boolean;
258259
}) {
259-
const configuredTarget = params.configuredTarget ?? "auto";
260+
const sandboxRequired = params.sandboxRequired === true;
261+
if (sandboxRequired && !params.sandboxAvailable) {
262+
throw new Error("This session requires a sandbox, but its sandbox runtime is unavailable.");
263+
}
264+
if (sandboxRequired && params.elevatedRequested) {
265+
throw new Error("Elevated execution is unavailable because this session requires a sandbox.");
266+
}
267+
// Session isolation outranks every agent, session, and request-scoped host preference.
268+
const configuredTarget = sandboxRequired ? "auto" : (params.configuredTarget ?? "auto");
260269
const requestedTarget = params.requestedTarget ?? null;
270+
if (sandboxRequired && (requestedTarget === "gateway" || requestedTarget === "node")) {
271+
throw new Error(
272+
`exec host not allowed (requested ${renderExecTargetLabel(requestedTarget)}; this session requires a sandbox).`,
273+
);
274+
}
261275
if (
262276
requestedTarget &&
263277
!isRequestedExecTargetAllowed({

0 commit comments

Comments
 (0)