From 653e7b623efc75089f8aea7d9c89cc5916d0a8b6 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Sat, 14 Nov 2026 05:15:56 -0800 Subject: [PATCH 1/5] chore(quest): claim quest/m2/mesh-device-bounds.md Quest-Claim: a8474d41cc835782 From 6d3aaf49553d4b0919c687db56f8ce2f4c2b5a63 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Sat, 14 Nov 2026 05:53:08 -0800 Subject: [PATCH 2/5] feat(moq-auth)!: an enrollment key carries a use budget, and mesh tokens last 15 minutes Co-Authored-By: Claude Opus 5.5 --- doc/bin/relay/auth.md | 9 ++-- quest/m2/README.md | 2 +- quest/m2/mesh-device-bounds.md | 12 ------ quest/m2/mesh-grant-shape.md | 1 - quest/m3/mesh/README.md | 2 +- rs/moq-auth/src/mesh/contract_tests.rs | 48 ++++++++++++--------- rs/moq-auth/src/mesh/coordinator.rs | 58 ++++++++++++++++---------- rs/moq-cli/src/auth.rs | 20 +++++---- 8 files changed, 83 insertions(+), 69 deletions(-) delete mode 100644 quest/m2/mesh-device-bounds.md diff --git a/doc/bin/relay/auth.md b/doc/bin/relay/auth.md index 80022a41215..34db90c3e4a 100644 --- a/doc/bin/relay/auth.md +++ b/doc/bin/relay/auth.md @@ -462,16 +462,17 @@ moq auth serve --key-dir /etc/moq/keys \ --mesh-url https://mesh.example.com --mesh-listen 127.0.0.1:4441 \ --mesh-key /etc/moq/mesh.jwk --mesh-state /var/lib/moq/mesh.json \ --mesh-relay https://relay.example.com -moq auth mesh create-key --tag robot --reusable --expires 7d +moq auth mesh create-key --tag robot --uses 20 --expires 7d moq auth mesh revoke ``` Every request proves the endpoint key by signing a fresh, single-use challenge bound to `--mesh-url`, so no token is issued for a key the caller does not hold. A device joins with an enrollment key, with no human in the -loop (single-use unless `--reusable`; revoked or expired keys enroll -nothing). It refreshes its token -two thirds of the way through `--mesh-token-ttl` (default 1h) by proving +loop. Each key enrolls at most `--uses` devices (default 1), so a leaked key +admits no more than its owner allowed; a device it already enrolled may +enroll again for free, and revoked or expired keys enroll nothing. It refreshes its token +two thirds of the way through `--mesh-token-ttl` (default 15m) by proving the key again, so a revoked device is cut off within one token lifetime. A revoked device cannot enroll again. Each enrollment and refresh also returns every member's unique, DNS-safe name, defaulting to the device's hostname. diff --git a/quest/m2/README.md b/quest/m2/README.md index 86bb7a1ffb7..965c0b952f4 100644 --- a/quest/m2/README.md +++ b/quest/m2/README.md @@ -39,7 +39,7 @@ Decided 2026-11-12 (maintainer, /quest-audit before the cut): in m2). The padding and JS rung disable quests are parked in m5. - ✅ Joined m2, each a small break the cut would otherwise freeze: the mesh [grant shape](/quest/m2/mesh-grant-shape.md) and - [key budget](/quest/m2/mesh-device-bounds.md), since `moq_auth::mesh` + key budget, since `moq_auth::mesh` publishes for the first time at this cut; [auth key validation](/quest/m2/auth-key-validation.md); the [RTMPS connect](/quest/m2/rtmp-rtmps-tcurl.md) signature; diff --git a/quest/m2/mesh-device-bounds.md b/quest/m2/mesh-device-bounds.md deleted file mode 100644 index 2a9976d684f..00000000000 --- a/quest/m2/mesh-device-bounds.md +++ /dev/null @@ -1,12 +0,0 @@ -# [S] Mesh enrollment is bounded and revocation takes effect - -## Goal - -The mesh coordinator (`rs/moq-auth/src/mesh/coordinator.rs`) stops assuming its device store stays small and its revocations wait for token expiry: - -- A reusable enrollment key carries a use budget set when it is created, so the coordinator holds at most what its keys allow. Today a reusable key enrolls any number of endpoints, and each enroll clones the whole store, rewrites the state file and returns every member under one mutex, so a leaked key can mint thousands. -- A revoked device loses access within a bounded time, not only at its token's `exp` (1h by default): either `decide` checks revocation for mesh tokens, or mesh tokens are short-lived with revalidation on. - -## Plan - -Found by the 2026-11-07 invariant audit (auth-7, auth-8). The budget belongs to the key's owner, not a server-wide constant or rate limit, per REVIEW.md's rule against constant caps. diff --git a/quest/m2/mesh-grant-shape.md b/quest/m2/mesh-grant-shape.md index 12e234606d1..5d8788e10cd 100644 --- a/quest/m2/mesh-grant-shape.md +++ b/quest/m2/mesh-grant-shape.md @@ -39,5 +39,4 @@ signature does. Wire: none. ## Related -- [Mesh enrollment is bounded](/quest/m2/mesh-device-bounds.md) - the other mesh contract change before the cut - [Mesh enrollment can grow](/quest/m2/api-mesh-enrollment.md) - fences the enrollment reply diff --git a/quest/m3/mesh/README.md b/quest/m3/mesh/README.md index 268b1d25a54..581608f1874 100644 --- a/quest/m3/mesh/README.md +++ b/quest/m3/mesh/README.md @@ -124,7 +124,7 @@ Decided 2026-11-12 (maintainer, /quest-audit before the cut): - ✅ The contract changes land in m2, because the cut publishes `moq_auth::mesh` for the first time: the [grant shape](/quest/m2/mesh-grant-shape.md) and the - [key budget](/quest/m2/mesh-device-bounds.md). + key budget. - The JS enrollment client and the guide are parked in m5: the application they were planned for enrolls with certificates and documents itself. diff --git a/rs/moq-auth/src/mesh/contract_tests.rs b/rs/moq-auth/src/mesh/contract_tests.rs index 6f3f043fc5b..0b8d97dc53b 100644 --- a/rs/moq-auth/src/mesh/contract_tests.rs +++ b/rs/moq-auth/src/mesh/contract_tests.rs @@ -39,9 +39,9 @@ impl Mesh { Client::new(self.base.clone(), signer).unwrap() } - fn key(&self, reusable: bool) -> String { + fn key(&self, uses: u32) -> String { let new = NewKey { - reusable, + uses: std::num::NonZeroU32::new(uses).unwrap(), tags: vec!["robot".into()], ..Default::default() }; @@ -61,7 +61,7 @@ impl Mesh { async fn an_enrollment_key_grants_the_endpoints_subtree() { let mesh = Mesh::new().await; let device = mesh.device(); - let enrollment = device.enroll(&mesh.key(false), Some("Robot 1")).await.unwrap(); + let enrollment = device.enroll(&mesh.key(1), Some("Robot 1")).await.unwrap(); assert_eq!(enrollment.name, "robot-1"); assert_eq!( @@ -85,29 +85,39 @@ async fn an_enrollment_key_grants_the_endpoints_subtree() { #[tokio::test] async fn a_single_use_key_enrolls_once() { let mesh = Mesh::new().await; - let key = mesh.key(false); + let key = mesh.key(1); let device = mesh.device(); let first = device.enroll(&key, Some("pi")).await.unwrap(); let err = mesh.device().enroll(&key, None).await.unwrap_err(); assert_eq!(Mesh::refused(err), ErrorCode::InvalidGrant); - // The device it enrolled can retry, as after a lost reply, and keeps its name. - let retried = device.enroll(&key, Some("other")).await.unwrap(); + // The device it enrolled can retry, as after a lost reply, without spending a use. + let retried = device.enroll(&key, Some("pi")).await.unwrap(); assert_eq!(retried.name, first.name); assert!(mesh.key.verify(&retried.token).is_ok()); - let reusable = mesh.key(true); - let first = mesh.device().enroll(&reusable, Some("bot")).await.unwrap(); - let second = mesh.device().enroll(&reusable, Some("bot")).await.unwrap(); + let shared = mesh.key(2); + let bot = mesh.device(); + let first = bot.enroll(&shared, Some("bot")).await.unwrap(); + let second = mesh.device().enroll(&shared, Some("bot")).await.unwrap(); assert_eq!(first.name, "bot"); assert_eq!(second.name, "bot-2"); assert_eq!(second.members.len(), 3); + + // Its budget spent, the key admits no new device, but one it enrolled may return. + let err = mesh.device().enroll(&shared, None).await.unwrap_err(); + assert_eq!(Mesh::refused(err), ErrorCode::InvalidGrant); + bot.enroll(&shared, None).await.unwrap(); + assert_eq!(mesh.coordinator.devices().len(), 3); + let (id, _) = shared.split_once('.').unwrap(); + let info = mesh.coordinator.keys().into_iter().find(|key| key.id == id).unwrap(); + assert_eq!(info.used, 2); } #[tokio::test] async fn a_revoked_or_unknown_key_enrolls_nothing() { let mesh = Mesh::new().await; - let key = mesh.key(true); + let key = mesh.key(10); let id = key.split_once('.').unwrap().0; assert!(mesh.coordinator.revoke_key(id).unwrap()); let err = mesh.device().enroll(&key, None).await.unwrap_err(); @@ -127,7 +137,7 @@ async fn a_proof_from_the_wrong_key_is_refused() { proof.endpoint = victim.endpoint(); let request = EnrollRequest { proof, - key: mesh.key(true), + key: mesh.key(10), name: None, }; assert_eq!( @@ -166,7 +176,7 @@ async fn refresh_issues_a_new_token_until_revoked() { let err = device.refresh().await.unwrap_err(); assert_eq!(Mesh::refused(err), ErrorCode::AccessDenied); - let enrollment = device.enroll(&mesh.key(true), Some("pi")).await.unwrap(); + let enrollment = device.enroll(&mesh.key(10), Some("pi")).await.unwrap(); let refreshed = device.refresh().await.unwrap(); assert_eq!(refreshed.name, "pi"); assert!(mesh.key.verify(&refreshed.token).is_ok()); @@ -176,8 +186,8 @@ async fn refresh_issues_a_new_token_until_revoked() { let err = device.refresh().await.unwrap_err(); assert_eq!(Mesh::refused(err), ErrorCode::AccessDenied); - // A reusable key cannot bring a revoked device back. - let err = device.enroll(&mesh.key(true), None).await.unwrap_err(); + // A key with uses left cannot bring a revoked device back. + let err = device.enroll(&mesh.key(10), None).await.unwrap_err(); assert_eq!(Mesh::refused(err), ErrorCode::AccessDenied); } @@ -188,7 +198,7 @@ async fn renew_refreshes_before_expiry() { let ttl = Duration::from_secs(3); let mesh = Mesh::with_ttl(ttl).await; let device = mesh.device(); - let enrollment = device.enroll(&mesh.key(true), None).await.unwrap(); + let enrollment = device.enroll(&mesh.key(10), None).await.unwrap(); let mut renew = std::pin::pin!(device.renew(&enrollment)); // The first poll arms the wait for two thirds of the token's life, before any request. let mut cx = std::task::Context::from_waker(std::task::Waker::noop()); @@ -206,7 +216,7 @@ async fn only_an_issued_challenge_is_accepted() { let enroll = |challenge: Vec| { let request = EnrollRequest { proof: Proof::sign(&holder, &mesh.base, challenge), - key: mesh.key(true), + key: mesh.key(10), name: None, }; mesh.coordinator.enroll(&request).unwrap_err().error @@ -232,7 +242,7 @@ async fn renew_retries_a_transient_refusal() { let mesh = Mesh::with_ttl(Duration::from_secs(3)).await; let signer = Arc::new(Ed25519KeyPair::generate().unwrap()); let device = Client::new(mesh.base.clone(), signer.clone()).unwrap(); - let enrollment = device.enroll(&mesh.key(true), None).await.unwrap(); + let enrollment = device.enroll(&mesh.key(10), None).await.unwrap(); let fresh = device.refresh().await.unwrap(); // A coordinator that restarts between issuing the challenge and seeing the proof. @@ -290,11 +300,11 @@ fn a_failed_save_spends_nothing() { let err = coordinator.enroll(&enroll(&coordinator)).unwrap_err(); assert_eq!(err.error, ErrorCode::ServerError); assert!(coordinator.devices().is_empty()); - assert!(!coordinator.keys()[0].used); + assert_eq!(coordinator.keys()[0].used, 0); std::fs::remove_dir(dir.path().join("mesh.tmp")).unwrap(); coordinator.enroll(&enroll(&coordinator)).unwrap(); - assert!(coordinator.keys()[0].used); + assert_eq!(coordinator.keys()[0].used, 1); } #[tokio::test] diff --git a/rs/moq-auth/src/mesh/coordinator.rs b/rs/moq-auth/src/mesh/coordinator.rs index cee6b7e5206..f2681e1601f 100644 --- a/rs/moq-auth/src/mesh/coordinator.rs +++ b/rs/moq-auth/src/mesh/coordinator.rs @@ -11,6 +11,7 @@ //! replay state is one number per enrolled device, so no caller can spend another's room. use std::collections::HashMap; +use std::num::NonZeroU32; use std::path::PathBuf; use std::sync::atomic::{AtomicU64, Ordering}; use std::sync::{Arc, Mutex}; @@ -52,12 +53,13 @@ pub struct Config { pub relays: Vec, /// The JSON file enrollment keys and devices persist to; `None` keeps them in memory. pub state: Option, - /// How long an issued token lasts. + /// How long an issued token lasts. Relays verify a token on their own, so this is also + /// the longest a revoked device keeps its access. pub token_ttl: Duration, } impl Config { - /// A coordinator at `url` signing with `key`, with hour-long tokens, no relays, and no + /// A coordinator at `url` signing with `key`, with 15-minute tokens, no relays, and no /// state file. pub fn new(url: url::Url, key: Key) -> Self { Self { @@ -65,7 +67,7 @@ impl Config { key, relays: Vec::new(), state: None, - token_ttl: Duration::from_secs(3600), + token_ttl: Duration::from_secs(900), } } } @@ -91,9 +93,9 @@ struct StoredKey { #[serde_as(as = "Option")] #[serde(default, skip_serializing_if = "Option::is_none")] expires: Option, - reusable: bool, + uses: NonZeroU32, #[serde(default)] - used: bool, + used: u32, #[serde(default)] revoked: bool, } @@ -132,10 +134,10 @@ pub struct KeyInfo { #[serde_as(as = "Option")] #[serde(default, skip_serializing_if = "Option::is_none")] pub expires: Option, - /// Whether it enrolls more than one device. - pub reusable: bool, - /// Whether a single-use key has enrolled its device. - pub used: bool, + /// How many devices it may enroll. + pub uses: NonZeroU32, + /// How many devices it has enrolled. + pub used: u32, /// Whether the owner revoked it. pub revoked: bool, /// The key itself, returned only when it is created. @@ -149,7 +151,7 @@ impl From<&StoredKey> for KeyInfo { id: key.id.clone(), tags: key.tags.clone(), expires: key.expires, - reusable: key.reusable, + uses: key.uses, used: key.used, revoked: key.revoked, key: None, @@ -159,7 +161,7 @@ impl From<&StoredKey> for KeyInfo { /// `POST /mesh/keys` on the admin API: what the new enrollment key allows. #[serde_as] -#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)] +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] #[serde(default)] #[non_exhaustive] pub struct NewKey { @@ -168,8 +170,20 @@ pub struct NewKey { /// How long until it stops enrolling; `None` never expires. Whole seconds on the wire. #[serde_as(as = "Option>")] pub expires_in: Option, - /// Whether it enrolls more than one device. - pub reusable: bool, + /// How many devices it may enroll, so a leaked key admits at most this many. A device + /// it already enrolled may enroll again without spending one. + pub uses: NonZeroU32, +} + +impl Default for NewKey { + /// A key that enrolls one device and never expires. + fn default() -> Self { + Self { + tags: Vec::new(), + expires_in: None, + uses: NonZeroU32::MIN, + } + } } #[derive(Default)] @@ -268,21 +282,21 @@ impl Coordinator { "the enrollment key has expired", )); } - if !key.reusable && key.used { + let endpoint = request.proof.endpoint; + let known = inner.store.devices.iter().any(|device| device.endpoint == endpoint); + if !known && key.used >= key.uses.get() { return Err(ErrorReply::new( ErrorCode::InvalidGrant, - "the enrollment key was already used", + "the enrollment key has no uses left", )); } let tags = key.tags.clone(); - let reusable = key.reusable; let id = id.to_string(); - let endpoint = request.proof.endpoint; let enrollment = self.commit(&mut inner, |store| { self.admit(store, endpoint, request.name.as_deref(), tags)?; - if !reusable && let Some(key) = store.keys.iter_mut().find(|key| key.id == id) { - key.used = true; + if !known && let Some(key) = store.keys.iter_mut().find(|key| key.id == id) { + key.used += 1; } self.issue(store, endpoint) })?; @@ -318,8 +332,8 @@ impl Coordinator { hash: hex(&sha256(secret.as_bytes())), tags: new.tags.clone(), expires: new.expires_in.map(|ttl| kio::clock::wall().saturating_add(ttl)), - reusable: new.reusable, - used: false, + uses: new.uses, + used: 0, revoked: false, }; let mut info = KeyInfo::from(&stored); @@ -726,7 +740,7 @@ mod tests { let coordinator = Coordinator::new(Config::new(base.clone(), key)).unwrap(); let secret = coordinator .create_key(&NewKey { - reusable: true, + uses: NonZeroU32::new(2).unwrap(), ..Default::default() }) .unwrap() diff --git a/rs/moq-cli/src/auth.rs b/rs/moq-cli/src/auth.rs index 63f1a03c8d6..469934b4635 100644 --- a/rs/moq-cli/src/auth.rs +++ b/rs/moq-cli/src/auth.rs @@ -554,11 +554,12 @@ struct MeshServe { #[serde(default, skip_serializing_if = "Option::is_none")] state: Option, - /// How long a mesh token lasts; devices refresh it two thirds of the way through. + /// How long a mesh token lasts, which bounds how long a revoked device keeps access; + /// devices refresh it two thirds of the way through. #[usage( name = "mesh-token-ttl", long = "mesh-token-ttl", - default = "1h", + default = "15m", setting = "mesh.token_ttl" )] token_ttl: moq_tokio::cli::Duration, @@ -572,7 +573,7 @@ impl Default for MeshServe { key: None, relay: Vec::new(), state: None, - token_ttl: std::time::Duration::from_secs(3600).into(), + token_ttl: std::time::Duration::from_secs(900).into(), } } } @@ -1002,9 +1003,9 @@ enum MeshCommand { #[usage(long)] expires: Option, - /// Enroll any number of devices, instead of one. - #[usage(long)] - reusable: bool, + /// How many devices it may enroll. + #[usage(long, default = "1")] + uses: std::num::NonZeroU32, }, /// List enrollment keys, without their secrets. @@ -1039,11 +1040,11 @@ impl Mesh { url }; let request = match &self.command { - MeshCommand::CreateKey { tag, expires, reusable } => { + MeshCommand::CreateKey { tag, expires, uses } => { let mut new = moq_auth::mesh::NewKey::default(); new.tags = tag.clone(); new.expires_in = expires.map(std::time::Duration::from); - new.reusable = *reusable; + new.uses = *uses; client.post(url("/mesh/keys", &[])).json(&new) } MeshCommand::Keys => client.get(url("/mesh/keys", &[])), @@ -1374,7 +1375,8 @@ mod tests { "create-key", "--tag", "robot", - "--reusable", + "--uses", + "20", "--expires", "1d", ][..], From 532dfee2b256d8bc2d73c49ced507b0bc4c59259 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Sat, 14 Nov 2026 06:16:09 -0800 Subject: [PATCH 3/5] fix(moq-auth): only the key that enrolled a device re-enrolls it for free Co-Authored-By: Claude Opus 5.5 --- rs/moq-auth/src/mesh/contract_tests.rs | 11 +++++++++++ rs/moq-auth/src/mesh/coordinator.rs | 24 +++++++++++++++++++++--- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/rs/moq-auth/src/mesh/contract_tests.rs b/rs/moq-auth/src/mesh/contract_tests.rs index 0b8d97dc53b..cdad2676a9b 100644 --- a/rs/moq-auth/src/mesh/contract_tests.rs +++ b/rs/moq-auth/src/mesh/contract_tests.rs @@ -112,6 +112,17 @@ async fn a_single_use_key_enrolls_once() { let (id, _) = shared.split_once('.').unwrap(); let info = mesh.coordinator.keys().into_iter().find(|key| key.id == id).unwrap(); assert_eq!(info.used, 2); + + // An exhausted key cannot re-enroll a device another key admitted. + let other = mesh.key(1); + let moved = mesh.device(); + moved.enroll(&other, None).await.unwrap(); + // The client falls back to a refresh, which leaves the device on its own key. + moved.enroll(&shared, None).await.unwrap(); + let (other_id, _) = other.split_once('.').unwrap(); + let devices = mesh.coordinator.devices(); + assert!(devices.iter().any(|device| device.key == other_id && device.name == "device")); + assert_eq!(mesh.coordinator.keys().into_iter().find(|key| key.id == id).unwrap().used, 2); } #[tokio::test] diff --git a/rs/moq-auth/src/mesh/coordinator.rs b/rs/moq-auth/src/mesh/coordinator.rs index f2681e1601f..c83b5ad55b4 100644 --- a/rs/moq-auth/src/mesh/coordinator.rs +++ b/rs/moq-auth/src/mesh/coordinator.rs @@ -109,6 +109,8 @@ pub struct Device { pub endpoint: PublicKey, /// Its unique, DNS-safe name. pub name: String, + /// The ID of the enrollment key it last enrolled with. + pub key: String, /// The tags of the enrollment key it joined with. #[serde(default, skip_serializing_if = "Vec::is_empty")] pub tags: Vec, @@ -283,7 +285,13 @@ impl Coordinator { )); } let endpoint = request.proof.endpoint; - let known = inner.store.devices.iter().any(|device| device.endpoint == endpoint); + // Only the key that enrolled a device re-enrolls it for free, so an exhausted key + // cannot move other devices onto its tags. + let known = inner + .store + .devices + .iter() + .any(|device| device.endpoint == endpoint && device.key == id); if !known && key.used >= key.uses.get() { return Err(ErrorReply::new( ErrorCode::InvalidGrant, @@ -294,7 +302,7 @@ impl Coordinator { let id = id.to_string(); let enrollment = self.commit(&mut inner, |store| { - self.admit(store, endpoint, request.name.as_deref(), tags)?; + self.admit(store, endpoint, request.name.as_deref(), &id, tags)?; if !known && let Some(key) = store.keys.iter_mut().find(|key| key.id == id) { key.used += 1; } @@ -461,7 +469,14 @@ impl Coordinator { } /// Record `endpoint` as enrolled, or update its name and tags if it already is. - fn admit(&self, store: &mut Store, endpoint: PublicKey, name: Option<&str>, tags: Vec) -> Reply<()> { + fn admit( + &self, + store: &mut Store, + endpoint: PublicKey, + name: Option<&str>, + key: &str, + tags: Vec, + ) -> Reply<()> { refuse_revoked(store, endpoint)?; let devices = &mut store.devices; let current = devices.iter().position(|device| device.endpoint == endpoint); @@ -472,11 +487,13 @@ impl Coordinator { match current { Some(index) => { devices[index].name = name; + devices[index].key = key.into(); devices[index].tags = tags; } None => devices.push(Device { endpoint, name, + key: key.into(), tags, enrolled: kio::clock::wall(), revoked: false, @@ -716,6 +733,7 @@ mod tests { let device = |byte, name: &str| Device { endpoint: PublicKey::from_bytes([byte; 32]), name: name.into(), + key: String::new(), tags: Vec::new(), enrolled: kio::clock::wall(), revoked: false, From e5652c34fb4876faf0c6af939a59218825e38773 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Sat, 14 Nov 2026 06:20:49 -0800 Subject: [PATCH 4/5] style(moq-auth): format the contract test Co-Authored-By: Claude Opus 5.5 --- rs/moq-auth/src/mesh/contract_tests.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/rs/moq-auth/src/mesh/contract_tests.rs b/rs/moq-auth/src/mesh/contract_tests.rs index cdad2676a9b..4e6d70a78af 100644 --- a/rs/moq-auth/src/mesh/contract_tests.rs +++ b/rs/moq-auth/src/mesh/contract_tests.rs @@ -121,8 +121,20 @@ async fn a_single_use_key_enrolls_once() { moved.enroll(&shared, None).await.unwrap(); let (other_id, _) = other.split_once('.').unwrap(); let devices = mesh.coordinator.devices(); - assert!(devices.iter().any(|device| device.key == other_id && device.name == "device")); - assert_eq!(mesh.coordinator.keys().into_iter().find(|key| key.id == id).unwrap().used, 2); + assert!( + devices + .iter() + .any(|device| device.key == other_id && device.name == "device") + ); + assert_eq!( + mesh.coordinator + .keys() + .into_iter() + .find(|key| key.id == id) + .unwrap() + .used, + 2 + ); } #[tokio::test] From 4767e002dde282aa713beadafc3452edbf5b8138 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Sat, 14 Nov 2026 09:28:23 -0800 Subject: [PATCH 5/5] docs(moq-auth): only a device's last enrollment key re-enrolls it for free Co-Authored-By: Claude Opus 5.5 --- doc/bin/relay/auth.md | 4 ++-- rs/moq-auth/src/mesh/coordinator.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/doc/bin/relay/auth.md b/doc/bin/relay/auth.md index 34db90c3e4a..7988d236f09 100644 --- a/doc/bin/relay/auth.md +++ b/doc/bin/relay/auth.md @@ -470,8 +470,8 @@ Every request proves the endpoint key by signing a fresh, single-use challenge bound to `--mesh-url`, so no token is issued for a key the caller does not hold. A device joins with an enrollment key, with no human in the loop. Each key enrolls at most `--uses` devices (default 1), so a leaked key -admits no more than its owner allowed; a device it already enrolled may -enroll again for free, and revoked or expired keys enroll nothing. It refreshes its token +admits no more than its owner allowed; a device whose last enrollment used +that key may enroll again for free, and revoked or expired keys enroll nothing. It refreshes its token two thirds of the way through `--mesh-token-ttl` (default 15m) by proving the key again, so a revoked device is cut off within one token lifetime. A revoked device cannot enroll again. Each enrollment and refresh also returns diff --git a/rs/moq-auth/src/mesh/coordinator.rs b/rs/moq-auth/src/mesh/coordinator.rs index c83b5ad55b4..57aee97cc36 100644 --- a/rs/moq-auth/src/mesh/coordinator.rs +++ b/rs/moq-auth/src/mesh/coordinator.rs @@ -100,7 +100,7 @@ struct StoredKey { revoked: bool, } -/// An enrolled device. A revoked one stays recorded so a reusable key cannot re-enroll it. +/// An enrolled device. A revoked one stays recorded so no key can re-enroll it. #[serde_as] #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] #[non_exhaustive] @@ -173,7 +173,7 @@ pub struct NewKey { #[serde_as(as = "Option>")] pub expires_in: Option, /// How many devices it may enroll, so a leaked key admits at most this many. A device - /// it already enrolled may enroll again without spending one. + /// whose last enrollment used this key may enroll again without spending one. pub uses: NonZeroU32, }