Home > database >  How to connect to Azure Table Storage using RBAC
How to connect to Azure Table Storage using RBAC

Time:03-12

I want to connect to Azure Table Storage using RBAC. I have done the role assignment in the portal but I could not find a way to connect to Azure Table form .NET code. I could find a lot of documentation on how to connect to BlobClient

static void CreateBlobContainer(string accountName, string containerName)
{
    // Construct the blob container endpoint from the arguments.
    string containerEndpoint = string.Format("https://{0}.blob.core.windows.net/{1}",
                                                accountName,
                                                containerName);

    // Get a token credential and create a service client object for the blob container.
    BlobContainerClient containerClient = new BlobContainerClient(new Uri(containerEndpoint),
                                                                  new DefaultAzureCredential());

    // Create the container if it does not exist.
    containerClient.CreateIfNotExists();
}

But could not find the similar documentation for Azure Table Acess.

Has anyone done this before?

CodePudding user response:

The patterns for authorizing with Azure Active Directory and other token sources for the current generation of the Azure SDK are based on credentials from the Azure.Identity package.

The rough equivalent to the snippet you shared would look like the following for Tables:

// Construct a new TableClient using a TokenCredential.
var client = new TableClient(
    new Uri(storageUri),
    tableName,
    new DefaultAzureCredential());

// Create the table if it doesn't already exist to verify we've successfully authenticated.
await client.CreateIfNotExistsAsync();

More information can be found in the Azure Tables authorization sample and the Azure.Identity library overvivew.

CodePudding user response:

I'm not sure I understand what you mean by "connect to Azure Table Storage using RBAC". RBAC is an authorization mechanism -- not a connection mechanism.

Here is documentation on Azure Tables client library for .NET: https://docs.microsoft.com/en-us/dotnet/api/overview/azure/data.tables-readme

  • Related