Skip to content

feat(net): a request grant admits only the request kinds it names - #9640

Draft
ksletmoe-aws wants to merge 2 commits into
moq-dev:mainfrom
ksletmoe-aws:quest/kind-aware-request-grants
Draft

ksletmoe-aws wants to merge 2 commits into
moq-dev:mainfrom
ksletmoe-aws:quest/kind-aware-request-grants

Conversation

@ksletmoe-aws

Copy link
Copy Markdown
Contributor

NOTE: draft, opened beside #9630, whose subscriber credential (auth::Handle::set_subscribe_auth) is the consumer motivating this change. The branch is independent of #9630 and based on main; review #9630 first.

Problem

With #9630, one subscriber credential rides every SUBSCRIBE, standalone FETCH and TRACK_STATUS its session sends, so an acceptor needs to grant some of those kinds and not others: a token scoped to live viewing must not read past groups or probe tracks it was not granted. It cannot today. A grant issued to a moq-transport request token covers SUBSCRIBE, FETCH and TRACK_STATUS alike through its subscribe prefixes, and SUBSCRIBE_NAMESPACE through any subscribe prefix. Link::verify_request verifies a token once per session while any request naming it is open, so a later request reusing the token shares the first verdict and never reaches the acceptor.

Approach

  • auth::Grant gains kinds: RequestKinds, the request kinds a request-borne grant admits. RequestKind::covers checks it for every request naming the token, in RequestGrant::new, renew, and an acceptor's Issued::update, so a request reusing a shared token is held to it too. Grant::default() and Grant::all() admit every kind, so existing acceptors behave as before.
  • RequestKind is public, #[non_exhaustive], with the read kind split into Subscribe, Fetch (standalone) and TrackStatus, beside PublishNamespace, Discover and Publish. A joining FETCH stays under its subscription's grant.
  • Session scope (AUTH-stream grants, Handle::authorize) admits every kind, so Request::accept and Issued::update refuse an AUTH token's grant that narrows kinds rather than silently widen it. The refusal is logged, the peer is told only "grant refused", and on update it ends the existing grant.
  • A grant narrowed to {Subscribe} also refuses the standalone FETCHes and TRACK_STATUS a subscriber sends for group recovery and fills on that token, so that subscriber loses head recovery on route changes. Grant Fetch and TrackStatus beside Subscribe to keep it.
  • Tests:
    • a_grant_admits_only_its_request_kinds_on_a_shared_token (publisher, moq-transport 18, 20, 22, 23): a SUBSCRIBE-only grant keeps its subscription and a joining FETCH (draft 18), and refuses a TRACK_STATUS, a standalone FETCH and a SUBSCRIBE_NAMESPACE reusing the SUBSCRIBE's token, which never reach the acceptor. A default grant admits all of them.
    • a_renewal_without_the_subscribe_kind_ends_the_subscription (publisher, moq-transport 18 and 22): a REQUEST_UPDATE renewed without SUBSCRIBE gets REQUEST_ERROR with the unauthorized code, and the subscription ends with PUBLISH_DONE UPDATE_FAILED.
    • a_reused_token_is_held_to_the_grants_kinds, an_update_dropping_the_kind_ends_the_request, a_renewal_dropping_the_kind_is_refused (the old grant stays at the auth layer; the publisher ends the subscription on any refused renewal, as before), an_auth_token_refuses_a_narrowed_grant, a_grant_covers_only_its_kinds.

Impact

  • moq-net (additive): auth::Grant.kinds, auth::RequestKind, auth::RequestKinds (all, contains, without, From<RequestKind>, FromIterator; no Default, since the empty set is not a grant's default). Grant is #[non_exhaustive], so the field is not a break; Grant::default() still grants no paths.
  • Behavior: none for an acceptor that leaves kinds at its default. An AUTH token's grant that narrows kinds is refused.
  • Wire: none.

Alternatives

  • A narrower read role beside subscribe (for example track_status prefixes) instead of a kinds set: one field per kind multiplies prefix sets, and the kinds set composes with the existing prefixes.
  • Verifying a token again for each request kind instead of sharing its verdict: it costs an acceptor round trip per request and changes the shared-token lifetime feat(auth)!: share request-token grants and end attachment leases #7211 settled.

Follow-ups

  • moq-relay could map an optional moq_auth::Grant kinds field into auth::Grant::kinds.
  • A test for a token on a peer's PUBLISH (ServePublish): no harness drives one today, so its RequestKind::Publish enforcement is untested, as before this change.
  • js/net and moq-ffi verify no request-borne tokens, so they need no counterpart.

Validation

Locally on the head, based on main 48ec786: cargo fmt --check; cargo clippy -D warnings over moq-net, moq-relay, moq-ffi, moq-tokio and libmoq with all features, and moq-net with no default features; cargo doc -D warnings for moq-net with all features and with none; cargo shear; cargo sort --check; sh/rs/coroutines.sh moq-net; sh/markdown.sh check; nextest over moq-net, moq-relay, moq-ffi, moq-tokio and moq-auth, 6261 passed. just ci was not run: this host has no Nix or quest binary.

Models

Implementer: Kiro, claude-opus-5.5. Reviewed in separate adversarial sessions (claude-fable-5.1 and claude-opus-5.5) before the first push.

(Written with AI assistance: Claude Opus 5.5)

A grant issued to a moq-transport request token covered SUBSCRIBE,
FETCH and TRACK_STATUS alike by its subscribe prefixes, and
SUBSCRIBE_NAMESPACE by any subscribe prefix. Requests reusing a token
share its first verdict, so an acceptor that granted a SUBSCRIBE also
admitted the other reads at those paths, with no way to refuse them.

`auth::Grant` gains `kinds`, a `RequestKinds` set checked for every
request naming the token; the default is every kind. `RequestKind` is
public again with the reads split into Subscribe, Fetch and
TrackStatus, and `auth::Request::{kind, path}` report the request that
named the token first. A quest plans moq-relay's use of both.
…path}

The acceptor needs only to grant some request kinds and not others;
the first naming request's kind and path depend on request order and
have no consumer. Drop them and the relay quest, and log an acceptor
that narrows an AUTH token's kinds while telling the peer only that the
grant was refused. Add a wire test for a renewal granted without
SUBSCRIBE on a live subscription.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant