Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions doc/bin/relay/auth.md
Original file line number Diff line number Diff line change
Expand Up @@ -425,9 +425,10 @@ subscribe = []
Upgrade auth servers before relays when adopting the `webtransport` or `tls` transport value.
WebTransport sessions report `webtransport`; native QUIC sessions report `quic`.
`tls://` sessions report `tls`; plaintext `tcp://` sessions report `tcp`.
An auth server built before `tls` existed does not fail to parse it: the Rust and JavaScript
parsers read an unrecognized transport name as `unknown`, so admission then depends on how your
policy treats `unknown`. Update any policy keyed on `tcp` for stream links to handle `tls` too.
A `moq auth serve` from a `release` build answers 422 to a request naming a transport it predates,
such as `webtransport` or `tls`, which the relay refuses. Current parsers read an unrecognized
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
transport name as `unknown`, so admission then depends on how your policy treats `unknown`.
Update any policy keyed on `tcp` for stream links to handle `tls` too.

`moq auth serve` is the reference auth server, answering the contract above.

Expand Down
27 changes: 27 additions & 0 deletions quest/m1/precut-fixes/relay-backoff-backport.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# [XS] Backport the relay redial backoff reset to the next release

## Goal

A relay on the next `release` patch redials a cluster peer from the first
backoff ceiling once an attempt connected, so a flap after a long outage no
longer waits out 30 s.

## Plan

Decided by the maintainer when the PR that finished `relay-config-loud` was
picked: ✅ backport only the redial backoff reset to `release`, and leave the
two startup refusals on `main` (rejected: backporting all of it, which would
let a patch stop a working relay from booting on a config that ran before; no
backport, which leaves a flapping peer waiting out 30 s on `release`).

Port the backoff reset from that PR as a separate PR onto `release`, per
RELEASE.md, keeping the published API.
`rs/moq-relay/src/cluster.rs` `run_remote` on `release` has the same dead
`Ok(()) if elapsed >= stable_threshold` branch, because `run_remote_once` only
returns an error. Report whether the attempt connected (any observation with
`connects > 0`) and pass it to `Redial::next`, which starts over at the first
ceiling when it did, including on the immediate retry after the cluster token
rotated.

Do not port `cluster.api.root` without `cluster.api.url` or `cluster.token`
with no peer to dial as startup errors: those stay on `main`.
40 changes: 0 additions & 40 deletions quest/m1/precut-fixes/relay-config-loud.md

This file was deleted.

10 changes: 10 additions & 0 deletions rs/moq-auth/src/grant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,16 @@ mod tests {
}
}

/// A subsecond cadence writes as the nearest whole second, never the zero a relay refuses.
#[test]
fn a_subsecond_revalidate_writes_rounded() {
let mut grant = full();
for (cadence, seconds) in [(750, 1), (1400, 1), (1600, 2)] {
grant.revalidate = Some(Duration::from_millis(cadence));
assert_eq!(serde_json::to_value(&grant).unwrap()["revalidate"], seconds);
}
}

#[test]
fn round_trips_in_seconds() {
let grant = full();
Expand Down
19 changes: 13 additions & 6 deletions rs/moq-auth/src/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,11 +252,19 @@ pub struct Jwk {
pub material: KeyMaterial,

/// The key ID, useful for rotating keys.
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(
default,
skip_serializing_if = "Option::is_none",
deserialize_with = "crate::wire::present"
)]
pub kid: Option<crate::KeyId>,

/// Optional authorization limits for tokens signed by this key.
#[serde(default, skip_serializing_if = "Option::is_none")]
#[serde(
default,
skip_serializing_if = "Option::is_none",
deserialize_with = "crate::wire::present"
)]
pub scope: Option<crate::Scope>,
}

Expand Down Expand Up @@ -736,10 +744,9 @@ fn deserialize_base64url_optional<'de, D>(deserializer: D) -> Result<Option<Vec<
where
D: Deserializer<'de>,
{
let s: Option<String> = Option::deserialize(deserializer)?;
s.map(|s| decode_base64url(&s))
.transpose()
.map_err(serde::de::Error::custom)
// A present field: `null` is refused, as `@moq/auth` does, rather than read as absent.
let s = String::deserialize(deserializer)?;
decode_base64url(&s).map(Some).map_err(serde::de::Error::custom)
}

/// A key field: unpadded base64url, or padded for backwards compatibility. Empty is refused,
Expand Down
25 changes: 23 additions & 2 deletions rs/moq-auth/src/wire.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,28 @@ impl TryFrom<Object<Grant>> for crate::Grant {

/// A present field, refusing an explicit `null` rather than reading it as absent,
/// so a `null` can't hide one encoding from the mixed-encoding check.
fn present<'de, D: Deserializer<'de>, T: Deserialize<'de>>(deserializer: D) -> Result<Option<T>, D::Error> {
pub(crate) fn present<'de, D: Deserializer<'de>, T: Deserialize<'de>>(deserializer: D) -> Result<Option<T>, D::Error> {
T::deserialize(deserializer).map(Some)
}

/// A present `revalidate` in whole seconds, refusing `null` as [`present`] does.
mod revalidate {
use super::*;

pub(super) fn serialize<S: serde::Serializer>(value: &Option<Duration>, serializer: S) -> Result<S::Ok, S::Error> {
match value {
// Rounded to the nearest second, as `DurationSeconds` writes it: a `750ms` interval
// must not truncate to a zero the relay refuses.
Some(value) => <DurationSeconds<u64> as serde_with::SerializeAs<Duration>>::serialize_as(value, serializer),
None => serializer.serialize_none(),
}
}

pub(super) fn deserialize<'de, D: Deserializer<'de>>(deserializer: D) -> Result<Option<Duration>, D::Error> {
<DurationSeconds<u64> as serde_with::DeserializeAs<'de, Duration>>::deserialize_as(deserializer).map(Some)
}
}

/// A present time in whole unix seconds, from the epoch to the clock's last second, which
/// `@moq/auth` holds exactly too. Anything else is refused rather than saturated, and an
/// explicit `null` rather than read as absent, which for `exp` would mean never.
Expand Down Expand Up @@ -300,14 +318,17 @@ pub(crate) struct Grant {
publish: Access,
#[serde(skip_serializing_if = "Access::is_unset")]
subscribe: Access,
#[serde(deserialize_with = "present")]
root: Option<String>,
#[serde(skip_serializing_if = "BTreeMap::is_empty")]
mounts: BTreeMap<String, String>,
#[serde(with = "seconds", skip_serializing_if = "Option::is_none")]
expires: Option<kio::clock::Wall>,
#[serde_as(as = "Option<DurationSeconds<u64>>")]
#[serde(with = "revalidate", skip_serializing_if = "Option::is_none")]
revalidate: Option<Duration>,
#[serde(deserialize_with = "present")]
tier: Option<String>,
#[serde(deserialize_with = "present")]
label: Option<String>,
#[serde(deserialize_with = "present")]
link: Option<Link>,
Expand Down
47 changes: 47 additions & 0 deletions rs/moq-auth/tests/corpus.json
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,47 @@
},
"valid": false
},
{
"name": "a_null_scope",
"jwk": { "kty": "oct", "alg": "HS256", "k": "Fp8kipWUJeUFqeSqWym_tRC_tyI8z-QpqopIGrbrD68", "scope": null },
"valid": false
},
{
"name": "a_null_kid",
"jwk": { "kty": "oct", "alg": "HS256", "k": "Fp8kipWUJeUFqeSqWym_tRC_tyI8z-QpqopIGrbrD68", "kid": null },
"valid": false
},
{
"name": "a_null_key_ops",
"jwk": {
"kty": "oct",
"alg": "HS256",
"k": "Fp8kipWUJeUFqeSqWym_tRC_tyI8z-QpqopIGrbrD68",
"key_ops": null
},
"valid": false
},
{
"name": "a_null_scope_root",
"jwk": {
"kty": "oct",
"alg": "HS256",
"k": "Fp8kipWUJeUFqeSqWym_tRC_tyI8z-QpqopIGrbrD68",
"scope": { "root": null, "publish": ["**"] }
},
"valid": false
},
{
"name": "a_null_okp_private_key",
"jwk": {
"kty": "OKP",
"alg": "EdDSA",
"crv": "Ed25519",
"x": "UiU9fT_SdBBpkFtJPRCY0gX1jK_Dr9syYLFuEz4QUM4",
"d": null
},
"valid": false
},
{
"name": "short_secret",
"jwk": { "kty": "oct", "alg": "HS256", "k": "c2hvcnQ" },
Expand Down Expand Up @@ -617,6 +658,12 @@
},
{ "name": "unknown_link", "grant": { "publish": ["**"], "link": "downstream" }, "valid": false },
{ "name": "null_link", "grant": { "publish": ["**"], "link": null }, "valid": false },
{ "name": "null_root", "grant": { "publish": ["**"], "root": null }, "valid": false },
{ "name": "null_revalidate", "grant": { "publish": ["**"], "revalidate": null }, "valid": false },
{ "name": "null_tier", "grant": { "publish": ["**"], "tier": null }, "valid": false },
{ "name": "null_label", "grant": { "publish": ["**"], "label": null }, "valid": false },
{ "name": "null_mounts", "grant": { "publish": ["**"], "mounts": null }, "valid": false },
{ "name": "null_peer", "grant": { "publish": ["**"], "peer": null }, "valid": false },
{ "name": "positional", "grant": [["**"]], "valid": false },
{ "name": "null_grant", "grant": null, "valid": false }
]
Expand Down
24 changes: 21 additions & 3 deletions rs/moq-relay/src/auth/refresh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,6 @@ impl Refresh {
Err(lease::Reason::Expired) => return Err(moq_net::Error::Expired),
Err(_) => return Err(moq_net::Error::Unauthorized),
}
if lease.pacer.is_none() && Caps::of(&initial.grant).is_capped() {
return Err(moq_net::Error::Unauthorized);
}
initial.initial = true;
// The connection applies the first caps itself, with the window it opens.
let caps = Caps::of(&initial.grant);
Expand All @@ -133,6 +130,10 @@ impl Refresh {
pacer: lease.pacer.clone(),
caps,
};
// The same root, mounts, link, role, and cap checks a refreshed grant passes.
if !this.valid(&this.credentials[&0].grant) {
return Err(moq_net::Error::Unauthorized);
}
this.authorize();
Ok(this)
}
Expand Down Expand Up @@ -656,6 +657,23 @@ mod tests {
.await;
}

/// Setup holds the grant it reads to the root, mounts, and link admission bound the session to.
#[tokio::test(start_paused = true)]
async fn a_moved_root_mount_or_link_before_protocol_setup_is_refused() {
let _clock = manual();
type Change = fn(&mut moq_auth::Grant);
let changes: [Change; 3] = [
|grant| grant.root = Some("elsewhere".into()),
|grant| {
grant.mounts.insert("m".into(), "other".into());
},
|grant| grant.link = Some(moq_auth::Link::Peer),
];
for change in changes {
refused_before_setup(change, SessionError::Unauthorized).await;
}
}

#[tokio::test(start_paused = true)]
async fn a_grant_expiring_before_protocol_setup_is_refused_as_expired() {
let clock = manual();
Expand Down
Loading