Sitemap

Walking through Azure Cloud || Part-7

10 min readMay 3, 2025

If you are landing first time, this is the link to go for you. In this blog, we shall learn about ManagedIdentities from Microsoft-Azure :-

Press enter or click to view image in full size

Example #1

Question → How the permissions are checked for the Users ?

Answer → We can basically assign different Roles to a particular User.

Press enter or click to view image in full size

Question → Showcase how can our Application, can access some resources which are present in our Azure Storage Account, using the very basic approach ?

Answer → Here is how we can access the files present in our Storage-Container :-

Step #1.) Let’s first see the files which are present inside our container :-

  • Storage Name → “appstore55455344243
  • Container Name → “data”
Press enter or click to view image in full size

Step #2.) Let’s now navigate to “Access Keys” section for our Storage Account. Below screenshot, we can see the ConnectionString and Key that we can use, in order to access this storage-account :-

Press enter or click to view image in full size

Step #3.) Here is how our code looks like in order to access this file. We make use of following things :-

  • BlobServiceClient
  • BlobContainerClient
  • BlobClient
Press enter or click to view image in full size

In the above approach, there is a problem — We have manually entered the credentials (i.e. ConnectionString) inside our code.

Question → Showcase how can our Application, can access some resources which are present in our Azure Storage Account without having to mention the connectionString ?

Answer → This can be done with the help of “Application-Object”.

Step #1.) Let’s first see navigate inside our EntraId first.

Press enter or click to view image in full size

Step #2.) We would register an Application now :-

Press enter or click to view image in full size

Step #3.) We would now supply the name of the Application :- In our case, we are specifying the name as “blobapp”.

Press enter or click to view image in full size

Step #4.) Once our Application is registered successfully, we take note of following things :-

  • TenantId.
  • ClientId
Press enter or click to view image in full size

Step #5.) We would now go inside the : “Certificates and Secrets” as shown below and create the “Client-Secrets”.

Press enter or click to view image in full size

Here is we can see the “Client Secrets” :-

Press enter or click to view image in full size

Step #6.) Now, so far we registered an Application and now, we need to allocate the permission to this Application-Object. So, let’s first go inside the Storage-Account → Access-Control → Add-Role-Assignment.

Press enter or click to view image in full size

Next :-

  • We have selected the role as : “Storage Blob Data Reader”.
  • Under the option : “Assign access to” :-we choose : “User, Group, or Service Principal” :-
  • When we click on Select-Members → we can select our Application-Object i.e. “blobapp”.
Press enter or click to view image in full size

Finally, once the Role is assigned to this ApplicationObject, this is ready to be used in our application-codebase.

Press enter or click to view image in full size

Step #7.) Now, we shall directly access the files, which are present inside our Storage-Account → Container → Files using :-

  • ClientSecretCredential
  • BlobClient
Press enter or click to view image in full size

Now, when we execute our code at our local-personal-On-Premise-machine, we shall be able to download the file successfully now :-

Press enter or click to view image in full size

Question → What’s the main dis-advantage of using Application-Object mechanism of accessing the Azure-Resources from the Application codebase ?

Answer → The main problem here is :- Even though, we have made use of RBAC, we still needed to embed the credentials of the Application-Object in our codebase :-

Example #2

Question → What is the alternative to the Application-Objects ?

Answer → The alternative to the “Application Object” is to use : “Managed Entities”. This gives us a way for our Applications to authenticate to Azure Resources without the need of embedding the credentials.

Press enter or click to view image in full size

Question → What is the main requirement in order to use the “Managed Entities” ?

Answer → The main requirement is :

  • Our application-code needs to be hosted on a service that supports Managed-Entities like VM, App-Engine, etc.
  • Under the hoods, the “Managed Entities” shall create a Service-Principal for that resource.

Step #1.) After our first is successfully created at our Azure Account, Under the “Identities” section, we enable the System Managed Entity :-

Press enter or click to view image in full size

Once we enable the “System Assigned Managed Entity”, here is how it would look :-

Press enter or click to view image in full size

Step #2.) Now, let’s assign the RBACs. Here, we are saying , we shall allocate the permissions of accessing the Storage-Account to our VM.

  • So, for this, we go to the Storage-Account → “Access Control (IAM)”.
  • Please note that, this is the Account, that has to be accessed by our application-codebase.
Press enter or click to view image in full size

Step #3.) We shall choose the Role as : “Storage Blob Data Reader” and move forward :-

  • We choose : “Managed Identity”.
  • Under Members, we choose our VM, to which the access to Storage-Account has to be assigned.
Press enter or click to view image in full size

So, here we choose our VM that we created in aforementioned-step :-

Press enter or click to view image in full size

After the Role has been assigned to the afore-shown VM, here is how the UI would look like. Now, we hit the : “Review and Assign” button.

Step #4.) The class that we shall use to access the Storage-Account from the Application-codebase is : “DefaultAzureCredential” :-

Press enter or click to view image in full size

Step #5.) The code to access the Storage-Account & objects in the container , through the DefaultAzureCredential looks like as follows :-

  • BlobClient.
Press enter or click to view image in full size

Please note that :-

  • The aforementioned code-base can’t be executed at our local-on-premise-machine, rather this code can only be executed at VM, which is present inside our Azure Ecosystem.
  • In the above mentioned steps, we have created the VM (at which we shall be running the afore-shown code-piece).
  • So, we first build the code at our local and would take the executables at our VM.

Question → How does DefaultAzureCredential works under the hoods ?

Answer → Under the hoods, it generates a token, which VM shall be used to hit the Storage-Accounts :-

Step #1.) Here, Azure exposes this endpoint, which we shall copy from here :-

Press enter or click to view image in full size

Step #2.) Let’s now write this code, to access the token for the Storage-Account :-

Press enter or click to view image in full size

Step #3.) We build this code at our local machine and take this executable at the VM. Once the executable is there is at the VM, we shall execute it and we can now see the token, which is what being used under the hoods of ManagedEntity :-

Press enter or click to view image in full size

Step #4.) Now, we can also fetch, some more informations from this Token :-

Press enter or click to view image in full size

Step #5.) Now, we again build the code at our local :-

Press enter or click to view image in full size

We now take the executable to VM :-

Press enter or click to view image in full size

We now execute the same DLL at VM and we can see some additional information from this Token :-

  • client_id
  • token_type
Press enter or click to view image in full size

Step #6.) Here is now, we can execute our code to access the Storage Account too :-

Press enter or click to view image in full size

The procedure would remain same. Build at Local → Transfer to VM → Execute at VM.

Example #3

Question:- Demonstrate the concept of Managed-Identities with some different example ?

Step #1.) Imagine that we have a Virtual-Machine.

  • First, we go and enable the System-Assigned Identity at this VM.
  • Once we enable to System-Assigned Managed-Identity for this Resource (VM), it would be able to call other Azure services.
Press enter or click to view image in full size

Once we enable the System-Assigned-Managed-Identity for this VM, we can see it’s Principal-Id :-

Press enter or click to view image in full size

Step #2.) Imagine that our application is running at the afore-said VM and it wants to access the below shown Storage-Account (“tempfunction4567grob884”), then we shall have to : “Add the Role Assignment” on the storage-Account :-

Press enter or click to view image in full size

Here, we have to choose the Job-Function-Role : “Storage Blob Data Contributor”, because we want our VM to be able to contribute to the Storage Blob Data :-

Press enter or click to view image in full size

Under the Members section, we can choose “Managed-Identity” and under the MI, we can choose the VM (for which we enabled the MI in step #1) :-

Press enter or click to view image in full size

We shall be able to see the VM (for which we enabled the MI in step #1) :-

Press enter or click to view image in full size

Here, we can see the final step :-

Press enter or click to view image in full size

So, finally now, our application (running at our VM) would now be able to access the Storage-Account automatically.

Example #4

Question:- Demonstrate the concept of UAMI with some different example ?

Step #1.) Let’s first create an User-Assigned-managed-Identity :-

Press enter or click to view image in full size

This is how our UAMI would look like, once it is succesfully created :-

Press enter or click to view image in full size

Step #2.) Now, we go to our Storage-Account and attach this UAMI to this Storage Account :-

Press enter or click to view image in full size

From the Role, we shall assign the : “Storage Blob Data Delegator” role to the Storage-Account :-

Press enter or click to view image in full size

Now, we associate the Managed-Identity to this Storage-Account :-

Press enter or click to view image in full size

Here is how, it would look, after we attach the MI to this Storage-Account :-

Press enter or click to view image in full size

And we can see here that, UAMI has been associated with the Storage-Account succesfully :-

Press enter or click to view image in full size

Step #3.) Now, we associate the afore-created UAMI with our Virtual-Machine.

  • Note that, our intention here is that, our application running on this VM, should be able to access the afore-shown Storage-Account.
  • We can attach this UAMI to as many resources as we want. Say tomorrow some App-Function wants to access this Storage-Account, then we can associate this same UAMI to that App-Function as well. We don’t need to enable the MI again & again inside the Storage-Account.
Press enter or click to view image in full size

Let’s add the Identity to our VM now :-

Press enter or click to view image in full size

--

--

aditya goel
aditya goel

Written by aditya goel

Software Engineer for Big Data distributed systems

No responses yet