Diffinery

homeflare/celldpublic

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