Azure共享访问签名 - 签名不匹配

wal*_*ark 16 c# azure azure-storage-blobs

我收到这个错误:

<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:6c3fc9a8-cdf6-4874-a141-10282b709022 Time:2014-07-30T10:48:43.8634735Z
</Message>
<AuthenticationErrorDetail>
Signature did not match. String to sign used was rwl 2014-07-31T04:48:20Z /acoustie/$root 2014-02-14
</AuthenticationErrorDetail>
</Error>
Run Code Online (Sandbox Code Playgroud)

我在生成sas(共享访问签名)时得到它,然后将容器uri末尾的sas粘贴到浏览器中.这是生成的sas的完整地址:

https://acoustie.blob.core.windows.net/mark?sv=2014-02-14&sr=c&sig=E6w%2B3B8bAXK8Lhvvr62exec5blSxsA62aSWAg7rmX4g%3D&se=2014-07-30T13%3A30%3A14Z&sp=rwl
Run Code Online (Sandbox Code Playgroud)

我已经搜索了SO和谷歌,并尝试了很多组合,据我所知,我正在做的一切正确,我知道我不是,我只是看不到它...真的希望有人可以提供帮助: - \

为了清楚起见,我在容器上生成一个sas,而不是特定的blob,而不是在根容器上.blob上的访问被定义为Public Blob.我的最终目标是简单地允许使用sas写入容器,而'debugging'我已经为SharedAccessBlobPolicy添加了大部分权限.

我尝试在容器名称的开头和结尾添加\ .没变.

这是我用来生成sas的代码:

    var blobClient = storageAccount.CreateCloudBlobClient();
    //Get a reference to the blob container 
    var container = blobClient.GetContainerReference(containerName);

    // Do not set start time so the sas becomes valid immediately.
    var sasConstraints = new SharedAccessBlobPolicy 
    {
        SharedAccessExpiryTime = DateTime.UtcNow.AddMinutes(30), 
        Permissions = SharedAccessBlobPermissions.Write 
        | SharedAccessBlobPermissions.Read
        | SharedAccessBlobPermissions.List,
    };

    var sasContainerToken = container.GetSharedAccessSignature(sasConstraints);

    //Return the URI string for the container, including the SAS token.
        var sas = string.Format("{0}{1}", container.Uri.AbsoluteUri, sasContainerToken);
        Logger.Debug("SAS: {0}", sas);
        return sas;
Run Code Online (Sandbox Code Playgroud)

它生成一个签名,它似乎不是一个有效的签名.

我尝试了不同的容器,更改了Access策略,有无启动时间,从现在开始延长到12个小时(我在UTC + 10时区),我改变它似乎并不重要导致相同的"签名不匹配"错误.

我甚至尝试使用旧版本的'WindowsAzure.Storage',所以我现在尝试了4.2和4.1.甚至在不同的浏览器中尝试过uri,真的不应该有所作为但是嘿......

任何建议都非常感谢:-)

Gau*_*tri 36

简答:

添加comp=list&restype=container到您的SAS URL,您不应该收到此错误.

答案很长:

基本上,从您的SAS URL,Azure存储服务无法识别您尝试访问的资源是blob还是容器,并假设它是一个blob.由于它假定资源类型为blob,因此它使用$rootblob容器进行SAS计算(您可以从错误消息中看到).由于SAS是针对markblob容器计算的,因此会出现此Signature Does Not Match错误.通过指定restype=container您告诉存储服务将资源视为container.comp=list根据REST API规范是必需的.

  • 刚刚更新了我的答案.关于你对SAS的评论不包括必要的位,我认为这不是SAS的意图.SAS提供对存储资源的时间/权限限制访问.您使用此SAS执行的操作取决于您.HTH. (2认同)