Diffinery

homeflare/celldpublic

celld/docs/security.md
155 lines · 7.2 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
13celld depends on two external security boundaries:
14
15- A trusted private network protects the internal listener. Use an encrypted
16 overlay when the private network does not provide confidentiality.
17- Object storage credentials control the fleet. Give each credential access to
18 one fleet bucket only.
19
20## Separate the listeners
21
22celld opens two HTTP listeners. The public listener serves the deployed Worker,
23and the internal listener serves the peer protocol and the operator API.
24
25Use `--listen` for the public listener. Expose this listener through a load
26balancer, a reverse proxy, or a public firewall rule.
27
28Use `--internal-listen` for the internal listener. Its default address is
29`127.0.0.1:0`, so celld selects an available loopback port at each start. Use
30`--advertise` to give peers an address that reaches this listener.
31
32An explicit advertised address requires an explicit internal-listener address.
33celld also rejects an explicit non-loopback public listener without an explicit
34internal listener. These checks prevent an obsolete one-listener configuration.
35
36celld cannot verify a hostname or a translated port. You must route the
37advertised address to the internal listener, and you must not route it to the
38public listener.
39
40The public listener reserves only `/.well-known/celld/health`. A healthy node
41returns a 200 response with `{"ok":true}`, and an unhealthy node returns a 503
42response. The deployed Worker owns `/health` and every other public path.
43
44The internal listener does not pass an unknown path to the Worker. It returns a
45404 response, so an operator request cannot become an application request.
46
47## Protect each surface
48
49| Surface | Required protection |
50| --- | --- |
51| The public listener | Terminate TLS and authenticate users in a proxy or the application. |
52| The internal listener | Restrict access to trusted operators and fleet nodes. Use an encrypted overlay when the private network does not provide confidentiality. |
53| The fleet bucket | Restrict the credentials to one fleet bucket. |
54
55The internal listener has three request groups:
56
57- Most operator routes let an operator inspect or control a node without
58 request authentication.
59- The `/peer/tunnel` route establishes a tunnel for cell fetch, RPC, and
60 WebSocket calls. The establishment request carries the fleet HMAC, a clock
61 limit, and replay protection, so only a holder of the fleet secret can open
62 a tunnel. Each call then crosses inside the tunnel as plain HTTP with the
63 cell scope in a reserved header, and these inner calls are not signed.
64- The peer-control routes coordinate fleet nodes, and the reserved-cell routes
65 access runtime state. These routes use the fleet HMAC for request
66 authentication, a clock limit, and replay protection.
67
68All three groups require the trusted private network.
69
70The tunnel permits a request body to stream to the owner, so the fleet HMAC
71cannot sign an individual call. The establishment signature decides who can
72open a tunnel, and a tunneled call can address an application class or a
73runtime class, so every path to a runtime class demands the fleet secret.
74The signature does not authenticate the bytes after the establishment, and
75it does not encrypt any traffic. The private network must therefore stay
76trusted, and the fleet HMAC does not replace this network boundary.
77
78celld does not terminate TLS on either listener. Do not expose the internal
79listener to the public internet. Use an encrypted overlay such as WireGuard or
80Tailscale when the network does not provide the required confidentiality.
81
82## Use the internal operator API
83
84The internal operator API is available in the released binary. It is an alpha
85interface, so a release can change its paths or response formats.
86
87These routes do not authenticate the caller:
88
89- `/state` reports node state.
90- `/cell/<SCOPE>` resolves or activates a cell.
91- `/evict/<SCOPE>` evicts a resident cell.
92- `/do/<ID>` sends a direct request to an ordinary Durable Object.
93- `POST /shutdown` starts a graceful ownership handoff. The
94 `handoff=preserve` query prepares a same-node reload.
95
96The `/do/<ID>` route refuses every reserved runtime class. These classes include
97D1, Workflows, KV, and Queues. Their operator protocols can access application
98data or change runtime state, so they use the HMAC-authenticated
99`/runtime/<SCOPE>` route.
100
101`/peer/probe` returns a signed diagnostic response. The peer protocol also
102uses other reserved internal paths. An operator must not call these paths
103directly.
104
105## Set the forwarded-header policy
106
107celld ignores `X-Forwarded-Host` and `X-Forwarded-Proto` by default. Set
108`--trust-forwarded-headers` or `CELLD_TRUST_FORWARDED_HEADERS=1` only when a
109trusted proxy replaces both headers. celld uses the last value in each header,
110so an earlier client value does not override the proxy value.
111
112celld always takes the path and query from the request target. It ignores the
113scheme and authority in an absolute-form target, so a client cannot bypass the
114host policy through the request line.
115
116Without a trusted proxy, the `Host` header controls the hostname in
117`request.url`. celld accepts a hostname, an IPv4 address, or a bracketed IPv6
118address, with an optional port. It rejects malformed and noncanonical values,
119and it uses `celld.local` when no source gives a valid host.
120
121These checks keep the path and query valid, but they do not make the hostname
122trustworthy. An application must not use an unchecked hostname for an
123authorization decision. Use a trusted proxy or check the hostname against a
124list in the Worker.
125
126## Limit request bodies
127
128The public Worker listener and `/do/<ID>` have a 1 GiB request body limit by
129default. Set `CELLD_MAX_REQUEST_BODY_BYTES` to a smaller positive value to
130change the limit. celld returns status 413 for a declared oversized body and
131when a Worker reads past the limit.
132
133For a method other than `GET` or `HEAD`, `/do/<ID>` streams a body when its
134declared length is at least 1 MiB or its length is unknown. celld collects each
135smaller body before dispatch.
136
137## Protect the fleet bucket
138
139The fleet bucket is the root of authority for the fleet. It stores the
140deployments, the cell state, the ownership leases, the node leases, and the
141shared peer-authentication secret.
142
143A person who holds the bucket credentials controls the fleet. Give each
144credential access to one fleet bucket only, and replace a credential after a
145suspected disclosure.
146
147## Understand cell ownership
148
149Each cell is a SQLite database with one writer. One node owns a cell at a time,
150and an ownership epoch fences each cell. A node that loses its lease cannot
151modify the current cell state.
152
153This fencing protects storage consistency, but it does not isolate hostile
154applications. See [what celld guarantees](guarantees.md) for the storage protocol,
155and see [limitations](limitations.md) for the complete alpha boundary.