Diffinery

homeflare/celldpublic

celld/docs/security.md
161 lines · 7.5 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>` evicts a resident cell.
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## Set the forwarded-header policy
112
113celld ignores `X-Forwarded-Host` and `X-Forwarded-Proto` by default. Set
114`--trust-forwarded-headers` or `CELLD_TRUST_FORWARDED_HEADERS=1` only when a
115trusted proxy replaces both headers. celld uses the last value in each header,
116so an earlier client value does not override the proxy value.
117
118celld always takes the path and query from the request target. It ignores the
119scheme and authority in an absolute-form target, so a client cannot bypass the
120host policy through the request line.
121
122Without a trusted proxy, the `Host` header controls the hostname in
123`request.url`. celld accepts a hostname, an IPv4 address, or a bracketed IPv6
124address, with an optional port. It rejects malformed and noncanonical values,
125and it uses `celld.local` when no source gives a valid host.
126
127These checks keep the path and query valid, but they do not make the hostname
128trustworthy. An application must not use an unchecked hostname for an
129authorization decision. Use a trusted proxy or check the hostname against a
130list in the Worker.
131
132## Limit request bodies
133
134The public Worker listener and `/do/<ID>` have a 1 GiB request body limit by
135default. Set `CELLD_MAX_REQUEST_BODY_BYTES` to a smaller positive value to
136change the limit. celld returns status 413 for a declared oversized body and
137when a Worker reads past the limit.
138
139For a method other than `GET` or `HEAD`, `/do/<ID>` streams a body when its
140declared length is at least 1 MiB or its length is unknown. celld collects each
141smaller body before dispatch.
142
143## Protect the fleet bucket
144
145The fleet bucket is the root of authority for the fleet. It stores the
146deployments, the cell state, the ownership leases, the node leases, and the
147shared peer-authentication secret.
148
149A person who holds the bucket credentials controls the fleet. Give each
150credential access to one fleet bucket only, and replace a credential after a
151suspected disclosure.
152
153## Understand cell ownership
154
155Each cell is a SQLite database with one writer. One node owns a cell at a time,
156and an ownership epoch fences each cell. A node that loses its lease cannot
157modify the current cell state.
158
159This fencing protects storage consistency, but it does not isolate hostile
160applications. See [what celld guarantees](guarantees.md) for the storage protocol,
161and see [limitations](limitations.md) for the complete alpha boundary.