Azure 使用 REST api 和托管标识创建 blob 容器 - 403 错误

Azure create blob container using REST api and managed identity - 403 error

我正在尝试使用 REST 在存储帐户下创建 blob 容器 api

我正在使用托管标识(用于应用程序服务、节点应用程序)与存储帐户进行交互。此托管标识对资源组和存储帐户具有必要的权限 - 存储帐户贡献者和存储 blob 数据贡献者

以下是我要执行的步骤:

强制性 header我在第二步发送的是:

我得到: 状态代码:403,状态消息:'Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.'

发送授权时我是否遗漏了什么 header。找不到使用托管身份调用创建容器 api 的任何示例。

另一种选择是使用 blob 存储 sdk (https://docs.microsoft.com/en-us/azure/storage/blobs/storage-quickstart-blobs-nodejs),但找不到任何使用托管身份创建容器的示例。

非常感谢任何使这项工作成功的建议。

谢谢,

首先,您无法使用托管身份 调用 Rest API。 Authorization header 需要授权方案、账户名和签名。

在 Node.js 中使用 JavaScript v12 SDK 管理 blob:

您可以使用 @azure/identity 作为托管身份。

const { ManagedIdentityCredential } = require("@azure/identity");
const { BlobServiceClient } = require("@azure/storage-blob");

const credential = new ManagedIdentityCredential("<USER_ASSIGNED_MANAGED_IDENTITY_CLIENT_ID>");

const blobServiceClient = new BlobServiceClient(
    `https://${account}.blob.core.windows.net`,
    credential
);