Commit 3b53aca
committed
feat(mediaauth): playback authorization plane (token + IP/country/UA/referer chain)
Open-Streamer had no media-plane access control: anyone who could reach a
stream URL could watch it, the ?token= param was recorded but never enforced,
and a tokened SRT streamid failed to resolve (audit S-13). Add a playback
authorizer enforced across every delivery protocol.
internal/mediaauth: a Flussonic-style chain — deny IP/country/UA wins, then
allow-list gates (IP/country/UA + Referer allowed-domains), then a per-stream
token-policy gate. Tokens are HMAC-SHA256, client-signed and server-verified
(token = "<exp>.<base64url(HMAC(secret, code|exp))>"): constant-time compare,
expiry- and stream-code-bound. The server only verifies — clients mint tokens
with the shared secret via the documented SignToken format (no mint endpoint).
Wiring (authorize before any bytes/state):
- HTTP (HLS/DASH/MPEGTS/DVR) in dispatchMedia.mediaAllowed.
- RTMP/SRT/RTSP play sites via publisher.playAllowed.
Effective policy = per-stream Stream.PlaybackAuth (public/token, template-
inherited) else global auth.media.default_policy; static rules are global.
Country uses the existing sessions GeoIP. Disabled by default (no behaviour
change); fail-closed when token policy has no secret. Config auth.media.*,
hot-reloaded via the runtime diff (atomic snapshot swap). Per-stream policy is
resolved from the publisher's in-memory table for live streams (O(1), no store
read on the hot path) and from the store for stopped-stream DVR archives so a
token stream isn't downgraded.
Also fixes: SRT srtStreamCode strips the ?token= query so tokened streamids
resolve; ABR renditions key auth on the parent stream code so a token for
<code> covers /<code>/track_N/… (adversarial review found both — without the
strip, token playback of transcoded/ABR streams was broken).
Closes the media-plane half of S-13. Caveats (separate findings): IP/country
rules trust RealIP/X-Forwarded-For, so they need a trusted proxy (S-15/S-17);
RTMP play carries no token (IP/country still apply); the dynamic HTTP-callback
backend and per-stream rule overrides are planned follow-ups.
Tests: internal/mediaauth chain+token suite (deny/allow per dimension, token
sign/verify/expiry/tamper/cross-stream, per-stream override, fail-closed,
hot-reload), TestStripABRTrackSlug. Adversarially reviewed.1 parent 82c47cb commit 3b53aca
19 files changed
Lines changed: 1127 additions & 9 deletions
File tree
- api/docs
- cmd/server
- config
- docs/audit
- internal
- api
- domain
- mediaauth
- publisher
- runtime
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1941 | 1941 | | |
1942 | 1942 | | |
1943 | 1943 | | |
| 1944 | + | |
| 1945 | + | |
| 1946 | + | |
| 1947 | + | |
1944 | 1948 | | |
1945 | 1949 | | |
1946 | 1950 | | |
| |||
2104 | 2108 | | |
2105 | 2109 | | |
2106 | 2110 | | |
| 2111 | + | |
| 2112 | + | |
| 2113 | + | |
2107 | 2114 | | |
2108 | 2115 | | |
2109 | 2116 | | |
| |||
2227 | 2234 | | |
2228 | 2235 | | |
2229 | 2236 | | |
| 2237 | + | |
| 2238 | + | |
| 2239 | + | |
| 2240 | + | |
| 2241 | + | |
| 2242 | + | |
| 2243 | + | |
| 2244 | + | |
| 2245 | + | |
| 2246 | + | |
| 2247 | + | |
| 2248 | + | |
| 2249 | + | |
| 2250 | + | |
| 2251 | + | |
| 2252 | + | |
| 2253 | + | |
| 2254 | + | |
| 2255 | + | |
| 2256 | + | |
| 2257 | + | |
| 2258 | + | |
| 2259 | + | |
| 2260 | + | |
| 2261 | + | |
| 2262 | + | |
| 2263 | + | |
| 2264 | + | |
| 2265 | + | |
| 2266 | + | |
| 2267 | + | |
| 2268 | + | |
| 2269 | + | |
| 2270 | + | |
| 2271 | + | |
| 2272 | + | |
| 2273 | + | |
| 2274 | + | |
| 2275 | + | |
| 2276 | + | |
| 2277 | + | |
| 2278 | + | |
| 2279 | + | |
| 2280 | + | |
| 2281 | + | |
| 2282 | + | |
| 2283 | + | |
| 2284 | + | |
| 2285 | + | |
| 2286 | + | |
| 2287 | + | |
| 2288 | + | |
| 2289 | + | |
| 2290 | + | |
| 2291 | + | |
| 2292 | + | |
| 2293 | + | |
| 2294 | + | |
| 2295 | + | |
2230 | 2296 | | |
2231 | 2297 | | |
2232 | 2298 | | |
| |||
3242 | 3308 | | |
3243 | 3309 | | |
3244 | 3310 | | |
| 3311 | + | |
| 3312 | + | |
| 3313 | + | |
| 3314 | + | |
3245 | 3315 | | |
3246 | 3316 | | |
3247 | 3317 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1934 | 1934 | | |
1935 | 1935 | | |
1936 | 1936 | | |
| 1937 | + | |
| 1938 | + | |
| 1939 | + | |
| 1940 | + | |
1937 | 1941 | | |
1938 | 1942 | | |
1939 | 1943 | | |
| |||
2097 | 2101 | | |
2098 | 2102 | | |
2099 | 2103 | | |
| 2104 | + | |
| 2105 | + | |
| 2106 | + | |
2100 | 2107 | | |
2101 | 2108 | | |
2102 | 2109 | | |
| |||
2220 | 2227 | | |
2221 | 2228 | | |
2222 | 2229 | | |
| 2230 | + | |
| 2231 | + | |
| 2232 | + | |
| 2233 | + | |
| 2234 | + | |
| 2235 | + | |
| 2236 | + | |
| 2237 | + | |
| 2238 | + | |
| 2239 | + | |
| 2240 | + | |
| 2241 | + | |
| 2242 | + | |
| 2243 | + | |
| 2244 | + | |
| 2245 | + | |
| 2246 | + | |
| 2247 | + | |
| 2248 | + | |
| 2249 | + | |
| 2250 | + | |
| 2251 | + | |
| 2252 | + | |
| 2253 | + | |
| 2254 | + | |
| 2255 | + | |
| 2256 | + | |
| 2257 | + | |
| 2258 | + | |
| 2259 | + | |
| 2260 | + | |
| 2261 | + | |
| 2262 | + | |
| 2263 | + | |
| 2264 | + | |
| 2265 | + | |
| 2266 | + | |
| 2267 | + | |
| 2268 | + | |
| 2269 | + | |
| 2270 | + | |
| 2271 | + | |
| 2272 | + | |
| 2273 | + | |
| 2274 | + | |
| 2275 | + | |
| 2276 | + | |
| 2277 | + | |
| 2278 | + | |
| 2279 | + | |
| 2280 | + | |
| 2281 | + | |
| 2282 | + | |
| 2283 | + | |
| 2284 | + | |
| 2285 | + | |
| 2286 | + | |
| 2287 | + | |
| 2288 | + | |
2223 | 2289 | | |
2224 | 2290 | | |
2225 | 2291 | | |
| |||
3235 | 3301 | | |
3236 | 3302 | | |
3237 | 3303 | | |
| 3304 | + | |
| 3305 | + | |
| 3306 | + | |
| 3307 | + | |
3238 | 3308 | | |
3239 | 3309 | | |
3240 | 3310 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
213 | 213 | | |
214 | 214 | | |
215 | 215 | | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
216 | 223 | | |
217 | 224 | | |
218 | 225 | | |
| |||
331 | 338 | | |
332 | 339 | | |
333 | 340 | | |
| 341 | + | |
| 342 | + | |
334 | 343 | | |
335 | 344 | | |
336 | 345 | | |
| |||
442 | 451 | | |
443 | 452 | | |
444 | 453 | | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
445 | 504 | | |
446 | 505 | | |
447 | 506 | | |
| |||
1405 | 1464 | | |
1406 | 1465 | | |
1407 | 1466 | | |
| 1467 | + | |
| 1468 | + | |
| 1469 | + | |
| 1470 | + | |
| 1471 | + | |
1408 | 1472 | | |
1409 | 1473 | | |
1410 | 1474 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| 33 | + | |
33 | 34 | | |
34 | 35 | | |
35 | 36 | | |
| |||
133 | 134 | | |
134 | 135 | | |
135 | 136 | | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
136 | 142 | | |
137 | 143 | | |
138 | 144 | | |
| |||
144 | 150 | | |
145 | 151 | | |
146 | 152 | | |
| 153 | + | |
147 | 154 | | |
148 | 155 | | |
149 | 156 | | |
| |||
330 | 337 | | |
331 | 338 | | |
332 | 339 | | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
333 | 382 | | |
334 | 383 | | |
335 | 384 | | |
| |||
0 commit comments