-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
This commit adds a new TCP cluster rewrite filter which allows users to rewrite TCP cluster names obtained via TLS SNI by matching via regex configuration. Signed-off-by: Venil Noronha <[email protected]>
- Loading branch information
1 parent
2003747
commit a004f90
Showing
16 changed files
with
568 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
# Copyright 2018 Istio Authors. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
################################################################################ | ||
# | ||
|
||
package(default_visibility = ["//visibility:public"]) | ||
|
||
load( | ||
"@envoy//bazel:envoy_build_system.bzl", | ||
"envoy_cc_binary", | ||
"envoy_cc_library", | ||
"envoy_cc_test", | ||
) | ||
|
||
envoy_cc_library( | ||
name = "tcp_cluster_rewrite_lib", | ||
srcs = ["tcp_cluster_rewrite.cc"], | ||
hdrs = ["tcp_cluster_rewrite.h"], | ||
repository = "@envoy", | ||
deps = [ | ||
"//external:tcp_cluster_rewrite_config_cc_proto", | ||
"@envoy//source/exe:envoy_common_lib", | ||
], | ||
) | ||
|
||
envoy_cc_library( | ||
name = "config_lib", | ||
srcs = ["config.cc"], | ||
hdrs = ["config.h"], | ||
repository = "@envoy", | ||
deps = [ | ||
":tcp_cluster_rewrite_lib", | ||
"//src/envoy/utils:utils_lib", | ||
"//external:tcp_cluster_rewrite_config_cc_proto", | ||
"@envoy//source/exe:envoy_common_lib", | ||
], | ||
) | ||
|
||
envoy_cc_test( | ||
name = "tcp_cluster_rewrite_test", | ||
srcs = ["tcp_cluster_rewrite_test.cc"], | ||
repository = "@envoy", | ||
deps = [ | ||
":tcp_cluster_rewrite_lib", | ||
":config_lib", | ||
"@envoy//test/mocks/network:network_mocks", | ||
"@envoy//test/mocks/server:server_mocks", | ||
"@envoy//test/mocks/stream_info:stream_info_mocks", | ||
], | ||
) | ||
|
||
envoy_cc_test( | ||
name = "config_test", | ||
srcs = ["config_test.cc"], | ||
repository = "@envoy", | ||
deps = [ | ||
":config_lib", | ||
"@envoy//test/mocks/server:server_mocks", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* Copyright 2018 Istio Authors. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include "src/envoy/tcp/tcp_cluster_rewrite/config.h" | ||
#include "src/envoy/tcp/tcp_cluster_rewrite/tcp_cluster_rewrite.h" | ||
|
||
#include "envoy/registry/registry.h" | ||
#include "envoy/server/filter_config.h" | ||
#include "src/envoy/utils/config.h" | ||
|
||
using namespace ::istio::envoy::config::filter::network::tcp_cluster_rewrite; | ||
|
||
namespace Envoy { | ||
namespace Tcp { | ||
namespace TcpClusterRewrite { | ||
|
||
Network::FilterFactoryCb | ||
TcpClusterRewriteFilterConfigFactory::createFilterFactory( | ||
const Json::Object& config_json, Server::Configuration::FactoryContext&) { | ||
v2alpha1::TcpClusterRewrite config_pb; | ||
if (!Utils::ReadV2Config(config_json, &config_pb)) { | ||
throw EnvoyException("Failed to parse JSON config"); | ||
} | ||
return createFilterFactory(config_pb); | ||
} | ||
|
||
Network::FilterFactoryCb | ||
TcpClusterRewriteFilterConfigFactory::createFilterFactoryFromProto( | ||
const Protobuf::Message& config, Server::Configuration::FactoryContext&) { | ||
return createFilterFactory( | ||
dynamic_cast<const v2alpha1::TcpClusterRewrite&>(config)); | ||
} | ||
|
||
ProtobufTypes::MessagePtr | ||
TcpClusterRewriteFilterConfigFactory::createEmptyConfigProto() { | ||
return ProtobufTypes::MessagePtr{new v2alpha1::TcpClusterRewrite}; | ||
} | ||
|
||
Network::FilterFactoryCb | ||
TcpClusterRewriteFilterConfigFactory::createFilterFactory( | ||
const v2alpha1::TcpClusterRewrite& config_pb) { | ||
TcpClusterRewriteFilterConfigSharedPtr config( | ||
std::make_shared<TcpClusterRewriteFilterConfig>(config_pb)); | ||
return [config](Network::FilterManager& filter_manager) -> void { | ||
filter_manager.addReadFilter( | ||
std::make_shared<TcpClusterRewriteFilter>(config)); | ||
}; | ||
} | ||
|
||
/** | ||
* Static registration for the TCP cluster rewrite filter. @see RegisterFactory. | ||
*/ | ||
static Registry::RegisterFactory< | ||
TcpClusterRewriteFilterConfigFactory, | ||
Server::Configuration::NamedNetworkFilterConfigFactory> | ||
registered_; | ||
|
||
} // namespace TcpClusterRewrite | ||
} // namespace Tcp | ||
} // namespace Envoy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* Copyright 2018 Istio Authors. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "envoy/config/filter/network/tcp_cluster_rewrite/v2alpha1/config.pb.h" | ||
|
||
#include "envoy/network/connection.h" | ||
#include "envoy/network/filter.h" | ||
#include "envoy/registry/registry.h" | ||
#include "envoy/server/filter_config.h" | ||
|
||
using namespace ::istio::envoy::config::filter::network::tcp_cluster_rewrite; | ||
|
||
namespace Envoy { | ||
namespace Tcp { | ||
namespace TcpClusterRewrite { | ||
|
||
/** | ||
* Config registration for the TCP cluster rewrite filter. @see | ||
* NamedNetworkFilterConfigFactory. | ||
*/ | ||
class TcpClusterRewriteFilterConfigFactory | ||
: public Server::Configuration::NamedNetworkFilterConfigFactory { | ||
public: | ||
Network::FilterFactoryCb createFilterFactory( | ||
const Json::Object&, Server::Configuration::FactoryContext&) override; | ||
|
||
Network::FilterFactoryCb createFilterFactoryFromProto( | ||
const Protobuf::Message&, | ||
Server::Configuration::FactoryContext&) override; | ||
|
||
ProtobufTypes::MessagePtr createEmptyConfigProto() override; | ||
|
||
std::string name() override { return "tcp_cluster_rewrite"; } | ||
|
||
private: | ||
Network::FilterFactoryCb createFilterFactory( | ||
const v2alpha1::TcpClusterRewrite& config_pb); | ||
}; | ||
|
||
} // namespace TcpClusterRewrite | ||
} // namespace Tcp | ||
} // namespace Envoy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* Copyright 2018 Istio Authors. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include "src/envoy/tcp/tcp_cluster_rewrite/config.h" | ||
|
||
#include "test/mocks/server/mocks.h" | ||
|
||
#include "gmock/gmock.h" | ||
#include "gtest/gtest.h" | ||
|
||
using namespace ::istio::envoy::config::filter::network::tcp_cluster_rewrite; | ||
using testing::_; | ||
|
||
namespace Envoy { | ||
namespace Tcp { | ||
namespace TcpClusterRewrite { | ||
|
||
TEST(ConfigTest, ConfigTest) { | ||
NiceMock<Server::Configuration::MockFactoryContext> context; | ||
TcpClusterRewriteFilterConfigFactory factory; | ||
v2alpha1::TcpClusterRewrite config = | ||
*dynamic_cast<v2alpha1::TcpClusterRewrite*>( | ||
factory.createEmptyConfigProto().get()); | ||
|
||
config.set_cluster_pattern("connection\\.sni"); | ||
config.set_cluster_replacement("replacement.sni"); | ||
|
||
Network::FilterFactoryCb cb = | ||
factory.createFilterFactoryFromProto(config, context); | ||
Network::MockConnection connection; | ||
EXPECT_CALL(connection, addReadFilter(_)); | ||
cb(connection); | ||
} | ||
|
||
} // namespace TcpClusterRewrite | ||
} // namespace Tcp | ||
} // namespace Envoy |
Oops, something went wrong.