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
8 changes: 8 additions & 0 deletions src/istio/control/http/attributes_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,14 @@ void AttributesBuilder::ExtractAuthAttributes(CheckData *check_data) {
builder.AddProtoStructStringMap(utils::AttributeName::kRequestAuthClaims,
claims->second.struct_value());
}
return;
}

// Fallback to source.principal extracted from mTLS if no authentication
// filter is installed
std::string source_user;
if (check_data->GetPrincipal(true, &source_user)) {
builder.AddString(utils::AttributeName::kSourcePrincipal, source_user);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you also need kSourceUser?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

source.user is being deprecated, so we can drop it in the next release.

}
}

Expand Down
6 changes: 6 additions & 0 deletions src/istio/control/http/attributes_builder_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,12 @@ attributes {
string_value: "/books"
}
}
attributes {
key: "source.principal"
value {
string_value: "test_user"
}
}
)";

const char kCheckAttributes[] = R"(
Expand Down
10 changes: 5 additions & 5 deletions src/istio/control/http/request_handler_impl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ TEST_F(RequestHandlerImplTest, TestHandlerDisabledCheck) {
::testing::NiceMock<MockHeaderUpdate> mock_header;
// Report is enabled so Attributes are extracted.
EXPECT_CALL(mock_data, GetSourceIpPort(_, _)).Times(1);
EXPECT_CALL(mock_data, GetPrincipal(_, _)).Times(1);
EXPECT_CALL(mock_data, GetPrincipal(_, _)).Times(2);

// Check should NOT be called.
EXPECT_CALL(*mock_client_, Check(_, _, _, _)).Times(0);
Expand All @@ -194,7 +194,7 @@ TEST_F(RequestHandlerImplTest, TestPerRouteAttributes) {
::testing::NiceMock<MockCheckData> mock_data;
::testing::NiceMock<MockHeaderUpdate> mock_header;
EXPECT_CALL(mock_data, GetSourceIpPort(_, _)).Times(1);
EXPECT_CALL(mock_data, GetPrincipal(_, _)).Times(1);
EXPECT_CALL(mock_data, GetPrincipal(_, _)).Times(2);

// Check should be called.
EXPECT_CALL(*mock_client_, Check(_, _, _, _))
Expand Down Expand Up @@ -222,7 +222,7 @@ TEST_F(RequestHandlerImplTest, TestDefaultRouteAttributes) {
::testing::NiceMock<MockCheckData> mock_data;
::testing::NiceMock<MockHeaderUpdate> mock_header;
EXPECT_CALL(mock_data, GetSourceIpPort(_, _)).Times(1);
EXPECT_CALL(mock_data, GetPrincipal(_, _)).Times(1);
EXPECT_CALL(mock_data, GetPrincipal(_, _)).Times(2);

// Check should be called.
EXPECT_CALL(*mock_client_, Check(_, _, _, _))
Expand Down Expand Up @@ -255,7 +255,7 @@ TEST_F(RequestHandlerImplTest, TestRouteAttributes) {
::testing::NiceMock<MockCheckData> mock_data;
::testing::NiceMock<MockHeaderUpdate> mock_header;
EXPECT_CALL(mock_data, GetSourceIpPort(_, _)).Times(1);
EXPECT_CALL(mock_data, GetPrincipal(_, _)).Times(1);
EXPECT_CALL(mock_data, GetPrincipal(_, _)).Times(2);

ServiceConfig route_config;
auto map3 = route_config.mutable_mixer_attributes()->mutable_attributes();
Expand Down Expand Up @@ -370,7 +370,7 @@ TEST_F(RequestHandlerImplTest, TestHandlerCheck) {
::testing::NiceMock<MockCheckData> mock_data;
::testing::NiceMock<MockHeaderUpdate> mock_header;
EXPECT_CALL(mock_data, GetSourceIpPort(_, _)).Times(1);
EXPECT_CALL(mock_data, GetPrincipal(_, _)).Times(1);
EXPECT_CALL(mock_data, GetPrincipal(_, _)).Times(2);

// Check should be called.
EXPECT_CALL(*mock_client_, Check(_, _, _, _)).Times(1);
Expand Down