Python: forward Azure AI Search query-source identity - #6915
Python: forward Azure AI Search query-source identity#6915Karunanidhi Mishra (kmishra1204) wants to merge 6 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
Adds an opt-in way for Python agentic Azure AI Search retrieval to forward a caller’s query-time identity (Entra token) to Knowledge Base retrieval requests, enabling document-level permission trimming scenarios without changing existing API key/managed identity defaults.
Changes:
- Added an optional
query_source_credentialparameter toAzureAISearchContextProviderand forwarded its token toKnowledgeBaseRetrievalClient.retrieve(...)viax_ms_query_source_authorization. - Documented query-time identity forwarding in the package README.
- Added regression tests covering both default behavior (no header) and forwarding behavior (header present + correct scope).
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| python/packages/azure-ai-search/agent_framework_azure_ai_search/_context_provider.py | Adds query_source_credential, obtains the Search scope token, and forwards it on agentic retrieval calls. |
| python/packages/azure-ai-search/tests/test_aisearch_context_provider.py | Adds assertions and a new test verifying the authorization header forwarding behavior. |
| python/packages/azure-ai-search/README.md | Documents the query-time user identity option and shows how to pass query_source_credential. |
|
Updated in bd48f59 to address the async credential feedback: the docs now say query_source_credential must be an async Azure credential, _query_source_authorization() raises a clear TypeError if a sync credential is passed, and there is regression coverage for that misuse case. |
Python Test Coverage Report •
Python Unit Test Overview
|
||||||||||||||||||||||||||||||
Evan Mattson (moonbox3)
left a comment
There was a problem hiding this comment.
Please also have a look at the failing CI/CD (code quality) checks.
5e049aa to
0d860aa
Compare
|
Thanks for the CI note. I rebased this branch on current What changed:
Validation run locally:
I also ran |
0d860aa to
38b5ac4
Compare
|
Rebased this branch onto current upstream Current head: Validation rerun locally:
Results:
Live status after push: code checks have no failures. The remaining visible gates are the merge gatekeeper still in progress and the queued |
|
Updated in Change made:
Validation rerun:
|
|
Also removed the manual Current review-response commits:
Validation after the latest push:
I resolved the two review threads that these commits address. |
|
Karunanidhi Mishra (@kmishra1204) please accept the CLA |
|
Karunanidhi Mishra (@kmishra1204) ping to accept the CLA please |
|
We appreciate your work on this. We need to get this fix in, so superseded by #7278. |
Summary
query_source_credentialtoAzureAISearchContextProviderThis addresses the Python side of #6864. The option is explicit so existing API key and managed identity flows keep their current behavior unless a caller supplies an async query-source credential.
Validation
uv run --project python --dev --no-sync pytest -q python/packages/azure-ai-search/tests/test_aisearch_context_provider.py::TestAgenticSearch::test_minimal_reasoning_returns_results python/packages/azure-ai-search/tests/test_aisearch_context_provider.py::TestAgenticSearch::test_query_source_credential_forwards_authorization_token python/packages/azure-ai-search/tests/test_aisearch_context_provider.py::TestAgenticSearch::test_query_source_credential_requires_async_credentialuv run --project python --dev --no-sync ruff check python/packages/azure-ai-search/agent_framework_azure_ai_search/_context_provider.py python/packages/azure-ai-search/tests/test_aisearch_context_provider.pyuv run --project python --dev --no-sync pyright python/packages/azure-ai-search/agent_framework_azure_ai_search/_context_provider.pygit diff --check -- python/CHANGELOG.md python/packages/azure-ai-search/README.md python/packages/azure-ai-search/agent_framework_azure_ai_search/_context_provider.py python/packages/azure-ai-search/tests/test_aisearch_context_provider.py