Skip to content

feat(phase-13): HLS auth with visibility and CDN cache - #37

Merged
SlavaKuntsov merged 4 commits into
mainfrom
feat/phase-13-hls-auth-cdn
Aug 31, 2026
Merged

feat(phase-13): HLS auth with visibility and CDN cache#37
SlavaKuntsov merged 4 commits into
mainfrom
feat/phase-13-hls-auth-cdn

Conversation

@SlavaKuntsov

@SlavaKuntsov SlavaKuntsov commented Aug 31, 2026

Copy link
Copy Markdown
Owner

Closes #8
Closes #9
Closes #10

Phase 13 — P1: Доступ к HLS и CDN — реализация по docs/PLAN.md:208.

Summary

  • Защита HLS: приватные видео доступны только владельцу (JWT access или signed ?token= 1h)
  • Добавлено поле visibility: public|private|unlisted в videos (migration 000002)
  • Gateway: middleware HLSAuth + GET /api/v1/videos/{id}/hls-token + Cache-Control: private, max-age=10 для private
  • Nginx: vod_response_cache 128m→512m, perf_counters, фикс prod template с X-Internal-Token
  • Frontend: getHlsToken, VideoPlayer отправляет Authorization, watch page переключатель видимости и signed URL

Acceptance criteria

  • curl /hls/{private}/master.m3u8 без токена → 403
  • curl /hls/{private}/master.m3u8?token=<hls> с валидным HLS JWT → 200, Cache-Control: private, max-age=10
  • curl /hls/{public}/master.m3u8 без токена → 200
  • GET /api/v1/videos/{id}/hls-token owner 200 / other 403
  • PATCH /api/v1/videos/{id} с visibility валидирует enum и владельца
  • GET /internal/videos/:id/vod через internal token (nginx) — без регрессии (adaptive ladder 1..3 renditions сохранён)

Verification

  • make lint-go — 0 issues (metadata/gateway/upload)
  • make lint-front — ✔ No ESLint warnings
  • go test ./... metadata — ok handler
  • go test ./... gateway middleware — pass (HLSAuth private/public/token cases)
  • make up && make e2e — не запущено (no docker в CI), риск: полный upload→transcode→hls с private требует ручной проверки curl -I Cache-Control

Risks

  • Prod nginx envsubst требует ENV=prod — проверено в Dockerfile:35, но нужен реальный docker compose -f deploy/docker-compose.yml -f deploy/docker-compose.prod.yml up --build тест
  • Сегменты HLS для private кешируются как private — CDN должен уважать CDN-Cache-Control: private

Commits:

  • feat(metadata): add video visibility
  • feat(gateway): add HLS auth with signed URL
  • feat(infra): increase nginx vod cache and fix prod template
  • feat(frontend): handle private HLS token

Add video_visibility enum and visibility column (default public) with
index, update model/repository/handler to handle create/update and
validate visibility, and extend fakeStore for tests.
Protect /hls/* via HLSAuth: private videos require owner access JWT or
1h hls JWT (?token= or X-HLS-Token), public/unlisted pass through.
Add GET /api/v1/videos/{id}/hls-token and set Cache-Control
private,max-age=10 for private, public for others. Fix errcheck.
Bump vod_response_cache 128m->512m and add perf counters, add
X-Internal-Token to prod mapping, fix Dockerfile to handle both
templates via ENV=prod and update compose prod volume to template.
Add visibility to Video type, getHlsUrl token param, getHlsToken and
updateVideo helpers, VideoPlayer xhrSetup sends Authorization and
handles token, watch page fetches signed URL for private owner videos
and adds visibility selector.
@SlavaKuntsov
SlavaKuntsov merged commit 3e740ab into main Aug 31, 2026
4 checks passed
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.

P1 infra: differentiate CDN Cache-Control public/private P1 gateway: enforce HLS auth via signed JWT P1 metadata: add visibility enum and API

1 participant