Skip to content

Conversation

@peternied
Copy link

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 --info however, this was done to very quickly access the endpoint and should be properly moved/rearranged

Check List

  • New functionality includes testing
  • New functionality has been documented
  • Commits are signed per the DCO using --signoff

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.

peternied added 11 commits June 8, 2023 21:32
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>
@peternied peternied requested a review from RyanL1997 as a code owner June 12, 2023 17:13
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'
Copy link
Author

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));
Copy link
Author

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 {
Copy link
Author

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()));
Copy link
Author

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

Copy link

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 {
Copy link
Author

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

@RyanL1997
Copy link
Owner

I will merge this one into my fork and fix this:

/home/runner/work/security/security/src/integrationTest/java/org/opensearch/security/http/OnBehalfOfJwtAuthorizationHeaderFactory.java:49: error: incompatible types: LongSupplier cannot be converted to Optional<LongSupplier>
		JwtVendor jwtVendor = new JwtVendor(settings, currentTime);

@RyanL1997 RyanL1997 merged commit eb5552b into RyanL1997:add-oboauthcbackend-registry Jun 12, 2023
@peternied peternied deleted the feature/extensions branch June 12, 2023 20:47
.map(value -> Math.min(value, 72)) // Max duration is 72 hours
.orElse(24); // Fallback to default;

final String source = "self-issued";
Copy link

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.

Copy link

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.

Copy link
Author

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;
Copy link

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.

Copy link
Author

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

@cwperks
Copy link

cwperks commented Jun 13, 2023

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.

@RyanL1997
Copy link
Owner

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 opensearch-project#2773 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 tokenManagementIndex?). I will leave some comments on the PR you linked.

RyanL1997 added a commit that referenced this pull request Jun 22, 2023
Signed-off-by: Ryan Liang <jiallian@amazon.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants