Diffinery

homeflare/celldpublic

celld/docs/security.md
161 lines · 8.0 KBRaw History
1# Security
2
3celld v0.6.3 is a beta release. It is not safe for hostile multi-tenant use.
4Only the latest release receives security fixes.
5
6## Security boundary
7
8One fleet runs one application. celld trusts the application code, the fleet
9nodes, and the operators. Application code can use its configured bindings and
10can consume shared node resources. Do not run code from mutually distrusting
11tenants in one fleet.
12
13Application code cannot reach the engine's host functions. An internal script
14receives them as function parameters, and `globalThis` carries no
15`__`-prefixed property. A Worker Loader worker with `globalOutbound: null`
16therefore reaches the host only through the capabilities in its `env`.
17
18celld depends on two external boundaries: a trusted private network protects
19the internal listener, and object storage credentials control the fleet.
20
21## Separate the listeners
22
23celld opens two HTTP listeners and terminates TLS on neither.
24
25| Listener | Serves | Required protection |
26| --- | --- | --- |
27| `--listen` (public) | The deployed Worker | Terminate TLS and authenticate users in a proxy or the application. |
28| `--internal-listen` (default `127.0.0.1:0`, a free loopback port) | The peer protocol and the operator API | Restrict access to trusted operators and fleet nodes. Never expose it to the public internet. Use an encrypted overlay such as WireGuard or Tailscale when the network does not provide confidentiality. |
29
30`--advertise` gives peers the internal address. celld rejects an explicit
31`--advertise` or a non-loopback `--listen` without an explicit
32`--internal-listen`. celld cannot verify a hostname or a translated port, so
33you must route the advertised address to the internal listener.
34
35The public listener reserves only `/.well-known/celld/health`: 200 with
36`{"ok":true}` when healthy, 503 otherwise. The Worker owns every other public
37path, including `/health`. The internal listener returns 404 for an unknown
38path, so an operator request cannot become an application request.
39
40The internal listener has three request groups, and all three require the
41trusted private network:
42
43- Most operator routes have no request authentication.
44- `/peer/tunnel` opens a tunnel for cell fetch, RPC, and WebSocket calls. The
45 establishment request carries the fleet HMAC, a clock limit, and replay
46 protection. The calls inside the tunnel are plain, unsigned HTTP.
47- The peer-control and reserved-cell routes sign each request with the fleet
48 HMAC, a clock limit, and replay protection.
49
50Every path to a runtime class therefore demands the fleet secret. The HMAC
51does not authenticate tunnel bytes after establishment and does not encrypt
52traffic, so it does not replace the private network.
53
54## Use the internal operator API
55
56The operator API is an alpha interface. A release can change its paths or
57response formats. These routes do not authenticate the caller:
58
59- `/state` reports node state.
60- `/cell/<SCOPE>` resolves or activates a cell.
61- `/evict/<SCOPE>` tries to evict a resident cell and reports the result.
62- `/do/<ID>` sends a direct request to an ordinary Durable Object.
63- `POST /shutdown` starts a graceful ownership handoff. `handoff=preserve`
64 prepares a same-node reload.
65
66`/do/<ID>` refuses every reserved runtime class, such as D1, Workflows, KV,
67and Queues, because their protocols can access application data. Use the
68HMAC-authenticated `/runtime/<SCOPE>` route for these classes.
69
70`/peer/probe` returns a signed diagnostic response. Do not call the other
71reserved peer paths directly.
72
73### Read an eviction result
74
75An accepted eviction waits for the operation to finish, and a refused one
76returns at once. Concurrent callers can join one eviction, so the success
77count does not equal the stop count.
78
79The Rust method `AppHandle::evict` returns `Result<EvictSuccess, EvictError>`.
80`Evicted` confirms a completed runtime stop, and `AlreadyAbsent` confirms
81settled local absence. A caller that needs a completed eviction must check for
82`Evicted`. Over HTTP, both return 200 with `{"ok":true}`. `kind()` and
83`reason()` on the error match the HTTP error body. A later request can
84reactivate the cell before the response arrives.
85
86A missing cell or a settled `Inactive`, `Dormant`, or `Remote` cell is locally
87absent. A pending activation, stop, or ownership transfer prevents that
88result. The request does not evict a remote runtime. A dormant cell keeps its
89ownership and its hibernated host sockets. The node refuses during
90preservation, reload, or local inventory confirmation, or when it lacks
91authority.
92
93An error body has this form:
94
95```json
96{"ok":false,"error":{"kind":"refused","reason":"cell_active"}}
97```
98
99| Status | Kind | Reason | Cause |
100| --- | --- | --- | --- |
101| 409 | `refused` | `cell_active` | The cell has active work or a socket that requires a runtime. |
102| 409 | `refused` | `cell_transitioning` | The cell has another lifecycle transition. |
103| 409 | `refused` | `alarm_imminent` | The alarm residency policy retains the cell. |
104| 409 | `refused` | `alarm_uncovered` | The alarm coverage is unconfirmed, or a firing alarm blocks eviction during pressure shedding. |
105| 503 | `refused` | `node_unavailable` | The node cannot accept the eviction. |
106| 503 | `refused` | `eviction_limit` | The node has reached its eviction concurrency limit. |
107| 409 | `cancelled` | `new_activity` | A new request cancels an accepted eviction. |
108| 409 | `cancelled` | `alarm_activity` | An alarm observation or firing cancels an accepted eviction. |
109| 409 | `cancelled` | `node_fenced` | The node loses its authority during the eviction. |
110| 503 | `failed` | `actor_unavailable` | The request cannot reach the Actor. |
111| 500 | `failed` | `reply_lost` | A delivered request loses its reply, so its outcome is unknown. |
112| 500 | `failed` | `durability_failed` | The durability verification fails. |
113| 500 | `failed` | `durability_timeout` | The durability verification exceeds its operation deadline. |
114| 500 | `failed` | `runtime_stop_failed` | The runtime stop reports a failure. |
115
116A malformed scope returns 400. An error does not prove that the runtime is
117still resident. The runtime stop has no overall timeout, so a stop that never
118returns keeps the request pending.
119
120## Set the forwarded-header policy
121
122celld ignores `X-Forwarded-Host` and `X-Forwarded-Proto` by default. Set
123`--trust-forwarded-headers` or `CELLD_TRUST_FORWARDED_HEADERS=1` only when a
124trusted proxy replaces both headers. celld uses the last value in each header,
125so an earlier client value cannot override the proxy value.
126
127celld takes the path and query from the request target and ignores the scheme
128and authority of an absolute-form target. Without a trusted proxy, the `Host`
129header sets the hostname in `request.url`. celld accepts a hostname, an IPv4
130address, or a bracketed IPv6 address, with an optional port. It rejects
131malformed and noncanonical values and falls back to `celld.local`.
132
133The hostname is still client-controlled. Do not use an unchecked hostname for
134an authorization decision. Use a trusted proxy, or check the hostname against a
135list in the Worker.
136
137## Limit request bodies
138
139The public listener and `/do/<ID>` limit a request body to 1 GiB by default.
140Set `CELLD_MAX_REQUEST_BODY_BYTES` to a smaller positive value to lower it.
141celld returns 413 for a declared oversized body and when a Worker reads past
142the limit.
143
144For a method other than `GET` or `HEAD`, `/do/<ID>` streams a body of unknown
145length or of at least 1 MiB. It collects a smaller body before dispatch.
146
147## Protect the fleet bucket
148
149The fleet bucket is the root of authority. It stores the deployments, the cell
150state, the ownership and node leases, and the shared peer-authentication
151secret. A holder of the bucket credentials controls the fleet. Give each
152credential access to one fleet bucket only, and rotate it after a suspected
153disclosure.
154
155## Cell ownership
156
157Each cell is a SQLite database with one writer. An ownership epoch fences each
158cell, so a node that loses its lease cannot modify the current state. This
159fencing protects storage consistency. It does not isolate hostile
160applications. See [what celld guarantees](guarantees.md) and
161[limitations](limitations.md).