-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Why does not gateway forward headers as-is? #311
Comments
Forwarding as-is would potentially mean collisions in the 'grpc-*' space. |
I would be open to reconsidering this but it would be a backwards incompatible change. Thoughts? |
@tmc , we are interested in this one, too. We have multi use-cases where we need headers to be forwarded to grpc server. Can this be added as a configuration so that users of this library can tell which Additional headers to forward. I can think of following options:
|
Here are our use-cases:
|
@tmc just curious why the forwarding of headers would be a backwards incompatible change? as for the collisions in the 'grpc-*' space, couldn't we just strip out all incoming grpc-* headers. that appears to be the same approach that google takes on gcp to prevent external requests appearing to look like they came from Google's own internal proxies. although i can appreciate a need for additional customizability, i curious whether a simpler pass-through (+ stripping headers with reserved prefixes) wouldn't suffice. |
@lucas-natraj we'd have to keep sending with the grpcgateway- prefix as we do now which while a bit messy is probably ok. I'm open to a diff that forwards headers more directly. |
perhaps i'm referring to something tangential but iirc the code seems to indicate 2 special prefixes. |
@lucas-natraj , I think you should use #336 . Then you will be able to send header as you wish, without gateway forcing you to change you header key. With that pr, you should initiate the Mux like below:
On the grpc side, you will find this is the Context metadata as "x-api-key". This is what we are doing for our api. |
@tamalsaha yeah i did see that, and i can totally see the usefulness of it. my comment was just questioning whether we could just allow custom headers directly (which appears to be the main issue at hand). seems like the only concern was that there would be collisions with an existing prefix. hence my suggestion to strip out any conflicting headers but still allow the ones that don't conflict. |
I think given there is already a special prefix (grpc-*), the best case may be to allow custom headers via user configuration. Also, this avoid extra processing for detecting collision for users who do not need these extra headers. |
hmm. i'm a tad confused..
i can see the need for adding a then there are some headers that just don't make sense -> add them to a blacklist. all other headers, however, seem pretty ok to just pass through unaltered. i've read through the short discussion on #213 (perhaps there were other issues where this was hashed out?), but i'm still unsure why a whitelist approach was adopted, rather than a blacklist. was there a specific problem that the whitelist approach addresses? either way, i'm late to the discussion, so i'll take whatever i can get.. 😄 |
@lucas-natraj You're right that this issue, IMO represents moving to a blacklist vs a whitelist. In general the likelihood of introducing unwanted outcomes with a blacklist are higher but if we feel like we cover our bases here I think we'll be fine. If we arrive at blacklist over whitelist we can do a release that mimics old and new behavior and then deprecate old behavior in a subsequent release. |
I think a sane default here is to continue whitelisting and supply customization capabilities with approaches like #360. That said it is an interesting question as to whether or not the |
yeah, i do understand.. my primary concerns with the current approach -
so, at this point, i'm not entirely sure why either prefix ( i think that the pr from @tamalsaha does improve things, but i'm just concerned that it is really just layering on a patch for something that needn't have been there in the first place.. (if that makes sense..) good discussion though.. but i'm happy to accept whatever.. it's not that big a deal anyway. |
Since we are thinking this from first principles, I would like to give my 2cs. In my view, grpc-gateway is a stopgap solution until everything speaks HTTP/2 natively. As a result, gateway should be invisible to the grpc server implementation. Nothing in my grpc server implementation should require knowing about the request is coming from gateway. In that light I think it makes sense passing all headers from user request to grpc server with these changes:
So, I think that automatically adding grpcgateway- prefix, stripping Grpc-Metadata- prefix should be stopped. Then we can also give user control via some pr like #336 if they want to do some additional processing. One such use-case we have is, we want to know the actual VERB used by json http endpoint. We add that using #336 .
The last thing is we should decide how the response headers returned from grpc server are passed back to user. Our use case here is, when rate limiting is enabled, our grpc server returns headers like
How do to pass it back to the caller? |
The logic behind not forwarding headers arbitrarily is that many people have some kind of internal header that does special stuff. An auth impersonation header is an example of something that If you had an "Authorization: token" header and another "Impersonation: $other_user_id". Inside the network, you would expect the service receiving the call to process the request as $other_user_id assuming the auth token granted impersonation permissions. The way I thought that was currently implemented was with a find and replace where it took Grpc-Metadata-x and made it just x in the request. That way you had the x- namespace of headers that were manipulable by the client and it removed everything else. Evidently my understanding is wrong. It looks like including a client side header of Grpc-Metadata-Impersonate would get you impersonation which is an... interesting result. I think @lucas-natraj's analysis is correct. As I read it I think the behavior of passing through Grpc-Metadata is a bug or possibly better viewed as an implementation artifact from days before we thought about headers. There should probably be a whitelist, a customizable whitelist at that. I wonder if this is such a common usecase that we should make a really easy way to do it. We could make it pluggable with the current implementation as the default and then change the default later. Does anyone have any thoughts? |
@achew22 thanks for your input. I agree with your and @lucas-natraj's analysis. @tamalsaha great proposal. @tamalsaha while related, can you start a new issue re: trailing metadata to http response code mapping? I assume it will mirror the request metadata population you've laid out. I think the next steps I'd like to take are:
|
Hi,
Why does not gateway forward headers as-is? Is there a technical reason for this?
Thanks.
The text was updated successfully, but these errors were encountered: