Skip to content

Commit 5a54244

Browse files
authored
feat(fleet): multi-tenant hosting via openclaw fleet cell supervisor (#104527)
* feat(fleet): add openclaw fleet cell supervisor for multi-tenant hosting * test(fleet): cover cell profile, registry, containers, and service flows * docs(fleet): document multi-tenant hosting and the fleet CLI * fix(fleet): verify upgrade replacements and release foreign-collision reservations * fix(fleet): gate upgrade commit on replacement health * docs(fleet): mark fleet experimental and pin its single-host scope * test(fleet): make incomplete-profile casts explicit for test-type lane * fix(state): regenerate kysely schema artifacts after rebase conflict
1 parent cdb58ca commit 5a54244

28 files changed

Lines changed: 5346 additions & 2 deletions

‎.github/labeler.yml‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,14 @@
225225
- "src/daemon/**"
226226
- "docs/gateway/**"
227227

228+
"fleet":
229+
- changed-files:
230+
- any-glob-to-any-file:
231+
- "src/fleet/**"
232+
- "src/cli/fleet-cli/**"
233+
- "docs/gateway/multi-tenant-hosting.md"
234+
- "docs/cli/fleet.md"
235+
228236
"docs":
229237
- changed-files:
230238
- any-glob-to-any-file:

‎docs/cli/fleet.md‎

Lines changed: 250 additions & 0 deletions
Large diffs are not rendered by default.

‎docs/docs.json‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1632,7 +1632,8 @@
16321632
"gateway/gateway-lock",
16331633
"gateway/background-process",
16341634
"gateway/restart-recovery",
1635-
"gateway/multiple-gateways"
1635+
"gateway/multiple-gateways",
1636+
"gateway/multi-tenant-hosting"
16361637
]
16371638
},
16381639
{
@@ -1744,6 +1745,7 @@
17441745
"cli/crestodian",
17451746
"cli/daemon",
17461747
"cli/doctor",
1748+
"cli/fleet",
17471749
"cli/gateway",
17481750
"cli/health",
17491751
"cli/logs",

‎docs/docs_map.md‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1499,6 +1499,25 @@ Do not edit it by hand; run `pnpm docs:map:gen`.
14991499
- H2: macOS: launchctl env overrides
15001500
- H2: Related
15011501

1502+
## cli/fleet.md
1503+
1504+
- Route: /cli/fleet
1505+
- Headings:
1506+
- H1: openclaw fleet
1507+
- H2: Quick start
1508+
- H2: Tenant IDs
1509+
- H2: fleet create
1510+
- H3: Create options
1511+
- H2: fleet list
1512+
- H2: fleet status
1513+
- H2: fleet start, fleet stop, and fleet restart
1514+
- H2: fleet upgrade
1515+
- H2: fleet rm
1516+
- H2: Storage and container layout
1517+
- H2: Security profile
1518+
- H2: Token handling
1519+
- H2: Related
1520+
15021521
## cli/flows.md
15031522

15041523
- Route: /cli/flows
@@ -3463,6 +3482,19 @@ Do not edit it by hand; run `pnpm docs:map:gen`.
34633482
- H2: Console formatting (subsystem logging)
34643483
- H2: Related
34653484

3485+
## gateway/multi-tenant-hosting.md
3486+
3487+
- Route: /gateway/multi-tenant-hosting
3488+
- Headings:
3489+
- H1: Multi-tenant hosting
3490+
- H2: Why each tenant needs a cell
3491+
- H2: Architecture
3492+
- H2: Trust boundary
3493+
- H2: Isolation ladder
3494+
- H2: Quick start
3495+
- H2: Deferred from the MVP
3496+
- H2: Related
3497+
34663498
## gateway/multiple-gateways.md
34673499

34683500
- Route: /gateway/multiple-gateways
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
---
2+
summary: "Host multiple tenant trust domains as one isolated OpenClaw Gateway cell per tenant"
3+
read_when:
4+
- You are hosting OpenClaw for multiple users or organizations
5+
- You need to choose an isolation boundary for tenant workloads
6+
title: "Multi-tenant hosting"
7+
---
8+
9+
# Multi-tenant hosting
10+
11+
OpenClaw's default security model is one trusted operator boundary per Gateway, not hostile multi-tenant isolation inside one shared Gateway. Hosting users or organizations that do not share a trust boundary therefore means running a separate complete OpenClaw instance for each tenant.
12+
13+
`openclaw fleet` calls each isolated instance a **cell**. A cell is a full Gateway in a hardened container with its own state, credentials, workspace, channel accounts, token, and loopback-only host port.
14+
15+
Fleet is **experimental**: its commands, flags, and container profile can change between releases without a deprecation window while the surface settles.
16+
17+
## Why each tenant needs a cell
18+
19+
An authenticated operator inside one Gateway has a trusted control-plane role. Session IDs select routing; they do not authorize one tenant against another. Agent sandboxing can reduce the effect of untrusted content and tool execution, but it does not turn one shared Gateway into a tenant authorization boundary.
20+
21+
Use one cell per tenant so each trust domain has a separate Gateway process, container, persistent state tree, and Gateway credential. This follows the [Gateway security model](/gateway/security): do not co-locate mutually untrusted users in one OpenClaw process or one OS user.
22+
23+
## Architecture
24+
25+
The Fleet CLI is a host-side lifecycle supervisor. It records cells in the OpenClaw state database and asks a local Docker or Podman runtime to create, inspect, start, stop, replace, and remove their containers. Remote runtime endpoints are rejected because Fleet's bind paths and loopback URLs belong to the local host; remote cell hosts are deferred until they have an explicit storage and endpoint contract. Fleet does not proxy tenant messages and does not add a shared application-level data path between cells.
26+
27+
Each cell runs the official `ghcr.io/openclaw/openclaw` image on its own user-defined bridge network. Separate bridges prevent direct container-IP traffic between cells while retaining outbound NAT access for providers and channels. This is not an egress firewall; apply host or runtime network policy when a tenant needs outbound restrictions. The cell Gateway listens on port `18789` inside the container, while the runtime publishes it only to `127.0.0.1:<allocated-port>` on the host. An operator can place an approved reverse proxy, SSH tunnel, or tailnet in front of that loopback endpoint when remote access is needed.
28+
29+
Persistent Gateway state comes from `<state-dir>/fleet/cells/<tenant>/` and is mounted at `/home/node/.openclaw`. Auth-profile encryption keys come from the separate `<state-dir>/fleet/auth-profile-secrets/<tenant>/` host path and are mounted at `/home/node/.config/openclaw`, matching the official [Docker persistence layout](/install/docker#storage-and-persistence). The key is not nested beneath the ordinary state mount. Per-tenant channel accounts terminate inside the cell that owns them, so there is no shared channel account or shared inbound message router in the Fleet MVP.
30+
31+
The official image defaults to the non-root `node` user with UID 1000. Fleet uses host-compatible user mappings so private bind mounts stay writable: Podman uses `keep-id`, rootful Docker uses the invoking non-root identity, and rootless Docker maps container root to the unprivileged daemon user. Docker and Podman apply a private `:Z` relabel when host SELinux is active. The container profile avoids privileged host features and is rootless-friendly, but rootless operation is a host runtime choice and prerequisite, not something Fleet enables automatically.
32+
33+
## Trust boundary
34+
35+
Multi-tenancy protects tenants from each other. The Fleet operator and the host are trusted by every tenant. Resistance to a compromised host is a non-goal.
36+
37+
This means a host administrator can inspect container configuration and environment, read mounted cell data, replace images, or enter containers. Gateway tokens and values passed with `--env` are visible to an administrator through Docker or Podman inspection. Use host controls, administrative access policy, monitoring, backups, and an approved secret manager accordingly.
38+
39+
The baseline prevents accidental wildcard network exposure and removes common container escalation primitives, but it does not make an untrusted host safe.
40+
41+
## Isolation ladder
42+
43+
Choose the boundary that matches the tenants you host:
44+
45+
1. **Hardened container baseline.** Fleet drops all Linux capabilities, enables `no-new-privileges`, applies PID, memory, and CPU limits, uses separate persistent mounts and bridge networks, and publishes only to host loopback. This is the MVP profile for tenants that trust the operator and host.
46+
2. **Stronger container or VM isolation.** For higher-risk workloads, configure Docker or Podman to use a stronger OCI isolation runtime such as gVisor or Kata Containers, or place cells in microVMs. This is runtime or infrastructure configuration; Fleet's `--runtime docker|podman` option chooses the container CLI, not the OCI isolation backend. See Docker's [alternative container runtimes](https://docs.docker.com/engine/daemon/alternative-runtimes/) and the [Docker VM runtime guide](/install/docker-vm-runtime).
47+
3. **Separate machines for hostile tenants.** Do not co-locate hostile tenants in one OpenClaw process or OS user. When tenants do not trust the same host operator or need a stronger administrative boundary, use separate VMs or physical hosts with separate runtime administration.
48+
49+
No rung in this ladder changes the OpenClaw application trust model: one Gateway remains one trusted operator domain.
50+
51+
## Quick start
52+
53+
Create a cell. The command prints a generated Gateway token once, so store it immediately:
54+
55+
```bash
56+
openclaw fleet create acme
57+
```
58+
59+
Open the reported `http://127.0.0.1:<port>` URL on the Fleet host, authenticate with that tenant's token, and configure provider credentials and channel accounts inside the cell.
60+
61+
Check the container state and Gateway liveness:
62+
63+
```bash
64+
openclaw fleet status acme
65+
```
66+
67+
Upgrade while preserving the host port, mounted data, resource profile, user-supplied environment, and Gateway token:
68+
69+
```bash
70+
openclaw fleet upgrade acme
71+
```
72+
73+
Remove the container and registry row while retaining tenant data:
74+
75+
```bash
76+
openclaw fleet rm acme --force
77+
```
78+
79+
To delete persistent tenant data too, add `--purge-data`. Purge requires `--force`, is irreversible, and performs a resolved-path containment check before deleting anything:
80+
81+
```bash
82+
openclaw fleet rm acme --purge-data --force
83+
```
84+
85+
See the [`openclaw fleet` CLI reference](/cli/fleet) for every command and option.
86+
87+
## Deferred from the MVP
88+
89+
The first Fleet release deliberately leaves these surfaces to later designs:
90+
91+
- Shared channel accounts or a shared ingress router
92+
- Slimmed-down per-tenant host processes instead of complete OpenClaw instances
93+
- Remote cell hosts managed by one supervisor
94+
- A tenant self-service portal, billing plane, or delegated administration UI
95+
96+
These features need explicit identity, routing, authorization, and failure-domain contracts. They should not be approximated by sharing one Gateway or its credentials across tenants. They are also not Fleet's lane: Fleet stays a single-host lifecycle supervisor, and multi-machine, identity-governed fleets belong to a dedicated control-plane layer above it.
97+
98+
## Related
99+
100+
- [`openclaw fleet`](/cli/fleet)
101+
- [Gateway security](/gateway/security)
102+
- [Multiple gateways](/gateway/multiple-gateways)
103+
- [Docker](/install/docker)
104+
- [Podman](/install/podman)

‎docs/gateway/security/index.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ title: "Security"
2424
- Inside one Gateway, authenticated operator access is a trusted control-plane role, not a per-user tenant role.
2525
- `sessionKey` (session IDs, labels) is a routing selector, not an authorization token.
2626

27+
Hosting multiple users or organizations? Run one isolated Gateway cell per tenant instead of sharing a Gateway. See [Multi-tenant hosting](/gateway/multi-tenant-hosting).
28+
2729
Before changing remote access, DM policy, reverse proxy, or public exposure, run through the [Gateway exposure runbook](/gateway/security/exposure-runbook) as a pre-flight/rollback checklist.
2830

2931
## `openclaw security audit`

‎docs/install/docker.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ Docker is **optional**. Use it for an isolated, throwaway gateway environment or
1010

1111
The default sandbox backend uses Docker when `agents.defaults.sandbox` is enabled, but sandboxing is off by default and does not require the gateway itself to run in Docker. SSH and OpenShell sandbox backends are also available; see [Sandboxing](/gateway/sandboxing).
1212

13+
Hosting multiple users? See [Multi-tenant hosting](/gateway/multi-tenant-hosting) for the one-cell-per-tenant model.
14+
1315
## Prerequisites
1416

1517
- Docker Desktop (or Docker Engine) + Docker Compose v2

‎src/cli/command-catalog.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,10 @@ export const cliCommandCatalog: readonly CliCommandCatalogEntry[] = [
276276
commandPath: ["worktrees"],
277277
policy: { loadPlugins: "never", networkProxy: "bypass" },
278278
},
279+
{
280+
commandPath: ["fleet"],
281+
policy: { loadPlugins: "never", networkProxy: "bypass" },
282+
},
279283
{
280284
commandPath: ["doctor"],
281285
policy: {

‎src/cli/fleet-cli.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { registerFleetCli } from "./fleet-cli/register.js";
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
import { beforeEach, describe, expect, it, vi } from "vitest";
2+
3+
const mocks = await vi.hoisted(async () => {
4+
const { createCliRuntimeMock } = await import("../test-runtime-mock.js");
5+
return {
6+
...createCliRuntimeMock(vi),
7+
create: vi.fn(),
8+
list: vi.fn(),
9+
status: vi.fn(),
10+
lifecycle: vi.fn(),
11+
upgrade: vi.fn(),
12+
remove: vi.fn(),
13+
};
14+
});
15+
16+
vi.mock("../../runtime.js", () => ({ defaultRuntime: mocks.defaultRuntime }));
17+
vi.mock("../../fleet/service.runtime.js", () => ({
18+
createFleetService: () => ({
19+
create: mocks.create,
20+
list: mocks.list,
21+
status: mocks.status,
22+
lifecycle: mocks.lifecycle,
23+
upgrade: mocks.upgrade,
24+
remove: mocks.remove,
25+
}),
26+
}));
27+
28+
import {
29+
runFleetCreateCommand,
30+
runFleetListCommand,
31+
runFleetRemoveCommand,
32+
runFleetStatusCommand,
33+
} from "./commands.runtime.js";
34+
35+
describe("fleet command output", () => {
36+
beforeEach(() => {
37+
vi.clearAllMocks();
38+
mocks.runtimeLogs.length = 0;
39+
mocks.runtimeErrors.length = 0;
40+
});
41+
42+
it("writes the documented secret-bearing create JSON shape", async () => {
43+
const result = {
44+
tenant: "acme",
45+
containerName: "openclaw-cell-acme",
46+
port: 19_100,
47+
image: "ghcr.io/openclaw/openclaw:latest",
48+
runtime: "docker" as const,
49+
started: true,
50+
token: "gw-token",
51+
tokenNote: "Shown once. Store this Gateway token securely.",
52+
url: "http://127.0.0.1:19100",
53+
nextStep:
54+
"Open http://127.0.0.1:19100, then configure per-tenant channel accounts inside the cell.",
55+
};
56+
mocks.create.mockResolvedValue(result);
57+
58+
await runFleetCreateCommand({ tenant: "acme", json: true });
59+
60+
expect(mocks.defaultRuntime.writeJson).toHaveBeenCalledWith(result);
61+
});
62+
63+
it("prints the Gateway token exactly once in human create output", async () => {
64+
mocks.create.mockResolvedValue({
65+
tenant: "acme",
66+
containerName: "openclaw-cell-acme",
67+
port: 19_100,
68+
image: "image",
69+
runtime: "docker",
70+
started: true,
71+
token: "one-token",
72+
tokenNote: "Shown once. Store this Gateway token securely.",
73+
url: "http://127.0.0.1:19100",
74+
nextStep: "Open the cell.",
75+
});
76+
77+
await runFleetCreateCommand({ tenant: "acme", json: false });
78+
79+
expect(mocks.runtimeLogs.join("\n").match(/one-token/gu)).toHaveLength(1);
80+
expect(mocks.runtimeLogs.join("\n")).toContain("Shown once");
81+
});
82+
83+
it("wraps deterministic list JSON in a cells object", async () => {
84+
const cells = [
85+
{
86+
tenant: "acme",
87+
state: "running",
88+
port: 19_100,
89+
image: "image",
90+
created: "2026-01-01T00:00:00.000Z",
91+
},
92+
];
93+
mocks.list.mockResolvedValue(cells);
94+
95+
await runFleetListCommand({ json: true });
96+
97+
expect(mocks.defaultRuntime.writeJson).toHaveBeenCalledWith({ cells });
98+
});
99+
100+
it("writes status JSON and describes retained data on removal", async () => {
101+
const status = {
102+
tenant: "acme",
103+
containerName: "openclaw-cell-acme",
104+
runtime: "docker" as const,
105+
port: 19_100,
106+
image: "image",
107+
created: "2026-01-01T00:00:00.000Z",
108+
dataDir: "/tmp/acme",
109+
container: { state: "running", running: true, managed: true },
110+
health: {
111+
status: "ok" as const,
112+
url: "http://127.0.0.1:19100/healthz",
113+
httpStatus: 200,
114+
},
115+
};
116+
mocks.status.mockResolvedValue(status);
117+
mocks.remove.mockResolvedValue({ tenant: "acme", action: "rm", dataPurged: false });
118+
119+
await runFleetStatusCommand({ tenant: "acme", json: true });
120+
await runFleetRemoveCommand({ tenant: "acme", force: false, purgeData: false });
121+
122+
expect(mocks.defaultRuntime.writeJson).toHaveBeenCalledWith(status);
123+
expect(mocks.runtimeLogs).toContain("Removed fleet cell acme; data retained.");
124+
});
125+
});

0 commit comments

Comments
 (0)