chore: dev to main merge - #908
Open
Ragini-Microsoft wants to merge 4 commits into
Open
Conversation
fix: fixed 'DefaultCredential' CodeQL issues.
Contributor
Coverage Report •
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request standardizes Azure credential selection across backend services and the image content agent by switching between DefaultAzureCredential and ManagedIdentityCredential based on APP_ENV, and updates tests/fixtures to make the environment-driven behavior explicit and deterministic.
Changes:
- Updated credential selection in backend services and
image_content_agentto useDefaultAzureCredentialwhenAPP_ENV=dev, otherwiseManagedIdentityCredential. - Added
APP_ENVdefaults in the test environment fixture and patchedAPP_ENVper-test for dev/prod credential-path coverage. - Tightened assertions in tests to ensure
DefaultAzureCredential()is called with no arguments.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/backend/agents/image_content_agent.py | Switches OpenAI auth to environment-based credential selection for both image-generation paths. |
| src/backend/services/blob_service.py | Switches Blob Storage auth to environment-based credential selection. |
| src/backend/services/cosmos_service.py | Switches Cosmos DB auth to environment-based credential selection. |
| src/tests/agents/test_image_content_agent.py | Forces APP_ENV in the managed-identity test to validate the prod path. |
| src/tests/services/test_blob_service.py | Forces APP_ENV per test and asserts DefaultAzureCredential() is called without args. |
| src/tests/services/test_cosmos_service.py | Forces APP_ENV per test and asserts DefaultAzureCredential() is called without args. |
| src/tests/conftest.py | Sets APP_ENV=dev by default for tests (with per-test overrides for prod paths). |
Suppressed comments (1)
src/backend/agents/image_content_agent.py:329
- This prod path always constructs
ManagedIdentityCredential(client_id=app_settings.base_settings.azure_client_id), butazure_client_idis optional (settings.py:466). PassingNoneexplicitly can be rejected by the SDK and makes it harder to use system-assigned managed identity. Consider only passingclient_idwhen it’s set, otherwise callManagedIdentityCredential()with no args (and add a test for prod with no client id if supported).
app_env = os.environ.get("APP_ENV", "prod").lower()
if app_env == "dev":
credential = DefaultAzureCredential()
else:
credential = ManagedIdentityCredential(
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
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 updates how Azure credentials are selected throughout the backend and improves related test coverage. The main change is to consistently choose between
DefaultAzureCredentialandManagedIdentityCredentialbased on theAPP_ENVenvironment variable, simplifying local development and production authentication logic. Corresponding tests are updated to explicitly setAPP_ENVto ensure correct credential selection.Credential selection logic improvements:
image_content_agent.py,blob_service.py, andcosmos_service.pyto useDefaultAzureCredentialwhenAPP_ENVis"dev", andManagedIdentityCredentialotherwise. This standardizes authentication logic across services. [1] [2] [3] [4]osimports where needed to support environment variable access. [1] [2] [3]Test improvements:
image_content_agent,blob_service, andcosmos_serviceto patchos.environ["APP_ENV"]as"dev"or"prod"to explicitly test both credential paths. [1] [2] [3] [4] [5]DefaultAzureCredentialis called without arguments. [1] [2]APP_ENVto"dev"by default in themock_environmenttest fixture for local authentication, with managed-identity tests overriding as needed.Does this introduce a breaking change?
Golden Path Validation
Deployment Validation