-
Notifications
You must be signed in to change notification settings - Fork 24.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
This PR adds a new Rest endpoint to clear caches used by service account authentication.
- Loading branch information
Showing
11 changed files
with
454 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
...arch/xpack/security/rest/action/service/RestClearServiceAccountTokenStoreCacheAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.security.rest.action.service; | ||
|
||
import org.elasticsearch.client.node.NodeClient; | ||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.license.XPackLicenseState; | ||
import org.elasticsearch.rest.RestRequest; | ||
import org.elasticsearch.rest.action.RestActions; | ||
import org.elasticsearch.xpack.core.security.action.ClearSecurityCacheAction; | ||
import org.elasticsearch.xpack.core.security.action.ClearSecurityCacheRequest; | ||
import org.elasticsearch.xpack.core.security.support.Validation; | ||
import org.elasticsearch.xpack.security.rest.action.SecurityBaseRestHandler; | ||
|
||
import java.io.IOException; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
import static org.elasticsearch.rest.RestRequest.Method.POST; | ||
|
||
public class RestClearServiceAccountTokenStoreCacheAction extends SecurityBaseRestHandler { | ||
|
||
public RestClearServiceAccountTokenStoreCacheAction(Settings settings, XPackLicenseState licenseState) { | ||
super(settings, licenseState); | ||
} | ||
|
||
@Override | ||
public List<Route> routes() { | ||
return org.elasticsearch.common.collect.List.of( | ||
new Route(POST, "/_security/service/{namespace}/{service}/credential/token/{name}/_clear_cache")); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "xpack_security_clear_service_account_token_store_cache"; | ||
} | ||
|
||
@Override | ||
protected RestChannelConsumer innerPrepareRequest(RestRequest request, NodeClient client) throws IOException { | ||
final String namespace = request.param("namespace"); | ||
final String service = request.param("service"); | ||
String[] tokenNames = request.paramAsStringArrayOrEmptyIfAll("name"); | ||
|
||
ClearSecurityCacheRequest req = new ClearSecurityCacheRequest().cacheName("service"); | ||
if (tokenNames.length == 0) { | ||
// This is the wildcard case for tokenNames | ||
req.keys(namespace + "/" + service + "/"); | ||
} else { | ||
final Set<String> qualifiedTokenNames = new HashSet<>(tokenNames.length); | ||
for (String name: tokenNames) { | ||
if (false == Validation.isValidServiceAccountTokenName(name)) { | ||
throw new IllegalArgumentException(Validation.INVALID_SERVICE_ACCOUNT_TOKEN_NAME_MESSAGE + " got: [" + name + "]"); | ||
} | ||
qualifiedTokenNames.add(namespace + "/" + service + "/" + name); | ||
} | ||
req.keys(qualifiedTokenNames.toArray(new String[0])); | ||
} | ||
return channel -> client.execute(ClearSecurityCacheAction.INSTANCE, req, new RestActions.NodesResponseRestListener<>(channel)); | ||
} | ||
} |
Oops, something went wrong.