fix(tools): support regional Discovery Engine endpoints#4720
fix(tools): support regional Discovery Engine endpoints#4720kaligautier wants to merge 2 commits intogoogle:mainfrom
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the DiscoveryEngineSearchTool to correctly handle regional Google Cloud Discovery Engine endpoints. Previously, the tool exclusively used the global endpoint, leading to errors when interacting with resources in specific geographical regions. The changes introduce dynamic endpoint resolution based on resource IDs and ensure proper configuration of the SearchServiceClient, thereby improving the tool's robustness and usability across different Google Cloud regions. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
|
Response from ADK Triaging Agent Hello @kaligautier, thank you for your contribution! Before we can merge this PR, you'll need to sign the Contributor License Agreement (CLA). It seems like the CLA check has failed. You can find more information and sign the CLA at https://cla.developers.google.com/. Thanks! |
There was a problem hiding this comment.
Code Review
This pull request adds support for regional Discovery Engine endpoints by introducing a helper function, _build_client_options, to parse the location from the resource ID and construct the appropriate api_endpoint for the SearchServiceClient, while preserving an existing quota_project_id. While the implementation includes new unit tests, the parsing logic for the location uses a permissive regular expression that is vulnerable to Server-Side Request Forgery (SSRF), potentially allowing an attacker to redirect API requests and steal Google Cloud credentials. It is recommended to tighten the regular expression to only allow valid location characters to address this security concern.
d3d01f7 to
6582365
Compare
6582365 to
84e5c57
Compare
|
@llalitkumarrr si working |
Link to Issue or Description of Change
1. Link to an existing issue (if applicable):
2. Or, if no issue exists, describe the change:
Problem:
DiscoveryEngineSearchToolwas always initialized with the default globalendpoint. This caused 400 errors for non-global data stores/search engines
(
eu,us,europe-west1, etc.).Additionally, location extraction from the resource id was too permissive.
Malformed values could be used to construct an unsafe
api_endpoint.Solution:
globalkeeps default endpoint,regional locations use
<location>-discoveryengine.googleapis.com).locationinput toDiscoveryEngineSearchToolso callers canexplicitly set
global,us,eu, etc.locationoptional: when not provided, infer fromdata_store_id/search_engine_id, then fallback toglobal.locationis provided and resource id contains alocation, both must match.
(
[a-z0-9-]) for both explicit and inferred locations.ValueError.quota_project_idinClientOptions.Testing Plan
Unit Tests:
Summary of passed
pytestresults:.venv/bin/pytest tests/unittests/tools/test_discovery_engine_search_tool.py -q .................. [100%] 18 passed in 1.75sManual End-to-End (E2E) Tests:
Manual local verification was run by instantiating the tool with representative
resource IDs and checking the endpoint passed to
SearchServiceClient:Invalid input verification (local):
location="attacker.com#"raisesValueError.locations/attacker.com#raisesValueError.Checklist
Additional context
This PR now contains a single squashed commit.