AzureFunctionapp APPSETTING_ getting appended

Viewed 149

I have a .net core 2.0 Azure function app, and i have a Keyvault initializer code which fetches values from keyvault and assigns to a ConcurrentDictionary, the functionality works fine, but i see lot of dependency failures for each of the keyvault URI settings. My guess is APPSETTING_ is getting appended to each of the setting values. My code logic is reading all Environment variables and trying to find out what all settings contain Keyvault domain address, for those values i am making a call to Keyvault API to resolve the values.

Code:

        var envVar = Environment.GetEnvironmentVariables(EnvironmentVariableTarget.Process);
        var retryInstance = RetryHelper.Instance;
        SecretBundle secretBundle = new SecretBundle();

        var keyVaultAddress = ConfigurationHelper.GetEnvironmentVariables("KeyVaultBaseUrl");

        if (!string.IsNullOrWhiteSpace(keyVaultAddress))
        {
            foreach (string envKey in envVar.Keys)
            {
                string envValue = envVar[envKey].ToString();

                //Check if previously the values have been added to the dictionary or not
                if (envValue.Contains(Constants.VAULT) && envValue.Contains(Constants.HTTPS) && !KeyVaultValues.ContainsKey(envKey))
                {
                    retryInstance.RetryAction( () =>
                    {
                        secretBundle = KeyVaultInitializer.GetValuesFromKeyvault(envKey,
                        keyVaultAddress).Result;
                    }, Constants.MAXRETRIES, Constants.WAITBETWEENRETRY, RetryHelper.BackOffStrategy.Linear);

                    if (secretBundle != null && secretBundle.Value != null )
                        KeyVaultValues.TryAdd(envKey, secretBundle.Value);
                }
            }
        } else
        {
            //TODO: Log failure event
        }

enter image description here

2 Answers

You are passing envKey to KeyVaultInitializer.GetValuesFromKeyvault, surely you'd want to use the value of the setting, not the key?

You can't use "_" in a secret name.

An object-name is a user provided name for and must be unique within a Key Vault. The name must be a 1-127 character string, containing only 0-9, a-z, A-Z, and -.

Related