I have an Azure Function in Python where I'm getting a secret from Key Vault. The Azure Function is part of an App Service with Managed Identity configured, so I do not have a Service Principal. To access Key Vault, I'm using the azure identity library and the DefaultAzureCredential class.
My issue is that with local debugging of this function, credentials are not detected. I know that the debugger use a different shell, so login environment variables are not set. I tried to specify the "env" property in launch.json but get a warning that I'm not allowed to add it, same thing if I rename it to "environment". I also tried the InteractiveBrowserCredential class to login with my user account as a workaround, but then the credentials are dismissed as incorrect to access Key Vault.
How could I setup my VS Code local debugging environment to work with the managed identity of App Service?
Here is an except of my code:
import os
import logging
import azure.functions as func
from azure.storage.blob import BlobServiceClient
from azure.identity import DefaultAzureCredential, UsernamePasswordCredential
from azure.keyvault.secrets import SecretClient
def main(req: func.HttpRequest) -> func.HttpResponse:
vault_url = os.environ['KeyVaultUrl']
credential = DefaultAzureCredential()
secret_client = SecretClient(vault_url=vault_url, credential=credential)
access_key = secret_client.get_secret(os.environ['StorageSecretName'])
Thank you

