Diffinery

homeflare/celldpublic

celld/docs/security.md
131 lines · 6.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## Separate the public and internal listeners
7
8celld opens two HTTP listeners. The public listener serves the deployed Worker,
9and the internal listener serves the peer protocol and the operator API.
10
11Use `--listen` for the public listener. Expose only this listener through a load
12balancer, a reverse proxy, or a public firewall rule.
13
14Use `--internal-listen` for the internal listener. Its default address is
15`127.0.0.1:0`, so celld selects an available loopback port at each start.
16The startup output reports the selected address.
17
18Use `--advertise` to give peers the address of the internal listener. Bind the
19internal listener to a private interface, or protect it with a private overlay.
20Do not expose this listener to the public internet.
21
22An explicit advertised address requires an explicit internal-listener address.
23Set both command-line options, or use their equivalent environment variables.
24celld also rejects an explicit non-loopback public listener without an explicit
25internal listener. This rule identifies an obsolete one-listener configuration.
26
27celld cannot verify that an advertised hostname or a translated port reaches
28the internal listener. You must route the advertised address to the internal
29listener, and you must not route it to the public Worker listener.
30
31The public listener reserves only `/__celld/health`. A healthy node returns a
32200 response with `{"ok":true}`, and an unhealthy node returns a 503 response.
33The deployed Worker owns `/health` and every other public path.
34
35The internal listener does not pass an unknown path to the Worker. It returns a
36404 response, so an operator request cannot become an application request.
37
38## Set the forwarded-header policy
39
40A Worker reads the request URL from `request.url`. An application can route on
41the hostname and build an absolute link from this URL. Therefore, celld ignores
42`X-Forwarded-Host` and `X-Forwarded-Proto` by default.
43
44Set `--trust-forwarded-headers` only when a trusted proxy replaces both headers.
45celld then reads the last value in each header, so an earlier client value does
46not override the proxy value. The equivalent environment variable is
47`CELLD_TRUST_FORWARDED_HEADERS=1`.
48
49celld always takes the path and query from the request target. It ignores an
50absolute-form request target's scheme and authority, so a direct client cannot
51bypass the host policy through the request line.
52
53## Protect the internal listener
54
55Most of the operator API does not authenticate its requests. A client that
56can reach the internal listener can inspect state, start direct work, evict a
57cell, or stop the process. Therefore, a firewall or a private overlay must
58restrict access to trusted operators and fleet nodes.
59
60The D1 route is the exception, because a D1 database holds application data
61and runs the SQL that a caller sends. That route authenticates each request
62with the fleet secret, and the unauthenticated `/do/NAME` route refuses a D1
63database. An unauthenticated client on the internal listener can therefore
64stop a node, but it cannot read or change the contents of a D1 database.
65The refusal protects only the D1 database: the `/do/NAME` route still sends
66an unauthenticated request to the `fetch` handler of an ordinary Durable
67Object, so that handler runs whatever code it contains for that request. The
68difference is the SQL: only the D1 route runs arbitrary SQL that the caller
69wrote, and a Durable Object runs only its own code.
70
71Peer requests on the same listener keep their protocol authentication. Each
72peer request has an HMAC, a body signature, a clock limit, and replay
73protection. The private network adds protection, but it does not replace the
74peer authentication.
75
76celld does not terminate TLS on the internal listener. Use an encrypted overlay
77such as WireGuard or Tailscale when the private network does not provide the
78required confidentiality.
79
80## Internal operator API
81
82The internal operator API is available in the released binary. The API is an
83alpha interface, so a release can change its paths or response formats.
84
85- `/state` reports the current occupancy, eviction, and restoration values. It
86 remains available while a graceful shutdown drains existing work.
87- `/cell/NAME` resolves or activates a cell for an operator check.
88- `/evict/NAME` evicts a resident cell.
89- `/do/NAME` sends a direct Durable Object request. This route refuses a D1
90 database, because the route does not authenticate its caller.
91- `/__d1/SCOPE` sends SQL to a D1 database. This route authenticates each
92 request with the fleet secret, so a caller needs the bucket credentials.
93 The `celld d1` command uses this route.
94- `POST /shutdown` starts a graceful ownership handoff.
95- `POST /shutdown?handoff=preserve` prepares a clean same-node reload and keeps
96 the ownership records.
97- `/__celld/probe` serves the signed diagnostic probe.
98
99The peer protocol also uses reserved internal paths. An operator must not call
100these paths directly, and celld continues to authenticate each peer request.
101
102## Protect the fleet bucket
103
104The fleet bucket is the root of authority for the fleet. It stores the
105deployments, the cell state, the ownership leases, the node leases, and the
106shared peer-authentication secret.
107
108A person who holds the bucket credentials controls the fleet. Give each
109credential access to one fleet bucket only, and replace a credential after a
110suspected disclosure.
111
112## Keep one writer for each cell
113
114Each cell is a SQLite database with one writer. One node owns a cell at a time,
115and an ownership epoch fences each cell.
116
117A node that loses its lease cannot modify the current cell state. The
118[ownership and fencing](fencing.md) page describes this mechanism.
119
120A fleet has no shared multi-tenant scheduler or shared placement layer. A
121defective cell can access only its own database, but it can consume resources
122on its fleet nodes.
123
124## Protect the public application
125
126celld does not authenticate the users of the deployed application. It also does
127not terminate public TLS. Put the required authentication and TLS in front of
128the public listener.
129
130Keep the internal listener private, and keep the bucket credentials secret.
131See the [limitations](limitations.md) page for the complete alpha boundary.