Skip to content

Service Accounts - HLRC #72431

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
merged 16 commits into from
Jun 17, 2021
Merged

Service Accounts - HLRC #72431

merged 16 commits into from
Jun 17, 2021

Conversation

ywangd
Copy link
Member

@ywangd ywangd commented Apr 28, 2021

This PR adds corresponding components in High Level Rest Client for the new APIs related to the service accounts feature.

@ywangd ywangd added >enhancement :Security/Client Security in clients (Transport, Rest) v8.0.0 v7.14.0 labels Apr 28, 2021
@ywangd ywangd requested a review from tvernum April 28, 2021 23:59
@elasticmachine elasticmachine added the Team:Security Meta label for security team label Apr 28, 2021
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-security (Team:Security)

@ywangd
Copy link
Member Author

ywangd commented Apr 29, 2021

@elasticmachine update branch

final AuthenticateResponse response = new AuthenticateResponse(
new User((String) a[0], ((List<String>) a[1]), (Map<String, Object>) a[2],
(String) a[3], (String) a[4]), (Boolean) a[5], (RealmInfo) a[6], (RealmInfo) a[7], (String) a[8],
Map.of(TOKEN_NAME_FIELD, ((Map<String, Object>) a[9]).get(NAME_FIELD)));
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this is right. The JSON response exposes token as a field, so the Java response object should too.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's certainly weird. But the AuthenticateResponse class is pretty weird already. It's internal structure (fields) mimics the server side Authenticate, i.e. both have:

  • User object
  • Auth realm
  • Lookup realm
  • Auth type

But the issue is that server side Authenticate has a quite different serialisation (JSON) form than its internal structure. This means, the client side AuthenticateResponse needs to bridge this difference by declaring a parser that has the shape of the JSON form, but a constructor to restore the internal structure.

I was trying to fit my changes with a similar style. I agree it's awkward and will change it to be a top level token field. But we might want to revamp AuthenticateResponse so that all other fields are also aligned with the JSON response from the server side, instead of the backing class's internal strcuture.

@ywangd
Copy link
Member Author

ywangd commented May 27, 2021

Took me a while to get back to this. It's now ready for another look. Thanks!

@ywangd ywangd requested a review from tvernum June 10, 2021 08:10
Copy link
Contributor

@tvernum tvernum left a comment

Choose a reason for hiding this comment

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

I'm happy as-is, but I wonder whether we should be using a real class rather than a Map.

@@ -114,24 +124,35 @@ public String getAuthenticationType() {
return authenticationType;
}

public Map<String, Object> getToken() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be some new (nested?) class rather than a Map ?

I'm of 2 minds

  • on one hand, it's hardly ever going to be used, so simple seems better
  • but, really it should be a type like (almost) everything else in the HLRC.

Copy link
Member Author

Choose a reason for hiding this comment

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

I just made the change to replace the Map with a nested TokenInfo class. But now I still think it might be better for it to be just a Map because this field is more of the metadata for the authentication type field. Also its own fields may not all exist or make sense for different token types if we decide to expand it to cover other types. For example, name does not apply to OAuth Tokens. So it needs to be declared as StringOrNull. Overall I think its simpler for it to be just a Map.

Copy link
Member Author

Choose a reason for hiding this comment

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

In case it is not clear from the last comment: I am keeping the token field as a Map. The change is in another branch that I decided to not merge.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sorry to drag on this minor issue, but I decided to make one small change: When the response does not have a token field, instead of an empty Map, the code now represents it just as a null value. I think a null value is more accurate semantically. Also this would be the case if we replace the Map with a named class. So overall I feel null is better suited.

@ywangd
Copy link
Member Author

ywangd commented Jun 17, 2021

@elasticmachine run elasticsearch-ci/part-2

@ywangd ywangd merged commit 2350369 into elastic:master Jun 17, 2021
@ywangd ywangd changed the title Service Accounts - HRLC Service Accounts - HLRC Jun 17, 2021
ywangd added a commit to ywangd/elasticsearch that referenced this pull request Jun 17, 2021
This PR adds corresponding components in High Level Rest Client for the new
APIs related to the service accounts feature.
ywangd added a commit that referenced this pull request Jun 17, 2021
This PR adds corresponding components in High Level Rest Client for the new
APIs related to the service accounts feature.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>enhancement :Security/Client Security in clients (Transport, Rest) Team:Security Meta label for security team v7.14.0 v8.0.0-alpha1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants