Skip to main content

Module moq_authz

Module moq_authz 

Source
Expand description

Subscribe-time authorization + per-tenant announce scoping for the moq streaming plane (#276).

§Why this module exists

#274 made the moq streaming plane network-reachable (served on web_transport_quinn at /moq, and over the iroh moql ALPN via crate::transport::iroh_moq::IrohMoqProtocolHandler). That moved the open-subscribe surface onto the network. This is not a content hole — stream content is already protected by the §7.5 trust model (a 64-hex DH-derived HKDF-of-ECDH capability topic, unguessable and learned only from a signed StreamInfo over authenticated RPC, plus a per-frame chained HMAC). #276 is metadata defense-in-depth:

  1. A connected peer can announce-enumerate broadcast (topic) names — moq announces broadcasts by prefix, so a subscriber’s announced() cursor sees every broadcast under its allowed prefix. Without scoping, a peer in tenant A could enumerate tenant B’s broadcast names.
  2. Subscribe-time authorization: a public stream stays open (preserving the working same-tenant subscribe model), but a private stream is gated through the existing policy engine.

§moq-net’s authorization primitive

moq_net::Server exposes no per-subscribe callback. Authorization in moq-net is enforced structurally: a session can only enumerate/subscribe to broadcasts that are visible through the [OriginConsumer] handed to Server::with_publish. [OriginConsumer::scope] / [OriginConsumer::with_root] narrow that visibility by path prefix. So per-tenant announce scoping is implemented by handing each accepted session a tenant-scoped consumer (see tenant_scoped_consumer) — a subscriber that cannot see a broadcast cannot subscribe to it either.

The subscribe authorization hook (SubscribeAuthorizer) is the pluggable policy layer on top of that structural scoping, for the public-vs-private distinction within a tenant. Until moq-net exposes the per-track callback tracked by #276, installing an authorizer rejects the session at admission. This is intentionally coarse but fail-closed: an installed policy is never retained as dead configuration while tracks are served around it.

Track names are hierarchical {tenant}/{service}/{topic}/{instance} (the #134 CDN-portability invariant). The first path segment is the tenant.

Structs§

DefaultAuthorizer
Default authorizer: public streams are open, private streams are policy-gated, and unknown classification fails closed for safety.
MacSubscribeAuthorizer
SubscribeAuthorizer backed by the shared MoqEventPep MAC floor.
PeerIdentity
Identity of the subscribing peer, as far as the moq accept path can determine it.

Enums§

SubscribeDecision
The outcome of a subscribe-authorization check.
Visibility
Whether a stream is publicly subscribable or policy-gated.

Constants§

TRACK_NAME_SEP
The hierarchical track-name separator ({tenant}/{service}/{topic}/{instance}).

Traits§

SubscribeAuthorizer
Pluggable subscribe-time authorization hook for the moq accept path.

Functions§

filter_announces_by_tenant
Pure per-tenant announce filter — the independently-testable core of the scoping behaviour.
is_valid_tenant_segment
Return whether tenant is one non-empty MoQ path segment.
tenant_of
Extract the {tenant} segment from a hierarchical track / broadcast name.
tenant_prefix
Build the tenant prefix ({tenant}/) used to scope announce enumeration.
tenant_scoped_consumer
Restrict an [OriginConsumer] to a single tenant’s broadcasts.

Type Aliases§

PolicyGate
Evaluates a policy decision for a (subject, tenant, track) tuple. Returns true to allow. This is the seam onto the existing Casbin/PolicyService (PolicyManager::check_with_domain) without hyprstream-rpc depending on the hyprstream crate.
SharedSubscribeAuthorizer
Shared handle to a SubscribeAuthorizer suitable for stashing on a long-lived server/handler.
VisibilityFn
Classifies a track name as public or private. Returning Visibility::Public keeps the existing open model; Visibility::Private routes through the policy gate.