fix: Replace DefaultAzureCredential with ManagedIdentityCredential for production-safe authentication #1871
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 refactor to replace the usage of
DefaultAzureCredential
with a new helper functionget_azure_credential
, which dynamically selects the appropriate credential type based on the application environment (APP_ENV
). Additionally, it includes minor fixes and adjustments to environment variable names. Below are the most important changes grouped by theme:Credential Refactor:
code/backend/batch/utilities/helpers/azure_credential_utils.py
: Added theget_azure_credential
andget_azure_credential_async
functions to dynamically select betweenDefaultAzureCredential
andManagedIdentityCredential
based on the environment (APP_ENV
).DefaultAzureCredential
withget_azure_credential
for consistent credential handling:database_factory.py
[1] [2]postgresdbservice.py
[1] [2]azure_blob_storage_client.py
[1] [2] [3]azure_computer_vision_client.py
[1] [2]azure_form_recognizer_helper.py
[1] [2]azure_postgres_helper.py
[1] [2]azure_search_helper.py
[1] [2] [3] [4]env_helper.py
[1] [2] [3]llm_helper.py
[1] [2]azure_search_datasource.py
[1] [2]azure_search_index.py
[1] [2]azure_search_indexer.py
[1] [2]Environment Variable Updates:
.env.sample
: AddedAPP_ENV
to specify the application environment (e.g.,dev
,prod
) for dynamic credential selection.env_helper.py
: Corrected a typo in the environment variable name fromSEMENTIC_KERNEL_SYSTEM_PROMPT
toSEMANTIC_KERNEL_SYSTEM_PROMPT
.These changes improve the flexibility and maintainability of credential management across the codebase while ensuring consistency in environment variable usage.
Does this introduce a breaking change?
How to Test
What to Check
Verify that the following are valid: