0

我正在创建一个 SAS 令牌:

$start = [System.DateTime]::Now.AddMonths(-1)
$end = [System.DateTime]::Now.AddMonths(1)
$cloudConfigSas = New-AzStorageBlobSASToken -Container "myContainer" -Blob "myBlob" -Permission "rwd" -Protocol HttpsOnly -StartTime $start -ExpiryTime $end -FullUri -Context $storageContext

完整的 uri 具有以下格式:

https://{myStorage}.blob.core.windows.net/{myContainer}/{myBlob}.json?sv=2019-02-02&sr=b&sig=M8ZphKYAVr8vUk5V2F5QkcJOCmp05%2ByoPhcWPMrcSeI%3D&spr=https&st=2020-01-12T22% 3A54%3A14Z&se=2021-01-13T22%3A54%3A14Z&sp=rwd

尝试访问它时,我收到以下错误

<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:{myRequestID} Time:2020-01-14T00:19:08.2434298Z</Message>
<AuthenticationErrorDetail>Signature did not match. String to sign used was rwd 2020-01-12T22:54:14Z 2021-01-13T22:54:14Z /blob/{myStorage}/{myContainer}/{myBlob} https 2019-02-02 b </AuthenticationErrorDetail>
</Error>
4

1 回答 1

1

根据我的测试,您的脚本应该可以工作。尝试使用New-AzStorageContext如下。

$storageContext = New-AzStorageContext -StorageAccountName storageaccount -StorageAccountKey 4i41SDZ3xxxxxxZJYA==
$start = [System.DateTime]::Now.AddMonths(-1)
$end = [System.DateTime]::Now.AddMonths(1)
$cloudConfigSas = New-AzStorageBlobSASToken -Container "test1" -Blob "batch.json" -Permission "rwd" -Protocol HttpsOnly -StartTime $start -ExpiryTime $end -FullUri -Context $storageContext

在此处输入图像描述

在此处输入图像描述

在浏览器中访问它:

在此处输入图像描述

于 2020-01-14T01:24:51.057 回答