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

http2: replaces nghttp2 functions with equivalents from QUICHE. #24943

Merged
merged 8 commits into from
Feb 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion changelogs/current.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ minor_behavior_changes:
- area: healthcheck
change: |
If active HC is enabled and a host is ejected by outlier detection, a successful active health check unejects the host and consider it healthy. This also clears all the outlier detection counters. This behavior change can be reverted by setting ``envoy.reloadable_features_successful_active_health_check_uneject_host`` to ``false``.

- area: local_ratelimit
change: |
Tokens from local descriptor's token buckets are burned before tokens from the default token bucket.
- area: http2
change: |
Request authorities are now validated with a library function from QUICHE rather than nghttp2. This behavior change can be reverted by setting ``envoy.reloadable_features.http2_validate_authority_with_quiche`` to ``false``.

bug_fixes:
# *Changes expected to improve the state of the world and are unlikely to have negative effects*
Expand Down
1 change: 1 addition & 0 deletions source/common/http/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,7 @@ envoy_cc_library(
hdrs = ["header_utility.h"],
external_deps = [
"nghttp2",
"quiche_http2_adapter",
Copy link
Member

Choose a reason for hiding this comment

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

I'm by no means a bazel expert, but should this continue to reference nghttp2 until the runtime flag is removed?

],
deps = [
":header_map_lib",
Expand Down
14 changes: 10 additions & 4 deletions source/common/http/header_utility.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#include "absl/strings/match.h"
#include "nghttp2/nghttp2.h"
#include "quiche/http2/adapter/header_validator.h"

namespace Envoy {
namespace Http {
Expand Down Expand Up @@ -190,17 +191,22 @@ bool HeaderUtility::schemeIsValid(const absl::string_view scheme) {
}

bool HeaderUtility::headerValueIsValid(const absl::string_view header_value) {
return nghttp2_check_header_value(reinterpret_cast<const uint8_t*>(header_value.data()),
header_value.size()) != 0;
return http2::adapter::HeaderValidator::IsValidHeaderValue(header_value,
Copy link
Contributor

Choose a reason for hiding this comment

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

Hm, do we need a runtime guard for this? I would imagine it's possible that this is a behavior change in the event that QUICHE and nghttp2 do something different?

Copy link
Contributor

Choose a reason for hiding this comment

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

What do you think about a runtime guard for this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let me see if I can write a unit test that demonstrates whether there is/is not a behavior change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

With ObsTextOption::kAllow, the set of characters allowed by the oghttp2 method is exactly the same as the nghttp2 function.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hm. Can we write a unit test then where we loop through all the possible characters and verify we get the same output? I just want to make 100% sure that this change doesn't result in some crazy corner case behavior change which isn't protected by a runtime guard? Or alternatively, if it obvious from inspection can you point me at the two methods? (Sorry to be pedantic here!)

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for the offline discussion and the pointer to the test.

http2::adapter::ObsTextOption::kAllow);
}

bool HeaderUtility::headerNameContainsUnderscore(const absl::string_view header_name) {
return header_name.find('_') != absl::string_view::npos;
}

bool HeaderUtility::authorityIsValid(const absl::string_view header_value) {
return nghttp2_check_authority(reinterpret_cast<const uint8_t*>(header_value.data()),
header_value.size()) != 0;
if (Runtime::runtimeFeatureEnabled(
"envoy.reloadable_features.http2_validate_authority_with_quiche")) {
return http2::adapter::HeaderValidator::IsValidAuthority(header_value);
} else {
return nghttp2_check_authority(reinterpret_cast<const uint8_t*>(header_value.data()),
header_value.size()) != 0;
}
}

bool HeaderUtility::isSpecial1xx(const ResponseHeaderMap& response_headers) {
Expand Down
1 change: 1 addition & 0 deletions source/common/runtime/runtime_features.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ RUNTIME_GUARD(envoy_reloadable_features_enable_intermediate_ca);
RUNTIME_GUARD(envoy_reloadable_features_enable_update_listener_socket_options);
RUNTIME_GUARD(envoy_reloadable_features_finish_reading_on_decode_trailers);
RUNTIME_GUARD(envoy_reloadable_features_fix_hash_key);
RUNTIME_GUARD(envoy_reloadable_features_http2_validate_authority_with_quiche);
RUNTIME_GUARD(envoy_reloadable_features_http3_sends_early_data);
RUNTIME_GUARD(envoy_reloadable_features_http_filter_avoid_reentrant_local_reply);
RUNTIME_GUARD(envoy_reloadable_features_http_reject_path_with_fragment);
Expand Down
3 changes: 3 additions & 0 deletions test/fuzz/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ envoy_cc_test_library(
name = "utility_lib",
srcs = ["utility.cc"],
hdrs = ["utility.h"],
external_deps = [
"quiche_http2_adapter",
],
deps = [
":common_proto_cc_proto",
"//source/common/common:empty_string",
Expand Down
4 changes: 2 additions & 2 deletions test/fuzz/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include "test/mocks/upstream/host.h"
#include "test/test_common/utility.h"

#include "nghttp2/nghttp2.h"
#include "quiche/http2/adapter/header_validator.h"

// Strong assertion that applies across all compilation modes and doesn't rely
// on gtest, which only provides soft fails that don't trip oss-fuzz failures.
Expand Down Expand Up @@ -53,7 +53,7 @@ inline std::string replaceInvalidHostCharacters(absl::string_view string) {
std::string filtered;
filtered.reserve(string.length());
for (const char& c : string) {
if (nghttp2_check_authority(reinterpret_cast<const uint8_t*>(&c), 1)) {
if (http2::adapter::HeaderValidator::IsValidAuthority(absl::string_view(&c, 1))) {
filtered.push_back(c);
} else {
filtered.push_back('0');
Expand Down