Skip to content

Allow alternate schemes in Kestrel requests #34013

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

Merged
merged 2 commits into from
Jul 6, 2021

Conversation

Tratcher
Copy link
Member

@Tratcher Tratcher commented Jul 1, 2021

Fixes #30532. Multiple HTTP/2 proxies for gRPC have been taking advantage of the :scheme header to forward the client's original scheme instead of using x-forwarded-proto headers. This change allows the developer to opt into mismatched schemes. Note the scheme must still be a valid format.

@Tratcher Tratcher added this to the 6.0-preview7 milestone Jul 1, 2021
@Tratcher Tratcher requested review from halter73 and JamesNK July 1, 2021 22:39
@Tratcher Tratcher self-assigned this Jul 1, 2021
@Tratcher Tratcher requested a review from BrennanConroy as a code owner July 1, 2021 22:39
@ghost ghost added the area-runtime label Jul 1, 2021
Copy link
Member

@JamesNK JamesNK left a comment

Choose a reason for hiding this comment

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

LGTM

@JamesNK JamesNK added the api-ready-for-review API is ready for formal API review - https://github.com/dotnet/apireviews label Jul 1, 2021
@ghost
Copy link

ghost commented Jul 1, 2021

Thank you for submitting this for API review. This will be reviewed by @dotnet/aspnet-api-review at the next meeting of the ASP.NET Core API Review group. Please ensure you take a look at the API review process documentation and ensure that:

  • The PR contains changes to the reference-assembly that describe the API change. Or, you have included a snippet of reference-assembly-style code that illustrates the API change.
  • The PR describes the impact to users, both positive (useful new APIs) and negative (breaking changes).
  • Someone is assigned to "champion" this change in the meeting, and they understand the impact and design of the change.

@Tratcher Tratcher requested a review from blowdart July 2, 2021 17:47
@Tratcher Tratcher added api-approved API was approved in API review, it can be implemented and removed api-ready-for-review API is ready for formal API review - https://github.com/dotnet/apireviews labels Jul 2, 2021
var str = CoreStrings.FormatHttp3StreamErrorSchemeMismatch(RequestHeaders[HeaderNames.Scheme], Scheme);
Abort(new ConnectionAbortedException(str), Http3ErrorCode.ProtocolError);
return false;
if (!ServerOptions.AllowAlternateSchemes || !Uri.CheckSchemeName(headerScheme))
Copy link
Member

Choose a reason for hiding this comment

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

CheckSchemeName is a new check, perf?

Copy link
Member Author

Choose a reason for hiding this comment

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

Note this new check only happens after the standard match checks have failed and you've opted into AllowAlternateSchemes, there should be no impact on the normal scenario.

I tried using Http2ConnectionHeadersBenchmark to measure this but the results between runs are wildly inconsistent.

Http2ConnectionHeadersBenchmark.MakeRequest:
AllowAlternateSchemes = false (default)

Method HeadersCount HeadersChange Mean Error StdDev Median Op/s Gen 0 Gen 1 Gen 2 Allocated
MakeRequest 1 False 47.663 us 0.9468 us 2.3226 us 47.941 us 20,980.6 - - - 416 B
MakeRequest 1 True 10.594 us 0.6478 us 1.7950 us 10.339 us 94,390.8 - - - 416 B
MakeRequest 4 False 8.633 us 0.1712 us 0.1601 us 8.620 us 115,840.4 - - - 416 B
MakeRequest 4 True 8.509 us 0.1538 us 0.2206 us 8.510 us 117,517.1 - - - 416 B
MakeRequest 32 False 12.754 us 0.3164 us 0.9179 us 12.351 us 78,404.7 - - - 416 B
MakeRequest 32 True 14.856 us 0.2850 us 0.2526 us 14.779 us 67,312.7 - - - 416 B

2nd run

Method HeadersCount HeadersChange Mean Error StdDev Median Op/s Gen 0 Gen 1 Gen 2 Allocated
MakeRequest 1 False 36.428 us 2.2939 us 6.7635 us 35.743 us 27,451.4 - - - 426 B
MakeRequest 1 True 37.094 us 2.4211 us 7.1387 us 35.420 us 26,958.4 - - - 424 B
MakeRequest 4 False 32.664 us 3.2156 us 9.3291 us 35.267 us 30,614.4 - - - 416 B
MakeRequest 4 True 8.444 us 0.1659 us 0.2679 us 8.353 us 118,424.5 - - - 416 B
MakeRequest 32 False 11.609 us 0.2135 us 0.1893 us 11.601 us 86,139.0 - - - 416 B
MakeRequest 32 True 14.142 us 0.2702 us 0.2528 us 14.023 us 70,712.6 - - - 416 B

AllowAlternateSchemes = false and scheme == "https" (same as the gRPC TLS termination scenario)

Method HeadersCount HeadersChange Mean Error StdDev Op/s Gen 0 Gen 1 Gen 2 Allocated
MakeRequest 1 False 36.66 us 2.118 us 6.246 us 27,276.3 - - - 423 B
MakeRequest 1 True 34.40 us 2.340 us 6.900 us 29,070.2 - - - 425 B
MakeRequest 4 False 34.19 us 2.033 us 5.995 us 29,249.5 - - - 423 B
MakeRequest 4 True 38.31 us 1.672 us 4.929 us 26,106.1 - - - 422 B
MakeRequest 32 False 12.15 us 0.243 us 0.532 us 82,297.0 - - - 416 B
MakeRequest 32 True 14.02 us 0.267 us 0.307 us 71,317.8 - - - 416 B

2nd run

Method HeadersCount HeadersChange Mean Error StdDev Op/s Gen 0 Gen 1 Gen 2 Allocated
MakeRequest 1 False 7.744 us 0.1548 us 0.1372 us 129,124.5 - - - 416 B
MakeRequest 1 True 8.157 us 0.1626 us 0.3133 us 122,594.2 - - - 416 B
MakeRequest 4 False 37.638 us 1.3081 us 3.8364 us 26,568.7 - - - 427 B
MakeRequest 4 True 8.455 us 0.1690 us 0.3451 us 118,279.9 - - - 416 B
MakeRequest 32 False 11.770 us 0.2220 us 0.1968 us 84,961.1 - - - 416 B
MakeRequest 32 True 14.149 us 0.2154 us 0.1909 us 70,677.3 - - - 416 B

@Tratcher Tratcher merged commit 2c553fd into dotnet:main Jul 6, 2021
@Tratcher Tratcher deleted the tratcher/alternateschemes branch July 6, 2021 19:29
@amcasey amcasey added area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions and removed area-runtime labels Jun 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-approved API was approved in API review, it can be implemented area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

GRPC :scheme pseudo-header passed from proxy/loadbalancer causes ConnectionAbortedException
5 participants