You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

设置过期时间后Azure SAS Token仍未失效的问题排查

Azure Blob SAS Token过期时间不生效问题

我使用以下Python函数生成Azure Blob的SAS Token,代码中设置过期时间为当前时间加60分钟,但实际两小时后该Token仍能正常访问文件。我已通过浏览器隐私模式测试排除缓存影响,也确认存储账户中未配置任何访问策略,但问题依然存在。

from datetime import datetime, timedelta
from azure.storage.blob import BlobServiceClient, BlobSasPermissions, generate_blob_sas


def generate_sas_token(connection_string: str, container_name: str, blob_name: str, duration: int = 60) -> tuple[str, str]:
    blob_service_client = BlobServiceClient.from_connection_string(connection_string)
    sas_token = generate_blob_sas(
        account_name=blob_service_client.account_name,
        container_name=container_name,
        blob_name=blob_name,
        account_key=blob_service_client.credential.account_key,
        permission=BlobSasPermissions(read=True),  # 设置所需权限
        expiry=datetime.now() + timedelta(minutes=duration)  # 设置过期时间
    )
    sas_url = f"https://{blob_service_client.account_name}.blob.core.windows.net/{container_name}/{blob_name}?{sas_token}"
    return sas_token, sas_url

已排查的内容:

  • 使用浏览器隐私模式访问,排除缓存干扰
  • 确认存储账户无任何访问策略配置
  • 代码逻辑中明确指定了expiry参数为当前时间加指定分钟数

请问我哪里遗漏了?代码看起来没有错误。

内容的提问来源于stack exchange,提问作者Daniel

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.19 20:36:05