You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by zw...@apache.org on 2020/04/09 18:08:46 UTC
[trafficserver] 02/02: Adds partial_blind_route sni action
This is an automated email from the ASF dual-hosted git repository.
zwoop pushed a commit to branch 9.0.x
in repository https://gitbox.apache.org/repos/asf/trafficserver.git
commit 58a636088540415019b7d98a944fa3be520cca5e
Author: Randall Meyer <rr...@apache.org>
AuthorDate: Thu Mar 19 14:00:15 2020 -0700
Adds partial_blind_route sni action
(cherry picked from commit 325029bba3a5281f7e7f562ec5108e507f3ca1a4)
---
doc/admin-guide/files/sni.yaml.en.rst | 7 +++
iocore/net/I_NetVConnection.h | 2 +
iocore/net/P_SNIActionPerformer.h | 13 ++--
iocore/net/P_SSLConfig.h | 1 +
iocore/net/P_SSLNetVConnection.h | 14 ++++-
iocore/net/P_SSLSNI.h | 1 +
iocore/net/SSLSNIConfig.cc | 3 +-
iocore/net/YamlSNIConfig.cc | 7 +++
iocore/net/YamlSNIConfig.h | 3 +
proxy/http/HttpConfig.h | 13 ++--
proxy/http/HttpSM.cc | 34 +++++------
proxy/http/HttpTransact.cc | 3 +-
.../tls/tls_partial_blind_tunnel.test.py | 70 ++++++++++++++++++++++
13 files changed, 136 insertions(+), 35 deletions(-)
diff --git a/doc/admin-guide/files/sni.yaml.en.rst b/doc/admin-guide/files/sni.yaml.en.rst
index 4d67807..76f5aa9 100644
--- a/doc/admin-guide/files/sni.yaml.en.rst
+++ b/doc/admin-guide/files/sni.yaml.en.rst
@@ -121,6 +121,13 @@ forward_route Destination as an FQDN and port, separated by a colon
This is similar to tunnel_route, but it terminates the TLS connection and forwards the
decrypted traffic. |TS| will not interpret the decrypted data, so the contents do not
need to be HTTP.
+
+partial_blind_route Destination as an FQDN and port, separated by a colon ``:``.
+
+ This is similar to forward_route in that |TS| terminates the incoming TLS connection. In
+ addition partial_blind_route creates a new TLS connection to the specified origin. It does
+ not interpret the decrypted data before passing it to the origin TLS connection, so
+ the contents do not need to be HTTP.
========================= ==============================================================================
Client verification, via ``verify_client``, corresponds to setting
diff --git a/iocore/net/I_NetVConnection.h b/iocore/net/I_NetVConnection.h
index f3bb310..4512d6e 100644
--- a/iocore/net/I_NetVConnection.h
+++ b/iocore/net/I_NetVConnection.h
@@ -213,6 +213,8 @@ struct NetVCOptions {
*/
const char *ssl_client_ca_cert_path = nullptr;
+ bool tls_upstream = false;
+
/// Reset all values to defaults.
/**
diff --git a/iocore/net/P_SNIActionPerformer.h b/iocore/net/P_SNIActionPerformer.h
index f3886b6..8dc95fe 100644
--- a/iocore/net/P_SNIActionPerformer.h
+++ b/iocore/net/P_SNIActionPerformer.h
@@ -92,7 +92,8 @@ private:
class TunnelDestination : public ActionItem
{
public:
- TunnelDestination(const std::string_view &dest, bool decrypt) : destination(dest), tunnel_decrypt(decrypt)
+ TunnelDestination(const std::string_view &dest, bool decrypt, bool tls_upstream)
+ : destination(dest), tunnel_decrypt(decrypt), tls_upstream(tls_upstream)
{
need_fix = (destination.find_first_of('$') != std::string::npos);
}
@@ -107,16 +108,14 @@ public:
// If needed, we will try to amend the tunnel destination.
if (ctx._fqdn_wildcard_captured_groups && need_fix) {
const auto &fixed_dst = replace_match_groups(destination, *ctx._fqdn_wildcard_captured_groups);
- ssl_netvc->set_tunnel_destination(fixed_dst, tunnel_decrypt);
+ ssl_netvc->set_tunnel_destination(fixed_dst, tunnel_decrypt, tls_upstream);
Debug("TunnelDestination", "Destination now is [%s], configured [%s]", fixed_dst.c_str(), destination.c_str());
} else {
- ssl_netvc->set_tunnel_destination(destination, tunnel_decrypt);
+ ssl_netvc->set_tunnel_destination(destination, tunnel_decrypt, tls_upstream);
}
}
return SSL_TLSEXT_ERR_OK;
}
- std::string destination;
- bool tunnel_decrypt = false;
private:
bool
@@ -184,7 +183,11 @@ private:
return real_dst;
}
+ std::string destination;
+
+ bool tunnel_decrypt;
bool need_fix;
+ bool tls_upstream;
};
class VerifyClient : public ActionItem
diff --git a/iocore/net/P_SSLConfig.h b/iocore/net/P_SSLConfig.h
index 628eb63..c11f20b 100644
--- a/iocore/net/P_SSLConfig.h
+++ b/iocore/net/P_SSLConfig.h
@@ -93,6 +93,7 @@ struct SSLConfigParams : public ConfigInfo {
char *clientCACertPath;
YamlSNIConfig::Policy verifyServerPolicy;
YamlSNIConfig::Property verifyServerProperties;
+ bool tls_server_connection;
int client_verify_depth;
long ssl_ctx_options;
long ssl_client_ctx_options;
diff --git a/iocore/net/P_SSLNetVConnection.h b/iocore/net/P_SSLNetVConnection.h
index 8145ec5..b18094b 100644
--- a/iocore/net/P_SSLNetVConnection.h
+++ b/iocore/net/P_SSLNetVConnection.h
@@ -357,7 +357,7 @@ public:
return tunnel_port;
}
- /* Returns true if this vc was configured for forward_route
+ /* Returns true if this vc was configured for forward_route or partial_blind_route
*/
bool
decrypt_tunnel()
@@ -365,8 +365,16 @@ public:
return has_tunnel_destination() && tunnel_decrypt;
}
+ /* Returns true if this vc was configured partial_blind_route
+ */
+ bool
+ upstream_tls()
+ {
+ return has_tunnel_destination() && tls_upstream;
+ }
+
void
- set_tunnel_destination(const std::string_view &destination, bool decrypt)
+ set_tunnel_destination(const std::string_view &destination, bool decrypt, bool upstream_tls)
{
auto pos = destination.find(":");
if (nullptr != tunnel_host) {
@@ -380,6 +388,7 @@ public:
tunnel_host = ats_strndup(destination.data(), destination.length());
}
tunnel_decrypt = decrypt;
+ tls_upstream = upstream_tls;
}
int populate_protocol(std::string_view *results, int n) const override;
@@ -486,6 +495,7 @@ private:
char *tunnel_host = nullptr;
in_port_t tunnel_port = 0;
bool tunnel_decrypt = false;
+ bool tls_upstream = false;
X509_STORE_CTX *verify_cert = nullptr;
// Null-terminated string, or nullptr if there is no SNI server name.
diff --git a/iocore/net/P_SSLSNI.h b/iocore/net/P_SSLSNI.h
index f121b6d..6e83c2f 100644
--- a/iocore/net/P_SSLSNI.h
+++ b/iocore/net/P_SSLSNI.h
@@ -45,6 +45,7 @@ struct NextHopProperty {
std::string client_key_file; // full path to client key file for lookup
YamlSNIConfig::Policy verifyServerPolicy = YamlSNIConfig::Policy::UNSET; // whether to verify the next hop
YamlSNIConfig::Property verifyServerProperties = YamlSNIConfig::Property::UNSET; // what to verify on the next hop
+ bool tls_upstream = false; // whether the upstream connection should be TLS
SSL_CTX *ctx = nullptr; // ctx generated off the certificate to present to this server
NextHopProperty() {}
diff --git a/iocore/net/SSLSNIConfig.cc b/iocore/net/SSLSNIConfig.cc
index 61f7dad..a77ed90 100644
--- a/iocore/net/SSLSNIConfig.cc
+++ b/iocore/net/SSLSNIConfig.cc
@@ -78,7 +78,7 @@ SNIConfigParams::loadSNIConfig()
ai->actions.push_back(std::make_unique<TLSValidProtocols>(item.protocol_mask));
}
if (item.tunnel_destination.length() > 0) {
- ai->actions.push_back(std::make_unique<TunnelDestination>(item.tunnel_destination, item.tunnel_decrypt));
+ ai->actions.push_back(std::make_unique<TunnelDestination>(item.tunnel_destination, item.tunnel_decrypt, item.tls_upstream));
}
ai->actions.push_back(std::make_unique<SNI_IpAllow>(item.ip_allow, item.fqdn));
@@ -102,6 +102,7 @@ SNIConfigParams::loadSNIConfig()
nps->setGlobName(item.fqdn);
nps->prop.verifyServerPolicy = item.verify_server_policy;
nps->prop.verifyServerProperties = item.verify_server_properties;
+ nps->prop.tls_upstream = item.tls_upstream;
} // end for
}
diff --git a/iocore/net/YamlSNIConfig.cc b/iocore/net/YamlSNIConfig.cc
index b7b053a..e467903 100644
--- a/iocore/net/YamlSNIConfig.cc
+++ b/iocore/net/YamlSNIConfig.cc
@@ -98,6 +98,7 @@ std::set<std::string> valid_sni_config_keys = {TS_fqdn,
TS_verify_client,
TS_tunnel_route,
TS_forward_route,
+ TS_partial_blind_route,
TS_verify_origin_server,
TS_verify_server_policy,
TS_verify_server_properties,
@@ -154,9 +155,15 @@ template <> struct convert<YamlSNIConfig::Item> {
if (node[TS_tunnel_route]) {
item.tunnel_destination = node[TS_tunnel_route].as<std::string>();
item.tunnel_decrypt = false;
+ item.tls_upstream = false;
} else if (node[TS_forward_route]) {
item.tunnel_destination = node[TS_forward_route].as<std::string>();
item.tunnel_decrypt = true;
+ item.tls_upstream = false;
+ } else if (node[TS_partial_blind_route]) {
+ item.tunnel_destination = node[TS_partial_blind_route].as<std::string>();
+ item.tunnel_decrypt = true;
+ item.tls_upstream = true;
}
// remove before 9.0.0 release
diff --git a/iocore/net/YamlSNIConfig.h b/iocore/net/YamlSNIConfig.h
index 9644d24..a94fc2b 100644
--- a/iocore/net/YamlSNIConfig.h
+++ b/iocore/net/YamlSNIConfig.h
@@ -33,6 +33,7 @@ TSDECL(disable_h2);
TSDECL(verify_client);
TSDECL(tunnel_route);
TSDECL(forward_route);
+TSDECL(partial_blind_route);
TSDECL(verify_server_policy);
TSDECL(verify_server_properties);
TSDECL(verify_origin_server);
@@ -51,6 +52,7 @@ struct YamlSNIConfig {
verify_client,
tunnel_route, // blind tunnel action
forward_route, // decrypt data and then blind tunnel action
+ partial_blind_route, // decrypt data; partial blind routing
verify_server_policy, // this applies to server side vc only
verify_server_properties, // this applies to server side vc only
client_cert,
@@ -72,6 +74,7 @@ struct YamlSNIConfig {
uint8_t host_sni_policy = 255;
std::string tunnel_destination;
bool tunnel_decrypt = false;
+ bool tls_upstream = false;
Policy verify_server_policy = Policy::UNSET;
Property verify_server_properties = Property::UNSET;
std::string client_cert;
diff --git a/proxy/http/HttpConfig.h b/proxy/http/HttpConfig.h
index 42f15cf..bf567bd 100644
--- a/proxy/http/HttpConfig.h
+++ b/proxy/http/HttpConfig.h
@@ -464,9 +464,8 @@ struct OverridableHttpConfigParams {
MgmtByte keep_alive_enabled_out = 1;
MgmtByte keep_alive_post_out = 1; // share server sessions for post
- MgmtInt server_min_keep_alive_conns = 0;
- MgmtByte server_session_sharing_match = TS_SERVER_SESSION_SHARING_MATCH_BOTH;
- // MgmtByte share_server_sessions;
+ MgmtInt server_min_keep_alive_conns = 0;
+ MgmtByte server_session_sharing_match = TS_SERVER_SESSION_SHARING_MATCH_BOTH;
MgmtByte auth_server_session_private = 1;
MgmtByte fwd_proxy_auth_to_parent = 0;
MgmtByte uncacheable_requests_bypass_parent = 1;
@@ -562,9 +561,9 @@ struct OverridableHttpConfigParams {
/////////////////////////////////////////////////
MgmtByte allow_half_open = 1;
- /////////////////////////////
- // server verification mode//
- /////////////////////////////
+ //////////////////////////////
+ // server verification mode //
+ //////////////////////////////
MgmtByte ssl_client_verify_server = 0;
char *ssl_client_verify_server_policy = nullptr;
char *ssl_client_verify_server_properties = nullptr;
@@ -670,7 +669,7 @@ struct OverridableHttpConfigParams {
size_t proxy_response_server_string_len = 0; // Updated when server_string is set.
///////////////////////////////////////////////////////////////////
- // Global User Agent header //
+ // Global User Agent header //
///////////////////////////////////////////////////////////////////
char *global_user_agent_header = nullptr; // This does not get free'd by us!
size_t global_user_agent_header_size = 0; // Updated when user_agent is set.
diff --git a/proxy/http/HttpSM.cc b/proxy/http/HttpSM.cc
index fa43824..8b1483c 100644
--- a/proxy/http/HttpSM.cc
+++ b/proxy/http/HttpSM.cc
@@ -276,8 +276,6 @@ HttpSM::cleanup()
api_hooks.clear();
http_parser_clear(&http_parser);
- // t_state.content_control.cleanup();
-
HttpConfig::release(t_state.http_config_param);
m_remap->release();
@@ -488,6 +486,7 @@ HttpSM::attach_client_session(ProxyTransaction *client_vc, IOBufferReader *buffe
milestones[TS_MILESTONE_TLS_HANDSHAKE_END] = ssl_vc->sslHandshakeEndTime;
}
}
+
const char *protocol_str = client_vc->get_protocol_string();
client_protocol = protocol_str ? protocol_str : "-";
@@ -584,6 +583,7 @@ HttpSM::setup_blind_tunnel_port()
t_state.hdr_info.client_request.url_create(&u);
u.scheme_set(URL_SCHEME_TUNNEL, URL_LEN_TUNNEL);
t_state.hdr_info.client_request.url_set(&u);
+
if (ssl_vc->has_tunnel_destination()) {
const char *tunnel_host = ssl_vc->get_tunnel_host();
t_state.hdr_info.client_request.url_get()->host_set(tunnel_host, strlen(tunnel_host));
@@ -4049,18 +4049,6 @@ HttpSM::do_remap_request(bool run_inline)
void
HttpSM::do_hostdb_lookup()
{
- /*
- //////////////////////////////////////////
- // if a connection to the origin server //
- // is currently opened --- close it. //
- //////////////////////////////////////////
- if (m_origin_server_vc != 0) {
- origin_server_close(CLOSE_CONNECTION);
- if (m_response_body_tunnel_buffer_.buf() != 0)
- m_response_body_tunnel_buffer_.reset();
- }
- */
-
ink_assert(t_state.dns_info.lookup_name != nullptr);
ink_assert(pending_action == nullptr);
@@ -4890,7 +4878,7 @@ HttpSM::do_http_server_open(bool raw)
set_server_session_private(true);
}
- if (raw == false && TS_SERVER_SESSION_SHARING_MATCH_NONE != t_state.txn_conf->server_session_sharing_match &&
+ if ((raw == false) && TS_SERVER_SESSION_SHARING_MATCH_NONE != t_state.txn_conf->server_session_sharing_match &&
(t_state.txn_conf->keep_alive_post_out == 1 || t_state.hdr_info.request_content_length == 0) && !is_private() &&
ua_txn != nullptr) {
HSMresult_t shared_result;
@@ -5041,7 +5029,13 @@ HttpSM::do_http_server_open(bool raw)
opt.ip_family = ip_family;
+ int scheme_to_use = t_state.scheme; // get initial scheme
+ bool tls_upstream = scheme_to_use == URL_WKSIDX_HTTPS;
if (ua_txn) {
+ SSLNetVConnection *ssl_vc = dynamic_cast<SSLNetVConnection *>(ua_txn->get_netvc());
+ if (ssl_vc && raw) {
+ tls_upstream = ssl_vc->upstream_tls();
+ }
opt.local_port = ua_txn->get_outbound_port();
const IpAddr &outbound_ip = AF_INET6 == opt.ip_family ? ua_txn->get_outbound_ip6() : ua_txn->get_outbound_ip4();
@@ -5064,8 +5058,6 @@ HttpSM::do_http_server_open(bool raw)
}
}
- int scheme_to_use = t_state.scheme; // get initial scheme
-
if (!t_state.is_websocket) { // if not websocket, then get scheme from server request
int new_scheme_to_use = t_state.hdr_info.server_request.url_get()->scheme_get_wksidx();
// if the server_request url scheme was never set, try the client_request
@@ -5075,19 +5067,23 @@ HttpSM::do_http_server_open(bool raw)
if (new_scheme_to_use >= 0) { // found a new scheme, use it
scheme_to_use = new_scheme_to_use;
}
+ if (!tls_upstream) {
+ tls_upstream = scheme_to_use == URL_WKSIDX_HTTPS;
+ }
}
// draft-stenberg-httpbis-tcp recommends only enabling TFO on indempotent methods or
// those with intervening protocol layers (eg. TLS).
- if (scheme_to_use == URL_WKSIDX_HTTPS || HttpTransactHeaders::is_method_idempotent(t_state.method)) {
+ if (tls_upstream || HttpTransactHeaders::is_method_idempotent(t_state.method)) {
opt.f_tcp_fastopen = (t_state.txn_conf->sock_option_flag_out & NetVCOptions::SOCK_OPT_TCP_FAST_OPEN);
}
+
opt.ssl_client_cert_name = t_state.txn_conf->ssl_client_cert_filename;
opt.ssl_client_private_key_name = t_state.txn_conf->ssl_client_private_key_filename;
opt.ssl_client_ca_cert_name = t_state.txn_conf->ssl_client_ca_cert_filename;
- if (scheme_to_use == URL_WKSIDX_HTTPS) {
+ if (tls_upstream) {
SMDebug("http", "calling sslNetProcessor.connect_re");
int len = 0;
diff --git a/proxy/http/HttpTransact.cc b/proxy/http/HttpTransact.cc
index 79d87fe..6ff0ccf 100644
--- a/proxy/http/HttpTransact.cc
+++ b/proxy/http/HttpTransact.cc
@@ -5416,7 +5416,8 @@ HttpTransact::check_request_validity(State *s, HTTPHdr *incoming_hdr)
HttpTransact::ResponseError_t
HttpTransact::check_response_validity(State *s, HTTPHdr *incoming_hdr)
{
- ink_assert(s->next_hop_scheme == URL_WKSIDX_HTTP || s->next_hop_scheme == URL_WKSIDX_HTTPS);
+ ink_assert(s->next_hop_scheme == URL_WKSIDX_HTTP || s->next_hop_scheme == URL_WKSIDX_HTTPS ||
+ s->next_hop_scheme == URL_WKSIDX_TUNNEL);
if (incoming_hdr == nullptr) {
return NON_EXISTANT_RESPONSE_HEADER;
diff --git a/tests/gold_tests/tls/tls_partial_blind_tunnel.test.py b/tests/gold_tests/tls/tls_partial_blind_tunnel.test.py
new file mode 100644
index 0000000..59def68
--- /dev/null
+++ b/tests/gold_tests/tls/tls_partial_blind_tunnel.test.py
@@ -0,0 +1,70 @@
+'''
+'''
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you 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.
+
+Test.Summary = 'Testing partial_blind_tunnel'
+
+ts = Test.MakeATSProcess("ts", select_ports=True, enable_tls=True)
+server_bar = Test.MakeOriginServer("server_bar", ssl=True)
+
+request_bar_header = {"headers": "GET / HTTP/1.1\r\nHost: bar.com\r\n\r\n", "timestamp": "1469733493.993", "body": ""}
+response_bar_header = {"headers": "HTTP/1.1 200 OK\r\nConnection: close\r\n\r\n", "timestamp": "1469733493.993", "body": "ok bar"}
+server_bar.addResponse("sessionlog_bar.json", request_bar_header, response_bar_header)
+
+# add ssl materials like key, certificates for the server
+ts.addSSLfile("ssl/signed-foo.pem")
+ts.addSSLfile("ssl/signed-foo.key")
+ts.addSSLfile("ssl/signed-bar.pem")
+ts.addSSLfile("ssl/signed-bar.key")
+ts.addSSLfile("ssl/signer.pem")
+
+# Need no remap rules. Everything should be proccessed by sni
+
+# Make sure the TS server certs are different from the origin certs
+ts.Disk.ssl_multicert_config.AddLine(
+ 'dest_ip=* ssl_cert_name=signed-foo.pem ssl_key_name=signed-foo.key'
+)
+
+# Case 1, global config policy=permissive properties=signature
+# override for foo.com policy=enforced properties=all
+ts.Disk.records_config.update({
+ 'proxy.config.ssl.server.cert.path': '{0}'.format(ts.Variables.SSLDir),
+ 'proxy.config.ssl.server.private_key.path': '{0}'.format(ts.Variables.SSLDir),
+ 'proxy.config.http.connect_ports': '{0} {1}'.format(ts.Variables.ssl_port, server_bar.Variables.SSL_Port),
+ 'proxy.config.ssl.client.CA.cert.path': '{0}'.format(ts.Variables.SSLDir),
+ 'proxy.config.ssl.client.CA.cert.filename': 'signer.pem',
+})
+
+# foo.com should terminate. and reconnect via TLS upstream to bar.com
+ts.Disk.sni_yaml.AddLines([
+ "sni:",
+ "- fqdn: 'foo.com'",
+ " partial_blind_route: 'localhost:{0}'".format(server_bar.Variables.SSL_Port),
+ ])
+
+tr = Test.AddTestRun("Partial Blind Route")
+tr.Processes.Default.Command = "curl --http1.1 -v --resolve 'foo.com:{0}:127.0.0.1' -k https://foo.com:{0}".format(ts.Variables.ssl_port)
+tr.ReturnCode = 0
+tr.Processes.Default.StartBefore(server_bar)
+tr.Processes.Default.StartBefore(Test.Processes.ts)
+tr.StillRunningAfter = ts
+
+tr.Processes.Default.Streams.All += Testers.ExcludesExpression("Could Not Connect", "Curl attempt should have succeeded")
+tr.Processes.Default.Streams.All += Testers.ExcludesExpression("Not Found on Accelerato",
+ "Should not try to remap on Traffic Server")
+tr.Processes.Default.Streams.All += Testers.ContainsExpression("HTTP/1.1 200 OK", "Should get a successful response")
+tr.Processes.Default.Streams.All += Testers.ContainsExpression("ok bar", "Body is expected")