-
Notifications
You must be signed in to change notification settings - Fork 340
[Feature/Extension] Add oboauthcbackend registry and set up e2e endpoint testing flow #2857
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
Merged
RyanL1997
merged 75 commits into
opensearch-project:feature/extensions
from
RyanL1997:add-oboauthcbackend-registry
Jul 7, 2023
Merged
Changes from all commits
Commits
Show all changes
75 commits
Select commit
Hold shift + click to select a range
5582c5c
Fix build break
peternied 8c8bb88
Make authenticator name more concise
peternied 0f7b493
Clean up how roles are (de)encrypted
peternied 4b5d48e
Single constructor
peternied baa1312
More JwtVendor cleanup - but not sure if this works?
peternied 2cb7cae
Add OBO Authenticator into the Authc Backend list
RyanL1997 196fbea
Fix the logic of feching er/dr for rolesObject
RyanL1997 6e96de6
Fix of the OBO unit tests of Bearer header
RyanL1997 a85a3e9
Set up oboconfig
RyanL1997 98674b8
Adding this obo config to xcontent builder and remove unused imports
RyanL1997 aa4e599
Adding this obo config to xcontent builder and create obo authz heade…
RyanL1997 8204874
Done happy testing case
RyanL1997 293791e
Fix the header
RyanL1997 847f551
Revert the temorary fix of zstd library
RyanL1997 1047729
Misc cleanup
peternied d00e2e7
Remove bad import
peternied f46070f
Add endpoint and test that interactions with JwtVendor
peternied 4896a4b
AlFix to do both decrypt and encrypt tokens
peternied 71dd17f
Add basic parameters and update test to use them
peternied 8c0d750
Change ConfigModelV7's imports
RyanL1997 b36bde0
Re-apply zstd dependency fix
RyanL1997 a6bc8c0
Update OSSecurityPlugin class
RyanL1997 4351752
Fix the optional longsupplier for current time
RyanL1997 2a129af
Set up the subscriber to grab signingkey and encryptionkey from confi…
RyanL1997 61eaee0
Set up manual testing with stronger signing key
RyanL1997 640bc33
Modify JwtVendor to grab mapped roles
RyanL1997 9148a98
Add backend roles + dcf listener for obo config + Fix the role grabbi…
RyanL1997 a455250
Add obo auth integ test case with endopoint + remove manual testing c…
RyanL1997 07aa292
Add obo auth integ test case with endopoint + remove manual testing c…
RyanL1997 0ed28b5
Fix Code Hygiene, remove unused imports
RyanL1997 26670ac
Remove some stale TODOs
RyanL1997 12bd3e8
Change the * imports into seprate ones in OBOAuthenticationTest
RyanL1997 0e590ba
Remove another unused import in jwtVendor
RyanL1997 d1341e2
Add license header for CreateOnBehalfOfToken + OnBehalfOfJwtAuthentic…
RyanL1997 9e832cf
Remove wording "extension" in OnBehalfOfJwtAuthenticationTest's testi…
RyanL1997 626c853
Trim the obo integ test body
RyanL1997 e755753
Switch to java base64 decoder in OBOAuthenticator L75
RyanL1997 68af23a
Add stack trace to see the error of base64 decoder
RyanL1997 66b52e9
Fix the formatting in DynamicConfigModelV7
RyanL1997 983267b
Fix the typo of minimalKeyFormat + adding a debugging statement to ch…
RyanL1997 4999a58
Fix the signingKeys + encryptionKeys in src/integrationTest/resources…
RyanL1997 d95ad8b
Fix the signingKeys + encryptionKeys in src/test/resources/config.yml…
RyanL1997 dcec4e9
Remove debugging statements and add obo setting in src/test/resources…
RyanL1997 cd2eac6
Add a debug statement to print dcm.getobosettings
RyanL1997 be83625
Fix the missing comma in src/test/resources/restapi/securityconfig_no…
RyanL1997 8836e8c
Add obo setting to test config of src/test/resources/config_anon.yml
RyanL1997 817436d
Add obo setting into multiple testing config files
RyanL1997 7cb5cb5
Add checking for obo setting's presence
RyanL1997 eb9f5a4
Add checking for obo setting's presence with correct status type of s…
RyanL1997 d448af6
Revert back those testing configs
RyanL1997 275294a
Remove the security role adding in noop auth backend class
RyanL1997 2b64b8b
Add the check of NoOpAuthbackend in the backend registry
RyanL1997 896e826
Fix both impersonation tests
RyanL1997 729329b
Trim the obo integration test and add a new test case for tempered token
RyanL1997 cfed763
Change into matcher for OBO authenticator.
RyanL1997 df18f61
Rename the create obo token action
RyanL1997 ed14cea
Add description in the testing config of signingKey + encryptionKey
RyanL1997 a29992f
Fix the token duration
RyanL1997 7b6221f
No backendRoles by default
RyanL1997 d243fe5
Change the roles claim extraction error log msg
RyanL1997 8540862
Resolve some comments of formatting
RyanL1997 b4be662
Update the issuer to represent the cluster
RyanL1997 8e0631f
Fix the obo token's duration issue
RyanL1997 144efdf
Fix unused imports
RyanL1997 b2f5d2b
Merge branch 'feature/extensions' into add-oboauthcbackend-registry
RyanL1997 ce9baa2
Fix formatting again after branch sync
RyanL1997 0495b50
Fix Impersonation tests again
RyanL1997 b8c9ba1
Add api parameter for services (aud)
RyanL1997 49a705b
Remove the obo config json config files
RyanL1997 4b7e42a
Remove the obo config in src/test/resources/config.yml
RyanL1997 dfa6df9
Remove the obo config in src/test/resources/restapi/securityconfig_no…
RyanL1997 cb47792
Add back the obo config of securityconfig_nondefault.json
RyanL1997 bc574c4
Make a keyUtil for checking algo
RyanL1997 9340e6c
Extend the keyUtil and add to OBO authbackend
RyanL1997 cd203b8
Apply KeyUtil to both OBO and HTTPJWT authbackend
RyanL1997 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
134 changes: 134 additions & 0 deletions
134
src/integrationTest/java/org/opensearch/security/http/OnBehalfOfJwtAuthenticationTest.java
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,134 @@ | ||
| /* | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * | ||
| * The OpenSearch Contributors require contributions made to | ||
| * this file be licensed under the Apache-2.0 license or a | ||
| * compatible open source license. | ||
| * | ||
| * Modifications Copyright OpenSearch Contributors. See | ||
| * GitHub history for details. | ||
| */ | ||
|
|
||
| package org.opensearch.security.http; | ||
|
|
||
| import java.nio.charset.StandardCharsets; | ||
| import java.util.Base64; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope; | ||
| import org.apache.hc.core5.http.Header; | ||
| import org.apache.hc.core5.http.message.BasicHeader; | ||
| import org.junit.ClassRule; | ||
| import org.junit.Test; | ||
| import org.junit.runner.RunWith; | ||
|
|
||
| import org.opensearch.test.framework.OnBehalfOfConfig; | ||
| import org.opensearch.test.framework.TestSecurityConfig; | ||
| import org.opensearch.test.framework.cluster.ClusterManager; | ||
| import org.opensearch.test.framework.cluster.LocalCluster; | ||
| import org.opensearch.test.framework.cluster.TestRestClient; | ||
|
|
||
| import static org.hamcrest.MatcherAssert.assertThat; | ||
| import static org.hamcrest.Matchers.aMapWithSize; | ||
| import static org.hamcrest.Matchers.allOf; | ||
| import static org.hamcrest.Matchers.equalTo; | ||
| import static org.hamcrest.Matchers.hasKey; | ||
| import static org.opensearch.test.framework.TestSecurityConfig.AuthcDomain.AUTHC_HTTPBASIC_INTERNAL; | ||
| import static org.opensearch.test.framework.TestSecurityConfig.Role.ALL_ACCESS; | ||
|
|
||
| @RunWith(com.carrotsearch.randomizedtesting.RandomizedRunner.class) | ||
| @ThreadLeakScope(ThreadLeakScope.Scope.NONE) | ||
| public class OnBehalfOfJwtAuthenticationTest { | ||
|
|
||
| public static final String POINTER_USERNAME = "/user_name"; | ||
|
|
||
| static final TestSecurityConfig.User ADMIN_USER = new TestSecurityConfig.User("admin").roles(ALL_ACCESS); | ||
|
|
||
| private static final String signingKey = Base64.getEncoder() | ||
| .encodeToString( | ||
| "jwt signing key for an on behalf of token authentication backend for testing of OBO authentication".getBytes( | ||
| StandardCharsets.UTF_8 | ||
| ) | ||
| ); | ||
| private static final String encryptionKey = Base64.getEncoder().encodeToString("encryptionKey".getBytes(StandardCharsets.UTF_8)); | ||
| public static final String ADMIN_USER_NAME = "admin"; | ||
| public static final String DEFAULT_PASSWORD = "secret"; | ||
| public static final String OBO_TOKEN_REASON = "{\"reason\":\"Test generation\"}"; | ||
| public static final String OBO_ENDPOINT_PREFIX = "_plugins/_security/api/user/onbehalfof"; | ||
|
|
||
| @ClassRule | ||
| public static final LocalCluster cluster = new LocalCluster.Builder().clusterManager(ClusterManager.SINGLENODE) | ||
| .anonymousAuth(false) | ||
| .users(ADMIN_USER) | ||
| .nodeSettings( | ||
| Map.of( | ||
| "plugins.security.allow_default_init_securityindex", | ||
| true, | ||
| "plugins.security.restapi.roles_enabled", | ||
| List.of("user_admin__all_access") | ||
| ) | ||
| ) | ||
| .authc(AUTHC_HTTPBASIC_INTERNAL) | ||
| .onBehalfOf(new OnBehalfOfConfig().signing_key(signingKey).encryption_key(encryptionKey)) | ||
| .build(); | ||
|
|
||
| @Test | ||
| public void shouldAuthenticateWithOBOTokenEndPoint() { | ||
| Header adminOboAuthHeader; | ||
|
|
||
| try (TestRestClient client = cluster.getRestClient(ADMIN_USER_NAME, DEFAULT_PASSWORD)) { | ||
|
|
||
| client.assertCorrectCredentials(ADMIN_USER_NAME); | ||
|
|
||
| TestRestClient.HttpResponse response = client.postJson(OBO_ENDPOINT_PREFIX, OBO_TOKEN_REASON); | ||
| response.assertStatusCode(200); | ||
|
|
||
| Map<String, Object> oboEndPointResponse = response.getBodyAs(Map.class); | ||
| assertThat(oboEndPointResponse, allOf(aMapWithSize(3), hasKey("user"), hasKey("onBehalfOfToken"), hasKey("duration"))); | ||
|
|
||
| String encodedOboTokenStr = oboEndPointResponse.get("onBehalfOfToken").toString(); | ||
|
|
||
| adminOboAuthHeader = new BasicHeader("Authorization", "Bearer " + encodedOboTokenStr); | ||
| } | ||
|
|
||
| try (TestRestClient client = cluster.getRestClient(adminOboAuthHeader)) { | ||
|
|
||
| TestRestClient.HttpResponse response = client.getAuthInfo(); | ||
| response.assertStatusCode(200); | ||
|
|
||
| String username = response.getTextFromJsonBody(POINTER_USERNAME); | ||
| assertThat(username, equalTo(ADMIN_USER_NAME)); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void shouldNotAuthenticateWithATemperedOBOToken() { | ||
| Header adminOboAuthHeader; | ||
|
|
||
| try (TestRestClient client = cluster.getRestClient(ADMIN_USER_NAME, DEFAULT_PASSWORD)) { | ||
|
|
||
| client.assertCorrectCredentials(ADMIN_USER_NAME); | ||
|
|
||
| TestRestClient.HttpResponse response = client.postJson(OBO_ENDPOINT_PREFIX, OBO_TOKEN_REASON); | ||
| response.assertStatusCode(200); | ||
|
|
||
| Map<String, Object> oboEndPointResponse = response.getBodyAs(Map.class); | ||
| assertThat(oboEndPointResponse, allOf(aMapWithSize(3), hasKey("user"), hasKey("onBehalfOfToken"), hasKey("duration"))); | ||
|
|
||
| String encodedOboTokenStr = oboEndPointResponse.get("onBehalfOfToken").toString(); | ||
| StringBuilder stringBuilder = new StringBuilder(encodedOboTokenStr); | ||
| stringBuilder.deleteCharAt(encodedOboTokenStr.length() - 1); | ||
| String temperedOboTokenStr = stringBuilder.toString(); | ||
|
|
||
| adminOboAuthHeader = new BasicHeader("Authorization", "Bearer " + temperedOboTokenStr); | ||
| } | ||
|
|
||
| try (TestRestClient client = cluster.getRestClient(adminOboAuthHeader)) { | ||
|
|
||
| TestRestClient.HttpResponse response = client.getAuthInfo(); | ||
| response.assertStatusCode(401); | ||
| response.getBody().contains("Unauthorized"); | ||
| } | ||
| } | ||
| } |
44 changes: 44 additions & 0 deletions
44
src/integrationTest/java/org/opensearch/test/framework/OnBehalfOfConfig.java
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| /* | ||
| * Copyright OpenSearch Contributors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * | ||
| * The OpenSearch Contributors require contributions made to | ||
| * this file be licensed under the Apache-2.0 license or a | ||
| * compatible open source license. | ||
| * | ||
| */ | ||
| package org.opensearch.test.framework; | ||
|
|
||
| import java.io.IOException; | ||
|
|
||
| import org.apache.commons.lang3.StringUtils; | ||
|
|
||
| import org.opensearch.core.xcontent.ToXContent; | ||
| import org.opensearch.core.xcontent.ToXContentObject; | ||
| import org.opensearch.core.xcontent.XContentBuilder; | ||
|
|
||
| public class OnBehalfOfConfig implements ToXContentObject { | ||
| private String signing_key; | ||
| private String encryption_key; | ||
|
|
||
| public OnBehalfOfConfig signing_key(String signing_key) { | ||
| this.signing_key = signing_key; | ||
| return this; | ||
| } | ||
|
|
||
| public OnBehalfOfConfig encryption_key(String encryption_key) { | ||
| this.encryption_key = encryption_key; | ||
| return this; | ||
| } | ||
|
|
||
| @Override | ||
| public XContentBuilder toXContent(XContentBuilder xContentBuilder, ToXContent.Params params) throws IOException { | ||
| xContentBuilder.startObject(); | ||
| xContentBuilder.field("signing_key", signing_key); | ||
| if (StringUtils.isNoneBlank(encryption_key)) { | ||
| xContentBuilder.field("encryption_key", encryption_key); | ||
| } | ||
| xContentBuilder.endObject(); | ||
| return xContentBuilder; | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.