-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
client: Add CallOption for setting authority; allow even without WithInsecure #3444
Comments
Note that it's actually possible for the name resolver to override the authority by setting the https://github.com/grpc/grpc-go/blob/master/clientconn.go#L1219 This means exposing The real authority is only passed outside gRPC in the The
What are you ultimately trying to accomplish by accessing the authority? |
We have use cases where |
What are you trying to do with authority in the interceptors? Is it just for logging or other purposes? |
Logging is certainly an important feature, but more generally we desire to customise the outgoing request based on the authority header, as it is used in authentication on the receiving end. After some discussions with colleagues, it became clear that |
Implementing an HTTP-level interceptor is not something we have plans or resources for at this time. It sounds like you may need a L7 proxy to do what you need, or possibly to reassess your design since this doesn't sound like anything we've heard requested before. |
This issue is labeled as requiring an update from the reporter, and no update has been received after 7 days. If no update is provided in the next 7 days, this issue will be automatically closed. |
I should be a little more concrete, since I think my abstract discussion was both a hard piviot and may have scared you off. We are not looking to implement custom HTTP primitives, just interact with H2 headers via For our use case we need:
This reverse proxy listens on |
This issue is labeled as requiring an update from the reporter, and no update has been received after 7 days. If no update is provided in the next 7 days, this issue will be automatically closed. |
I believe I have provided satisfactory clarification, but if not please let me know what more would be helpful. |
This doesn't sound right to me. The I think there are a few different options you have here:
Of the three, I believe the first is the most commonly-used approach. |
A cursory browse through our infrastructure indicates that most calls are insecure, because TLS is managed outside of the Go runtime. Is there a better way to set things up, so that grpc.Dial("proxy.net", grpc.WithAuthority("service.net"), grpc.WithInsecure()) We also serve non gRPC through this proxy, so there is a desire to constrain ourselves to HTTP primitives that can be implemented for both traffic types. This pattern of request hosts in the dns resolution/tls differing from the request body is a long standing pattern that has worked well for us. Is this an antipattern, disallowed, or bad practice in gRPC specifically for some reason that does not exist in HTTP? Or is it just the Go gRPC implementation that has issues? That being said, I will also comment on your options:
This option seems problematic/moot based on the external TLS termination described above. Can you elaborate on how this would change in that world?
I can confirm this will not work for our infrastructure.
As described above, this is a big departure from prior art. If there is a strong argument it is possible, but it feels like the tail wagging the dog in our infrastructure. Could this be configured for the whole |
Have you looked into using PerRPCCredentials? This would allow you to set custom headers for RPCs on the connection. You would need to initialize them per- |
Alright, it seems like It is also interesting that |
Re initialize |
Let us assume we have both: e.g. authentication and custom route tracing; does that change your answer? They would both like access to the actual service ( Part of my issue, I do not know how to do this canonically, but would like to keep within the bounds of the existing http interface that we have build internally. |
I believe this will not work. If you set If you want to set the authority header, you can continue using |
Sounds good, so a future release will add the ability to To confirm, is Also, for my metrics/logging ask, it seems like an interceptor is the best bet (correct me if I am wrong), so can we extract |
Whoops -- we'll just use this bug for that. |
Yes, in order to create the credential header, we need access to the value that is currently stored in the :authority pseudo header. I was citing your previous comment that this was an option:
I am game, but I thought all the
Can you confirm what the
|
This is way late in the conversation, but in Java, |
This assumes a per-channel authority; if we do support setting it per-call then that wouldn't be useful to us.
They are all implemented by exported types, so a type assertion can see the values. E.g. https://godoc.org/google.golang.org/grpc#FailFastCallOption
|
Actually, disregard my comment, this seems to be a poor choice of name, as per the javadoc, this is `grpc.ClientConn.Target: /**
* The authority of the destination this channel connects to. Typically this is in the format
* {@code host:port}.
*
* @since 1.0.0
*/ |
Alright, so you are suggesting creating a new exported type: type AuthorityOption string And using it like so: grpc.WithUnaryInterceptor(func(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn, invoke grpc.UnaryInvoker, opts ...grpc.CallOption) error {
for _, o := opts {
if a, ok := o.(AuthorityOption); ok {
fmt.Println(string(a))
}
}
return invoke(ctx, method, req, reply, cc, opts)
}),
Is this possible with gRPC today? I can ignore it for |
Yes, exactly (except we'd probably make it a struct to be like the other call option types).
None of our credentials set this value, but it is valid for credentials to indicate they only provide message integrity but not encryption, and |
|
Posting description of how to go about implementing this from #4717. We are going to have to kick this can down the road for the time being, but if someone wants to implement this, we will be happy to review.
|
Closing this in favor of #5361 which captures only the tasks required to support this call option. |
Use case(s) - what problem will this feature solve?
I would like to write a
grpc.XxxClientInterceptor
that is able to safely extract and interact with the authority header.Proposed Solution
Since this information is currently hidden inside
grpc.ClientConn
, and that struct is an input to thegrpc.XxxYyyInterceptor
types, it seems reasonable to add a method to extract it.Alternatives Considered
Func
Instead of a method, this could be implemented as a function, but does not read as well.
Field
Currently authority is immutable, thus thread safe. Exposing a field would be easier than a method, but would break both guarantees.
Parameter
Since both
grpc.XxxClientInterceptor
types areEXPERIMENTAL API
s, you could just expose the value directly as a parameter. This seems pretty heavy for something that is not always required, and it double embeds the value (authority
andcc.authority
), so more edge cases and failure modes need be tested.Additional Context
Authority is an h2 pseudo header set by
grpc.WithAuthority
. Thisgrpc.DialOption
binds the givenstring
togrpc.dialOptions.authority
, thengrpc.Dial
andgrpc.DialContext
bind againstgrpc.ClientConn.authority
when called.The text was updated successfully, but these errors were encountered: