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
3 changes: 3 additions & 0 deletions include/istio/control/http/check_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ class CheckData {
// Returns true if connection is mutual TLS enabled.
virtual bool IsMutualTLS() const = 0;

// Get requested server name, SNI in case of TLS
virtual bool GetRequestedServerName(std::string *name) const = 0;

// These headers are extracted into top level attributes.
// This is for standard HTTP headers. It supports both HTTP/1.1 and HTTP2
// They can be retrieved at O(1) speed by environment (Envoy).
Expand Down
3 changes: 3 additions & 0 deletions include/istio/control/tcp/check_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ class CheckData {
// Returns true if connection is mutual TLS enabled.
virtual bool IsMutualTLS() const = 0;

// Get requested server name, SNI in case of TLS
virtual bool GetRequestedServerName(std::string* name) const = 0;

// Get downstream tcp connection id.
virtual std::string GetConnectionId() const = 0;
};
Expand Down
1 change: 1 addition & 0 deletions include/istio/utils/attribute_names.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ struct AttributeName {
static const char kConnectionSendTotalBytes[];
static const char kConnectionDuration[];
static const char kConnectionMtls[];
static const char kConnectionRequestedServerName[];
static const char kConnectionId[];
// Record TCP connection status: open, continue, close
static const char kConnectionEvent[];
Expand Down
4 changes: 4 additions & 0 deletions src/envoy/http/mixer/check_data.cc
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ std::map<std::string, std::string> CheckData::GetRequestHeaders() const {

bool CheckData::IsMutualTLS() const { return Utils::IsMutualTLS(connection_); }

bool CheckData::GetRequestedServerName(std::string* name) const {
return Utils::GetRequestedServerName(connection_, name);
}

bool CheckData::FindHeaderByType(HttpCheckData::HeaderType header_type,
std::string* value) const {
switch (header_type) {
Expand Down
2 changes: 2 additions & 0 deletions src/envoy/http/mixer/check_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ class CheckData : public ::istio::control::http::CheckData,

bool IsMutualTLS() const override;

bool GetRequestedServerName(std::string* name) const override;

bool FindHeaderByType(
::istio::control::http::CheckData::HeaderType header_type,
std::string* value) const override;
Expand Down
4 changes: 4 additions & 0 deletions src/envoy/tcp/mixer/filter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@ bool Filter::IsMutualTLS() const {
return Utils::IsMutualTLS(&filter_callbacks_->connection());
}

bool Filter::GetRequestedServerName(std::string* name) const {
return Utils::GetRequestedServerName(&filter_callbacks_->connection(), name);
}

bool Filter::GetDestinationIpPort(std::string* str_ip, int* port) const {
if (filter_callbacks_->upstreamHost() &&
filter_callbacks_->upstreamHost()->address()) {
Expand Down
1 change: 1 addition & 0 deletions src/envoy/tcp/mixer/filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class Filter : public Network::Filter,
bool GetSourceIpPort(std::string* str_ip, int* port) const override;
bool GetSourceUser(std::string* user) const override;
bool IsMutualTLS() const override;
bool GetRequestedServerName(std::string* name) const override;

// ReportData virtual functions.
bool GetDestinationIpPort(std::string* str_ip, int* port) const override;
Expand Down
10 changes: 10 additions & 0 deletions src/envoy/utils/utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,16 @@ bool IsMutualTLS(const Network::Connection* connection) {
connection->ssl()->peerCertificatePresented();
}

bool GetRequestedServerName(const Network::Connection* connection,
std::string* name) {
if (connection) {
*name = std::string(connection->requestedServerName());
return true;
}

return false;
}

Status ParseJsonMessage(const std::string& json, Message* output) {
::google::protobuf::util::JsonParseOptions options;
options.ignore_unknown_fields = true;
Expand Down
4 changes: 4 additions & 0 deletions src/envoy/utils/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ bool GetSourceUser(const Network::Connection* connection, std::string* user);
// Returns true if connection is mutual TLS enabled.
bool IsMutualTLS(const Network::Connection* connection);

// Get requested server name, SNI in case of TLS
bool GetRequestedServerName(const Network::Connection* connection,
std::string* name);

// Parse JSON string into message.
::google::protobuf::util::Status ParseJsonMessage(
const std::string& json, ::google::protobuf::Message* output);
Expand Down
6 changes: 6 additions & 0 deletions src/istio/control/http/attributes_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,12 @@ void AttributesBuilder::ExtractCheckAttributes(CheckData *check_data) {
builder.AddBool(utils::AttributeName::kConnectionMtls,
check_data->IsMutualTLS());

std::string requested_server_name;
if (check_data->GetRequestedServerName(&requested_server_name)) {
builder.AddString(utils::AttributeName::kConnectionRequestedServerName,
requested_server_name);
}

builder.AddTimestamp(utils::AttributeName::kRequestTime,
std::chrono::system_clock::now());

Expand Down
16 changes: 16 additions & 0 deletions src/istio/control/http/attributes_builder_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ attributes {
bool_value: true
}
}
attributes {
key: "connection.requested_server_name"
value {
string_value: "www.google.com"
}
}
attributes {
key: "source.principal"
value {
Expand Down Expand Up @@ -286,6 +292,11 @@ TEST(AttributesBuilderTest, TestCheckAttributes) {
EXPECT_CALL(mock_data, IsMutualTLS()).WillOnce(Invoke([]() -> bool {
return true;
}));
EXPECT_CALL(mock_data, GetRequestedServerName(_))
.WillOnce(Invoke([](std::string *name) -> bool {
*name = "www.google.com";
return true;
}));
EXPECT_CALL(mock_data, GetRequestHeaders())
.WillOnce(Invoke([]() -> std::map<std::string, std::string> {
std::map<std::string, std::string> map;
Expand Down Expand Up @@ -341,6 +352,11 @@ TEST(AttributesBuilderTest, TestCheckAttributesWithAuthNResult) {
EXPECT_CALL(mock_data, IsMutualTLS()).WillOnce(Invoke([]() -> bool {
return true;
}));
EXPECT_CALL(mock_data, GetRequestedServerName(_))
.WillOnce(Invoke([](std::string *name) -> bool {
*name = "www.google.com";
return true;
}));
EXPECT_CALL(mock_data, GetRequestHeaders())
.WillOnce(Invoke([]() -> std::map<std::string, std::string> {
std::map<std::string, std::string> map;
Expand Down
1 change: 1 addition & 0 deletions src/istio/control/http/mock_check_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class MockCheckData : public CheckData {
MOCK_CONST_METHOD1(GetAuthenticationResult,
bool(istio::authn::Result *result));
MOCK_CONST_METHOD0(IsMutualTLS, bool());
MOCK_CONST_METHOD1(GetRequestedServerName, bool(std::string *name));
};

// The mock object for HeaderUpdate interface.
Expand Down
6 changes: 6 additions & 0 deletions src/istio/control/tcp/attributes_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ void AttributesBuilder::ExtractCheckAttributes(CheckData* check_data) {
builder.AddBool(utils::AttributeName::kConnectionMtls,
check_data->IsMutualTLS());

std::string requested_server_name;
if (check_data->GetRequestedServerName(&requested_server_name)) {
builder.AddString(utils::AttributeName::kConnectionRequestedServerName,
requested_server_name);
}

builder.AddTimestamp(utils::AttributeName::kContextTime,
std::chrono::system_clock::now());
builder.AddString(utils::AttributeName::kContextProtocol, "tcp");
Expand Down
12 changes: 11 additions & 1 deletion src/istio/control/tcp/attributes_builder_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ attributes {
bool_value: true
}
}
attributes {
key: "connection.requested_server_name"
value {
string_value: "www.google.com"
}
}
attributes {
key: "source.principal"
value {
Expand Down Expand Up @@ -305,7 +311,11 @@ TEST(AttributesBuilderTest, TestCheckAttributes) {
return true;
}));
EXPECT_CALL(mock_data, GetConnectionId()).WillOnce(Return("1234-5"));

EXPECT_CALL(mock_data, GetRequestedServerName(_))
.WillOnce(Invoke([](std::string* name) -> bool {
*name = "www.google.com";
return true;
}));
RequestContext request;
AttributesBuilder builder(&request);
builder.ExtractCheckAttributes(&mock_data);
Expand Down
1 change: 1 addition & 0 deletions src/istio/control/tcp/mock_check_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class MockCheckData : public CheckData {
MOCK_CONST_METHOD2(GetSourceIpPort, bool(std::string* ip, int* port));
MOCK_CONST_METHOD1(GetSourceUser, bool(std::string* user));
MOCK_CONST_METHOD0(IsMutualTLS, bool());
MOCK_CONST_METHOD1(GetRequestedServerName, bool(std::string* name));
MOCK_CONST_METHOD0(GetConnectionId, std::string());
};

Expand Down
3 changes: 3 additions & 0 deletions src/istio/utils/attribute_names.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ const char AttributeName::kConnectionSendTotalBytes[] =
"connection.sent.bytes_total";
const char AttributeName::kConnectionDuration[] = "connection.duration";
const char AttributeName::kConnectionMtls[] = "connection.mtls";
const char AttributeName::kConnectionRequestedServerName[] =
"connection.requested_server_name";

// Downstream TCP connection id.
const char AttributeName::kConnectionId[] = "connection.id";
const char AttributeName::kConnectionEvent[] = "connection.event";
Expand Down