-
Notifications
You must be signed in to change notification settings - Fork 276
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
Add api token action to handle creation of api token index #4912
base: feature/api-tokens
Are you sure you want to change the base?
Add api token action to handle creation of api token index #4912
Conversation
Signed-off-by: Derek Ho <[email protected]>
Signed-off-by: Derek Ho <[email protected]>
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.
Left a few preliminary comments
import java.util.Map; | ||
import java.util.Set; | ||
|
||
import static org.opensearch.rest.RestRequest.Method.*; |
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.
remove wildcard import
|
||
public class ApiTokenApiAction extends AbstractApiAction { | ||
|
||
public static final String NAME_JSON_PROPERTY = "ip"; |
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.
Looks like this is copied from elsewhere? Can this be removed?
|
||
protected ApiTokenApiAction(ClusterService clusterService, ThreadPool threadPool, SecurityApiDependencies securityApiDependencies) { | ||
super(Endpoint.APITOKENS, clusterService, threadPool, securityApiDependencies); | ||
this.requestHandlersBuilder.configureRequestHandlers(this::authFailureConfigApiRequestHandlers); |
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.
nit: the naming also looks copied here. Can this be renamed?
public void createApiTokenIndexIfAbsent(Client client) { | ||
if (!apiTokenIndexExists()) { | ||
final Map<String, Object> indexSettings = ImmutableMap.of("index.number_of_shards", 1, "index.auto_expand_replicas", "0-all"); | ||
final CreateIndexRequest createIndexRequest = new CreateIndexRequest(ConfigConstants.OPENSEARCH_API_TOKENS_INDEX).settings(indexSettings); |
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.
FYI By subclassing AbstractApiAction this would be authorized like other security APIs. Like other API handlers, I think we will want to go to the transport layer here and execute a transport action and create the index from within there.
Any calls to a system index should be wrapped into threadContext.stashContext to assure that the plugin can perform the action regardless of the authenticated user's permissions.
Signed-off-by: Derek Ho <[email protected]>
Description
Adds an API action to handle creation of API tokens index during PUT calls
Issues Resolved
[List any issues this PR will resolve]
Is this a backport? If so, please add backport PR # and/or commits #, and remove
backport-failed
label from the original PR.Do these changes introduce new permission(s) to be displayed in the static dropdown on the front-end? If so, please open a draft PR in the security dashboards plugin and link the draft PR here
Testing
[Please provide details of testing done: unit testing, integration testing and manual testing]
Check 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.