fix: Replace DefaultAzureCredential with ManagedIdentityCredential for production-safe authentication#1871
Closed
Prasanjeet-Microsoft wants to merge 3 commits intoAzure-Samples:devfrom
Closed
Conversation
…ply with CodeQL security guidelines
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
DefaultAzureCredentialwith 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_credentialandget_azure_credential_asyncfunctions to dynamically select betweenDefaultAzureCredentialandManagedIdentityCredentialbased on the environment (APP_ENV).DefaultAzureCredentialwithget_azure_credentialfor 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_ENVto 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_PROMPTtoSEMANTIC_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: