Fetching secrets from KeyVault with Microsoft.Azure.Services.AppAuthentication is slow for the first call
See original GitHub issueContinuing the discussion from the issue #4645 (as the mentioned issue is closed)
I tried using the connection string RunAs=Developer; DeveloperTool=VisualStudio
and it skipped the second call (as shown in the image below) and directly went on to make the third call. So, the overall time it takes to fetch the access token and then secret is approx 4-6 seconds.
This is the code to initialize the key vault
static ConfigUtils()
{
// https://docs.microsoft.com/en-us/azure/app-service/overview-managed-identity?tabs=dotnet#asal
var azureServiceTokenProvider = new AzureServiceTokenProvider("RunAs=Developer; DeveloperTool=VisualStudio");
vaultClient = new KeyVaultClient(new KeyVaultClient.AuthenticationCallback(azureServiceTokenProvider.KeyVaultTokenCallback));
}
This is the code to fetch the secret
try
{
var secret = await vaultClient.GetSecretAsync(key);
return secret.Value;
}
My main concern is that it makes the first call (connection to key vault) as soon as it executes the line: var secret = await vaultClient.GetSecretAsync(key);
but then it makes the third call in the image above (skips the second call when using connection string: RunAs=Developer; DeveloperTool=VisualStudio
) but there is a delay of nearly 3 sec between the two calls.
Is it possible to reduce that delay between calls? @nonik0 would you be able to help here?
Issue Analytics
- State:
- Created 3 years ago
- Comments:10 (6 by maintainers)
Top GitHub Comments
For those encountering this issue even when using
RunAs=Developer; DeveloperTool=VisualStudio
, a temporary workaround is to useRunAs=Developer;DeveloperTool=AzureCLI
forAzureServiceTokenProvider
. Then simply make sure Azure CLI is installed on the system, and runaz login
once to authenticate (it should stay authenticated on the system for a while with regular use). It will be much faster from here.@anaismiller @crmann1 Any idea when this will get fixed or if this is on the roadmap somewhere? It took me a long time to figure out it’s the
AzureServiceTokenProvider
causing my app to start with seemingly random delays that ranged from 1 to 30+ seconds.We want to use managed identity as best security practice and the fact that Visual Studio could authenticate itself this way is great, but this random delay is a killer for development experience, because we have to endure it every time after a build/start.
Visual Studio is aware of the issue and will be fixed in a future release of VS