-
Notifications
You must be signed in to change notification settings - Fork 0
Adding end to end endpoint with various changes #1
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
Adding end to end endpoint with various changes #1
Conversation
Signed-off-by: Peter Nied <petern@amazon.com>
Signed-off-by: Peter Nied <petern@amazon.com>
Signed-off-by: Peter Nied <petern@amazon.com>
Signed-off-by: Peter Nied <petern@amazon.com>
… feature/extensions Signed-off-by: Peter Nied <petern@amazon.com>
Signed-off-by: Peter Nied <petern@amazon.com>
Signed-off-by: Peter Nied <petern@amazon.com>
Signed-off-by: Peter Nied <petern@amazon.com>
Signed-off-by: Peter Nied <petern@amazon.com>
Signed-off-by: Peter Nied <petern@amazon.com>
| runtimeOnly 'org.apache.ws.xmlschema:xmlschema-core:2.2.5' | ||
| runtimeOnly 'org.apache.santuario:xmlsec:2.2.3' | ||
| runtimeOnly 'com.github.luben:zstd-jni:1.5.2-1' | ||
| runtimeOnly 'com.github.luben:zstd-jni:1.5.5-3' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed the build break
| assertNotNull(body.getAsSettings("tenants")); | ||
| assertNotNull(body.getAsList("roles")); | ||
|
|
||
| response = rh.executePostRequest(getEndpointPrefix() + "/api/user/onbehalfof", "{\"reason\":\"Test generation\"}", encodeBasicHeader(testUser, testPass)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test only invokes the new endpoint and this should be deleted and replaced with changes in the integration tests that involve:
- Happy path flow, get token then use to call WhoAmI endpoint
- Basic error checking of the API
|
|
||
| import static org.opensearch.security.dlic.rest.support.Utils.addRoutesPrefix; | ||
|
|
||
| public class CreateOnBehalfOfToken extends BaseRestHandler { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This class was hastily created, it should be re-written and compacted significately. I was also betting that we could use the AuthZ on REST requests so transport actions weren't generated. Might make sense to make this follow the transport actions more formally until that has been merged/backported
| user.getName(), | ||
| source, | ||
| tokenDuration, | ||
| user.getSecurityRoles().stream().collect(Collectors.toList())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need more research into how these roles are populated, I'm not sure if this is correct
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For extensions the token will contain the mapped roles
| import org.opensearch.security.user.AuthCredentials; | ||
|
|
||
| public class HTTPOnBehalfOfJwtAuthenticator implements HTTPAuthenticator { | ||
| public class OnBehalfOfAuthenticator implements HTTPAuthenticator { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still has many opportunities to reuse the JwtVendor within this class rather than duplicate logic, but might be good fast followups rather than block the critical path
|
I will merge this one into my fork and fix this: |
| .map(value -> Math.min(value, 72)) // Max duration is 72 hours | ||
| .orElse(24); // Fallback to default; | ||
|
|
||
| final String source = "self-issued"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is cluster name then this should be able to be obtained from the ClusterState which you can get in createComponents.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
source is a bit confusing of a name here. This parameter is the audience claim in the JWT which is intended to be a unique identifier of the service/extension that would receive this token. For an endpoint to request the creation of a token, it may make sense to have this as a param.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this REST API's case, the token was created by self-issued by user. If this was generated by a plugin or extension, then it should be marked with the identifier for traceability. This is good feedback around if we have the correct information in the token for the audit log or other use cases
| .map(value -> (String)value) | ||
| .map(Integer::parseInt) | ||
| .map(value -> Math.min(value, 72)) // Max duration is 72 hours | ||
| .orElse(24); // Fallback to default; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO 24 hours is too wide of a window. This value should match any currently configured REST Handler timeouts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good called, we can change the defaults as needed
|
If we expand on this PR to also implement token revocation and richer management of these tokens then it may make sense to create a separate security index for token management. You can look at this PR which creates an index to store security information that is not supposed to be stored in the security configuration index. |
Hi @cwperks, thanks for the info. I would like ask some questions about the index (maybe called |
Description
I've done a pass over the feature branch and made several updates, so it is more testable and cleaned up some smaller style issues that were nagging at me.
Testing
Testing of the new API was done via
./gradlew test --tests org.opensearch.security.dlic.rest.api.AccountApiTest.testGetAccount --infohowever, this was done to very quickly access the endpoint and should be properly moved/rearrangedCheck List
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.