feat: replacing DefaultAzureCredential with ManagedIdentityCredential #524
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 several changes aimed at improving the handling of Azure credentials, adding environment-specific configurations, and addressing security concerns flagged by CodeQL. The most significant updates include introducing helper functions for Azure credential management, replacing direct usage of
DefaultAzureCredentialwith these helpers, and adding a new environment variable to differentiate between development and production environments.Azure Credential Management Enhancements:
get_azure_credentialandget_azure_credential_asyncinsrc/backend/helpers/azure_credential_utils.pyto dynamically select credentials based on theAPP_ENVenvironment variable. These functions useDefaultAzureCredentialin development andManagedIdentityCredentialin production.DefaultAzureCredentialwith calls to the new helper functions across multiple files, includingsrc/app.py,src/backend/api/agent/browse_agent_factory.py,src/backend/api/agent/section_agent_factory.py, andsrc/backend/api/agent/template_agent_factory.py. [1] [2] [3] [4] [5] [6]Environment-Specific Configuration:
APP_ENVwith a value ofProdin the Azure App Service configuration ininfra/deploy_app_service.bicepandinfra/main.json. This variable is used to determine the application environment (development or production). [1] [2]Security and CodeQL Compliance:
DefaultAzureCredentialusage with CodeQL comments to clarify that its usage is limited to local or development environments, addressing potential security concerns. Changes were made in several scripts, includinginfra/scripts/index_scripts/01_create_search_index.py,infra/scripts/index_scripts/02_process_data.py,scripts/chunk_documents.py, andscripts/embed_documents.py. [1] [2] [3] [4] [5] [6]These changes improve the maintainability, security, and configurability of the codebase, particularly in environments where Azure credentials are used.
Does this introduce a breaking change?
Golden Path Validation
Deployment Validation
What to Check
Verify that the following are valid