| 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 | The engine's host functions are not reachable from application code. An |
| 14 | internal script receives them as function parameters, so a bundle cannot name |
| 15 | a host function, and `globalThis` carries no `__`-prefixed property. A worker |
| 16 | that the Worker Loader loads with `globalOutbound: null` therefore reaches the |
| 17 | host only through the capabilities in its `env`. |
| 18 | |
| 19 | celld 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 | |
| 28 | celld opens two HTTP listeners. The public listener serves the deployed Worker, |
| 29 | and the internal listener serves the peer protocol and the operator API. |
| 30 | |
| 31 | Use `--listen` for the public listener. Expose this listener through a load |
| 32 | balancer, a reverse proxy, or a public firewall rule. |
| 33 | |
| 34 | Use `--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 | |
| 38 | An explicit advertised address requires an explicit internal-listener address. |
| 39 | celld also rejects an explicit non-loopback public listener without an explicit |
| 40 | internal listener. These checks prevent an obsolete one-listener configuration. |
| 41 | |
| 42 | celld cannot verify a hostname or a translated port. You must route the |
| 43 | advertised address to the internal listener, and you must not route it to the |
| 44 | public listener. |
| 45 | |
| 46 | The public listener reserves only `/.well-known/celld/health`. A healthy node |
| 47 | returns a 200 response with `{"ok":true}`, and an unhealthy node returns a 503 |
| 48 | response. The deployed Worker owns `/health` and every other public path. |
| 49 | |
| 50 | The internal listener does not pass an unknown path to the Worker. It returns a |
| 51 | 404 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 | |
| 61 | The 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 | |
| 74 | All three groups require the trusted private network. |
| 75 | |
| 76 | The tunnel permits a request body to stream to the owner, so the fleet HMAC |
| 77 | cannot sign an individual call. The establishment signature decides who can |
| 78 | open a tunnel, and a tunneled call can address an application class or a |
| 79 | runtime class, so every path to a runtime class demands the fleet secret. |
| 80 | The signature does not authenticate the bytes after the establishment, and |
| 81 | it does not encrypt any traffic. The private network must therefore stay |
| 82 | trusted, and the fleet HMAC does not replace this network boundary. |
| 83 | |
| 84 | celld does not terminate TLS on either listener. Do not expose the internal |
| 85 | listener to the public internet. Use an encrypted overlay such as WireGuard or |
| 86 | Tailscale when the network does not provide the required confidentiality. |
| 87 | |
| 88 | ## Use the internal operator API |
| 89 | |
| 90 | The internal operator API is available in the released binary. It is an alpha |
| 91 | interface, so a release can change its paths or response formats. |
| 92 | |
| 93 | These 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 | |
| 102 | The `/do/<ID>` route refuses every reserved runtime class. These classes include |
| 103 | D1, Workflows, KV, and Queues. Their operator protocols can access application |
| 104 | data 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 |
| 108 | uses other reserved internal paths. An operator must not call these paths |
| 109 | directly. |
| 110 | |
| 111 | ### Read an eviction result |
| 112 | |
| 113 | The eviction request waits for the accepted operation to finish. A refused |
| 114 | request does not wait for an idle period or another lifecycle transition. |
| 115 | An accepted request can join an eviction that is already running, and each |
| 116 | waiting caller receives that operation's result. |
| 117 | |
| 118 | The Rust method `AppHandle::evict` returns `Result<EvictSuccess, EvictError>`. |
| 119 | The success value `Evicted` confirms that the awaited eviction completes its |
| 120 | runtime stop. The success value `AlreadyAbsent` confirms settled local absence |
| 121 | when the Actor handles the request. A caller that requires a completed eviction |
| 122 | must check for `Evicted`. |
| 123 | |
| 124 | Multiple callers can join one eviction and receive `Evicted`, so the successful |
| 125 | call count does not measure the runtime stop count. |
| 126 | The error distinguishes a refusal, a cancellation, and an execution failure. |
| 127 | The Rust error methods `kind()` and `reason()` return the `kind` and `reason` |
| 128 | strings of the HTTP error body. |
| 129 | |
| 130 | The response uses `application/json`. Both success values use status 200 with |
| 131 | `{"ok":true}`, so the HTTP response does not distinguish them. |
| 132 | It confirms a completed eviction or a settled local absence at the decision |
| 133 | point. A later request can reactivate the cell before the response arrives. |
| 134 | |
| 135 | A missing cell or a settled `Inactive`, `Dormant`, or `Remote` cell counts |
| 136 | as locally absent. A pending activation, stop, or ownership transfer prevents |
| 137 | that result. The request does not evict a remote runtime. A dormant cell |
| 138 | keeps its ownership and its hibernated host sockets. |
| 139 | |
| 140 | The node checks its availability before it reports local absence. The node |
| 141 | refuses an eviction during preservation, reload, or local inventory |
| 142 | confirmation, or when it lacks authority. |
| 143 | |
| 144 | Every eviction error has this structure: |
| 145 | |
| 146 | ```json |
| 147 | {"ok":false,"error":{"kind":"refused","reason":"cell_active"}} |
| 148 | ``` |
| 149 | |
| 150 | The `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 | |
| 169 | The runtime stop has no overall timeout. A stop that does not return keeps |
| 170 | the eviction request pending. |
| 171 | |
| 172 | An error does not prove that the runtime remains resident. A malformed scope |
| 173 | still returns status 400 through the existing scope validation. |
| 174 | |
| 175 | ## Set the forwarded-header policy |
| 176 | |
| 177 | celld ignores `X-Forwarded-Host` and `X-Forwarded-Proto` by default. Set |
| 178 | `--trust-forwarded-headers` or `CELLD_TRUST_FORWARDED_HEADERS=1` only when a |
| 179 | trusted proxy replaces both headers. celld uses the last value in each header, |
| 180 | so an earlier client value does not override the proxy value. |
| 181 | |
| 182 | celld always takes the path and query from the request target. It ignores the |
| 183 | scheme and authority in an absolute-form target, so a client cannot bypass the |
| 184 | host policy through the request line. |
| 185 | |
| 186 | Without a trusted proxy, the `Host` header controls the hostname in |
| 187 | `request.url`. celld accepts a hostname, an IPv4 address, or a bracketed IPv6 |
| 188 | address, with an optional port. It rejects malformed and noncanonical values, |
| 189 | and it uses `celld.local` when no source gives a valid host. |
| 190 | |
| 191 | These checks keep the path and query valid, but they do not make the hostname |
| 192 | trustworthy. An application must not use an unchecked hostname for an |
| 193 | authorization decision. Use a trusted proxy or check the hostname against a |
| 194 | list in the Worker. |
| 195 | |
| 196 | ## Limit request bodies |
| 197 | |
| 198 | The public Worker listener and `/do/<ID>` have a 1 GiB request body limit by |
| 199 | default. Set `CELLD_MAX_REQUEST_BODY_BYTES` to a smaller positive value to |
| 200 | change the limit. celld returns status 413 for a declared oversized body and |
| 201 | when a Worker reads past the limit. |
| 202 | |
| 203 | For a method other than `GET` or `HEAD`, `/do/<ID>` streams a body when its |
| 204 | declared length is at least 1 MiB or its length is unknown. celld collects each |
| 205 | smaller body before dispatch. |
| 206 | |
| 207 | ## Protect the fleet bucket |
| 208 | |
| 209 | The fleet bucket is the root of authority for the fleet. It stores the |
| 210 | deployments, the cell state, the ownership leases, the node leases, and the |
| 211 | shared peer-authentication secret. |
| 212 | |
| 213 | A person who holds the bucket credentials controls the fleet. Give each |
| 214 | credential access to one fleet bucket only, and replace a credential after a |
| 215 | suspected disclosure. |
| 216 | |
| 217 | ## Understand cell ownership |
| 218 | |
| 219 | Each cell is a SQLite database with one writer. One node owns a cell at a time, |
| 220 | and an ownership epoch fences each cell. A node that loses its lease cannot |
| 221 | modify the current cell state. |
| 222 | |
| 223 | This fencing protects storage consistency, but it does not isolate hostile |
| 224 | applications. See [what celld guarantees](guarantees.md) for the storage protocol, |
| 225 | and see [limitations](limitations.md) for the complete alpha boundary. |