如何为 list\delete blob 创建 SAS 令牌
How to create SAS token to list\delete blobs
我试过这样创建 SAS(ADDING "Read" 权限没有任何变化):
但它对我不起作用。我只希望我的脚本获取 blob 列表、读取元数据和删除旧 blob。
Get-AzureStorageContainer : The remote server returned an error: (403)
Forbidden. HTTP Status Code: 403 - HTTP Error Message: This request is
not authorized to perform this operation.
此外,我想知道实现我的目标的最低可能权限是多少。
$ctx = New-AzureStorageContext -StorageAccountName xxx -SasToken zzz
$Containers = Get-AzureStorageContainer -Context $ctx
示例 sas 令牌:
?sv=2017-07-29&ss=b&srt=co&sp=dl&se=2018-03-31T21:24:06Z&st=2018-03-31T09:24:06Z&spr=https&sig=bWsg5sSPZF%2FaBXxfW6RoCH%2BlcFKBT6MFyMKTRM3I2jI%3D
所以这里有两件事:
您收到 403 错误:假设您使用的是您在问题中提到的相同 SAS 令牌以及 Get-AzureStorageContainer
Cmdlet, you will get this error. The reason for this is the purpose of this Cmdlet is to list blob containers in a storage account and for that you need to have Service
permission in your SAS token (srt
value in your SAS token should be sco
instead of co
). Because the required permission is not there in your SAS token, you are getting this 403 error. However if you use the same token along with Get-AzureStorageBlob
, 你不应该得到任何错误。
获取 blob 列表、读取元数据和删除旧 blob 的必要权限:为此,您需要以下权限:
- 允许的服务:Blob (b)
- 允许的资源类型:容器 (c) 和对象 (o)
- 允许的权限:列表 (l)、读取 (r) 和删除 (d)
通过这种组合,您应该能够使用 Get-AzureStorageBlob
列出 blob 容器中的 blob,读取其元数据并删除 blob。
更新
所以我所做的是按照您的步骤并尝试使用 Get-AzureStorageContainer
Cmdlet 列出 blob 容器。我也遇到了同样的错误 :)。
然后我 运行 带有 Debug
和 Verbose
开关的 Cmdlet 发现对于每个 blob 容器,此 Cmdlet 尝试获取 ACL
。
_https://account.blob.core.windows.net/my-container?sv=2017-07-29&ss=b&srt=sco&sp=dl&se=2018-03-31T23:28:27Z&st=2018-03-31T15:2
8:27Z&spr=https&sig=signature&api-version=2017-04-17&restype=container&comp=acl.
Confirm The remote server returned an error: (403) Forbidden. HTTP
Status Code: 403 - HTTP Error Message: This request is not authorized
to perform this operation. [Y] Yes [A] Yes to All [H] Halt Command
[S] Suspend [?] Help (default is "Y"): y Get-AzureStorageContainer :
The remote server returned an error: (403) Forbidden. HTTP Status
Code: 403 - HTTP Error Message: This request is not authorized to
perform this operation. At line:1 char:1
+ Get-AzureStorageContainer -Context $ctx -Debug -Verbose
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [Get-AzureStorageContainer], StorageException
+ FullyQualifiedErrorId : StorageException,Microsoft.WindowsAzure.Commands.Storage.Blob.Cmdlet.GetAzureStorageCont
ainerCommand
现在的问题是您无法使用共享访问签名获取容器的 ACL,您需要使用帐户密钥(创建共享访问签名也是如此)。这就是您从服务返回 403 错误的原因。
不确定您是否会将其归类为 Get-AzureStorageContainer
中的一个错误,或者是否希望提出一个功能请求,允许您在不获取其 ACL 的情况下列出 blob 容器,但现在的情况是这样,您不能使用此 Cmdlet 和 SAS 令牌列出 blob 容器。
我试过这样创建 SAS(ADDING "Read" 权限没有任何变化):
但它对我不起作用。我只希望我的脚本获取 blob 列表、读取元数据和删除旧 blob。
Get-AzureStorageContainer : The remote server returned an error: (403) Forbidden. HTTP Status Code: 403 - HTTP Error Message: This request is not authorized to perform this operation.
此外,我想知道实现我的目标的最低可能权限是多少。
$ctx = New-AzureStorageContext -StorageAccountName xxx -SasToken zzz
$Containers = Get-AzureStorageContainer -Context $ctx
示例 sas 令牌:
?sv=2017-07-29&ss=b&srt=co&sp=dl&se=2018-03-31T21:24:06Z&st=2018-03-31T09:24:06Z&spr=https&sig=bWsg5sSPZF%2FaBXxfW6RoCH%2BlcFKBT6MFyMKTRM3I2jI%3D
所以这里有两件事:
您收到 403 错误:假设您使用的是您在问题中提到的相同 SAS 令牌以及
Get-AzureStorageContainer
Cmdlet, you will get this error. The reason for this is the purpose of this Cmdlet is to list blob containers in a storage account and for that you need to haveService
permission in your SAS token (srt
value in your SAS token should besco
instead ofco
). Because the required permission is not there in your SAS token, you are getting this 403 error. However if you use the same token along withGet-AzureStorageBlob
, 你不应该得到任何错误。获取 blob 列表、读取元数据和删除旧 blob 的必要权限:为此,您需要以下权限:
- 允许的服务:Blob (b)
- 允许的资源类型:容器 (c) 和对象 (o)
- 允许的权限:列表 (l)、读取 (r) 和删除 (d)
通过这种组合,您应该能够使用 Get-AzureStorageBlob
列出 blob 容器中的 blob,读取其元数据并删除 blob。
更新
所以我所做的是按照您的步骤并尝试使用 Get-AzureStorageContainer
Cmdlet 列出 blob 容器。我也遇到了同样的错误 :)。
然后我 运行 带有 Debug
和 Verbose
开关的 Cmdlet 发现对于每个 blob 容器,此 Cmdlet 尝试获取 ACL
。
_https://account.blob.core.windows.net/my-container?sv=2017-07-29&ss=b&srt=sco&sp=dl&se=2018-03-31T23:28:27Z&st=2018-03-31T15:2 8:27Z&spr=https&sig=signature&api-version=2017-04-17&restype=container&comp=acl.
Confirm The remote server returned an error: (403) Forbidden. HTTP Status Code: 403 - HTTP Error Message: This request is not authorized to perform this operation. [Y] Yes [A] Yes to All [H] Halt Command [S] Suspend [?] Help (default is "Y"): y Get-AzureStorageContainer : The remote server returned an error: (403) Forbidden. HTTP Status Code: 403 - HTTP Error Message: This request is not authorized to perform this operation. At line:1 char:1 + Get-AzureStorageContainer -Context $ctx -Debug -Verbose + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : CloseError: (:) [Get-AzureStorageContainer], StorageException + FullyQualifiedErrorId : StorageException,Microsoft.WindowsAzure.Commands.Storage.Blob.Cmdlet.GetAzureStorageCont ainerCommand
现在的问题是您无法使用共享访问签名获取容器的 ACL,您需要使用帐户密钥(创建共享访问签名也是如此)。这就是您从服务返回 403 错误的原因。
不确定您是否会将其归类为 Get-AzureStorageContainer
中的一个错误,或者是否希望提出一个功能请求,允许您在不获取其 ACL 的情况下列出 blob 容器,但现在的情况是这样,您不能使用此 Cmdlet 和 SAS 令牌列出 blob 容器。