Diffinery

homeflare/celldpublic

v0.6.3

Upgrading from v0.6.2 can use a rolling update.

Until every node runs v0.6.3, a v0.6.2 node can still acquire a cell whose ownership record was lost and start it empty.

- Outbound TLS no longer trusts emSign ECC Root CA - G3, and it rejects any certificate chain through one of the eight eMudhra intermediate CA certificates whose private keys are public.
- rustls 0.23.46 fixes GHSA-2mjx-qc3c-rqvc, where a TLS 1.3 handshake message was accepted across an encryption level boundary.
- A node refuses to acquire a cell whose ownership record (`cells/<cell>/own.json`) is missing while its LTX is still in the bucket, instead of starting the cell at epoch 1 with an empty database. Requests that need the record fail, and the node logs `celld ownership record lost` at most once every 10 seconds per cell. The guarantees documentation describes how to restore the record.

Issues fixed:

- #293: Outbound TLS distrusts the compromised eMudhra CA certificates (webpki-roots 1.0.10, rustls-webpki 0.103.16).

Co-authored-by: Yusuke "Taka" Tanaka <[email protected]>
Bartek Iwańczuk authored signed1 parent 90b4301commit 8702f6d186c77698dbfb30cf29e3b1922a88f008Browse files
11 files changed+207−21
Files (11)
modifiedCargo.lock+9−8View file
@@ -285,7 +285,7 @@
285285
286286 [[package]]
287287 name = "celld"
288-version = "0.6.2"
288+version = "0.6.3"
289289 dependencies = [
290290 "aes",
291291 "aes-gcm",
@@ -335,6 +335,7 @@
335335 "rsa",
336336 "rusqlite",
337337 "rustls",
338+ "rustls-webpki",
338339 "serde",
339340 "serde_json",
340341 "sha1",
@@ -2686,9 +2687,9 @@
26862687
26872688 [[package]]
26882689 name = "rustls"
2689-version = "0.23.43"
2690+version = "0.23.46"
26902691 source = "registry+https://github.com/rust-lang/crates.io-index"
2691-checksum = "0283386ce02abc0151e1761d08802dfe86c173b0b494af5cbc086574e453da06"
2692+checksum = "48e13bd8c0e9365c43cfa5c9e8f9ad49d3c8444926c9aac819e0e4dc503c8fdf"
26922693 dependencies = [
26932694 "log",
26942695 "once_cell",
@@ -2732,9 +2733,9 @@
27322733
27332734 [[package]]
27342735 name = "rustls-webpki"
2735-version = "0.103.13"
2736+version = "0.103.16"
27362737 source = "registry+https://github.com/rust-lang/crates.io-index"
2737-checksum = "61c429a8649f110dddef65e2a5ad240f747e85f7758a6bccc7e5777bd33f756e"
2738+checksum = "4443b1b6d39d7c663139942cc4558262562d2c84123bb6282ef177009ca8b281"
27382739 dependencies = [
27392740 "ring",
27402741 "rustls-pki-types",
@@ -3144,7 +3145,7 @@
31443145 checksum = "32497e9a4c7b38532efcdebeef879707aa9f794296a4f0244f6f69e9bc8574bd"
31453146 dependencies = [
31463147 "fastrand",
3147- "getrandom 0.4.3",
3148+ "getrandom 0.3.4",
31483149 "once_cell",
31493150 "rustix 1.1.4",
31503151 "windows-sys 0.61.2",
@@ -3796,9 +3797,9 @@
37963797
37973798 [[package]]
37983799 name = "webpki-roots"
3799-version = "1.0.9"
3800+version = "1.0.10"
38003801 source = "registry+https://github.com/rust-lang/crates.io-index"
3801-checksum = "7dcd9d09a39985f5344844e66b0c530a33843579125f23e21e9f0f220850f22a"
3802+checksum = "1c1c8e20c8a38fc7d65abfe74eb7280e4aa667e8eec8bc84996d2874810748d9"
38023803 dependencies = [
38033804 "rustls-pki-types",
38043805 ]
modifiedCargo.toml+11−2View file
@@ -119,7 +119,15 @@
119119 reqwest = { version = "0.12", default-features = false }
120120 rsa = { version = "0.9", features = ["sha2"] }
121121 rusqlite = "0.31"
122-rustls = { version = "0.23", default-features = false, features = ["ring"] }
122+# 0.23.45 fixes GHSA-2mjx-qc3c-rqvc, where rustls accepts a TLS 1.3
123+# handshake message across an encryption level boundary.
124+rustls = { version = "0.23.46", default-features = false, features = ["ring"] }
125+# celld never imports rustls-webpki; this entry only sets a floor. 0.103.16
126+# rejects every chain through the eight eMudhra intermediate CA certificates
127+# whose private keys are public, and rustls itself accepts 0.103.14. Without
128+# the floor, a resolver can select a version that still trusts those chains
129+# on a host whose own trust store still holds the emSign ECC root.
130+rustls-webpki = { version = "0.103.16", default-features = false }
123131 serde = { version = "1", features = ["derive"] }
124132 serde_json = { version = "1", features = ["raw_value"] }
125133 sha1 = "0.10"
@@ -150,4 +158,5 @@
150158 # denoland/rusty_v8#2044 and #2045. Both ship in 152.1.0, so this is an
151159 # ordinary dependency again — no path override, and no hand-built archive.
152160 v8 = "152.1"
153-webpki-roots = "1"
161+# 1.0.10 drops the emSign ECC root, whose intermediate CA keys are public.
162+webpki-roots = "1.0.10"
modifiedcrates/celld/Cargo.toml+2−1View file
@@ -1,6 +1,6 @@
11 [package]
22 name = "celld"
3-version = "0.6.2"
3+version = "0.6.3"
44 edition = "2021"
55 rust-version = "1.94.1"
66 license = "Apache-2.0"
@@ -67,6 +67,7 @@
6767 rusqlite = { workspace = true, features = ["backup", "bundled", "hooks", "serialize"] }
6868 sqlite-vec.workspace = true
6969 rustls.workspace = true
70+rustls-webpki.workspace = true
7071 rsa.workspace = true
7172 serde.workspace = true
7273 serde_json.workspace = true
modifiedcrates/celld/actor.rs+76−6View file
@@ -199,17 +199,76 @@
199199 Bucket(Arc<BucketOwnership>),
200200 }
201201
202+fn ownership_read_failed(error: anyhow::Error) -> Failure {
203+ eprintln!("celld ownership read failed: {error:#}");
204+ Failure::Definite
205+}
206+
202207 impl Ownership {
208+ /// Read the record as it is stored. A missing record here means only that
209+ /// no record exists now, so this read must not decide a claim; the core
210+ /// reads through [`Self::read_owner_for_claim`].
203211 pub(crate) async fn read_owner(&self, cell: &str) -> Result<Option<OwnerRecord>, Failure> {
204212 match self {
205213 Self::Memory(memory) => Ok(memory.lock().await.owners.get(cell).cloned()),
206- Self::Bucket(bucket) => bucket.read_owner(cell).await.map_err(|error| {
207- eprintln!("celld ownership read failed: {error:#}");
208- Failure::Definite
209- }),
214+ Self::Bucket(bucket) => bucket.read_owner(cell).await.map_err(ownership_read_failed),
210215 }
211216 }
212217
218+ /// Read the record for the core, which claims epoch one as a fresh cell
219+ /// when the record is missing.
220+ pub(crate) async fn read_owner_for_claim(
221+ &self,
222+ cell: &str,
223+ ) -> Result<Option<OwnerRecord>, Failure> {
224+ // Memory ownership runs without replication, so it never has LTX.
225+ let Self::Bucket(bucket) = self else {
226+ return self.read_owner(cell).await;
227+ };
228+ if bucket.lost_record_held(cell, crate::asyncrt::mono_ms()) {
229+ return Err(Failure::Definite);
230+ }
231+ let record = self.read_owner(cell).await?;
232+ if record.is_some()
233+ || !bucket
234+ .ltx_exists(cell)
235+ .await
236+ .map_err(ownership_read_failed)?
237+ {
238+ return Ok(record);
239+ }
240+ // A claim writes the record before any LTX, and celld never deletes
241+ // the record, so LTX proves that a record existed before the listing.
242+ // A first claim on another node can still write it after the first
243+ // read. Only a read after the listing that finds no record proves a
244+ // loss; without it, this node fails a request that it can forward and
245+ // reports a record that exists.
246+ if let Some(record) = self.read_owner(cell).await? {
247+ return Ok(Some(record));
248+ }
249+ // A missing record tells the core that the cell was never owned, so
250+ // the core claims epoch one as a fresh cell and the activation
251+ // restores nothing. celld never deletes `own.json`, but a bucket
252+ // lifecycle rule, a manual cleanup, or a partial bucket copy can. The
253+ // cell would then serve an empty database beside its acknowledged
254+ // chain and ship over `e1/`, and a node that asks while the owner
255+ // still serves would become a second writer. Failing the read writes
256+ // nothing: each claim fails until an operator restores the record and
257+ // the hold ends.
258+ // A refusal in `LtxRepl::activate_with` comes too late, because the
259+ // claim has already written a record at epoch one. Each later wake
260+ // then advances one epoch, and a wake without a takeover can reuse a
261+ // stale local eviction snapshot, which skips the used-epoch check.
262+ eprintln!(
263+ "celld ownership record lost: cells/{cell}/own.json is missing, but the bucket \
264+ holds LTX under cells/{cell}/ltx/; refusing to claim {cell} as a new cell for \
265+ {} s. See the ownership record repair in docs/guarantees.md.",
266+ crate::ownership_store::LOST_RECORD_RECHECK_MS / 1_000
267+ );
268+ bucket.hold_lost_record(cell, crate::asyncrt::mono_ms());
269+ Err(Failure::Definite)
270+ }
271+
213272 async fn read_node_lease(&self, owner: &str) -> Result<Option<NodeLeaseRecord>, Failure> {
214273 match self {
215274 Self::Memory(memory) => Ok(memory.lock().await.leases.get(owner).cloned()),
@@ -2326,13 +2385,22 @@
23262385 .await
23272386 }
23282387
2388+ /// Build an Actor on the scripted cell host with the caller's peer client.
2389+ ///
2390+ /// `main` passes one client to both the Actor and the AppHandle of a node,
2391+ /// and the caller of this constructor can do the same. The arguments are
2392+ /// those of `from_environment`, with the scripted host in place of the
2393+ /// runtime and with that client added. The added client puts the
2394+ /// constructor one argument over the Clippy limit.
23292395 #[cfg(all(test, celld_internal_tests))]
2396+ #[allow(clippy::too_many_arguments)]
23302397 pub(crate) async fn from_environment_with_scripted_host(
23312398 limits: AdmissionLimits,
23322399 fail_publish_once: bool,
23332400 fence: mpsc::UnboundedSender<i32>,
23342401 host: crate::conformance_sim_cell_host::SimCellHost,
23352402 ownership: Option<Ownership>,
2403+ peer_http: reqwest::Client,
23362404 identity: ActorIdentity,
23372405 resume_generation: Option<String>,
23382406 ) -> anyhow::Result<Self> {
@@ -2345,7 +2413,7 @@
23452413 host: Some(CellHost::Scripted(host)),
23462414 drain_pins: DrainPinRegistry::default(),
23472415 ownership,
2348- peer_http: reqwest::Client::new(),
2416+ peer_http,
23492417 peer_auth,
23502418 },
23512419 identity,
@@ -2367,6 +2435,7 @@
23672435 fence: mpsc::UnboundedSender<i32>,
23682436 host: crate::conformance_sim_cell_host::SimCellHost,
23692437 ownership: Option<Ownership>,
2438+ peer_http: reqwest::Client,
23702439 identity: ActorIdentity,
23712440 decision_state: ScriptedActorDecisionState,
23722441 ) -> anyhow::Result<Self> {
@@ -2397,6 +2466,7 @@
23972466 fence,
23982467 host,
23992468 ownership,
2469+ peer_http,
24002470 identity,
24012471 resume_generation,
24022472 )
@@ -3237,7 +3307,7 @@
32373307 let timing_cell = cell.clone();
32383308 out.spawn_scoped(async move {
32393309 let started = crate::asyncrt::mono_ms();
3240- let result = ownership.read_owner(&cell).await;
3310+ let result = ownership.read_owner_for_claim(&cell).await;
32413311 CompletedEffect::timed(
32423312 Event::OwnerRead {
32433313 op,
modifiedcrates/celld/ownership_store.rs+47−0View file
@@ -383,6 +383,15 @@
383383 }
384384 }
385385
386+/// How long a node refuses a cell whose record it found lost before it reads
387+/// the bucket again. A due alarm of a dormant cell retries its wake every
388+/// 100 ms, and a draining donor retries a handoff every 250 ms, so without a
389+/// hold a lost record costs two GETs and a LIST, and one stderr line, per
390+/// retry until an operator repairs it. The hold stays below the default 25 s
391+/// no-progress window of a shutdown handoff and the default 60 s wake scan,
392+/// so a repair takes effect well within either.
393+pub(crate) const LOST_RECORD_RECHECK_MS: u64 = 10_000;
394+
386395 /// The production-compatible conditional object store used by ownership
387396 /// effects. A failed write is reported to the core as ambiguous unless the
388397 /// store definitively returned HTTP 412, or the attempt provably wrote no
@@ -416,6 +425,9 @@
416425 /// (one publish outstanding at a time), >= S implies the applied body
417426 /// IS the waiter's object.
418427 applied: tokio::sync::watch::Sender<(String, u64)>,
428+ /// Each cell whose record this node found lost, with the monotonic time
429+ /// at which its hold ends. See [`LOST_RECORD_RECHECK_MS`].
430+ lost_records: std::sync::Mutex<std::collections::BTreeMap<String, u64>>,
419431 }
420432
421433 /// What this node currently looks like, for peers deciding where to place a
@@ -513,6 +525,7 @@
513525 ambient_load_override: None,
514526 own_log: std::sync::Mutex::new((0, None)),
515527 applied: tokio::sync::watch::channel((String::new(), 0)).0,
528+ lost_records: std::sync::Mutex::default(),
516529 }
517530 }
518531
@@ -581,6 +594,40 @@
581594 Ok(Some(record))
582595 }
583596
597+ /// Whether the bucket holds any LTX for `cell`. LTX exists only under an
598+ /// epoch that a claim opened, and the claim writes the ownership record
599+ /// first, so LTX proves that a record existed before the listing.
600+ pub async fn ltx_exists(&self, cell: &str) -> anyhow::Result<bool> {
601+ self.bucket.list_any(&format!("cells/{cell}/ltx")).await
602+ }
603+
604+ /// Whether this node found the record of `cell` lost less than
605+ /// [`LOST_RECORD_RECHECK_MS`] ago. An ended hold is dropped, so the
606+ /// caller reads the bucket again.
607+ pub(crate) fn lost_record_held(&self, cell: &str, now_mono_ms: u64) -> bool {
608+ let mut lost = self.lost_records.lock().unwrap();
609+ match lost.get(cell) {
610+ Some(until) if now_mono_ms < *until => true,
611+ Some(_) => {
612+ lost.remove(cell);
613+ false
614+ }
615+ None => false,
616+ }
617+ }
618+
619+ /// Hold a confirmed loss of the record of `cell`. Ended holds are dropped
620+ /// here as well, so the map keeps only the cells refused within the last
621+ /// hold interval.
622+ pub(crate) fn hold_lost_record(&self, cell: &str, now_mono_ms: u64) {
623+ let mut lost = self.lost_records.lock().unwrap();
624+ lost.retain(|_, until| now_mono_ms < *until);
625+ lost.insert(
626+ cell.to_string(),
627+ now_mono_ms.saturating_add(LOST_RECORD_RECHECK_MS),
628+ );
629+ }
630+
584631 pub async fn read_node_lease(&self, owner: &str) -> anyhow::Result<Option<NodeLeaseRecord>> {
585632 load_node_lease(&self.bucket, owner).await
586633 }
modifiedcrates/logic/lib.rs+5−1View file
@@ -81,7 +81,11 @@
8181 pub struct RestoreSpec {
8282 pub epoch: Epoch,
8383 /// This activation conditionally created epoch one, so no replica can
84- /// precede it.
84+ /// precede it. The bucket shell reports a missing record only when no LTX
85+ /// exists under `cells/<cell>/ltx/`. A record deleted outside celld
86+ /// therefore produces a fresh activation only when that prefix holds no
87+ /// LTX of the cell: before the first drain of a node bundle, or after the
88+ /// LTX was deleted as well.
8589 pub fresh: bool,
8690 /// Ownership was seized from a different node (or a released record), so
8791 /// a previous local eviction cache is not authoritative.
modifieddocs/README.md+6−0View file
@@ -542,6 +542,12 @@
542542 failure on the owner of a forwarded Durable Object fetch can reach the
543543 caller as a 500 response. A v0.6.2 pair rejects the caller's `stub.fetch()`
544544 instead, as a local owner does. A rollback to v0.6.1 can also roll.
545+- **v0.6.2 to v0.6.3: rolling.** A v0.6.3 node no longer trusts the
546+ emSign ECC Root CA - G3 certificate or the eight compromised eMudhra
547+ intermediate CA certificates for outbound TLS, so upgrade each node
548+ promptly. Until every node runs v0.6.3, a v0.6.2 node can still acquire a
549+ cell whose ownership record was lost and start the cell with an empty
550+ database. A rollback to v0.6.2 can also roll.
545551
546552 ## Diagnose a fleet
547553
modifieddocs/guarantees.md+48−0View file
@@ -70,6 +70,13 @@
7070 `deploy-blobs/`, `log/`, `wake/`, and `telemetry/`, and deletes objects under
7171 some of them. An application must not write under any of them.
7272
73+An operator must not delete, expire, or overwrite an object under these
74+prefixes, except under `probe/` and `telemetry/`. celld reads these objects to
75+fence and restore cells, and celld deletes the objects that it no longer needs.
76+A bucket lifecycle rule therefore must not select an object under another
77+reserved prefix. With a key prefix, each reserved prefix follows the key prefix,
78+for example `PREFIX/telemetry/`.
79+
7380 ## The supervisor
7481
7582 Run celld under a supervisor that restarts the process, such as systemd, Docker
@@ -88,6 +95,47 @@
8895 two nodes cannot acquire the same cell. Every activation, a takeover or a local
8996 wake, advances the epoch, so an epoch never has two writers.
9097
98+The record is `cells/<cell>/own.json`. celld never deletes it, and it must stay
99+in the bucket for the life of the cell. A missing record next to LTX under
100+`cells/<cell>/ltx/` means that the record was lost, for example to a lifecycle
101+rule. celld then refuses to acquire the cell, because a new record at epoch 1
102+would start it with an empty database. Each request that must read the record,
103+to acquire the cell or to find its owner, fails, and the node writes
104+`celld ownership record lost` to stderr. The node then refuses the cell for 10
105+seconds without a bucket request, so it writes the line at most once in that
106+interval. A node that still serves the cell keeps serving it and keeps writing
107+LTX until it stops. That node cannot acknowledge a write that a bucket proof
108+covers, because the record no longer names it, so the write fails and the node
109+writes `celld output gate` to stderr. With `CELLD_DURABILITY=bucket`, every
110+write takes a bucket proof. celld detects the loss only from LTX under
111+`cells/<cell>/ltx/`. A new cell can keep its first writes in a node bundle under
112+`log/` until the tiering path drains them, so a loss before that drain starts
113+the cell empty.
114+
115+To restore the cell, first stop each node that served the cell with SIGTERM, not
116+with `POST /shutdown?handoff=preserve`. A preserved restart resumes its cells
117+without a read of the record, so the node keeps serving the cell. No peer can
118+acquire the cell, so its handoff cannot complete: the stop can take the whole
119+`CELLD_SHUTDOWN_TOTAL_MS` and log `shutdown_handoff_stalled`.
120+
121+A stopped process can still hold acknowledged writes in its node log, outside
122+the per-cell prefixes, so wait until that log is recovered. A new process with
123+the same `CELLD_NODE` recovers it during startup, so the log is recovered when
124+that process reports healthy. Without the same `CELLD_NODE`, a running node
125+with `CELLD_DURABILITY=fleet`, the default, recovers it after the lease of the
126+stopped process expires. In that case, wait until `nodes/<node>.json` of the
127+stopped process is absent, has no `log` object, or shows `"state": "sealed"` in
128+it. A stop that logs `node-log close: sealed epoch` has already sealed its log.
129+
130+Then write a released record, which names no node, at the newest epoch: the
131+numerically highest `e<epoch>` prefix under `cells/<cell>/ltx/`. For a newest
132+epoch of 7, the record is `{"node": "", "epoch": 7}`. After the refusal interval
133+ends, the next request acquires the cell at the next epoch and restores it from
134+the bucket. A released record skips the recovery of the node log of the
135+previous owner. A record that is written before these logs are recovered can
136+therefore lose acknowledged writes, and a node that still serves the cell
137+becomes a second writer.
138+
91139 ### The epoch prefix
92140
93141 The replicator copies each cell's SQLite data to `cells/<cell>/ltx/e<epoch>/`
modifieddocs/limitations.md+1−1View file
@@ -1,6 +1,6 @@
11 # Limitations
22
3-celld v0.6.2 is a beta release with these operational limits. See
3+celld v0.6.3 is a beta release with these operational limits. See
44 [Cloudflare compatibility](cloudflare-compat.md) for the supported services,
55 APIs, and Wrangler configuration.
66
modifieddocs/security.md+1−1View file
@@ -1,6 +1,6 @@
11 # Security
22
3-celld v0.6.2 is a beta release. It is not safe for hostile multi-tenant use.
3+celld v0.6.3 is a beta release. It is not safe for hostile multi-tenant use.
44 Only the latest release receives security fixes.
55
66 ## Security boundary
modifieddocs/telemetry.md+1−1View file
@@ -16,7 +16,7 @@
1616 | --- | --- | --- |
1717 | `CELLD_OTEL` | `0` | `0` disables telemetry. `1` writes Parquet to the fleet bucket. An HTTP(S) collector base URL selects OTLP/HTTP protobuf. |
1818 | `CELLD_OTEL_BUCKET` | the fleet bucket | A different bucket for the Parquet files, on the same endpoint and credentials. |
19-| `CELLD_OTEL_RETENTION` | `30d` | celld deletes telemetry files older than this. `none` disables the deletion, so your own lifecycle rules can control the data. |
19+| `CELLD_OTEL_RETENTION` | `30d` | celld deletes telemetry files older than this. `none` disables the deletion, so your own lifecycle rules can control the data. In the fleet bucket, such a rule must select only the `telemetry/` prefix, after the key prefix if the bucket value has one. [Guarantees](guarantees.md) lists the reserved prefixes that a rule must not select. |
2020 | `CELLD_OTEL_FLUSH_MS` | `300000` | celld writes a Parquet file after this many milliseconds of buffered events. |
2121 | `CELLD_OTEL_FLUSH_BYTES` | `5242880` | The estimated buffered bytes that trigger a flush before the interval ends. |
2222 | `OTEL_TRACES_SAMPLER` | `parentbased_always_on` | A standard sampler name. `traceidratio` with `OTEL_TRACES_SAMPLER_ARG` records a fraction of the traces. |