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

backport to 1.16: tls: fix detection of the upstream connection close event. (#13858) #14452

Merged
merged 5 commits into from
Dec 29, 2020
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
1 change: 1 addition & 0 deletions docs/root/version_history/current.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Bug Fixes
*Changes expected to improve the state of the world and are unlikely to have negative effects*

* lua: fixed crash when Lua script contains streamInfo():downstreamSslConnection().
* tls: fix detection of the upstream connection close event.

Removed Config or Runtime
-------------------------
Expand Down
1 change: 1 addition & 0 deletions include/envoy/registry/registry.h
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ template <class Base> class FactoryRegistry : public Logger::Loggable<Logger::Id
auto mapping = std::make_unique<absl::flat_hash_map<std::string, Base*>>();

for (const auto& [factory_name, factory] : factories()) {
UNREFERENCED_PARAMETER(factory_name);
if (factory == nullptr) {
continue;
}
Expand Down
1 change: 1 addition & 0 deletions source/common/config/new_grpc_mux_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ void NewGrpcMuxImpl::onDiscoveryResponse(

void NewGrpcMuxImpl::onStreamEstablished() {
for (auto& [type_url, subscription] : subscriptions_) {
UNREFERENCED_PARAMETER(type_url);
subscription->sub_state_.markStreamFresh();
}
trySendDiscoveryRequests();
Expand Down
1 change: 1 addition & 0 deletions source/common/init/manager_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ void ManagerImpl::dumpUnreadyTargets(envoy::admin::v3::UnreadyTargetsDumps& unre
auto& message = *unready_targets_dumps.mutable_unready_targets_dumps()->Add();
message.set_name(name_);
for (const auto& [target_name, count] : target_names_count_) {
UNREFERENCED_PARAMETER(count);
message.add_target_names(target_name);
}
}
Expand Down
1 change: 1 addition & 0 deletions source/common/router/scoped_rds.cc
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,7 @@ ScopedRdsConfigSubscription::detectUpdateConflictAndCleanupRemoved(
absl::flat_hash_map<uint64_t, std::string> scope_name_by_hash = scope_name_by_hash_;
absl::erase_if(scope_name_by_hash, [&updated_or_removed_scopes](const auto& key_name) {
auto const& [key, name] = key_name;
UNREFERENCED_PARAMETER(key);
return updated_or_removed_scopes.contains(name);
});
absl::flat_hash_map<std::string, envoy::config::route::v3::ScopedRouteConfiguration>
Expand Down
2 changes: 1 addition & 1 deletion source/extensions/transport_sockets/tls/ssl_handshaker.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class SslHandshakerImpl : public Ssl::ConnectionInfo, public Ssl::Handshaker {
// Ssl::Handshaker
Network::PostIoAction doHandshake() override;

Ssl::SocketState state() { return state_; }
Ssl::SocketState state() const { return state_; }
void setState(Ssl::SocketState state) { state_ = state; }
SSL* ssl() const { return ssl_.get(); }
Ssl::HandshakeCallbacks* handshakeCallbacks() { return handshake_callbacks_; }
Expand Down
10 changes: 9 additions & 1 deletion source/extensions/transport_sockets/tls/ssl_socket.cc
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,18 @@ Network::IoResult SslSocket::doRead(Buffer::Instance& read_buffer) {
case SSL_ERROR_WANT_READ:
break;
case SSL_ERROR_ZERO_RETURN:
// Graceful shutdown using close_notify TLS alert.
end_stream = true;
break;
case SSL_ERROR_SYSCALL:
if (result.error_.value() == 0) {
// Non-graceful shutdown by closing the underlying socket.
end_stream = true;
break;
}
FALLTHRU;
case SSL_ERROR_WANT_WRITE:
// Renegotiation has started. We don't handle renegotiation so just fall through.
// Renegotiation has started. We don't handle renegotiation so just fall through.
default:
drainErrorQueue();
action = PostIoAction::Close;
Expand Down
3 changes: 3 additions & 0 deletions source/server/admin/config_dump_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ ConfigDumpHandler::addResourceToDump(envoy::admin::v3::ConfigDump& dump,
}

for (const auto& [name, callback] : callbacks_map) {
UNREFERENCED_PARAMETER(name);
ProtobufTypes::MessagePtr message = callback();
ASSERT(message);

Expand Down Expand Up @@ -200,6 +201,7 @@ void ConfigDumpHandler::addAllConfigToDump(envoy::admin::v3::ConfigDump& dump,
}

for (const auto& [name, callback] : callbacks_map) {
UNREFERENCED_PARAMETER(name);
ProtobufTypes::MessagePtr message = callback();
ASSERT(message);

Expand All @@ -220,6 +222,7 @@ ProtobufTypes::MessagePtr ConfigDumpHandler::dumpEndpointConfigs() const {
auto endpoint_config_dump = std::make_unique<envoy::admin::v3::EndpointsConfigDump>();

for (const auto& [name, cluster_ref] : server_.clusterManager().clusters()) {
UNREFERENCED_PARAMETER(name);
const Upstream::Cluster& cluster = cluster_ref.get();
Upstream::ClusterInfoConstSharedPtr cluster_info = cluster.info();
envoy::config::endpoint::v3::ClusterLoadAssignment cluster_load_assignment;
Expand Down
4 changes: 4 additions & 0 deletions source/server/filter_chain_manager_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,7 @@ const Network::FilterChain* FilterChainManagerImpl::findFilterChainForSourceIpAn

void FilterChainManagerImpl::convertIPsToTries() {
for (auto& [destination_port, destination_ips_pair] : destination_ports_map_) {
UNREFERENCED_PARAMETER(destination_port);
// These variables are used as we build up the destination CIDRs used for the trie.
auto& [destination_ips_map, destination_ips_trie] = destination_ips_pair;
std::vector<std::pair<ServerNamesMapSharedPtr, std::vector<Network::Address::CidrRange>>>
Expand All @@ -568,8 +569,11 @@ void FilterChainManagerImpl::convertIPsToTries() {
// We need to get access to all of the source IP strings so that we can convert them into
// a trie like we did for the destination IPs above.
for (auto& [server_name, transport_protocols_map] : *server_names_map_ptr) {
UNREFERENCED_PARAMETER(server_name);
for (auto& [transport_protocol, application_protocols_map] : transport_protocols_map) {
UNREFERENCED_PARAMETER(transport_protocol);
for (auto& [application_protocol, source_arrays] : application_protocols_map) {
UNREFERENCED_PARAMETER(application_protocol);
for (auto& [source_ips_map, source_ips_trie] : source_arrays) {
std::vector<
std::pair<SourcePortsMapSharedPtr, std::vector<Network::Address::CidrRange>>>
Expand Down
15 changes: 2 additions & 13 deletions test/extensions/transport_sockets/tls/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@ envoy_cc_test(
"ssl_socket_test.cc",
],
data = [
"gen_unittest_certs.sh",
# TODO(mattklein123): We should consolidate all of our test certs in a single place as
# right now we have a bunch of duplication which is confusing.
"//test/config/integration/certs",
"//test/extensions/transport_sockets/tls/ocsp/test_data:certs",
"//test/extensions/transport_sockets/tls/test_data:certs",
"//test/extensions/transport_sockets/tls/ocsp:gen_ocsp_data",
],
external_deps = ["ssl"],
shard_count = 4,
Expand Down Expand Up @@ -74,12 +73,9 @@ envoy_cc_test(
"ssl_certs_test.h",
],
data = [
"gen_unittest_certs.sh",
"//test/extensions/transport_sockets/tls/ocsp:gen_ocsp_data",
"//test/extensions/transport_sockets/tls/ocsp/test_data:certs",
"//test/extensions/transport_sockets/tls/test_data:certs",
],
# Fails intermittantly on local build
tags = ["flaky_on_windows"],
deps = [
":ssl_test_utils",
"//source/common/common:base64_lib",
Expand Down Expand Up @@ -121,8 +117,6 @@ envoy_cc_test(
"utility_test.cc",
],
data = [
"gen_unittest_certs.sh",
"//test/extensions/transport_sockets/tls/ocsp:gen_ocsp_data",
"//test/extensions/transport_sockets/tls/test_data:certs",
],
external_deps = ["ssl"],
Expand Down Expand Up @@ -171,14 +165,9 @@ envoy_cc_test(
name = "handshaker_test",
srcs = ["handshaker_test.cc"],
data = [
"gen_unittest_certs.sh",
"//test/config/integration/certs",
"//test/extensions/transport_sockets/tls/test_data:certs",
],
external_deps = ["ssl"],
# TODO(sunjayBhatia): Diagnose openssl DLL load issue on Windows
# See: https://github.com/envoyproxy/envoy/pull/13276
tags = ["flaky_on_windows"],
deps = [
":ssl_socket_test",
":ssl_test_utils",
Expand Down
Loading