简体   繁体   中英

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

I am trying to create blob container under storage account using REST api

I am using managed identity (for app service, node application) to interact with storage account. This managed identity has necessary permission on resource group and storage account - storage account contributor and storage blob data contributor

Here are the steps I'm following:

mandatory headers I'm sending in the 2nd step are:

  • Authorization: Bearer access-token
  • x-ms-date: 2021-06-17T09:01:48.667Z
  • x-ms-version: 2020-04-08

I'm getting: statusCode: 403, statusMessage: 'Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.'

Is there anything I'm missing while sending authorization header. Couldn't find any example of calling create container api using managed identity.

Another option would be to use blob storage sdk ( https://docs.microsoft.com/en-us/azure/storage/blobs/storage-quickstart-blobs-nodejs ) but couldn't find any samples of creating container using managed identity.

Any pointers to make this work are greatly appreciated.

Thanks,

First, you couldn't call Rest API with managed identity . Authorization header needs the authorization scheme, account name, and signature.

在此处输入图片说明

Manage blobs with JavaScript v12 SDK in Node.js:

You could use @azure/identity for managed 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
);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM