An Azure service that is used to manage and protect cryptographic keys and other secrets used by cloud apps and services.
Hello Anonymous,
Welcome to the Microsoft Q&A and thank you for posting your questions here.
I understand that you are having error on Azure Key Vault access from Python application in Azure Kubernetes Service.
Your python code is correct. The Python application already detects a valid identity provider through the DefaultAzureCredential chain, which confirms that managed identity or workload identity initialization is functioning properly.
To resolve the issue, retrieve the outbound public IP addresses assigned to the Azure Kubernetes Service cluster and add them to the vault’s network access rules. This can be obtained using the Azure CLI:
az aks show \
--resource-group <resource-group> \
--name <cluster-name> \
--query networkProfile.loadBalancerProfile.effectiveOutboundIPs
After identifying the outbound IPs, navigate to the Key Vault Networking settings in the Azure portal and add those addresses to the firewall allow list, or alternatively enable the Allow trusted Microsoft services option if appropriate for the environment. Once the AKS outbound traffic is permitted, the Python SDK will successfully connect and retrieve secrets using the existing implementation:
from azure.identity import DefaultAzureCredential
from azure.keyvault.secrets import SecretClient
credential = DefaultAzureCredential()
client = SecretClient(
vault_url="https://<vault-name>.vault.azure.net/",
credential=credential
)
secret = client.get_secret("snowflake-password")
print(secret.value)
Implementation guidance for this configuration is documented in the official Azure networking and Key Vault documentation: https://learn.microsoft.com/en-us/azure/key-vault/general/network-security and https://learn.microsoft.com/en-us/azure/key-vault/secrets/quick-create-python. Once network access is properly configured, the application can authenticate through managed identity and retrieve secrets without experiencing connection timeouts.
I hope this is helpful! Do not hesitate to let me know if you have any other questions or clarifications.
Please don't forget to close up the thread here by upvoting and accept it as an answer if it is helpful.