feat(publisher): enforce playback token on the RTMP play path#32
Merged
Conversation
The RTMP play handler hardcoded an empty token into the media-auth chain, so a stream bound to a token-required policy was denied for every RTMP client with no way to authorize — token policies effectively excluded RTMP while working on HLS/DASH/SRT/RTSP. Carry the token on the play-URL query (rtmp://host/live/<code>?token=...), the same transport the SRT and RTSP play paths already use. The RTMP server forwards the session's raw query via PlayInfo.RawQuery (staying media-auth-agnostic) and the publisher extracts the token with the shared sessions.TokenFromQuery helper. User-Agent and Referer remain unset for RTMP, so those rules stay inert; IP / country / token now apply uniformly. Add table-driven auth tests for the RTMP play path and a reference doc for the playback-policy model with a per-protocol enforcement matrix.
unparam flagged playAllowed's referer argument: RTMP / SRT / RTSP all pass "" because none of those protocols carry a Referer (the AllowedDomains gate runs only on the HTTP path). Remove the parameter and update the call sites and tests; no behaviour change.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
rtmp://host/live/<code>?token=...), the same transport the SRT and RTSP play paths already use. The RTMP server forwards the session's raw query viaPlayInfo.RawQuery(staying media-auth-agnostic); the publisher extracts the token with the sharedsessions.TokenFromQueryhelper.Changes
internal/ingestor/push/rtmp_server.go— addPlayInfo.RawQuery, populated from the session's raw query.internal/publisher/serve_rtmp.go— extract the token from the play-URL query and pass it to the authorization chain.internal/publisher/serve_rtmp_auth_test.go— table-driven auth tests (valid / missing / empty / garbage / expired / other-stream / wrong-secret / public / nil-authorizer).docs/media-auth-policies.md— reference doc for the playback-policy model with a per-protocol enforcement matrix.Testing
go build,go vet,gofmtcleango test ./internal/publisher/ ./internal/ingestor/push/passNote
Unit tests cover the authorization decision. Whether a given client places the query on the tcURL vs. the play stream name is client-dependent — verify end-to-end with a real encoder/player.