【问题标题】:Azure Blob Storage Shared Access Signature - security?Azure Blob 存储共享访问签名 - 安全性?
【发布时间】:2022-10-21 21:20:48
【问题描述】:

我正在开发一个包含一些图像文件的 Azure Blob 存储。我想在我的网站中使用图像,但想安全地提取图像。我编写的代码是使用容器上生成的 SAS 令牌。但是,为了检索图像,图像文件的 URL 与作为 URL 参数传递的 SAS 令牌一起使用。从某种意义上说,任何在 SAS 令牌有效时获得令牌的人也可以下载图像,这难道不是不安全的吗?是否有某种方法可以将 SAS 令牌发布回请求标头中以使其受到保护?我将如何实现这一目标?

所以目前我可以以编程方式生成 SAS。但是当使用它来检索 blob 时,我不想使用 https://myblobstore.blob.core.windows.net/test/image-0_8.jpg?skoid=<>&sktid=<>&skt=<>&ske=<>&sks=b&skv=<>&st=<>&se=<>&sr=b&sp 的格式=r&sig=<>,因为任何人都可以读取签名。还有其他方法吗?

提前致谢, 杰克。

【问题讨论】:

    标签: azure-blob-storage shared-access-signatures


    【解决方案1】:

    我不确定 Web 应用程序是如何配置的。但是您可以使用以下代码概念,这可能会帮助您通过网站访问 blob 文件或图像,而无需在请求标头中显示 SAS URL。

    参考一段代码:- Download and display a private Azure Blob using ASP MVC

    其他参考:

    需要注意的几点:1) 确保设置正确的内容类型(或 Mime 类型) 2) 不要使用任何流式 API(即 文件流) - 默认情况下将下载文件 3)如果 可能尝试添加正确的标题(如果需要)

    Below is the whole source code (it's the controller part )
    //ViewModel  
    public class ViewModel  
    {  
    public string FileUrl { get; set; }  
    }
    {
    var readPolicy = new SharedAccessBlobPolicy()
    {
    Permissions = SharedAccessBlobPermissions.Read,
    SharedAccessExpiryTime = DateTime.UtcNow + TimeSpan.FromMinutes(5)
    };
    
    // Retrieve storage account from connection string.
    string conn = "DefaultEndpointsProtocol=https;AccountName=straccountname;AccountKey=key==;EndpointSuffix=core.windows.net";
    Microsoft.WindowsAzure.Storage.CloudStorageAccount storageAccount = CloudStorageAccount.Parse(conn);
    
    // Create the blob client.
    CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
    
    // Retrieve reference to a previously created container.
    CloudBlobContainer container = blobClient.GetContainerReference("test");
    
    // Retrieve reference to a blob ie "20200809_125724.jpg".
    CloudBlockBlob blockBlob = container.GetBlockBlobReference("20200809_125724.jpg");
    
    //------
    var newUri = new Uri(blockBlob.Uri.AbsoluteUri + blockBlob.GetSharedAccessSignature(readPolicy));
    var viewModel = new ViewModel()
    {
    FileUrl = newUri.ToString()
    };
    return View("Index", viewModel);
    // return View();
    }
    

    参考:https://learn.microsoft.com/en-us/answers/questions/252303/sas-url-to-display-in-browser-rather-than-download.html

    【讨论】:

    • 但是这一行不是将共享访问签名直接连接到 URI 吗? var newUri = new Uri(blockBlob.Uri.AbsoluteUri + blockBlob.GetSharedAccessSignature(readPolicy));当该请求发出时,它不会直接与 URL 请求上的 SAS 字符串一起发送出去吗?这是我的观点,它不是帖子或标题的一部分。如果我错了,请纠正我。
    【解决方案2】:

    您可能遗漏的内容(以及我暂时完全忘记的内容,因此进行研究并找到您的问题)是 HTTPS 查询字符串是加密的,就像请求的其他部分一样 - 因此这不是更多或比将 SAS 令牌传入(例如,标头或请求正文)更不安全。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-08-24
      • 2014-02-08
      • 2019-10-13
      • 1970-01-01
      • 2013-06-28
      • 1970-01-01
      • 1970-01-01
      • 2020-09-04
      相关资源
      最近更新 更多