Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

destination.principal derivation fix #1884

Merged
merged 2 commits into from
Jul 26, 2018
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
16 changes: 8 additions & 8 deletions src/istio/control/http/attributes_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,16 @@ void AttributesBuilder::ExtractRequestHeaderAttributes(CheckData *check_data) {
}

void AttributesBuilder::ExtractAuthAttributes(CheckData *check_data) {
utils::AttributesBuilder builder(&request_->attributes);
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't you need to update unit test for this, i.e remove this line
https://github.com/istio/proxy/blob/release-1.0/src/istio/control/http/attributes_builder_test.cc#L447

(I don't know why pre-submit tests didn't fail though)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Mock stubs were missing. Added and corrected the unit test.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah. 'Nice' mock :). Should make it nagged at least :)


std::string destination_principal;
if (check_data->GetPrincipal(false, &destination_principal)) {
builder.AddString(utils::AttributeName::kDestinationPrincipal,
destination_principal);
}

istio::authn::Result authn_result;
if (check_data->GetAuthenticationResult(&authn_result)) {
utils::AttributesBuilder builder(&request_->attributes);
if (!authn_result.principal().empty()) {
builder.AddString(utils::AttributeName::kRequestAuthPrincipal,
authn_result.principal());
Expand Down Expand Up @@ -110,7 +117,6 @@ void AttributesBuilder::ExtractAuthAttributes(CheckData *check_data) {
// Fallback to extract from jwt filter directly. This can be removed once
// authn filter is in place.
std::map<std::string, std::string> payload;
utils::AttributesBuilder builder(&request_->attributes);
if (check_data->GetJWTPayload(&payload) && !payload.empty()) {
// Populate auth attributes.
if (payload.count("iss") > 0 && payload.count("sub") > 0) {
Expand All @@ -134,12 +140,6 @@ void AttributesBuilder::ExtractAuthAttributes(CheckData *check_data) {
builder.AddString(utils::AttributeName::kSourceUser, source_user);
builder.AddString(utils::AttributeName::kSourcePrincipal, source_user);
}

std::string destination_principal;
if (check_data->GetPrincipal(false, &destination_principal)) {
builder.AddString(utils::AttributeName::kDestinationPrincipal,
destination_principal);
}
} // namespace http

void AttributesBuilder::ExtractForwardedAttributes(CheckData *check_data) {
Expand Down
13 changes: 9 additions & 4 deletions src/istio/control/http/attributes_builder_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,15 @@ TEST(AttributesBuilderTest, TestCheckAttributesWithAuthNResult) {
EXPECT_CALL(mock_data, IsMutualTLS()).WillOnce(Invoke([]() -> bool {
return true;
}));
EXPECT_CALL(mock_data, GetPrincipal(_, _))
.WillRepeatedly(Invoke([](bool peer, std::string *user) -> bool {
if (peer) {
*user = "test_user";
} else {
*user = "destination_user";
}
return true;
}));
EXPECT_CALL(mock_data, GetRequestedServerName(_))
.WillOnce(Invoke([](std::string *name) -> bool {
*name = "www.google.com";
Expand Down Expand Up @@ -443,10 +452,6 @@ TEST(AttributesBuilderTest, TestCheckAttributesWithAuthNResult) {
.mutable_attributes())[utils::AttributeName::kRequestAuthRawClaims]
.set_string_value("test_raw_claims");

// strip destination.principal for JWT-based authn
(*expected_attributes.mutable_attributes())
.erase(utils::AttributeName::kDestinationPrincipal);

EXPECT_TRUE(
MessageDifferencer::Equals(request.attributes, expected_attributes));
}
Expand Down