fix: 재생 URL에 읽기 전용 SAS 토큰 사용
This commit is contained in:
1 parent
059269c5e6
commit
ea7539ee43
3 files changed
+13
-4
No files matched your search
@@ -101,7 +101,8 @@ CORS_MAX_AGE=600 # Preflight 요청 캐시 시간 (초)
|
|||||||
# ================================
|
# ================================
|
||||||
# Azure Blob Storage 설정
|
# Azure Blob Storage 설정
|
||||||
# ================================
|
# ================================
|
||||||
AZURE_BLOB_SAS_TOKEN=your_sas_token # Azure Blob Storage SAS 토큰
|
AZURE_BLOB_SAS_TOKEN=your_sas_token # 업로드·삭제용 SAS 토큰 (서버 내부 전용)
|
||||||
|
AZURE_BLOB_PLAYBACK_SAS_TOKEN=your_readonly_sas_token # 재생 URL에 붙는 읽기 전용(sp=r) SAS 토큰
|
||||||
AZURE_BLOB_BASE_URL=https://... # Azure Blob Storage 기본 URL
|
AZURE_BLOB_BASE_URL=https://... # Azure Blob Storage 기본 URL
|
||||||
|
|
||||||
# ================================
|
# ================================
|
||||||
|
|||||||
@@ -91,16 +91,20 @@ async def close_shared_blob_client() -> None:
|
|||||||
|
|
||||||
|
|
||||||
def to_playback_url(blob_url: str | None) -> str | None:
|
def to_playback_url(blob_url: str | None) -> str | None:
|
||||||
"""DB에 저장된 SAS 미포함 공개 URL에 읽기용 SAS 토큰을 붙여 반환합니다.
|
"""DB에 저장된 SAS 미포함 공개 URL에 읽기 전용 SAS 토큰을 붙여 반환합니다.
|
||||||
|
|
||||||
Azure Blob 익명(공개) 접근은 x-ms-version 헤더가 없어 Range 요청을 지원하지
|
Azure Blob 익명(공개) 접근은 x-ms-version 헤더가 없어 Range 요청을 지원하지
|
||||||
않는 구버전 API로 처리되어 브라우저에서 영상/오디오 seek이 동작하지 않는다.
|
않는 구버전 API로 처리되어 브라우저에서 영상/오디오 seek이 동작하지 않는다.
|
||||||
SAS 토큰(sv= 포함)을 붙이면 최신 API 버전으로 처리되어 Range/Accept-Ranges가
|
SAS 토큰(sv= 포함)을 붙이면 최신 API 버전으로 처리되어 Range/Accept-Ranges가
|
||||||
정상 동작한다. DB에는 SAS 없는 URL을 그대로 저장하고, 응답 시점에만 붙인다.
|
정상 동작한다. DB에는 SAS 없는 URL을 그대로 저장하고, 응답 시점에만 붙인다.
|
||||||
|
|
||||||
|
이 URL은 API 응답으로 나가므로 재생용 토큰(AZURE_BLOB_PLAYBACK_SAS_TOKEN)만
|
||||||
|
쓴다. 미설정이어도 쓰기 권한이 있는 업로드용 토큰으로 대체하지 않고 SAS 없는
|
||||||
|
URL을 그대로 반환한다.
|
||||||
"""
|
"""
|
||||||
if not blob_url:
|
if not blob_url:
|
||||||
return blob_url
|
return blob_url
|
||||||
sas_token = azure_blob_settings.AZURE_BLOB_SAS_TOKEN.strip("?'\"")
|
sas_token = azure_blob_settings.AZURE_BLOB_PLAYBACK_SAS_TOKEN.strip("?'\"")
|
||||||
if not sas_token:
|
if not sas_token:
|
||||||
return blob_url
|
return blob_url
|
||||||
separator = "&" if "?" in blob_url else "?"
|
separator = "&" if "?" in blob_url else "?"
|
||||||
|
|||||||
@@ -158,7 +158,11 @@ class AzureBlobSettings(BaseSettings):
|
|||||||
|
|
||||||
AZURE_BLOB_SAS_TOKEN: str = Field(
|
AZURE_BLOB_SAS_TOKEN: str = Field(
|
||||||
default="",
|
default="",
|
||||||
description="Azure Blob Storage SAS 토큰",
|
description="Azure Blob Storage 업로드·삭제용 SAS 토큰 (서버 내부 전용, 응답에 노출 금지)",
|
||||||
|
)
|
||||||
|
AZURE_BLOB_PLAYBACK_SAS_TOKEN: str = Field(
|
||||||
|
default="",
|
||||||
|
description="재생 URL에 붙여 응답으로 내보내는 읽기 전용(sp=r) SAS 토큰",
|
||||||
)
|
)
|
||||||
AZURE_BLOB_BASE_URL: str = Field(
|
AZURE_BLOB_BASE_URL: str = Field(
|
||||||
default="https://ado2mediastoragepublic.blob.core.windows.net/ado2-media-public-access/ado2-media-original",
|
default="https://ado2mediastoragepublic.blob.core.windows.net/ado2-media-public-access/ado2-media-original",
|
||||||
|
|||||||
Reference in new issue
Block a user