| 1 | # Security |
| 2 | |
| 3 | celld is an alpha. It is not safe for hostile multi-tenant use. Security fixes |
| 4 | apply to the latest release only, so older alpha builds do not receive fixes. |
| 5 | |
| 6 | ## Security boundary |
| 7 | |
| 8 | One fleet runs one application, and celld trusts the application code, the fleet |
| 9 | nodes, and the operators. Application code can use its configured bindings and |
| 10 | can consume shared node resources. Do not run code from mutually distrusting |
| 11 | tenants in one fleet. |
| 12 | |
| 13 | celld 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 | |
| 22 | celld opens two HTTP listeners. The public listener serves the deployed Worker, |
| 23 | and the internal listener serves the peer protocol and the operator API. |
| 24 | |
| 25 | Use `--listen` for the public listener. Expose this listener through a load |
| 26 | balancer, a reverse proxy, or a public firewall rule. |
| 27 | |
| 28 | Use `--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 | |
| 32 | An explicit advertised address requires an explicit internal-listener address. |
| 33 | celld also rejects an explicit non-loopback public listener without an explicit |
| 34 | internal listener. These checks prevent an obsolete one-listener configuration. |
| 35 | |
| 36 | celld cannot verify a hostname or a translated port. You must route the |
| 37 | advertised address to the internal listener, and you must not route it to the |
| 38 | public listener. |
| 39 | |
| 40 | The public listener reserves only `/.well-known/celld/health`. A healthy node |
| 41 | returns a 200 response with `{"ok":true}`, and an unhealthy node returns a 503 |
| 42 | response. The deployed Worker owns `/health` and every other public path. |
| 43 | |
| 44 | The internal listener does not pass an unknown path to the Worker. It returns a |
| 45 | 404 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 | |
| 55 | The 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 | |
| 68 | All three groups require the trusted private network. |
| 69 | |
| 70 | The tunnel permits a request body to stream to the owner, so the fleet HMAC |
| 71 | cannot sign an individual call. The establishment signature decides who can |
| 72 | open a tunnel, and a tunneled call can address an application class or a |
| 73 | runtime class, so every path to a runtime class demands the fleet secret. |
| 74 | The signature does not authenticate the bytes after the establishment, and |
| 75 | it does not encrypt any traffic. The private network must therefore stay |
| 76 | trusted, and the fleet HMAC does not replace this network boundary. |
| 77 | |
| 78 | celld does not terminate TLS on either listener. Do not expose the internal |
| 79 | listener to the public internet. Use an encrypted overlay such as WireGuard or |
| 80 | Tailscale when the network does not provide the required confidentiality. |
| 81 | |
| 82 | ## Use the internal operator API |
| 83 | |
| 84 | The internal operator API is available in the released binary. It is an alpha |
| 85 | interface, so a release can change its paths or response formats. |
| 86 | |
| 87 | These 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 | |
| 96 | The `/do/<ID>` route refuses every reserved runtime class. These classes include |
| 97 | D1, Workflows, KV, and Queues. Their operator protocols can access application |
| 98 | data 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 |
| 102 | uses other reserved internal paths. An operator must not call these paths |
| 103 | directly. |
| 104 | |
| 105 | ## Set the forwarded-header policy |
| 106 | |
| 107 | celld ignores `X-Forwarded-Host` and `X-Forwarded-Proto` by default. Set |
| 108 | `--trust-forwarded-headers` or `CELLD_TRUST_FORWARDED_HEADERS=1` only when a |
| 109 | trusted proxy replaces both headers. celld uses the last value in each header, |
| 110 | so an earlier client value does not override the proxy value. |
| 111 | |
| 112 | celld always takes the path and query from the request target. It ignores the |
| 113 | scheme and authority in an absolute-form target, so a client cannot bypass the |
| 114 | host policy through the request line. |
| 115 | |
| 116 | Without a trusted proxy, the `Host` header controls the hostname in |
| 117 | `request.url`. celld accepts a hostname, an IPv4 address, or a bracketed IPv6 |
| 118 | address, with an optional port. It rejects malformed and noncanonical values, |
| 119 | and it uses `celld.local` when no source gives a valid host. |
| 120 | |
| 121 | These checks keep the path and query valid, but they do not make the hostname |
| 122 | trustworthy. An application must not use an unchecked hostname for an |
| 123 | authorization decision. Use a trusted proxy or check the hostname against a |
| 124 | list in the Worker. |
| 125 | |
| 126 | ## Limit request bodies |
| 127 | |
| 128 | The public Worker listener and `/do/<ID>` have a 1 GiB request body limit by |
| 129 | default. Set `CELLD_MAX_REQUEST_BODY_BYTES` to a smaller positive value to |
| 130 | change the limit. celld returns status 413 for a declared oversized body and |
| 131 | when a Worker reads past the limit. |
| 132 | |
| 133 | For a method other than `GET` or `HEAD`, `/do/<ID>` streams a body when its |
| 134 | declared length is at least 1 MiB or its length is unknown. celld collects each |
| 135 | smaller body before dispatch. |
| 136 | |
| 137 | ## Protect the fleet bucket |
| 138 | |
| 139 | The fleet bucket is the root of authority for the fleet. It stores the |
| 140 | deployments, the cell state, the ownership leases, the node leases, and the |
| 141 | shared peer-authentication secret. |
| 142 | |
| 143 | A person who holds the bucket credentials controls the fleet. Give each |
| 144 | credential access to one fleet bucket only, and replace a credential after a |
| 145 | suspected disclosure. |
| 146 | |
| 147 | ## Understand cell ownership |
| 148 | |
| 149 | Each cell is a SQLite database with one writer. One node owns a cell at a time, |
| 150 | and an ownership epoch fences each cell. A node that loses its lease cannot |
| 151 | modify the current cell state. |
| 152 | |
| 153 | This fencing protects storage consistency, but it does not isolate hostile |
| 154 | applications. See [what celld guarantees](guarantees.md) for the storage protocol, |
| 155 | and see [limitations](limitations.md) for the complete alpha boundary. |