Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Managed Identity - how to debug locally

I am using the following code to test system managed identity on my web app and it works fine when I deploy in Azure but is there a way to test locally(without giving permissions to my Azure account for the resource?)?

AzureServiceTokenProvider azureServiceTokenProvider = new AzureServiceTokenProvider();

KeyVaultClient keyVaultClient = new KeyVaultClient(new KeyVaultClient.AuthenticationCallback(azureServiceTokenProvider.KeyVaultTokenCallback));
var secret = await keyVaultClient.GetSecretAsync("https://EASDemo.vault.azure.net/secrets/test")
                .ConfigureAwait(false);
return new string[] { secret.Value };
like image 415
Pratik Mehta Avatar asked Feb 03 '19 11:02

Pratik Mehta


People also ask

How do I log into managed identity?

Create a user-assigned managed identity. Assign your user-assigned identity to your Windows VM. Grant the user-assigned identity access to a Resource Group in Azure Resource Manager. Get an access token using the user-assigned identity and use it to call Azure Resource Manager.

Does SQL Server support managed identity?

In addition to using a UMI and an SMI as the instance or server identity, you can use them to access the database by using the SQL connection string option Authentication=Active Directory Managed Identity . You need to map a SQL user to the managed identity in the target database.

How do I find my managed identity token?

Overview. A client application can request a managed identity app-only access token to access a given resource. The token is based on the managed identities for Azure resources service principal. As such, there's no need for the client to obtain an access token under its own service principal.


1 Answers

Options to test locally (VS, CLI) are documented here:

Authenticating with Visual Studio

To authenticate by using Visual Studio:

  1. Sign in to Visual Studio and use Tools > Options to open Options.
  2. Select Azure Service Authentication, choose an account for local development, and select OK.

If you run into problems using Visual Studio, such as errors that involve the token provider file, carefully review the preceding steps.

You may need to reauthenticate your developer token. To do so, select Tools > Options, and then select Azure Service Authentication. Look for a Re-authenticate link under the selected account. Select it to authenticate.

If you do not want to use your developer identity, you can also use a certificate or secret key (though not recommended as it can be checked in to source repository by mistake). These options are documented here.

like image 160
Varun Sharma Avatar answered Oct 06 '22 00:10

Varun Sharma