Skip to content
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

Return file-backed service tokens from all nodes #75200

Merged
merged 21 commits into from
Aug 3, 2021

Conversation

ywangd
Copy link
Member

@ywangd ywangd commented Jul 10, 2021

The Get service account credentials API now returns file-backed tokens from all nodes instead of only the local node. For each file-backed service token, we list names of the nodes where this token is found. The response also has a file_tokens._nodes field containing information about the overall request execution (it works the same way as the _nodes field of Nodes info API, etc.) Detailed response sample can be found in #74530 (comment)

This PR also removes the beta label from the API's documentation page.

Resolves: #74530

@ywangd ywangd added >enhancement :Security/Security Security issues without another label v8.0.0 v7.15.0 labels Jul 10, 2021
@ywangd ywangd requested a review from tvernum July 10, 2021 07:26
@elasticmachine elasticmachine added the Team:Security Meta label for security team label Jul 10, 2021
@elasticmachine
Copy link
Collaborator

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

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.

Sorry, I didn't get time to review all of this, but here's my feedback-so-far.

return serviceTokenInfos;
public List<ServiceTokenInfo> getTokenInfos() {
return Stream.concat(fileTokensResponse.getTokenInfos().stream(), indexTokenInfos.stream())
.collect(Collectors.toUnmodifiableList());
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 object, but it feels like you're trying too hard to restructure the response into the API you would like it to be, rather than represent the JSON API as it is.
We don't have to merge the file and index tokens into 1 list.

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 merged them because it felt easier to explain in the HLRC doc page. Now I think it's better to have consistency with the server side response. Updated to keep them separate.


import java.io.IOException;
import java.util.Collection;
import java.util.Map;
import java.util.Objects;

public class TokenInfo implements Writeable, ToXContentObject, Comparable<TokenInfo> {

private final String name;
private final TokenSource source;
Copy link
Contributor

Choose a reason for hiding this comment

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

The source seems weird now - file and index are handled so separately in the response objects, that it feels unnecessary to have this field.

Copy link
Member Author

Choose a reason for hiding this comment

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

The source can be computed based on the new nodeNames field, which has value null for index-based tokens. So I removed this field, but kept the getter to compute it on the fly.

@ywangd ywangd force-pushed the es-74530-all-file-tokens branch from e789bb5 to 94b7b90 Compare July 13, 2021 13:14
@ywangd ywangd requested a review from tvernum July 30, 2021 04:43
@ywangd
Copy link
Member Author

ywangd commented Jul 30, 2021

@tvernum I updated the PR based on the discussion with the following small change to response field names:

"nodes_credentials": {
  "_nodes": { ... },
  "file_tokens": {
     "token1": { .. },
     ...
   }
}

The intention is to accomodate possible future expansion for node-local credentials other than file-backed tokens.

…stTest/java/org/elasticsearch/xpack/security/operator/Constants.java
listener.onFailure(new IllegalStateException("authentication is required"));
} else {
serviceAccountService.createIndexToken(authentication, request, listener);
}
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 follow why this change is here (to move things from the actions to the service).

I don't have any opinion on it - I'm just confused about where it came from.
I assume it's a consequence of having the Nodes action that needs to query for index & file tokens separately, but I can't quite piece all the bits together.

Copy link
Member Author

Choose a reason for hiding this comment

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

You understanding is correct. Please let me fill in some more details.

The logic is not really moved from the "action" to the service, but rather moved from IndexServiceAccountTokenStore to the service. Because of the separation between index-token and file-token fetching, the service becomes more aware of the difference. Previously I tried to make the service not aware of the underlying difference between different stores by having just a single CompositeServiceAccountTokenStore. But this is no long suitable because we have to handle token fetching separately.

Now the service knows explicitly about both stores and can hence become a facade for both of them. So I think it is better have the abstraction layer here since it is already aware of it. That's why I decided to let the actions call into service instead of using the underlying store directly. I think in general I prefer this layer separation, but we are (I am) not consistent about it.

Since this action now uses the service and the service already handles HTTP TLS check, it is also moved into the service. One benefit is that I was able to test it in one place and delete a few tests for the actions.

@ywangd ywangd merged commit e4f7132 into elastic:master Aug 3, 2021
ywangd added a commit to ywangd/elasticsearch that referenced this pull request Aug 3, 2021
The Get service account credentials API now returns file-backed tokens from all
nodes instead of only the local node. For each file-backed service token, we
list names of the nodes where this token is found. The response for node-local
credentials (currently only file-backed tokens) is place inside the
"nodes_credentials.file_tokens" field. There is also a nodes_credentials._nodes
field containing information about the overall request execution (it works the
same way as the _nodes field of Nodes info API, etc.) Detailed response sample
can be found in elastic#74530

This PR also removes the beta label from the API's documentation page.

Resolves: elastic#74530
ywangd added a commit that referenced this pull request Aug 3, 2021
The Get service account credentials API now returns file-backed tokens from all
nodes instead of only the local node. For each file-backed service token, we
list names of the nodes where this token is found. The response for node-local
credentials (currently only file-backed tokens) is place inside the
"nodes_credentials.file_tokens" field. There is also a nodes_credentials._nodes
field containing information about the overall request execution (it works the
same way as the _nodes field of Nodes info API, etc.) Detailed response sample
can be found in #74530

This PR also removes the beta label from the API's documentation page.

Resolves: #74530
lockewritesdocs pushed a commit to lockewritesdocs/elasticsearch that referenced this pull request Aug 3, 2021
The Get service account credentials API now returns file-backed tokens from all
nodes instead of only the local node. For each file-backed service token, we
list names of the nodes where this token is found. The response for node-local
credentials (currently only file-backed tokens) is place inside the
"nodes_credentials.file_tokens" field. There is also a nodes_credentials._nodes
field containing information about the overall request execution (it works the
same way as the _nodes field of Nodes info API, etc.) Detailed response sample
can be found in elastic#74530

This PR also removes the beta label from the API's documentation page.

Resolves: elastic#74530
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>enhancement :Security/Security Security issues without another label Team:Security Meta label for security team v7.15.0 v8.0.0-alpha1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Get service account credentials should show file tokens from all nodes
4 participants