Diffinery

homeflare/celldpublic

celld/docs/security.md
226 lines · 11.0 KBRaw History
1# Security
2
3celld v0.6.1 is a beta release. It is not safe for hostile multi-tenant use.
4Security fixes apply to the latest release only, so older beta releases do not
5receive fixes.
6
7## Security boundary
8
9One fleet runs one application, and celld trusts the application code, the fleet
10nodes, and the operators. Application code can use its configured bindings and
11can consume shared node resources. Do not run code from mutually distrusting
12tenants in one fleet.
13
14The engine's host functions are not reachable from application code. An
15internal script receives them as function parameters, so a bundle cannot name
16a host function, and `globalThis` carries no `__`-prefixed property. A worker
17that the Worker Loader loads with `globalOutbound: null` therefore reaches the
18host only through the capabilities in its `env`.
19
20celld depends on two external security boundaries:
21
22- A trusted private network protects the internal listener. Use an encrypted
23 overlay when the private network does not provide confidentiality.
24- Object storage credentials control the fleet. Give each credential access to
25 one fleet bucket only.
26
27## Separate the listeners
28
29celld opens two HTTP listeners. The public listener serves the deployed Worker,
30and the internal listener serves the peer protocol and the operator API.
31
32Use `--listen` for the public listener. Expose this listener through a load
33balancer, a reverse proxy, or a public firewall rule.
34
35Use `--internal-listen` for the internal listener. Its default address is
36`127.0.0.1:0`, so celld selects an available loopback port at each start. Use
37`--advertise` to give peers an address that reaches this listener.
38
39An explicit advertised address requires an explicit internal-listener address.
40celld also rejects an explicit non-loopback public listener without an explicit
41internal listener. These checks prevent an obsolete one-listener configuration.
42
43celld cannot verify a hostname or a translated port. You must route the
44advertised address to the internal listener, and you must not route it to the
45public listener.
46
47The public listener reserves only `/.well-known/celld/health`. A healthy node
48returns a 200 response with `{"ok":true}`, and an unhealthy node returns a 503
49response. The deployed Worker owns `/health` and every other public path.
50
51The internal listener does not pass an unknown path to the Worker. It returns a
52404 response, so an operator request cannot become an application request.
53
54## Protect each surface
55
56| Surface | Required protection |
57| --- | --- |
58| The public listener | Terminate TLS and authenticate users in a proxy or the application. |
59| The internal listener | Restrict access to trusted operators and fleet nodes. Use an encrypted overlay when the private network does not provide confidentiality. |
60| The fleet bucket | Restrict the credentials to one fleet bucket. |
61
62The internal listener has three request groups:
63
64- Most operator routes let an operator inspect or control a node without
65 request authentication.
66- The `/peer/tunnel` route establishes a tunnel for cell fetch, RPC, and
67 WebSocket calls. The establishment request carries the fleet HMAC, a clock
68 limit, and replay protection, so only a holder of the fleet secret can open
69 a tunnel. Each call then crosses inside the tunnel as plain HTTP with the
70 cell scope in a reserved header, and these inner calls are not signed.
71- The peer-control routes coordinate fleet nodes, and the reserved-cell routes
72 access runtime state. These routes use the fleet HMAC for request
73 authentication, a clock limit, and replay protection.
74
75All three groups require the trusted private network.
76
77The tunnel permits a request body to stream to the owner, so the fleet HMAC
78cannot sign an individual call. The establishment signature decides who can
79open a tunnel, and a tunneled call can address an application class or a
80runtime class, so every path to a runtime class demands the fleet secret.
81The signature does not authenticate the bytes after the establishment, and
82it does not encrypt any traffic. The private network must therefore stay
83trusted, and the fleet HMAC does not replace this network boundary.
84
85celld does not terminate TLS on either listener. Do not expose the internal
86listener to the public internet. Use an encrypted overlay such as WireGuard or
87Tailscale when the network does not provide the required confidentiality.
88
89## Use the internal operator API
90
91The internal operator API is available in the released binary. It is an alpha
92interface, so a release can change its paths or response formats.
93
94These routes do not authenticate the caller:
95
96- `/state` reports node state.
97- `/cell/<SCOPE>` resolves or activates a cell.
98- `/evict/<SCOPE>` tries to evict a resident cell and reports the result.
99- `/do/<ID>` sends a direct request to an ordinary Durable Object.
100- `POST /shutdown` starts a graceful ownership handoff. The
101 `handoff=preserve` query prepares a same-node reload.
102
103The `/do/<ID>` route refuses every reserved runtime class. These classes include
104D1, Workflows, KV, and Queues. Their operator protocols can access application
105data or change runtime state, so they use the HMAC-authenticated
106`/runtime/<SCOPE>` route.
107
108`/peer/probe` returns a signed diagnostic response. The peer protocol also
109uses other reserved internal paths. An operator must not call these paths
110directly.
111
112### Read an eviction result
113
114The eviction request waits for the accepted operation to finish. A refused
115request does not wait for an idle period or another lifecycle transition.
116An accepted request can join an eviction that is already running, and each
117waiting caller receives that operation's result.
118
119The Rust method `AppHandle::evict` returns `Result<EvictSuccess, EvictError>`.
120The success value `Evicted` confirms that the awaited eviction completes its
121runtime stop. The success value `AlreadyAbsent` confirms settled local absence
122when the Actor handles the request. A caller that requires a completed eviction
123must check for `Evicted`.
124
125Multiple callers can join one eviction and receive `Evicted`, so the successful
126call count does not measure the runtime stop count.
127The error distinguishes a refusal, a cancellation, and an execution failure.
128The Rust error methods `kind()` and `reason()` return the `kind` and `reason`
129strings of the HTTP error body.
130
131The response uses `application/json`. Both success values use status 200 with
132`{"ok":true}`, so the HTTP response does not distinguish them.
133It confirms a completed eviction or a settled local absence at the decision
134point. A later request can reactivate the cell before the response arrives.
135
136A missing cell or a settled `Inactive`, `Dormant`, or `Remote` cell counts
137as locally absent. A pending activation, stop, or ownership transfer prevents
138that result. The request does not evict a remote runtime. A dormant cell
139keeps its ownership and its hibernated host sockets.
140
141The node checks its availability before it reports local absence. The node
142refuses an eviction during preservation, reload, or local inventory
143confirmation, or when it lacks authority.
144
145Every eviction error has this structure:
146
147```json
148{"ok":false,"error":{"kind":"refused","reason":"cell_active"}}
149```
150
151The `kind` and `reason` values have these meanings:
152
153| Status | Kind | Reason | Cause |
154| --- | --- | --- | --- |
155| 409 | `refused` | `cell_active` | The cell has active work or a socket that requires a runtime. |
156| 409 | `refused` | `cell_transitioning` | The cell has another lifecycle transition. |
157| 409 | `refused` | `alarm_imminent` | The alarm residency policy retains the cell. |
158| 409 | `refused` | `alarm_uncovered` | The alarm coverage is unconfirmed, or a firing alarm blocks eviction during pressure shedding. |
159| 503 | `refused` | `node_unavailable` | The node cannot accept the eviction. |
160| 503 | `refused` | `eviction_limit` | The node has reached its eviction concurrency limit. |
161| 409 | `cancelled` | `new_activity` | A new request cancels an accepted eviction. |
162| 409 | `cancelled` | `alarm_activity` | An alarm observation or firing cancels an accepted eviction. |
163| 409 | `cancelled` | `node_fenced` | The node loses its authority during the eviction. |
164| 503 | `failed` | `actor_unavailable` | The request cannot reach the Actor. |
165| 500 | `failed` | `reply_lost` | A delivered request loses its reply, so its outcome is unknown. |
166| 500 | `failed` | `durability_failed` | The durability verification fails. |
167| 500 | `failed` | `durability_timeout` | The durability verification exceeds its operation deadline. |
168| 500 | `failed` | `runtime_stop_failed` | The runtime stop reports a failure. |
169
170The runtime stop has no overall timeout. A stop that does not return keeps
171the eviction request pending.
172
173An error does not prove that the runtime remains resident. A malformed scope
174still returns status 400 through the existing scope validation.
175
176## Set the forwarded-header policy
177
178celld ignores `X-Forwarded-Host` and `X-Forwarded-Proto` by default. Set
179`--trust-forwarded-headers` or `CELLD_TRUST_FORWARDED_HEADERS=1` only when a
180trusted proxy replaces both headers. celld uses the last value in each header,
181so an earlier client value does not override the proxy value.
182
183celld always takes the path and query from the request target. It ignores the
184scheme and authority in an absolute-form target, so a client cannot bypass the
185host policy through the request line.
186
187Without a trusted proxy, the `Host` header controls the hostname in
188`request.url`. celld accepts a hostname, an IPv4 address, or a bracketed IPv6
189address, with an optional port. It rejects malformed and noncanonical values,
190and it uses `celld.local` when no source gives a valid host.
191
192These checks keep the path and query valid, but they do not make the hostname
193trustworthy. An application must not use an unchecked hostname for an
194authorization decision. Use a trusted proxy or check the hostname against a
195list in the Worker.
196
197## Limit request bodies
198
199The public Worker listener and `/do/<ID>` have a 1 GiB request body limit by
200default. Set `CELLD_MAX_REQUEST_BODY_BYTES` to a smaller positive value to
201change the limit. celld returns status 413 for a declared oversized body and
202when a Worker reads past the limit.
203
204For a method other than `GET` or `HEAD`, `/do/<ID>` streams a body when its
205declared length is at least 1 MiB or its length is unknown. celld collects each
206smaller body before dispatch.
207
208## Protect the fleet bucket
209
210The fleet bucket is the root of authority for the fleet. It stores the
211deployments, the cell state, the ownership leases, the node leases, and the
212shared peer-authentication secret.
213
214A person who holds the bucket credentials controls the fleet. Give each
215credential access to one fleet bucket only, and replace a credential after a
216suspected disclosure.
217
218## Understand cell ownership
219
220Each cell is a SQLite database with one writer. One node owns a cell at a time,
221and an ownership epoch fences each cell. A node that loses its lease cannot
222modify the current cell state.
223
224This fencing protects storage consistency, but it does not isolate hostile
225applications. See [what celld guarantees](guarantees.md) for the storage protocol,
226and see [limitations](limitations.md) for the complete beta boundary.