Skip to content
Closed
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
2 changes: 1 addition & 1 deletion include/istio/control/http/check_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class CheckData {
virtual bool IsMutualTLS() const = 0;

// Get requested server name, SNI in case of TLS
virtual std::string GetRequestedServerName() const = 0;
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
Expand Down
2 changes: 1 addition & 1 deletion include/istio/control/tcp/check_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class CheckData {
virtual bool IsMutualTLS() const = 0;

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

// Get downstream tcp connection id.
virtual std::string GetConnectionId() const = 0;
Expand Down
8 changes: 2 additions & 6 deletions src/envoy/http/mixer/check_data.cc
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,8 @@ std::map<std::string, std::string> CheckData::GetRequestHeaders() const {

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

std::string CheckData::GetRequestedServerName() const {
if (connection_) {
return std::string(connection_->requestedServerName());
}

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

bool CheckData::FindHeaderByType(HttpCheckData::HeaderType header_type,
Expand Down
2 changes: 1 addition & 1 deletion src/envoy/tcp/mixer/filter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ bool Filter::IsMutualTLS() const {
}

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

bool Filter::GetDestinationIpPort(std::string* str_ip, int* port) const {
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
4 changes: 2 additions & 2 deletions src/istio/control/http/attributes_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ void AttributesBuilder::ExtractCheckAttributes(CheckData *check_data) {
builder.AddBool(utils::AttributeName::kConnectionMtls,
check_data->IsMutualTLS());

std::string requested_server_name = check_data->GetRequestedServerName();
if (!requested_server_name.empty()) {
std::string requested_server_name;
if (check_data->GetRequestedServerName(&requested_server_name) {
builder.AddString(utils::AttributeName::kConnectionRequestedServerName,
requested_server_name);
}
Expand Down
14 changes: 10 additions & 4 deletions src/istio/control/http/attributes_builder_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,11 @@ TEST(AttributesBuilderTest, TestCheckAttributes) {
EXPECT_CALL(mock_data, IsMutualTLS()).WillOnce(Invoke([]() -> bool {
return true;
}));
EXPECT_CALL(mock_data, GetRequestedServerName())
.WillOnce(testing::Return("www.google.com"));
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 @@ -349,8 +352,11 @@ TEST(AttributesBuilderTest, TestCheckAttributesWithAuthNResult) {
EXPECT_CALL(mock_data, IsMutualTLS()).WillOnce(Invoke([]() -> bool {
return true;
}));
EXPECT_CALL(mock_data, GetRequestedServerName())
.WillOnce(testing::Return("www.google.com"));
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
2 changes: 1 addition & 1 deletion src/istio/control/http/mock_check_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class MockCheckData : public CheckData {
MOCK_CONST_METHOD1(GetAuthenticationResult,
bool(istio::authn::Result *result));
MOCK_CONST_METHOD0(IsMutualTLS, bool());
MOCK_CONST_METHOD0(GetRequestedServerName, std::string());
MOCK_CONST_METHOD0(GetRequestedServerName, bool(std::string *name));
};

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

std::string requested_server_name = check_data->GetRequestedServerName();
if (!requested_server_name.empty()) {
std::string requested_server_name;
if (check_data->GetRequestedServerName(&requested_server_name) {
builder.AddString(utils::AttributeName::kConnectionRequestedServerName,
requested_server_name);
}
Expand Down
8 changes: 5 additions & 3 deletions src/istio/control/tcp/attributes_builder_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -311,9 +311,11 @@ TEST(AttributesBuilderTest, TestCheckAttributes) {
return true;
}));
EXPECT_CALL(mock_data, GetConnectionId()).WillOnce(Return("1234-5"));
EXPECT_CALL(mock_data, GetRequestedServerName())
.WillOnce(Return("www.google.com"));

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
2 changes: 1 addition & 1 deletion src/istio/control/tcp/mock_check_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +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_METHOD0(GetRequestedServerName, std::string());
MOCK_CONST_METHOD0(GetRequestedServerName, bool(std::string* name));
MOCK_CONST_METHOD0(GetConnectionId, std::string());
};

Expand Down