question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Fetching secrets from KeyVault with Microsoft.Azure.Services.AppAuthentication is slow for the first call

See original GitHub issue

Continuing 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.

ab

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:closed
  • Created 3 years ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
felinepccommented, Feb 20, 2021

For those encountering this issue even when using RunAs=Developer; DeveloperTool=VisualStudio, a temporary workaround is to use RunAs=Developer;DeveloperTool=AzureCLI for AzureServiceTokenProvider . Then simply make sure Azure CLI is installed on the system, and run az 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.

2reactions
anaismillercommented, Dec 4, 2020

Visual Studio is aware of the issue and will be fixed in a future release of VS

Read more comments on GitHub >

github_iconTop Results From Across the Web

Reading a secret from Azure Key Vault takes a long time
I have yet to find anyone with a similar issue. First time using Key Vault, am I possibly not accessing it correctly? Microsoft...
Read more >
Azure function occationaly gets super slow accessing ...
I have a servicebus-triggered azure function that needs to retrieve some secrets from keyvault in the begining.
Read more >
Azure Key Vault - first GetSecret() takes more than 10 ...
I am experiencing a 13 seconds delay when getting a secret from the key vault. I have a Consumption Plan for the functions....
Read more >
Quickstart - Azure Key Vault secrets client library for .NET
Learn how to create, retrieve, and delete secrets from an Azure key vault using the .NET client library.
Read more >
How To Authorize Your Key Vault Secrets To Serverless ...
In this article, we will learn how to authorize our Azure Function to access Key Vault secrets.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found