Skip to content

xds/rbac: add additional handling for addresses with ports#8990

Merged
mbissa merged 2 commits intogrpc:masterfrom
mbissa:xds-rbac-handle-ipaddress-port
Mar 26, 2026
Merged

xds/rbac: add additional handling for addresses with ports#8990
mbissa merged 2 commits intogrpc:masterfrom
mbissa:xds-rbac-handle-ipaddress-port

Conversation

@mbissa
Copy link
Copy Markdown
Contributor

@mbissa mbissa commented Mar 20, 2026

Fixes: #8913

This PR enhances the rbac matcher to handle IP address string with a port attached.

The fix introduces the net.SplitHostPort utility function, ensuring the port is properly stripped out of the underlying peerInfo.Addr.String() and localAddr.String() values before parsing them with netip.ParseAddr. A fallback mechanism is also included in case SplitHostPort fails due to a missing port.

RELEASE NOTES:

  • xds/rbac: handle addresses with ports in IP matchers.

@mbissa mbissa added this to the 1.80 Release milestone Mar 20, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 20, 2026

Codecov Report

❌ Patch coverage is 50.00000% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.93%. Comparing base (b6597b3) to head (8b2575b).
⚠️ Report is 33 commits behind head on master.

Files with missing lines Patch % Lines
internal/xds/rbac/matchers.go 50.00% 3 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #8990      +/-   ##
==========================================
- Coverage   83.42%   82.93%   -0.49%     
==========================================
  Files         410      411       +1     
  Lines       32572    32941     +369     
==========================================
+ Hits        27172    27319     +147     
- Misses       4030     4209     +179     
- Partials     1370     1413      +43     
Files with missing lines Coverage Δ
internal/xds/rbac/matchers.go 75.71% <50.00%> (-1.79%) ⬇️

... and 65 files with indirect coverage changes

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

@@ -344,7 +345,15 @@ func newRemoteIPMatcher(cidrRange *v3corepb.CidrRange) (*remoteIPMatcher, error)
}

func (sim *remoteIPMatcher) match(data *rpcData) bool {
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.

How big of a change would it be to make match return a (bool, error) to enable callers to handle parsing errors?

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.

There are 11 implementations and each implementation has on an average of 4-5 references. This would need thorough testing and effort. I suggest we merge this and do that as a follow up.

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.

Sounds good, can you file a buganizer issue for this?

Copy link
Copy Markdown
Contributor

@arjan-bal arjan-bal left a comment

Choose a reason for hiding this comment

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

Can you please update the unit tests to practice the more common case of IP:Port strings while keeping some coverage for the IP-only case?

func (a *addr) String() string { return a.ipAddress }

@@ -344,7 +345,15 @@ func newRemoteIPMatcher(cidrRange *v3corepb.CidrRange) (*remoteIPMatcher, error)
}

func (sim *remoteIPMatcher) match(data *rpcData) bool {
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.

Sounds good, can you file a buganizer issue for this?

@arjan-bal arjan-bal removed their assignment Mar 26, 2026
@mbissa
Copy link
Copy Markdown
Contributor Author

mbissa commented Mar 26, 2026

Can you please update the unit tests to practice the more common case of IP:Port strings while keeping some coverage for the IP-only case?

func (a *addr) String() string { return a.ipAddress }

done.

@mbissa mbissa assigned arjan-bal and unassigned mbissa Mar 26, 2026
@arjan-bal
Copy link
Copy Markdown
Contributor

/gemini review

gemini-code-assist[bot]

This comment was marked as resolved.

@grpc grpc deleted a comment from gemini-code-assist Bot Mar 26, 2026
@grpc grpc deleted a comment from gemini-code-assist Bot Mar 26, 2026
Copy link
Copy Markdown
Contributor

@arjan-bal arjan-bal left a comment

Choose a reason for hiding this comment

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

LGTM

@arjan-bal arjan-bal assigned mbissa and unassigned arjan-bal Mar 26, 2026
@mbissa mbissa merged commit f1d1ce5 into grpc:master Mar 26, 2026
14 checks passed
mbissa added a commit to mbissa/grpc-go that referenced this pull request Mar 27, 2026
This PR enhances the rbac matcher to handle IP address string with a
port attached.

The fix introduces the `net.SplitHostPort` utility function, ensuring
the port is properly stripped out of the underlying
`peerInfo.Addr.String()` and `localAddr.String()` values before parsing
them with `netip.ParseAddr`. A fallback mechanism is also included in
case `SplitHostPort` fails due to a missing port.

RELEASE NOTES:
* xds/rbac: Add additional handling for addresses with ports
mbissa added a commit that referenced this pull request Mar 27, 2026
…9022)

Original PR: #8990

Cherry pick commit
[f1d1ce5](f1d1ce5)
into v1.80.x
This PR enhances the rbac matcher to handle IP address string with a
port attached.

The fix introduces the `net.SplitHostPort` utility function, ensuring
the port is properly stripped out of the underlying
`peerInfo.Addr.String()` and `localAddr.String()` values before parsing
them with `netip.ParseAddr`. A fallback mechanism is also included in
case `SplitHostPort` fails due to a missing port.

RELEASE NOTES:
* xds/rbac: Add additional handling for addresses with ports
This was referenced Apr 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

xds/rbac: IP address matching doesn't handle ports

2 participants