Skip to main content

Demystifying system-assigned managed identity and user-assigned managed identity for Azure Resources


Managing credentials and access rights across services it is always a challenge inside the cloud. Storing them inside the applications can be painful, even when they are encrypted. Managing all of them from one central location can be done quickly using managed to identify feature build on top of Azure AD.

Because it is so easy to see and the number of features is high, many people forget to understand better what option they should use depending on the use case. Let’s take a look at some questions that you should ask yourself when you need to manage the identity of cloud services inside Azure.

Q: What is the username password when I’m using user-assigned manage identity
R: When you create a user-assigned managed identity, there is no used as you have for Azure AD. Even if the name contains the word ‘user’, it does not mean that you manage a user. You have an identity that can be operated independently of the service instance that receives the identity.

Q: I want to be able to assign the same identity to multiple resources – configure one time and use in multiple places. What shall I use?
R: In this case, you need to use a user-assigned managed identity. Once the identity is created, you can assign it to multiple services. Remember that system-assigned managed identity is created and assigned from the beginning to a single instance. It is deleted automatically at the moment in time when the instances are deleted. For example, a system-assigned identity that provides access for an Azure Web App to Azure Key Vault will exist as long as the instance of the Azure Web App exist. At the moment in time when the Azure Web App is deleted, the identity it is also removed with all other information that exists in the Azure Key Vault access management and Azure AD.

Q: What is the lifecycle of the user-assigned managed identity?
R: The lifecycle is fully managed by you. You are the one that decide when the identity is deleted and can exist even when there are no Azure services instances assigned to it.

Q: What is the no. of Azure services that I can assign to user-assigned managed identity?
R: 0 to N. There is no limitation from this point of view. In comparison, system-assigned managed identity can be assigned to only one Azure service instance and cannot be defined without being attached to an instance. This is why user-assigned managed identities are seen as a stand-alone Azure resource, in comparison with the other ones that are part of the Azure service instance.

Q: When I shall use system-assigned managed identity?
R: This kind of identity is used with success when the identity is required by only one service. For example, you have only one Azure App Service or Azure Function that needs specific access rights. When you need to assign the identity for multiple services, user-assigned managed identity is the answer.

Q: What are managed identities?
R: Behind the scene, managed identities are service principals of a special type. They can be used only for Azure resources, and their life-cycle is around them.

Q: How does the system-assigned managed identity works?
R: When you assigned a managed identity, the Azure Resource Manager (ARM) would go to IMDS and assign the managed identity to the specific resource. Once the identity is attached to the resource, the Azure AD will 'connect' a role to the resource service principal. From that one, the resource can request an access token from IMDS endpoint that is used to access specific resources. The user-assigned managed identity is similar, with some small expectation because the life-cycle of the managed identity is outside the resource boundary. 

Comments

Popular posts from this blog

ADO.NET provider with invariant name 'System.Data.SqlClient' could not be loaded

Today blog post will be started with the following error when running DB tests on the CI machine:
threw exception: System.InvalidOperationException: The Entity Framework provider type 'System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer' registered in the application config file for the ADO.NET provider with invariant name 'System.Data.SqlClient' could not be loaded. Make sure that the assembly-qualified name is used and that the assembly is available to the running application. See http://go.microsoft.com/fwlink/?LinkId=260882 for more information. at System.Data.Entity.Infrastructure.DependencyResolution.ProviderServicesFactory.GetInstance(String providerTypeName, String providerInvariantName) This error happened only on the Continuous Integration machine. On the devs machines, everything has fine. The classic problem – on my machine it’s working. The CI has the following configuration:

TeamCity.NET 4.51EF 6.0.2VS2013
It seems that there …

GET call of REST API that contains '/'-slash character in the value of a parameter

Let’s assume that we have the following scenario: I have a public HTTP endpoint and I need to post some content using GET command. One of the parameters contains special characters like “\” and “/”. If the endpoint is an ApiController than you may have problems if you encode the parameter using the http encoder.
using (var httpClient = new HttpClient()) { httpClient.BaseAddress = baseUrl; Task<HttpResponseMessage> response = httpClient.GetAsync(string.Format("api/foo/{0}", "qwert/qwerqwer"))); response.Wait(); response.Result.EnsureSuccessStatusCode(); } One possible solution would be to encode the query parameter using UrlTokenEncode method of HttpServerUtility class and GetBytes method ofUTF8. In this way you would get the array of bytes of the parameter and encode them as a url token.
The following code show to you how you could write the encode and decode methods.
publ…

Entity Framework (EF) TransactionScope vs Database.BeginTransaction

In today blog post we will talk a little about a new feature that is available on EF6+ related to Transactions.
Until now, when we had to use transaction we used ‘TransactionScope’. It works great and I would say that is something that is now in our blood.
using (var scope = new TransactionScope(TransactionScopeOption.Required)) { using (SqlConnection conn = new SqlConnection("...")) { conn.Open(); SqlCommand sqlCommand = new SqlCommand(); sqlCommand.Connection = conn; sqlCommand.CommandText = ... sqlCommand.ExecuteNonQuery(); ... } scope.Complete(); } Starting with EF6.0 we have a new way to work with transactions. The new approach is based on Database.BeginTransaction(), Database.Rollback(), Database.Commit(). Yes, no more TransactionScope.
In the followi…