-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Authn uses protobuf.Struct to store claims and add list support for R…
…BAC (#1925) * Authn uses protobuf.Struct to store claims and add list support for RBAC - Change authn to use protobuf.Struct to store claims - Add list support for RBAC * Change based on the review comments
- Loading branch information
1 parent
a56144b
commit b993e07
Showing
10 changed files
with
210 additions
and
154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,7 +44,7 @@ const std::string kSecIstioAuthUserinfoHeaderValue = | |
{ | ||
"iss": "[email protected]", | ||
"sub": "[email protected]", | ||
"aud": "aud1", | ||
"aud": ["aud1", "aud2"], | ||
"non-string-will-be-ignored": 1512754205, | ||
"some-other-string-claims": "some-claims-kept" | ||
} | ||
|
@@ -273,15 +273,15 @@ TEST_F(ValidateJwtTest, JwtPayloadAvailable) { | |
R"({ | ||
"jwt": { | ||
"user": "[email protected]/[email protected]", | ||
"audiences": ["aud1"], | ||
"audiences": ["aud1", "aud2"], | ||
"presenter": "", | ||
"claims": { | ||
"aud": "aud1", | ||
"iss": "[email protected]", | ||
"sub": "[email protected]", | ||
"some-other-string-claims": "some-claims-kept" | ||
"aud": ["aud1", "aud2"], | ||
"iss": ["[email protected]"], | ||
"some-other-string-claims": ["some-claims-kept"], | ||
"sub": ["[email protected]"], | ||
}, | ||
raw_claims: "\n {\n \"iss\": \"[email protected]\",\n \"sub\": \"[email protected]\",\n \"aud\": \"aud1\",\n \"non-string-will-be-ignored\": 1512754205,\n \"some-other-string-claims\": \"some-claims-kept\"\n }\n " | ||
"raw_claims": "\n {\n \"iss\": \"[email protected]\",\n \"sub\": \"[email protected]\",\n \"aud\": [\"aud1\", \"aud2\"],\n \"non-string-will-be-ignored\": 1512754205,\n \"some-other-string-claims\": \"some-claims-kept\"\n }\n ", | ||
} | ||
} | ||
)", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,21 +63,47 @@ TEST(AuthnUtilsTest, GetJwtPayloadFromHeaderTest) { | |
R"( | ||
user: "[email protected]/[email protected]" | ||
audiences: ["aud1"] | ||
claims { | ||
key: "aud" | ||
value: "aud1" | ||
} | ||
claims { | ||
key: "iss" | ||
value: "[email protected]" | ||
} | ||
claims { | ||
key: "sub" | ||
value: "[email protected]" | ||
} | ||
claims { | ||
key: "some-other-string-claims" | ||
value: "some-claims-kept" | ||
claims: { | ||
fields: { | ||
key: "aud" | ||
value: { | ||
list_value: { | ||
values: { | ||
string_value: "aud1" | ||
} | ||
} | ||
} | ||
} | ||
fields: { | ||
key: "iss" | ||
value: { | ||
list_value: { | ||
values: { | ||
string_value: "[email protected]" | ||
} | ||
} | ||
} | ||
} | ||
fields: { | ||
key: "sub" | ||
value: { | ||
list_value: { | ||
values: { | ||
string_value: "[email protected]" | ||
} | ||
} | ||
} | ||
} | ||
fields: { | ||
key: "some-other-string-claims" | ||
value: { | ||
list_value: { | ||
values: { | ||
string_value: "some-claims-kept" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
raw_claims: ")" + | ||
StringUtil::escape(kSecIstioAuthUserinfoHeaderValue) + R"(")", | ||
|
@@ -95,17 +121,37 @@ TEST(AuthnUtilsTest, ProcessJwtPayloadWithNoAudTest) { | |
ASSERT_TRUE(Protobuf::TextFormat::ParseFromString( | ||
R"( | ||
user: "[email protected]/[email protected]" | ||
claims { | ||
key: "iss" | ||
value: "[email protected]" | ||
} | ||
claims { | ||
key: "sub" | ||
value: "[email protected]" | ||
} | ||
claims { | ||
key: "some-other-string-claims" | ||
value: "some-claims-kept" | ||
claims: { | ||
fields: { | ||
key: "iss" | ||
value: { | ||
list_value: { | ||
values: { | ||
string_value: "[email protected]" | ||
} | ||
} | ||
} | ||
} | ||
fields: { | ||
key: "sub" | ||
value: { | ||
list_value: { | ||
values: { | ||
string_value: "[email protected]" | ||
} | ||
} | ||
} | ||
} | ||
fields: { | ||
key: "some-other-string-claims" | ||
value: { | ||
list_value: { | ||
values: { | ||
string_value: "some-claims-kept" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
raw_claims: ")" + | ||
StringUtil::escape(kSecIstioAuthUserInfoHeaderWithNoAudValue) + | ||
|
@@ -127,28 +173,61 @@ TEST(AuthnUtilsTest, ProcessJwtPayloadWithTwoAudTest) { | |
user: "[email protected]/[email protected]" | ||
audiences: "aud1" | ||
audiences: "aud2" | ||
claims { | ||
key: "iss" | ||
value: "[email protected]" | ||
} | ||
claims { | ||
key: "sub" | ||
value: "[email protected]" | ||
} | ||
claims { | ||
key: "some-other-string-claims" | ||
value: "some-claims-kept" | ||
claims: { | ||
fields: { | ||
key: "aud" | ||
value: { | ||
list_value: { | ||
values: { | ||
string_value: "aud1" | ||
} | ||
values: { | ||
string_value: "aud2" | ||
} | ||
} | ||
} | ||
} | ||
fields: { | ||
key: "iss" | ||
value: { | ||
list_value: { | ||
values: { | ||
string_value: "[email protected]" | ||
} | ||
} | ||
} | ||
} | ||
fields: { | ||
key: "sub" | ||
value: { | ||
list_value: { | ||
values: { | ||
string_value: "[email protected]" | ||
} | ||
} | ||
} | ||
} | ||
fields: { | ||
key: "some-other-string-claims" | ||
value: { | ||
list_value: { | ||
values: { | ||
string_value: "some-claims-kept" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
raw_claims: ")" + | ||
StringUtil::escape(kSecIstioAuthUserInfoHeaderWithTwoAudValue) + | ||
R"(")", | ||
&expected_payload)); | ||
|
||
// The payload returned from ProcessJwtPayload() should be the same as | ||
// the expected. When the aud is a string array, the aud is not saved in the | ||
// claims. | ||
bool ret = AuthnUtils::ProcessJwtPayload( | ||
kSecIstioAuthUserInfoHeaderWithTwoAudValue, &payload); | ||
|
||
EXPECT_TRUE(ret); | ||
EXPECT_TRUE(MessageDifferencer::Equals(expected_payload, payload)); | ||
} | ||
|
Oops, something went wrong.