az storage blob upload-batch 的最低权限

Least privilege permissions for az storage blob upload-batch

我们的 CI 管道需要将一些文件备份到 Azure Blob 存储。我正在像这样使用 Azure CLI:az storage blob upload-batch -s . -d container/directory --account-name myaccount

在授予服务主体贡献者访问权限时,它按预期工作。但是,我想锁定权限,以便允许服务主体添加文件,但不能删除,例如。这需要什么权限?

我创建了一个自定义角色,赋予它与 Storage Blob Data Contributor 相同的权限,减去删除。这(以及直接使用 Storage Blob Data Contributor 角色)失败并返回 Storage account ... not found。好的,然后我继续向 blob 服务添加更多读取权限。还不够,现在我正处于它想做的地步Microsoft.Storage/storageAccounts/listKeys/action。但是,如果我授予它访问存储密钥的权限,那又有什么意义呢?使用存储密钥,SP 将拥有对该帐户的完全访问权限,我首先要避免这种情况。为什么 az storage blob upload-batch 请求密钥,我可以防止这种情况发生吗?

I've created a custom role giving it the same permissions as Storage Blob Data Contributor minus delete. This (and also just using the Storage Blob Data Contributor role directly) fails with a Storage account ... not found.

我也可以重现你的问题,实际上你所做的是有效的。诀窍是命令的--auth-mode参数,如果你没有指定它,它会默认使用key,然后命令会在找到你的存储时列出你订阅中的所有存储帐户帐户,它将列出帐户的密钥并使用密钥上传 blob。

但是,Storage Blob Data Contributor minus delete没有列出存储帐户的权限,那么你会得到错误。

要解决此问题,只需在您的命令中指定 --auth-mode login,然后它将使用您的服务主体的凭据获取访问令牌,然后使用该令牌调用 REST API - Put Blob to upload blobs, principle see Authorize access to blobs and queues using Azure Active Directory.

az storage blob upload-batch -s . -d container/directory --account-name myaccount --auth-mode login