fix: Replace DefaultAzureCredential with ManagedIdentityCredential for production-safe authentication #1876
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
DefaultAzureCredential
with a new utility function,get_azure_credential
, which selects the appropriate Azure credential based on the application environment (dev
orprod
). Additionally, a new environment variableAPP_ENV
has been added to.env.sample
to support this functionality. Below are the key changes grouped by theme:Credential Management Refactor:
get_azure_credential
inazure_credential_utils.py
, which dynamically selects betweenDefaultAzureCredential
andManagedIdentityCredential
based on theAPP_ENV
variable.DefaultAzureCredential
across multiple files to useget_azure_credential
, ensuring consistent credential management. For example:database_factory.py
: ReplacedDefaultAzureCredential
withget_azure_credential
inget_conversation_client
.azure_blob_storage_client.py
: Updated credential initialization increate_queue_client
and the class constructor. [1] [2]azure_computer_vision_client.py
: ReplacedDefaultAzureCredential
withget_azure_credential
in token provider setup.Environment Variable Addition:
APP_ENV
to.env.sample
to specify the application environment (e.g.,dev
orprod
). This variable is used to determine the credential type inget_azure_credential
.Bug Fix:
env_helper.py
by changingSEMENTIC_KERNEL_SYSTEM_PROMPT
toSEMANTIC_KERNEL_SYSTEM_PROMPT
.Documentation and Comments:
get_azure_credential
instead 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: