【问题标题】:Azure Blob Storage - Changing permissions of a container and accessing with SASAzure Blob 存储 - 更改容器的权限并使用 SAS 访问
【发布时间】:2014-08-17 13:30:14
【问题描述】:

我有一个 Azure Blob 容器,其中包含一些 blob。使用以下代码(成功)创建了容器:

if (container.CreateIfNotExists())
{
    var permissions = container.GetPermissions();
    permissions.PublicAccess = BlobContainerPublicAccessType.Off;
    container.SetPermissions(permissions);
}

您会看到权限设置为私有(即,PublicAccessOff)。

在我的代码的后面部分,我想使用SAS 打开权限,到期时间为1 hour。为了尝试这个,我正在使用代码:

if (container.Exists())
    {
    //Set the expiry time and permissions for the container.
    //In this case no start time is specified, so the shared access signature becomes valid immediately.
    SharedAccessBlobPolicy sasConstraints = new SharedAccessBlobPolicy();
    sasConstraints.SharedAccessExpiryTime = DateTime.UtcNow.AddHours(1);
    sasConstraints.Permissions = SharedAccessBlobPermissions.Read | SharedAccessBlobPermissions.List;

    //Generate the shared access signature on the container, setting the constraints directly on the signature.
    string sasContainerToken = container.GetSharedAccessSignature(sasConstraints);

    //Return the URI string for the container, including the SAS token.
    return container.Uri + sasContainerToken;
}

但是,无论我如何调整它,当我将浏览器导航到返回的 url(即container.Uri + sasContainerToken)时,我都会收到身份验证错误:

<Error>
  <Code>AuthenticationFailed</Code>
  <Message>
    Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature. RequestId:d7f89ef3-919b-4b86-9b4f-4a95273c20ff Time:2014-06-26T15:33:11.2754096Z
  </Message>
  <AuthenticationErrorDetail>
    Signature did not match. String to sign used was rl 2014-06-26T16:32:02Z /mycontainer/$root 2014-02-14
  </AuthenticationErrorDetail>
</Error>

谁能告诉我为什么我会看到这个身份验证错误?

我的最终网址看起来格式正确?:

https://myservice.blob.core.windows.net/mycontainer?sv=2014-02-14&sr=c&sig=0MSvKIRJnxWr2G%2Bh0mj%2BslbNtZM3VnjSF8KPhBKCPs8%3D&se=2014-06-26T16%3A32%3A02Z&sp=rl

我很茫然,所以任何指针都将不胜感激。

【问题讨论】:

    标签: c# azure azure-storage


    【解决方案1】:

    我也遇到了完全相同的错误:)。您不能使用共享访问签名执行与容器相关的操作(列出 blob 除外)。您需要使用帐户密钥对容器执行操作。从这个页面:http://msdn.microsoft.com/en-us/library/azure/jj721951.aspx

    使用共享访问签名支持的操作包括:

    • 读取和写入页面或块 Blob 内容、块列表、属性和元数据

    • 删除、租用和创建 blob 的快照

    • 列出容器中的 blob

    更新

    对于列出 blob,只需将 &amp;comp=list&amp;restype=container 添加到您的 URL 即可。所以你的网址应该是:

    https://myservice.blob.core.windows.net/mycontainer?sv=2014-02-14&sr=c&sig=0MSvKIRJnxWr2G%2Bh0mj%2BslbNtZM3VnjSF8KPhBKCPs8%3D&se=2014-06-26T16%3A32%3A02Z&sp=rl&comp=list&restype=container
    

    【讨论】:

    • 我实际上只想列出 blob url。听起来这应该是可能的。难道不能通过浏览器浏览以这种方式列出它们吗?
    • 哇...完美!谢谢!我没有在文档中遇到那些查询字符串参数。一定是在什么地方错过了他们。谢谢!已接受答案!
    • 它在这里...msdn.microsoft.com/en-us/library/azure/dd135734.aspx。在请求部分。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-16
    • 1970-01-01
    • 2019-03-13
    • 2021-05-02
    • 1970-01-01
    • 2023-04-07
    相关资源
    最近更新 更多