fix: Replace DefaultAzureCredential with ManagedIdentityCredential for production-safe authentication #1876
      
        
          +316
        
        
          −132
        
        
          
        
      
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Purpose
This pull request introduces a significant refactor to replace the use of
DefaultAzureCredentialwith a new utility function,get_azure_credential, which selects the appropriate Azure credential based on the application environment (devorprod). Additionally, a new environment variableAPP_ENVhas been added to.env.sampleto support this functionality. Below are the key changes grouped by theme:Credential Management Refactor:
get_azure_credentialinazure_credential_utils.py, which dynamically selects betweenDefaultAzureCredentialandManagedIdentityCredentialbased on theAPP_ENVvariable.DefaultAzureCredentialacross multiple files to useget_azure_credential, ensuring consistent credential management. For example:database_factory.py: ReplacedDefaultAzureCredentialwithget_azure_credentialinget_conversation_client.azure_blob_storage_client.py: Updated credential initialization increate_queue_clientand the class constructor. [1] [2]azure_computer_vision_client.py: ReplacedDefaultAzureCredentialwithget_azure_credentialin token provider setup.Environment Variable Addition:
APP_ENVto.env.sampleto specify the application environment (e.g.,devorprod). This variable is used to determine the credential type inget_azure_credential.Bug Fix:
env_helper.pyby changingSEMENTIC_KERNEL_SYSTEM_PROMPTtoSEMANTIC_KERNEL_SYSTEM_PROMPT.Documentation and Comments:
get_azure_credentialinstead ofDefaultAzureCredential. For example, inenv_helper.py.This refactor improves the flexibility and security of credential management by dynamically adapting to different environments, while maintaining backward compatibility for existing functionality.
Does this introduce a breaking change?
How to Test
What to Check
Verify that the following are valid: