Skip to content
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
9 changes: 9 additions & 0 deletions docs/configuration/http_conn_man/headers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ authentication TLS mesh which will make this header fully secure. Like *user-age
is determined by the :option:`--service-cluster` command line option. In order to enable this
feature you need to set the :ref:`user_agent <config_http_conn_man_add_user_agent>` option to true.

.. _config_http_conn_man_headers_downstream-service-node:

x-envoy-downstream-service-node
-------------------------------

Internal services may want to know the downstream node request comes from. This header
is quite similar to :ref:`config_http_conn_man_headers_downstream-service-cluster`, except the value is taken from
the :option:`--service-node` option.

.. _config_http_conn_man_headers_x-envoy-external-address:

x-envoy-external-address
Expand Down
1 change: 1 addition & 0 deletions include/envoy/http/header_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ class HeaderEntry {
HEADER_FUNC(ContentType) \
HEADER_FUNC(Date) \
HEADER_FUNC(EnvoyDownstreamServiceCluster) \
HEADER_FUNC(EnvoyDownstreamServiceNode) \
HEADER_FUNC(EnvoyExpectedRequestTimeoutMs) \
HEADER_FUNC(EnvoyExternalAddress) \
HEADER_FUNC(EnvoyForceTrace) \
Expand Down
1 change: 1 addition & 0 deletions source/common/http/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ envoy_cc_library(
"//include/envoy/http:codec_interface",
"//include/envoy/http:filter_interface",
"//include/envoy/http:header_map_interface",
"//include/envoy/local_info:local_info_interface",
"//include/envoy/network:connection_interface",
"//include/envoy/network:drain_decision_interface",
"//include/envoy/network:filter_interface",
Expand Down
7 changes: 4 additions & 3 deletions source/common/http/conn_manager_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,12 @@ ConnectionManagerTracingStats ConnectionManagerImpl::generateTracingStats(const
ConnectionManagerImpl::ConnectionManagerImpl(ConnectionManagerConfig& config,
Network::DrainDecision& drain_close,
Runtime::RandomGenerator& random_generator,
Tracing::HttpTracer& tracer, Runtime::Loader& runtime)
Tracing::HttpTracer& tracer, Runtime::Loader& runtime,
const LocalInfo::LocalInfo& local_info)
: config_(config), stats_(config_.stats()),
conn_length_(stats_.named_.downstream_cx_length_ms_.allocateSpan()),
drain_close_(drain_close), random_generator_(random_generator), tracer_(tracer),
runtime_(runtime) {}
runtime_(runtime), local_info_(local_info) {}

void ConnectionManagerImpl::initializeReadFilterCallbacks(Network::ReadFilterCallbacks& callbacks) {
read_callbacks_ = &callbacks;
Expand Down Expand Up @@ -465,7 +466,7 @@ void ConnectionManagerImpl::ActiveStream::decodeHeaders(HeaderMapPtr&& headers,
ConnectionManagerUtility::mutateRequestHeaders(
*request_headers_, connection_manager_.read_callbacks_->connection(),
connection_manager_.config_, *snapped_route_config_, connection_manager_.random_generator_,
connection_manager_.runtime_);
connection_manager_.runtime_, connection_manager_.local_info_);

// Check if tracing is enabled at all.
if (connection_manager_.config_.tracingConfig()) {
Expand Down
3 changes: 2 additions & 1 deletion source/common/http/conn_manager_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ class ConnectionManagerImpl : Logger::Loggable<Logger::Id::http>,
public:
ConnectionManagerImpl(ConnectionManagerConfig& config, Network::DrainDecision& drain_close,
Runtime::RandomGenerator& random_generator, Tracing::HttpTracer& tracer,
Runtime::Loader& runtime);
Runtime::Loader& runtime, const LocalInfo::LocalInfo& local_info);
~ConnectionManagerImpl();

static ConnectionManagerStats generateStats(const std::string& prefix, Stats::Store& stats);
Expand Down Expand Up @@ -504,6 +504,7 @@ class ConnectionManagerImpl : Logger::Loggable<Logger::Id::http>,
Runtime::RandomGenerator& random_generator_;
Tracing::HttpTracer& tracer_;
Runtime::Loader& runtime_;
const LocalInfo::LocalInfo& local_info_;
Network::ReadFilterCallbacks* read_callbacks_{};
};

Expand Down
8 changes: 7 additions & 1 deletion source/common/http/conn_manager_utility.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ void ConnectionManagerUtility::mutateRequestHeaders(Http::HeaderMap& request_hea
ConnectionManagerConfig& config,
const Router::Config& route_config,
Runtime::RandomGenerator& random,
Runtime::Loader& runtime) {
Runtime::Loader& runtime,
const LocalInfo::LocalInfo& local_info) {
// Clean proxy headers.
request_headers.removeConnection();
request_headers.removeEnvoyInternalRequest();
Expand Down Expand Up @@ -76,6 +77,7 @@ void ConnectionManagerUtility::mutateRequestHeaders(Http::HeaderMap& request_hea
} else {
if (edge_request) {
request_headers.removeEnvoyDownstreamServiceCluster();
request_headers.removeEnvoyDownstreamServiceNode();
}

request_headers.removeEnvoyRetryOn();
Expand All @@ -97,6 +99,10 @@ void ConnectionManagerUtility::mutateRequestHeaders(Http::HeaderMap& request_hea
if (user_agent_header.value().empty()) {
user_agent_header.value(config.userAgent().value());
}

if (!local_info.nodeName().empty()) {
request_headers.insertEnvoyDownstreamServiceNode().value(local_info.nodeName());
}
}

// If we are an external request, AND we are "using remote address" (see above), we set
Expand Down
3 changes: 2 additions & 1 deletion source/common/http/conn_manager_utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ class ConnectionManagerUtility {
static void mutateRequestHeaders(Http::HeaderMap& request_headers,
Network::Connection& connection, ConnectionManagerConfig& config,
const Router::Config& route_config,
Runtime::RandomGenerator& random, Runtime::Loader& runtime);
Runtime::RandomGenerator& random, Runtime::Loader& runtime,
const LocalInfo::LocalInfo& local_info);

static void mutateResponseHeaders(Http::HeaderMap& response_headers,
const Http::HeaderMap& request_headers,
Expand Down
1 change: 1 addition & 0 deletions source/common/http/headers.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class HeaderValues {
const LowerCaseString Cookie{"cookie"};
const LowerCaseString Date{"date"};
const LowerCaseString EnvoyDownstreamServiceCluster{"x-envoy-downstream-service-cluster"};
const LowerCaseString EnvoyDownstreamServiceNode{"x-envoy-downstream-service-node"};
const LowerCaseString EnvoyExternalAddress{"x-envoy-external-address"};
const LowerCaseString EnvoyForceTrace{"x-envoy-force-trace"};
const LowerCaseString EnvoyInternalRequest{"x-envoy-internal"};
Expand Down
6 changes: 3 additions & 3 deletions source/server/config/network/http_connection_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ NetworkFilterFactoryCb HttpConnectionManagerFilterConfigFactory::createFilterFac
std::shared_ptr<HttpConnectionManagerConfig> http_config(
new HttpConnectionManagerConfig(config, server));
return [http_config, &server](Network::FilterManager& filter_manager) mutable -> void {
filter_manager.addReadFilter(Network::ReadFilterSharedPtr{
new Http::ConnectionManagerImpl(*http_config, server.drainManager(), server.random(),
server.httpTracer(), server.runtime())});
filter_manager.addReadFilter(Network::ReadFilterSharedPtr{new Http::ConnectionManagerImpl(
*http_config, server.drainManager(), server.random(), server.httpTracer(), server.runtime(),
server.localInfo())});
};
}

Expand Down
3 changes: 2 additions & 1 deletion source/server/http/admin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,8 @@ Http::ServerConnectionPtr AdminImpl::createCodec(Network::Connection& connection

bool AdminImpl::createFilterChain(Network::Connection& connection) {
connection.addReadFilter(Network::ReadFilterSharedPtr{new Http::ConnectionManagerImpl(
*this, server_.drainManager(), server_.random(), server_.httpTracer(), server_.runtime())});
*this, server_.drainManager(), server_.random(), server_.httpTracer(), server_.runtime(),
server_.localInfo())});
return true;
}

Expand Down
2 changes: 2 additions & 0 deletions test/common/http/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ envoy_cc_test(
"//test/mocks/access_log:access_log_mocks",
"//test/mocks/buffer:buffer_mocks",
"//test/mocks/http:http_mocks",
"//test/mocks/local_info:local_info_mocks",
"//test/mocks/network:network_mocks",
"//test/mocks/runtime:runtime_mocks",
"//test/mocks/ssl:ssl_mocks",
Expand All @@ -118,6 +119,7 @@ envoy_cc_test(
"//source/common/runtime:runtime_lib",
"//source/common/runtime:uuid_util_lib",
"//test/mocks/http:http_mocks",
"//test/mocks/local_info:local_info_mocks",
"//test/mocks/network:network_mocks",
"//test/mocks/runtime:runtime_mocks",
"//test/mocks/upstream:upstream_mocks",
Expand Down
5 changes: 4 additions & 1 deletion test/common/http/conn_manager_impl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "test/mocks/buffer/mocks.h"
#include "test/mocks/common.h"
#include "test/mocks/http/mocks.h"
#include "test/mocks/local_info/mocks.h"
#include "test/mocks/network/mocks.h"
#include "test/mocks/runtime/mocks.h"
#include "test/mocks/ssl/mocks.h"
Expand Down Expand Up @@ -89,7 +90,8 @@ class HttpConnectionManagerImplTest : public Test, public ConnectionManagerConfi
ON_CALL(filter_callbacks_.connection_, ssl()).WillByDefault(Return(ssl_connection_.get()));
ON_CALL(filter_callbacks_.connection_, remoteAddress())
.WillByDefault(ReturnRef(remote_address_));
conn_manager_.reset(new ConnectionManagerImpl(*this, drain_close_, random_, tracer_, runtime_));
conn_manager_.reset(
new ConnectionManagerImpl(*this, drain_close_, random_, tracer_, runtime_, local_info_));
conn_manager_->initializeReadFilterCallbacks(filter_callbacks_);
}

Expand Down Expand Up @@ -177,6 +179,7 @@ class HttpConnectionManagerImplTest : public Test, public ConnectionManagerConfi
Optional<std::string> user_agent_;
Optional<std::chrono::milliseconds> idle_timeout_;
NiceMock<Runtime::MockRandomGenerator> random_;
NiceMock<LocalInfo::MockLocalInfo> local_info_;
std::unique_ptr<Ssl::MockConnection> ssl_connection_;
RouteConfigProvider route_config_provider_;
TracingConnectionManagerConfigPtr tracing_config_;
Expand Down
Loading