I have set up a separate test environment to try to retrieve app secrets from azure key vault. The @Microsoft.KeyVault(...) reference in Application Settings is not resolving to either the secret or the text of the reference when the test function is run to return environment variables.
Following this documentation to create an app service and authenticate it against the key vault, I have created a managed identity for my function, added that to AAD, created a specific access policy for this managed identity with the Get Secret scope in my key vault, and tried both with/without enabling the Read scope with the application as a user.
Running the diagnostic tool to resolve function app application setting references yields no errors. Entering the application setting as either @Microsoft.KeyVault(SecretUri=SecretUri)
or
@Microsoft.KeyVault(VaultName=myvault;SecretName=mysecret;SecretVersion={version})
does not appear to change anything. I've waited up to a half hour for changes in settings to replicate across Azure and ensure that the changes I've made are persistent.
Here is my function app to return environment variables (written in python):
import json
import logging
import os
import azure.functions as func
def main(req=None) -> func.HttpResponse:
logging.info('Python HTTP trigger function processed a request.')
try:
name = [os.environ["CLIENTID"]]
except:
name=dict()
for d in os.environ:
name[d]=os.environ[d]
if name:
return func.HttpResponse("Params\n{}".format(json.dumps(name, sort_keys=True, indent=4)))
else:
return func.HttpResponse(
"Please pass a name on the query string or in the request body",
status_code=400
)
I expected to be able to pull the environment variable CLIENTID. Instead, grabbing that variable fails and all environment variables are returned. I return all environment variables on purpose if I cannot return the singular variable since I wanted to make sure I captured it if the variable was renamed or there was a typing/case sensitivity issue.