-
Notifications
You must be signed in to change notification settings - Fork 25k
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 cache for application privileges #55836
Changes from all commits
b72d0d3
a02aba3
6d9fa0a
ee33fff
4bbd16d
df28676
4a63a16
a1d177c
05061f9
daafb80
545e27c
5987b3b
6094178
1c58309
9100c24
3f9c5b7
08865dd
b9538a8
9c5e947
f5b166c
1e7ce7c
f1f3e72
a7b5b40
5306bc1
03680bc
cdfe886
435993d
20be80d
d2f2f3e
f1f7035
db6020e
73dda1f
ea9172f
65f9524
04bb476
07b7837
34464d7
e87d897
5acc7ec
5e3174a
385fb12
e411dc9
58b3942
a8f8e81
9a763c3
a43b3ef
ac6c39f
8e1dc13
21c89fb
1499a26
3b7e773
83a0e19
3deef1e
9364e36
0280c3e
ae3c784
68a4dc1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.elasticsearch.client.security; | ||
|
||
import org.elasticsearch.client.Validatable; | ||
|
||
import java.util.Arrays; | ||
|
||
/** | ||
* The request used to clear the cache for native application privileges stored in an index. | ||
*/ | ||
public final class ClearPrivilegesCacheRequest implements Validatable { | ||
|
||
private final String[] applications; | ||
|
||
/** | ||
* Sets the applications for which caches will be evicted. When not set all privileges will be evicted from the cache. | ||
* | ||
* @param applications The application names | ||
*/ | ||
public ClearPrivilegesCacheRequest(String... applications) { | ||
this.applications = applications; | ||
} | ||
|
||
/** | ||
* @return an array of application names that will have the cache evicted or <code>null</code> if all | ||
*/ | ||
public String[] applications() { | ||
return applications; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
ClearPrivilegesCacheRequest that = (ClearPrivilegesCacheRequest) o; | ||
return Arrays.equals(applications, that.applications); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Arrays.hashCode(applications); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.elasticsearch.client.security; | ||
|
||
import org.elasticsearch.client.NodesResponseHeader; | ||
import org.elasticsearch.common.xcontent.ConstructingObjectParser; | ||
import org.elasticsearch.common.xcontent.XContentParser; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
/** | ||
* The response object that will be returned when clearing the privileges cache | ||
*/ | ||
public final class ClearPrivilegesCacheResponse extends SecurityNodesResponse { | ||
|
||
@SuppressWarnings("unchecked") | ||
private static final ConstructingObjectParser<ClearPrivilegesCacheResponse, Void> PARSER = | ||
new ConstructingObjectParser<>("clear_privileges_cache_response", false, | ||
args -> new ClearPrivilegesCacheResponse((List<Node>)args[0], (NodesResponseHeader) args[1], (String) args[2])); | ||
|
||
static { | ||
SecurityNodesResponse.declareCommonNodesResponseParsing(PARSER); | ||
} | ||
|
||
public ClearPrivilegesCacheResponse(List<Node> nodes, NodesResponseHeader header, String clusterName) { | ||
super(nodes, header, clusterName); | ||
} | ||
|
||
public static ClearPrivilegesCacheResponse fromXContent(XContentParser parser) throws IOException { | ||
return PARSER.parse(parser, null); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
|
||
-- | ||
:api: clear-privileges-cache | ||
:request: ClearPrivilegesCacheRequest | ||
:response: ClearPrivilegesCacheResponse | ||
-- | ||
[role="xpack"] | ||
[id="{upid}-{api}"] | ||
=== Clear Privileges Cache API | ||
|
||
[id="{upid}-{api}-request"] | ||
==== Clear Privileges Cache Request | ||
|
||
A +{request}+ supports defining the name of applications that the cache should be cleared for. | ||
|
||
["source","java",subs="attributes,callouts,macros"] | ||
-------------------------------------------------- | ||
include-tagged::{doc-tests-file}[{api}-request] | ||
-------------------------------------------------- | ||
<1> the name of the application(s) for which the cache should be cleared | ||
|
||
include::../execution.asciidoc[] | ||
|
||
[id="{upid}-{api}-response"] | ||
==== Clear Privileges Cache Response | ||
|
||
The returned +{response}+ allows to retrieve information about where the cache was cleared. | ||
|
||
["source","java",subs="attributes,callouts,macros"] | ||
-------------------------------------------------- | ||
include-tagged::{doc-tests-file}[{api}-response] | ||
-------------------------------------------------- | ||
<1> the list of nodes that the cache was cleared on |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
[role="xpack"] | ||
[[security-api-clear-privilege-cache]] | ||
=== Clear privileges cache API | ||
++++ | ||
<titleabbrev>Clear privileges cache</titleabbrev> | ||
++++ | ||
|
||
Evicts privileges from the native application privilege cache. | ||
The cache is also automatically cleared for applications that have their privileges updated. | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know we don't do this in the other clear cache docs (but we should strive to improve) however I think it's worth stating that the cache is automatically cleared when a privilege is modified. I mention it because There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes makes sense. I'll add "The cache is also automatically cleared for applications that have their privileges updated." |
||
[[security-api-clear-privilege-cache-request]] | ||
==== {api-request-title} | ||
|
||
`POST /_security/privilege/<application>/_clear_cache` | ||
|
||
[[security-api-clear-privilege-cache-prereqs]] | ||
==== {api-prereq-title} | ||
|
||
* To use this API, you must have at least the `manage_security` cluster | ||
privilege. | ||
|
||
[[security-api-clear-privilege-cache-desc]] | ||
==== {api-description-title} | ||
|
||
For more information about the native realm, see | ||
<<realms>> and <<native-realm>>. | ||
|
||
[[security-api-clear-privilege-cache-path-params]] | ||
==== {api-path-parms-title} | ||
|
||
`application`:: | ||
(string) The name of the application. If omitted, all entries are evicted from the cache. | ||
|
||
[[security-api-clear-privilege-cache-example]] | ||
==== {api-examples-title} | ||
|
||
The clear privileges cache API evicts privileges from the native application privilege cache. | ||
For example, to clear the cache for `myapp`: | ||
|
||
[source,console] | ||
-------------------------------------------------- | ||
POST /_security/privilege/myapp/_clear_cache | ||
-------------------------------------------------- |
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.
Per my comment above, maybe