Skip to content

chore: Dev to Main - #686

Open
PadhiAjit-Microsoft wants to merge 5 commits into
mainfrom
dev
Open

chore: Dev to Main#686
PadhiAjit-Microsoft wants to merge 5 commits into
mainfrom
dev

Conversation

@PadhiAjit-Microsoft

Copy link
Copy Markdown

Purpose

  • This pull request updates how Azure credentials are selected and used in both application code and tests, with a particular focus on differentiating behavior based on the APP_ENV environment variable. The main change is to ensure that in production, the code prefers user-assigned or system-assigned managed identities, and only falls back to AsyncDefaultAzureCredential in development. Additionally, the way credentials are retrieved in async functions has been adjusted, and tests have been updated to reflect the new logic.

Azure credential selection logic:

  • src/ContentProcessor/src/libs/utils/azure_credential_utils.py: Changed get_async_azure_credential() to check APP_ENV; in production, it now uses user-assigned or system-assigned managed identity, and only falls back to AsyncDefaultAzureCredential in other environments. Improved logging to clarify credential selection.

Async credential retrieval:

  • src/ContentProcessor/src/libs/utils/azure_credential_utils.py and src/ContentProcessor/src/libs/utils/credential_util.py: Updated get_async_bearer_token_provider() to call get_async_azure_credential() synchronously instead of awaiting it, reflecting that the credential function is no longer async. [1] [2]

Test updates:

Does this introduce a breaking change?

  • Yes
  • No

Golden Path Validation

  • I have tested the primary workflows (the "golden path") to ensure they function correctly without errors.

Deployment Validation

  • I have validated the deployment process successfully and all services are running as expected with this change.

What to Check

Verify that the following are valid

  • ...

Other Information

@github-actions

Copy link
Copy Markdown

Coverage

Coverage Report •
FileStmtsMissCoverMissing
libs/utils
   azure_credential_utils.py105694%196–198, 202–203, 206
TOTAL122516786% 

Tests Skipped Failures Errors Time
244 0 💤 0 ❌ 0 🔥 3.918s ⏱️

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request updates Azure credential selection for the ContentProcessor utilities, aiming to differentiate production vs. development behavior using APP_ENV, and aligns async token-provider creation and tests with the updated (non-async) credential factory.

Changes:

  • Updated async bearer token provider helpers to call get_async_azure_credential() synchronously (no await).
  • Modified get_async_azure_credential() to prefer managed identity when APP_ENV=prod, and fall back to AsyncDefaultAzureCredential otherwise, with updated logging.
  • Updated unit tests to set APP_ENV=dev and to patch the (now non-async) credential factory appropriately.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
src/ContentProcessor/src/libs/utils/azure_credential_utils.py Adjusts async credential selection logic based on APP_ENV and updates fallback/logging behavior.
src/ContentProcessor/src/libs/utils/credential_util.py Removes await when retrieving the async credential factory for token-provider creation.
src/tests/ContentProcessor/utils/test_azure_credential_utils.py Updates environment setup to set APP_ENV=dev to match new fallback behavior.
src/tests/ContentProcessor/utils/test_azure_credential_utils_extended.py Updates environment setup and mocking to match the non-async credential factory behavior.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +194 to +206
app_env = os.getenv("APP_ENV", "prod").lower()
if app_env == "prod":
client_id = os.getenv("AZURE_CLIENT_ID")
if client_id:
logging.info(
"[AUTH] APP_ENV=prod -> using async user-assigned managed identity: %s",
client_id,
)
return AsyncManagedIdentityCredential(client_id=client_id)
logging.info(
"[AUTH] APP_ENV=prod -> using async system-assigned managed identity"
)
return AsyncManagedIdentityCredential()
Comment on lines 109 to 111
for key in ["WEBSITE_SITE_NAME", "AZURE_CLIENT_ID", "MSI_ENDPOINT",
"IDENTITY_ENDPOINT", "KUBERNETES_SERVICE_HOST"]:
monkeypatch.delenv(key, raising=False)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants