Skip to content

resolver: add ValidateTargetURI for target URI validation - #9247

Open
hugehoo wants to merge 7 commits into
grpc:masterfrom
hugehoo:feat/validate-target-uri-8747
Open

resolver: add ValidateTargetURI for target URI validation#9247
hugehoo wants to merge 7 commits into
grpc:masterfrom
hugehoo:feat/validate-target-uri-8747

Conversation

@hugehoo

@hugehoo hugehoo commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Changes

  • add validation utility for target(grpc server) URI.
  • considered:
    • it parses as an RFC 3986 URI via net/url.Parse, and
    • its scheme has a resolver builder registered in the global resolver registry (resolver.Get).

Scope

  • PR intentionally contains only the utility and its unit tests.
  • Adoption in xDS bootstrap and other configuration-parsing paths will follow in separate PRs.

Testing

  • Table-driven tests cover:
    • Registered scheme, both authority form (scheme:///endpoint) and opaque form (scheme:endpoint)
    • Uppercase input for a registered scheme. url.Parse canonicalizes the scheme to lowercase per RFC 3986 §3.1, so the case difference does not surface at the registry lookup; the test pins this behavior.
    • Empty target.
    • host:port without a scheme, which is parsed as an unregistered scheme and so the common misconfiguration surfaces cleanly.
    • Unregistered scheme.
    • Unparseable input.

RELEASE NOTES: none

@codecov

codecov Bot commented Jul 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.26%. Comparing base (7d87045) to head (83f750a).
⚠️ Report is 39 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #9247      +/-   ##
==========================================
- Coverage   83.27%   83.26%   -0.01%     
==========================================
  Files         421      422       +1     
  Lines       34084    34096      +12     
==========================================
+ Hits        28382    28390       +8     
- Misses       4273     4274       +1     
- Partials     1429     1432       +3     
Files with missing lines Coverage Δ
balancer/rls/config.go 86.36% <100.00%> (+0.75%) ⬆️
internal/resolver/target.go 100.00% <100.00%> (ø)
internal/xds/bootstrap/bootstrap.go 64.15% <100.00%> (+0.21%) ⬆️

... and 24 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@hugehoo hugehoo changed the title grpcutil: add ValidateTargetURI for target URI validation resolver: add ValidateTargetURI for target URI validation Jul 17, 2026
@easwars easwars added the Type: Internal Cleanup Refactors, etc label Jul 17, 2026
@easwars easwars added this to the 1.84 Release milestone Jul 17, 2026
@easwars

easwars commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

@hugehoo : Could you please also update the callsites that you plan to change to use this helper. I think we got stuck the last time around when we got to that part. So, I don't want to add a utility without changing the callsites and knowing for sure that we have exactly what we need. Thanks for understanding.

@hugehoo

hugehoo commented Jul 18, 2026

Copy link
Copy Markdown
Contributor Author

@easwars thanks for review!

I've updated the callsites to use this helper, along with their tests:

  • balancer/rls/config.go: replaced the inline lookup_service validation with the helper.
  • internal/xds/bootstrap: ServerConfig.UnmarshalJSON now validates server_uri.

The helper now applies the default-scheme fallback for targets that don't parse as authority-form URIs, while still rejecting authority-form URIs (scheme://...) with an unregistered scheme, so scheme typos in configuration surface as errors.
This accepts existing host:port-style bootstrap configs and preserves RLS's existing rejection of targets like badScheme:///target.

"xds_servers": [
{
"server_uri": "ipv4:///127.0.0.1:443",
"server_uri": "passthrough:///127.0.0.1:443",

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

updated scheme to passthrough from ipv4 as server_uri validation added.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants