0

How do I retrieve the "secret value" in my Azure Function without using the properties of the Azure function?

Note: The value for the secret URL can be different every time the function is called, so it needs to resolve while running the application and not using configuration or function properties.

Similar problem but not solved using IBinder (my preferred solution):

  [FunctionName("functionName")]
        public async static void Run(
            [QueueTrigger("queueName", Connection = "StorageConnectionAppSetting")], 
            IBinder binder,
            ILogger log)
        {
         // TODO: how to resolve access from IBinder
          binder.
        }

background for the problem:

I have an application that has stored key/value pair within the Azure KeyVault in secrets while storing the data, I keep the Identifier for later retrieval:

"ClientSecretUri":"https://keyvault.vault.azure.net:443/secrets/1-ff6b03fc-12e8-427f-fa18-08d845672373/78c0211ceb5140a8990dec450eef1d23"

my code for storing the value is:

   var kvc = new KeyVaultClient(new KeyVaultClient.AuthenticationCallback(
                AzureAccessToken.GetAccessToken(APP_CLIENT_ID, APP_CLIENT_SECRET)
            ));

            var secretBundle = await kvc.SetSecretAsync(KEYVAULT_BASE_URI, keyToStoreInValut, clientSecret);

var ClientSecretUri = secretBundle.SecretIdentifier.Identifier;
cpoDesign
  • 8,953
  • 13
  • 62
  • 106

1 Answers1

0

As the code you provided, you can get the secret Identifier with ClientSecretUri.

Then you could use ClientSecretUri to access the latest secret value.

enter image description here

Joey Cai
  • 18,968
  • 1
  • 20
  • 30
  • KeyVaultClient is being deprecated in favor of SecretClient, available in our new package, Azure.Security.KeyVault.Secrets. We also split KeyClient and CertificateClient into separate packages. See https://aka.ms/valueprop and https://aka.ms/intro for more information. Used with DefaultAzureCredential from Azure.Identity, these are easier to use and do not require code changes from development to production environments. – Heath Sep 02 '20 at 23:59