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

http3: support Http3Options for downstream #15753

Merged
merged 20 commits into from
Apr 6, 2021
Merged
Show file tree
Hide file tree
Changes from 4 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
12 changes: 9 additions & 3 deletions api/envoy/config/core/v3/protocol.proto
Original file line number Diff line number Diff line change
Expand Up @@ -416,9 +416,15 @@ message GrpcProtocolOptions {

// [#not-implemented-hide:]
//
// A message which allows using HTTP/3 as an upstream protocol.
//
// Eventually this will include configuration for tuning HTTP/3.
// A message which allows using HTTP/3.
message Http3ProtocolOptions {
QuicProtocolOptions quic_protocol_options = 1;

// Allows invalid HTTP messaging and headers. When this option is disabled (default), then
// the whole HTTP/3 connection is terminated upon receiving invalid HEADERS frame. However,
// when this option is enabled, only the offending stream is terminated.
//
// If set, this overrides any HCM :ref:`stream_error_on_invalid_http_messaging
// <envoy_v3_api_field_extensions.filters.network.http_connection_manager.v3.HttpConnectionManager.stream_error_on_invalid_http_message>`.
google.protobuf.BoolValue override_stream_error_on_invalid_http_message = 2;
alyssawilk marked this conversation as resolved.
Show resolved Hide resolved
}
12 changes: 9 additions & 3 deletions api/envoy/config/core/v4alpha/protocol.proto

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ option (udpa.annotations.file_status).package_version_status = ACTIVE;
// HTTP connection manager :ref:`configuration overview <config_http_conn_man>`.
// [#extension: envoy.filters.network.http_connection_manager]

// [#next-free-field: 44]
// [#next-free-field: 45]
message HttpConnectionManager {
option (udpa.annotations.versioning).previous_message_type =
"envoy.config.filter.network.http_connection_manager.v2.HttpConnectionManager";
Expand Down Expand Up @@ -325,6 +325,10 @@ message HttpConnectionManager {
config.core.v3.Http2ProtocolOptions http2_protocol_options = 9
[(udpa.annotations.security).configure_for_untrusted_downstream = true];

// Additional HTTP/3 settings that are passed directly to the HTTP/3 codec.
config.core.v3.Http3ProtocolOptions http3_protocol_options = 44
[(udpa.annotations.security).configure_for_untrusted_downstream = true];
Copy link
Contributor Author

@danzh2010 danzh2010 Mar 30, 2021

Choose a reason for hiding this comment

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

@htuch The doc CI fails because this field is annotated with udpa.annotations.security, but doesn't have description in docs/protodoc_manifest.yaml. Do I need to document override_stream_error_on_invalid_http_message, the only field of Http3ProtocolOptions, there? http2_protocol_options doesn't have documentation about its similar fields in protodoc_manifest.yaml.

Copy link
Member

Choose a reason for hiding this comment

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

If there is anything security related, e.g. buffering, update the example manifest YAML as per offline discussion. If not, feel free to drop the security annotation.


// An optional override that the connection manager will write to the server
// header in responses. If not set, the default is *envoy*.
string server_name = 10
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,16 @@ All http2 details are rooted at *http2.*
http2.unexpected_underscore, Envoy was configured to drop requests with header keys beginning with underscores.
http2.unknown.nghttp2.error, An unknown error was encountered by nghttp2
http2.violation.of.messaging.rule, The stream was in violation of a HTTP/2 messaging rule.

Http3 details
~~~~~~~~~~~~~

All http3 details are rooted at *http3.*

.. csv-table::
:header: Name, Description
:widths: 1, 2

http3.invalid_header_field, One of the HTTP/3 headers was invalid
http3.headers.too.large, The size of headers (or trailers) exceeded the configured limits
http3.unexpected_underscore, Envoy was configured to drop or reject requests with header keys beginning with underscores.
12 changes: 9 additions & 3 deletions generated_api_shadow/envoy/config/core/v3/protocol.proto

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 9 additions & 3 deletions generated_api_shadow/envoy/config/core/v4alpha/protocol.proto

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions include/envoy/http/codec.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ namespace Http2 {
struct CodecStats;
}

namespace Http3 {
struct CodecStats;
}

// Legacy default value of 60K is safely under both codec default limits.
static constexpr uint32_t DEFAULT_MAX_REQUEST_HEADERS_KB = 60;
// Default maximum number of headers.
Expand Down
5 changes: 5 additions & 0 deletions include/envoy/upstream/upstream.h
Original file line number Diff line number Diff line change
Expand Up @@ -995,6 +995,11 @@ class ClusterInfo {
*/
virtual Http::Http2::CodecStats& http2CodecStats() const PURE;

/**
* @return the Http2 Codec Stats.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* @return the Http2 Codec Stats.
* @return the Http3 Codec Stats.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

*/
virtual Http::Http3::CodecStats& http3CodecStats() const PURE;

protected:
/**
* Invoked by extensionProtocolOptionsTyped.
Expand Down
4 changes: 3 additions & 1 deletion source/common/http/codec_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,9 @@ CodecClientProd::CodecClientProd(Type type, Network::ClientConnectionPtr&& conne
codec_ = std::unique_ptr<ClientConnection>(
Config::Utility::getAndCheckFactoryByName<Http::QuicHttpClientConnectionFactory>(
Http::QuicCodecNames::get().Quiche)
.createQuicClientConnection(*connection_, *this));
.createQuicClientConnection(*connection_, *this, host->cluster().http3CodecStats(),
host->cluster().http3Options(),
Http::DEFAULT_MAX_REQUEST_HEADERS_KB));
break;
}
}
Expand Down
12 changes: 12 additions & 0 deletions source/common/http/http3/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ envoy_cc_library(
name = "quic_codec_factory_lib",
hdrs = ["quic_codec_factory.h"],
deps = [
":codec_stats_lib",
"//include/envoy/config:typed_config_interface",
"//include/envoy/http:codec_interface",
"//include/envoy/network:connection_interface",
"@envoy_api//envoy/config/core/v3:pkg_cc_proto",
],
)

Expand All @@ -47,3 +49,13 @@ envoy_cc_library(
hdrs = ["well_known_names.h"],
deps = ["//source/common/singleton:const_singleton"],
)

envoy_cc_library(
name = "codec_stats_lib",
hdrs = ["codec_stats.h"],
deps = [
"//include/envoy/stats:stats_interface",
"//include/envoy/stats:stats_macros",
"//source/common/common:thread_lib",
],
)
17 changes: 14 additions & 3 deletions source/common/http/http3/quic_codec_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

#include <string>

#include "envoy/config/core/v3/protocol.pb.h"
#include "envoy/config/typed_config.h"
#include "envoy/http/codec.h"
#include "envoy/network/connection.h"

#include "common/http/http3/codec_stats.h"

namespace Envoy {
namespace Http {

Expand All @@ -14,8 +17,13 @@ class QuicHttpServerConnectionFactory : public Config::UntypedFactory {
public:
~QuicHttpServerConnectionFactory() override = default;

virtual std::unique_ptr<ServerConnection>
createQuicServerConnection(Network::Connection& connection, ConnectionCallbacks& callbacks) PURE;
virtual std::unique_ptr<ServerConnection> createQuicServerConnection(
Network::Connection& connection, ConnectionCallbacks& callbacks,
Http::Http3::CodecStats& stats,
const envoy::config::core::v3::Http3ProtocolOptions& http3_options,
const uint32_t max_request_headers_kb,
envoy::config::core::v3::HttpProtocolOptions::HeadersWithUnderscoresAction
headers_with_underscores_action) PURE;

std::string category() const override { return "envoy.quic_client_codec"; }
};
Expand All @@ -26,7 +34,10 @@ class QuicHttpClientConnectionFactory : public Config::UntypedFactory {
~QuicHttpClientConnectionFactory() override = default;

virtual std::unique_ptr<ClientConnection>
createQuicClientConnection(Network::Connection& connection, ConnectionCallbacks& callbacks) PURE;
createQuicClientConnection(Network::Connection& connection, ConnectionCallbacks& callbacks,
Http::Http3::CodecStats& stats,
const envoy::config::core::v3::Http3ProtocolOptions& http3_options,
const uint32_t max_request_headers_kb) PURE;

std::string category() const override { return "envoy.quic_server_codec"; }
};
Expand Down
18 changes: 18 additions & 0 deletions source/common/http/utility.cc
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,24 @@ initializeAndValidateOptions(const envoy::config::core::v3::Http2ProtocolOptions

} // namespace Utility
} // namespace Http2
namespace Http3 {
namespace Utility {
envoy::config::core::v3::Http3ProtocolOptions
initializeAndValidateOptions(const envoy::config::core::v3::Http3ProtocolOptions& options,
bool hcm_stream_error_set,
const Protobuf::BoolValue& hcm_stream_error) {
envoy::config::core::v3::Http3ProtocolOptions options_clone(options);
if (Runtime::runtimeFeatureEnabled(
"envoy.reloadable_features.hcm_stream_error_on_invalid_message") &&
!options.has_override_stream_error_on_invalid_http_message() && hcm_stream_error_set) {
options_clone.mutable_override_stream_error_on_invalid_http_message()->set_value(
hcm_stream_error.value());
}
return options_clone;
}

} // namespace Utility
} // namespace Http3

namespace Http {

Expand Down
8 changes: 8 additions & 0 deletions source/common/http/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,15 @@ initializeAndValidateOptions(const envoy::config::core::v3::Http2ProtocolOptions
const Protobuf::BoolValue& hcm_stream_error);
} // namespace Utility
} // namespace Http2
namespace Http3 {
namespace Utility {
envoy::config::core::v3::Http3ProtocolOptions
initializeAndValidateOptions(const envoy::config::core::v3::Http3ProtocolOptions& options,
bool hcm_stream_error_set,
const Protobuf::BoolValue& hcm_stream_error);

} // namespace Utility
} // namespace Http3
namespace Http {
namespace Utility {

Expand Down
4 changes: 4 additions & 0 deletions source/common/quic/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,12 @@ envoy_cc_library(
tags = ["nofips"],
deps = [
":envoy_quic_simulated_watermark_buffer_lib",
":envoy_quic_utils_lib",
":quic_filter_manager_connection_lib",
"//include/envoy/event:dispatcher_interface",
"//include/envoy/http:codec_interface",
"//source/common/http:codec_helper_lib",
"@envoy_api//envoy/config/core/v3:pkg_cc_proto",
],
)

Expand Down Expand Up @@ -189,8 +191,10 @@ envoy_cc_library(
"//source/common/common:assert_lib",
"//source/common/common:empty_string",
"//source/common/http:header_map_lib",
"//source/common/http/http3:codec_stats_lib",
"//source/common/network:connection_base_lib",
"//source/common/stream_info:stream_info_lib",
"@envoy_api//envoy/config/core/v3:pkg_cc_proto",
],
)

Expand Down
Loading