How to use Key Vault references for Azure Functions locally

Ahsan Habib 126 Reputation points
2022-04-24T19:19:48.693+00:00

Hello Everyone !!!

So Key Vault reference is a great feature. However, Is it possible to use this while I run my app locally? or I can say Is it possible to use @Microsoft.KeyVault(VaultName=myvault;SecretName=mysecret) locally?

If not, then I have to use the Key Vault SDK I believe. In that case, my question is, how to access and update the Connection Property ( for example, [EventHubOutput("my-eh", Connection = "EventHubConnectionString")]) of the Azure Function Trigger/binding attribute with the value of a Azure Key vault secret?

Note: I am using Azure Function V4 Isolated Process

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,909 questions
{count} votes

5 answers

Sort by: Most helpful
  1. Bruno Lucas 4,436 Reputation points MVP
    2022-04-28T03:24:51.407+00:00

    Hi @Ahsan Habib ,

    I added this to my git: https://github.com/blucas2016/TestVaultRefOnAZFunctionV4Isolated

    try to clone and modify the value for "Hub1ConnString" to your vault's secret path

    197136-image.png

    I've added that httptrigger just because makes it easier to debug and demo the parsing of the vault reference . as you see in the debug window the value is the conn string, not the vault ref

    197201-image.png

    I'm running my vs 2022 as admin:
    197096-image.png

    Sometimes it can be the firewall. But usually, firewall throws a specific error: https://brunolucas.blog/2022/02/27/code-and-test-azure-service-bus-and-azure-event-hub-triggers-locally/

    Let me know if that works. if Doesn't, I'm happy to expand on what I've done with more details.

    2 people found this answer helpful.

  2. Bruno Lucas 4,436 Reputation points MVP
    2022-08-20T01:55:20.2+00:00

    Hi @Oleksandr Kyselov
    When you say "My visual studio is running on admin mode and logged in with the azure account that has all rights necessary.", do you mean you can se the user (you are using to login into VS) has a vault policy with permission to read secrets?
    Look like you are adding the key along with the vault secret path:
    233036-image.png

    note my example does not have that key/hash part:

    233053-image.png

    try secrets/Secret1")

    1 person found this answer helpful.

  3. Bruno Lucas 4,436 Reputation points MVP
    2022-04-25T06:32:13.22+00:00

    Hi, by "run my app locally", do you mean debugging with Visual Studio?

    You need to create a vault policy for the user account you use to run visual studio.

    https://stackoverflow.com/questions/55027221/azure-functions-key-vault


  4. Sacher, Wolf-Rüdiger 21 Reputation points
    2023-07-25T09:26:36.3466667+00:00

    Hi @Ahsan Habib , great work! It helped me out of the box! Thank you very much!!!

    0 comments No comments

  5. Viacheslav Vodianov 0 Reputation points
    2023-08-17T09:47:42.08+00:00

    Had similar issue with non-isolated azure functions app, found solution that I haven't seen in the internet before: added Azure.Identity package over Nuget and it suddenly started to turn references into values.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.