fix: Replace DefaultAzureCredential with ManagedIdentityCredential for production-safe authentication #1872
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 usage of
DefaultAzureCredentialwith a custom utility functionget_azure_credentialacross the codebase. It also adds a new environment variableAPP_ENVto differentiate between development and production environments. The most important changes are grouped below by theme.Credential Management Refactor:
get_azure_credentialandget_azure_credential_asyncinazure_credential_utils.pyto dynamically select betweenDefaultAzureCredentialandManagedIdentityCredentialbased on theAPP_ENVenvironment variable ([code/backend/batch/utilities/helpers/azure_credential_utils.pyR1-R48](https://github.com/Azure-Samples/chat-with-your-data-solution-accelerator/pull/1872/files#diff-7da5073cced326c7dced13c0768484d67ae146b74dd907b44ebc20eb78bb9a7bR1-R48)).DefaultAzureCredentialwithget_azure_credentialin multiple files, includingdatabase_factory.py,postgresdbservice.py,azure_blob_storage_client.py,azure_computer_vision_client.py,azure_form_recognizer_helper.py,azure_postgres_helper.py,azure_search_helper.py,env_helper.py,llm_helper.py,azure_search_datasource.py,azure_search_index.py, andazure_search_indexer.py([[1]](https://github.com/Azure-Samples/chat-with-your-data-solution-accelerator/pull/1872/files#diff-a92ad8584f19aec266f80fe1d5decb9f8603008378f3c9c9cca31dc1401b3e29L5-R5),[[2]](https://github.com/Azure-Samples/chat-with-your-data-solution-accelerator/pull/1872/files#diff-a92ad8584f19aec266f80fe1d5decb9f8603008378f3c9c9cca31dc1401b3e29L28-R28),[[3]](https://github.com/Azure-Samples/chat-with-your-data-solution-accelerator/pull/1872/files#diff-e7dfe35613384cb3374f9b90a8ec2f7effb9e3f09f6c693636cce07fa4904987L4-R4),[[4]](https://github.com/Azure-Samples/chat-with-your-data-solution-accelerator/pull/1872/files#diff-e7dfe35613384cb3374f9b90a8ec2f7effb9e3f09f6c693636cce07fa4904987L24-R24),[[5]](https://github.com/Azure-Samples/chat-with-your-data-solution-accelerator/pull/1872/files#diff-0501618008f86eacf193f09a72a1f5ec7bf348b4b19e5c937657d62e039a75f3L15-R15),[[6]](https://github.com/Azure-Samples/chat-with-your-data-solution-accelerator/pull/1872/files#diff-0501618008f86eacf193f09a72a1f5ec7bf348b4b19e5c937657d62e039a75f3L28-R28),[[7]](https://github.com/Azure-Samples/chat-with-your-data-solution-accelerator/pull/1872/files#diff-0501618008f86eacf193f09a72a1f5ec7bf348b4b19e5c937657d62e039a75f3L59-R59),[[8]](https://github.com/Azure-Samples/chat-with-your-data-solution-accelerator/pull/1872/files#diff-b228a7a21f60cbc2f450086e1f8b430ab70df4579c1dae4c91dcc9d60477804fL3-R4),[[9]](https://github.com/Azure-Samples/chat-with-your-data-solution-accelerator/pull/1872/files#diff-b228a7a21f60cbc2f450086e1f8b430ab70df4579c1dae4c91dcc9d60477804fL59-R60),[[10]](https://github.com/Azure-Samples/chat-with-your-data-solution-accelerator/pull/1872/files#diff-c2f405722abb3fba86580c300caa1b9e14ea410594b11765a470cdbb703f5011L4-R4),[[11]](https://github.com/Azure-Samples/chat-with-your-data-solution-accelerator/pull/1872/files#diff-c2f405722abb3fba86580c300caa1b9e14ea410594b11765a470cdbb703f5011L22-R22),[[12]](https://github.com/Azure-Samples/chat-with-your-data-solution-accelerator/pull/1872/files#diff-50e3408b3f05e1cdccee7e3d8138209baebda958477121fe6a7e7c8289b89060L4-R4),[[13]](https://github.com/Azure-Samples/chat-with-your-data-solution-accelerator/pull/1872/files#diff-50e3408b3f05e1cdccee7e3d8138209baebda958477121fe6a7e7c8289b89060L27-R27),[[14]](https://github.com/Azure-Samples/chat-with-your-data-solution-accelerator/pull/1872/files#diff-8acbb6b44f9a1c4104fd339b585d57d8d628f8ceace3ccc6db9266b23c3106a7L5-R5),[[15]](https://github.com/Azure-Samples/chat-with-your-data-solution-accelerator/pull/1872/files#diff-8acbb6b44f9a1c4104fd339b585d57d8d628f8ceace3ccc6db9266b23c3106a7L52-R55),[[16]](https://github.com/Azure-Samples/chat-with-your-data-solution-accelerator/pull/1872/files#diff-8acbb6b44f9a1c4104fd339b585d57d8d628f8ceace3ccc6db9266b23c3106a7L64-R64),[[17]](https://github.com/Azure-Samples/chat-with-your-data-solution-accelerator/pull/1872/files#diff-8acbb6b44f9a1c4104fd339b585d57d8d628f8ceace3ccc6db9266b23c3106a7L288-R288),[[18]](https://github.com/Azure-Samples/chat-with-your-data-solution-accelerator/pull/1872/files#diff-7503275e90a545dba3519622ff9d0866a73e814ddbfbb61156137721bf2a6552L6-R7),[[19]](https://github.com/Azure-Samples/chat-with-your-data-solution-accelerator/pull/1872/files#diff-7503275e90a545dba3519622ff9d0866a73e814ddbfbb61156137721bf2a6552L219-R220),[[20]](https://github.com/Azure-Samples/chat-with-your-data-solution-accelerator/pull/1872/files#diff-7503275e90a545dba3519622ff9d0866a73e814ddbfbb61156137721bf2a6552L419-R420),[[21]](https://github.com/Azure-Samples/chat-with-your-data-solution-accelerator/pull/1872/files#diff-7503275e90a545dba3519622ff9d0866a73e814ddbfbb61156137721bf2a6552L431-R432),[[22]](https://github.com/Azure-Samples/chat-with-your-data-solution-accelerator/pull/1872/files#diff-43896759bad4bc2119807845cbb205a535d9caec19b671e07dcb6cfe73ec421aL11-R11),[[23]](https://github.com/Azure-Samples/chat-with-your-data-solution-accelerator/pull/1872/files#diff-43896759bad4bc2119807845cbb205a535d9caec19b671e07dcb6cfe73ec421aL169-R169),[[24]](https://github.com/Azure-Samples/chat-with-your-data-solution-accelerator/pull/1872/files#diff-191306cd0087ff3adec6be22022a25f09ad71cd8596aebb0050de612ec0b091eL10-R10),[[25]](https://github.com/Azure-Samples/chat-with-your-data-solution-accelerator/pull/1872/files#diff-191306cd0087ff3adec6be22022a25f09ad71cd8596aebb0050de612ec0b091eL22-R22),[[26]](https://github.com/Azure-Samples/chat-with-your-data-solution-accelerator/pull/1872/files#diff-9110c8709dac7271099ab02556bef8c9a110c6413badfff59eb0119c570d91a7L24-R24),[[27]](https://github.com/Azure-Samples/chat-with-your-data-solution-accelerator/pull/1872/files#diff-9110c8709dac7271099ab02556bef8c9a110c6413badfff59eb0119c570d91a7L42-R42),[[28]](https://github.com/Azure-Samples/chat-with-your-data-solution-accelerator/pull/1872/files#diff-5a2966c08715e2d467100ebf3b4a58b5fc3a34159aee19f22c0341d50a929dfcL5-R5)).Environment Configuration:
APP_ENVvariable to.env.sampleto specify the application environment (e.g.,devorprod) ([.env.sampleR66-R67](https://github.com/Azure-Samples/chat-with-your-data-solution-accelerator/pull/1872/files#diff-088d9f35d23a4347d221d71dd49b02b95001dff4abe637a40fe0bc04d502049cR66-R67)).Bug Fix:
SEMENTIC_KERNEL_SYSTEM_PROMPTtoSEMANTIC_KERNEL_SYSTEM_PROMPTinenv_helper.py([code/backend/batch/utilities/helpers/env_helper.pyL364-R366](https://github.com/Azure-Samples/chat-with-your-data-solution-accelerator/pull/1872/files#diff-7503275e90a545dba3519622ff9d0866a73e814ddbfbb61156137721bf2a6552L364-R366)).These changes improve the flexibility of credential management by supporting both development and production environments while maintaining security best practices.
Does this introduce a breaking change?
How to Test
What to Check
Verify that the following are valid: