Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

grpc: optional interface to provide channel authority #6752

Merged
merged 6 commits into from Dec 5, 2023

Conversation

Aditya-Sood
Copy link
Contributor

@Aditya-Sood Aditya-Sood commented Oct 27, 2023

Also implements the same for unix resolver's builder

Fixes #5360

RELEASE NOTES:

  • resolver: provide method for resolver to implement to override default channel authority (EXPERIMENTAL).

Also implements the same for unix resolver's builder
@codecov
Copy link

codecov bot commented Oct 27, 2023

Codecov Report

Merging #6752 (1dd2231) into master (b046cca) will increase coverage by 0.12%.
Report is 39 commits behind head on master.
The diff coverage is 100.00%.

❗ Current head 1dd2231 differs from pull request most recent head fb65458. Consider uploading reports for the commit fb65458 to get more accurate results

Additional details and impacted files

@Aditya-Sood
Copy link
Contributor Author

hi @dfawley, I have a couple queries:

  1. I changed the name of the interface method to GetServiceAuthority() to keep the same name as the java method - is that fine?

  2. The java method also places a couple more requirements on the implementation:

It must be from a trusted source, because if the authority is tampered with, RPCs may be sent to the attackers which may leak sensitive user data.
An implementation must generate it without blocking, typically in line, and must keep it unchanged. NameResolvers created from the same factory with the same argument must return the same authority.

Should we mention the same in our comments?

  1. Regarding your comment about "escapeAuthority", I checked the java codebase and it seems to expect the percent-encoding from the name resolver like you mentioned (link to file):
assertThat(resolver.getServiceAuthority()).isEqualTo("path%2Fto%2Fservice");

I guess we could add a line in the comments for GetServiceAuthority() asking users to do the encoding as part of their concrete method (for the sake of conforming to existing implementations), and add a check at the time of assigning the value to cc.authority for our verification?

@ginayeh ginayeh requested a review from dfawley October 31, 2023 16:20
@ginayeh ginayeh added P2 Type: Feature New features or improvements in behavior and removed P2 Hacktoberfest labels Oct 31, 2023
@ginayeh ginayeh added this to the 1.60 Release milestone Oct 31, 2023
Copy link
Member

@dfawley dfawley left a comment

Choose a reason for hiding this comment

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

Thank you for the PR! A few comments inline...

clientconn.go Outdated
// return channel authority.
cc.authority = "localhost"
case isAuthOverrider:
cc.authority = auth.GetServiceAuthority(cc.parsedTarget)
case strings.HasPrefix(endpoint, ":"):
cc.authority = "localhost" + endpoint
default:
Copy link
Member

Choose a reason for hiding this comment

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

Please delete the TODO below.

clientconn.go Outdated
@@ -1981,16 +1981,14 @@ func (cc *ClientConn) determineAuthority() error {
}

endpoint := cc.parsedTarget.Endpoint()
target := cc.target
auth, isAuthOverrider := any(cc.resolverBuilder).(resolver.AuthorityOverrider)
Copy link
Member

Choose a reason for hiding this comment

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

Why cast it to any first? That shouldn't be needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

my bad, cc.resolverBuilder is already an interface type
thanks

type AuthorityOverrider interface {
// GetServiceAuthority returns the authority to use for a ClientConn with the
// given target. It must not perform I/O or any other blocking operations.
GetServiceAuthority(t Target) string
Copy link
Member

Choose a reason for hiding this comment

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

Go style generally doesn't like GetXYZ. OverrideAuthority makes more sense given the name of the interface; otherwise AuthorityForTarget or something like that could be okay.

type AuthorityOverrider interface {
// GetServiceAuthority returns the authority to use for a ClientConn with the
// given target. It must not perform I/O or any other blocking operations.
GetServiceAuthority(t Target) string
Copy link
Member

Choose a reason for hiding this comment

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

Please name the parameter target to be explicit, or don't name it at all, as t doesn't really add documentation value here, and it's not necessary to name.

clientconn.go Outdated
@@ -1981,16 +1981,14 @@ func (cc *ClientConn) determineAuthority() error {
}

endpoint := cc.parsedTarget.Endpoint()
target := cc.target
auth, isAuthOverrider := any(cc.resolverBuilder).(resolver.AuthorityOverrider)
switch {
Copy link
Member

Choose a reason for hiding this comment

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

Optional: maybe just convert this into a few ifs and do the auth overrider as a compound if.

@Aditya-Sood
Copy link
Contributor Author

@dfawley thank you for the review, I have pushed the review changes to the PR
could you also weigh-in on points (2) and (3) in #6752 (comment) and let me know if any further work is required?

Copy link

This PR is labeled as requiring an update from the reporter, and no update has been received after 6 days. If no update is provided in the next 7 days, this issue will be automatically closed.

clientconn.go Outdated
case isAuthOverrider:
cc.authority = auth.GetServiceAuthority(cc.parsedTarget)
case strings.HasPrefix(endpoint, ":"):
} else if auth, isAuthOverrider := cc.resolverBuilder.(resolver.AuthorityOverrider); isAuthOverrider {
Copy link
Member

Choose a reason for hiding this comment

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

Go style: please name this ok instead of isAuthOverrider.

@@ -61,6 +61,10 @@ func (b *builder) Scheme() string {
return b.scheme
}

func (b *builder) OverrideAuthority(t resolver.Target) string {
Copy link
Member

Choose a reason for hiding this comment

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

Since t is unused, you can omit it entirely here.

@dfawley dfawley assigned arvindbr8 and unassigned Aditya-Sood Nov 14, 2023
@dfawley
Copy link
Member

dfawley commented Nov 14, 2023

+@arvindbr8 for a second pass

@arvindbr8 arvindbr8 added this to the 1.61 Release milestone Nov 14, 2023
Copy link

This PR is labeled as requiring an update from the reporter, and no update has been received after 6 days. If no update is provided in the next 7 days, this issue will be automatically closed.

@github-actions github-actions bot added the stale label Nov 22, 2023
@Aditya-Sood
Copy link
Contributor Author

hi @arvindbr8, could you please review the PR and remove the reporter clarification status?

resolver/resolver.go Outdated Show resolved Hide resolved
resolver/resolver.go Outdated Show resolved Hide resolved
clientconn.go Outdated Show resolved Hide resolved
@dfawley dfawley removed their assignment Dec 4, 2023
@easwars easwars merged commit 0866ce0 into grpc:master Dec 5, 2023
12 checks passed
@easwars
Copy link
Contributor

easwars commented Dec 5, 2023

@Aditya-Sood : Thank you for your contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Feature New features or improvements in behavior
Projects
None yet
Development

Successfully merging this pull request may close these issues.

grpc: add optional interface to return channel authority
5 participants