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

http: Change sendLocalReply to send percent-encoded GrpcMessage #6913

Merged
merged 14 commits into from
May 30, 2019
Merged

Conversation

dio
Copy link
Member

@dio dio commented May 13, 2019

Description: This patch changed sendLocalReply to send GrpcMessage in percent-encoded
instead of plain string following: https://github.com/grpc/grpc/blob/master/doc/PROTOCOL-HTTP2.md#responses.

Risk Level: Low
Testing: Unit tests
Docs Changes: N/A
Release Notes: Added
Fixes #6902

dio added 3 commits May 13, 2019 10:58
This patch changed sendLocalReply to send GrpcMessage in percent-encoded
instead of plain string.

Signed-off-by: Dhi Aurrahman <dio@tetrate.io>
Signed-off-by: Dhi Aurrahman <dio@tetrate.io>
Signed-off-by: Dhi Aurrahman <dio@tetrate.io>
@dio dio requested a review from snowp as a code owner May 13, 2019 08:11
@snowp snowp self-assigned this May 13, 2019
Copy link
Contributor

@snowp snowp left a comment

Choose a reason for hiding this comment

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

Nice, looks pretty good.

Does this seem like something that needs to be config guarded in some way? While I understand this to be the correct behavior I wonder if there are people relying on this/don't want to spend the CPU on encoding every response.

source/common/http/utility.cc Outdated Show resolved Hide resolved
source/common/http/utility.cc Outdated Show resolved Hide resolved
@dio
Copy link
Member Author

dio commented May 14, 2019

@snowp thanks for the review. Will address it soon. re: config, yeah probably that's a good point. Will try to introduce one for this.

dio added 2 commits May 14, 2019 12:05
Signed-off-by: Dhi Aurrahman <dio@tetrate.io>
Signed-off-by: Dhi Aurrahman <dio@tetrate.io>
@dio
Copy link
Member Author

dio commented May 14, 2019

@snowp for configuration, I think I'll add it after #6261 is merged.

dio added 3 commits May 14, 2019 22:02
Signed-off-by: Dhi Aurrahman <dio@tetrate.io>
Signed-off-by: Dhi Aurrahman <dio@tetrate.io>
Signed-off-by: Dhi Aurrahman <dio@tetrate.io>
@thorkildcognite
Copy link

Note that if this feature is not enabled, then it will take down envoy if the external auth service responds with a multi-line message. It is a point that someone could be parsing and using that header already, though, of course, but it sounds like something that should be default on (with a note in the release log)

@snowp
Copy link
Contributor

snowp commented May 15, 2019

Yeah it's a bit tricky due to this being used by out of repo filters, so we don't really know how it is being used. There seems to be 3 options: 1) config guard it 2) make the encoding behavior optional through a parameter to sendLocalReply and set it to true for all in-repo usages or 3) just update sendLocalyReply to always encode

I'm not sure how careful we have to be here wrt to the breaking change policy. @alyssawilk @mattklein123 Do you have any thoughts on how to best handle this?

@alyssawilk
Copy link
Contributor

I'd like @lizan 's take but if this is a correctness issue I'd be inclined to say we should always do it, but we could runtime guard the change to make sure if it causes problems it's easy for folks to roll back while we address.

@qiwzhang
Copy link
Contributor

Per https://github.com/grpc/grpc/blob/master/doc/PROTOCOL-HTTP2.md

The value portion of Status-Message is conceptually a Unicode string description of the error, physically encoded as UTF-8 followed by percent-encoding. Percent-encoding is specified in RFC 3986 §2.1, although the form used here has different restricted characters. When decoding invalid values, implementations MUST NOT error or throw away the message. At worst, the implementation can abort decoding the status message altogether such that the user would received the raw percent-encoded form. Alternatively, the implementation can decode valid portions while leaving broken %-encodings as-is or replacing them with a replacement character (e.g., '?' or the Unicode replacement character).

Grpc-Message should be percent-encoded.

Copy link
Member

@lizan lizan left a comment

Choose a reason for hiding this comment

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

We should just update sendLocalyReply, per gRPC spec it should be always precent-encoded.

source/common/http/utility.cc Show resolved Hide resolved
source/common/http/utility.cc Outdated Show resolved Hide resolved
Signed-off-by: Dhi Aurrahman <dio@tetrate.io>
dio added 2 commits May 17, 2019 10:31
Signed-off-by: Dhi Aurrahman <dio@tetrate.io>
Signed-off-by: Dhi Aurrahman <dio@tetrate.io>
Copy link
Contributor

@snowp snowp left a comment

Choose a reason for hiding this comment

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

Seems like the consensus is that we don't need to gate this on anything, which seems fine to me. My initial concern was about out of tree uses that might already be percent encoding the value given to sendLocalReply, but that might not be very common

source/common/http/utility.h Outdated Show resolved Hide resolved
Signed-off-by: Dhi Aurrahman <dio@tetrate.io>
@dio
Copy link
Member Author

dio commented May 21, 2019

/retest

@repokitteh-read-only
Copy link

🔨 rebuilding ci/circleci: tsan (failed build)

🐱

Caused by: a #6913 (comment) was created by @dio.

see: more, trace.

snowp
snowp previously approved these changes May 28, 2019
Copy link
Contributor

@snowp snowp left a comment

Choose a reason for hiding this comment

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

Sorry for the delay, this LGTM. @lizan Do you wanna do the senior review of this one?

Copy link
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

LGTM w/ small comment request. Thank you!

/wait

for (size_t i = 0; i < value.size(); ++i) {
const char& ch = value[i];
// https://github.com/grpc/grpc/blob/master/doc/PROTOCOL-HTTP2.md#responses.
if (ch < ' ' || ch >= '~' || ch == '%') {
Copy link
Member

Choose a reason for hiding this comment

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

This first check is a performance optimization, right? It took me a little while to figure out what was going on here. If so, can you add an explanatory comment about why we are doing it this way?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure. Added some comments.

dio added 2 commits May 30, 2019 15:40
Signed-off-by: Dhi Aurrahman <dio@tetrate.io>
Signed-off-by: Dhi Aurrahman <dio@tetrate.io>
Copy link
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

Awesome, thanks.

@mattklein123 mattklein123 merged commit f326331 into envoyproxy:master May 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Using a HTTP based external auth service with GRPC proxy entries crashes envoy on 401s
7 participants