I have created an user-assigned identity using account [email protected] and copied the clientid. After this I have assigned a role to this identity on a particular storage account. Also I have added this user-assigned identity to an azure function. Now I trying to execute some code through visual studio and my login account is [email protected]. I have below piece of code
string userAssignedClientId = "<your managed identity client Id>";
var credential = new DefaultAzureCredential(new DefaultAzureCredentialOptions {ManagedIdentityClientId = userAssignedClientId });
var blobClient = new BlobClient(new Uri("https://myaccount.blob.core.windows.net/mycontainer/myblob"), credential);
Now my question is how DefaultAzureCredential will do authentication? Will it allow user with account [email protected] to use clientid created using account [email protected]
Thanks @ Tiny Wang for the comment.
We have to use the same Azure Account which you have created the
Managed identity. If Managed Identity is Enabled , and you are usingDefaultAzureCredential, then the application will look for the Azure credentials which are used for creating the Managed Identity.As mentioned by Tiny Wang Here that account is referred as the
Azure Accountin which you have created theManaged Identity.When the Application is running locally, it uses the
VisualStudio,VSCode,Azure CLIorPowershellAuthentication.When the Application is deployed it uses the
Managed IdentityAuthentication.As mentioned in the MSDoc,
DefaultAzureCredentialwill follow the order of Authentication.If any of the Authentication is completed and satisfied, it stops the how DefaultAzureCredential will do authentication?process.
Check the below workaround how
ManagedIdentityCredentialworks in your scenario.I have created a Managed Identity with one
Azure account.And in Visual Studio I have logged in with different Azure Account.
When I tried to run with your code, I didn't get any error.
From this I understood that as we have mentioned
Managed Identity,the authentication is takingAzure Credentialsof the createdManaged Identityaccount irrespective of theVisual StudioAccount.But it may impact the access level of Azure resources. So, it is better to go with the same account.