Process for Python App Authentication to Azure OpenAI Service without Client Secrets (Avoiding AZURE_CLIENT_SECRET)

Nabil Kemerchou 0 Points de réputation
2025-04-23T15:07:31.2433333+00:00

Hello Microsoft Community,

I am developing a Python application that needs to authenticate with the Azure OpenAI Service to make API calls (for chat completions or embeddings).

Currently, the common approach I've seen involves setting up an Azure AD App Registration and using the following environment variables for authentication, likely via the azure-identity library:

AZURE_TENANT_ID

AZURE_CLIENT_ID

AZURE_CLIENT_SECRET

My concern is with the AZURE_CLIENT_SECRET. These secrets have an expiration date, requiring manual rotation. This process is less Secure

My Goal:

I want to implement a robust and secure authentication method for my Python application to connect to Azure OpenAI Service that avoids the need to manage and rotate client secrets (AZURE_CLIENT_SECRET).

My Questions:

  1. What are the recommended, production-ready alternatives to using client secrets for authenticating a Python application to Azure OpenAI?
  2. Managed Identity: If my application runs on a supported Azure service (like App Service, VMs, AKS), how can I configure and use a System-Assigned or User-Assigned Managed Identity for authentication? What specific Python azure-identity credential types should be used, and how does the openai library integrate with this?
  3. Client Certificates: Is using client certificates instead of secrets a viable and recommended alternative? What are the pros and cons regarding management and rotation compared to secrets?
  • Are there specific code examples or best practices within the Python azure-identity and openai SDKs for implementing these secretless authentication flows?

I appreciate any guidance, best practices, or code examples the community can provide to help implement a secure, secretless authentication flow.

Thank you!

Azure
Azure
Plateforme et infrastructure de cloud computing pour la génération, le déploiement et la gestion d’applications et de services à travers un réseau mondial de centres de données gérés par Microsoft.
495 questions
{count} votes

Votre réponse

Les réponses peuvent être marquées comme Réponses acceptées par l’auteur de la question, ce qui permet aux utilisateurs de connaître la réponse qui a résolu le problème de l’auteur.