-
Notifications
You must be signed in to change notification settings - Fork 24.8k
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
Introduce "ConditionalClusterPrivilege" #32073
Merged
tvernum
merged 3 commits into
elastic:security-app-privs
from
tvernum:app-priv/conditional-cluster-priv
Jul 17, 2018
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
31 changes: 31 additions & 0 deletions
31
...va/org/elasticsearch/xpack/core/security/authz/privilege/ConditionalClusterPrivilege.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,31 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.core.security.authz.privilege; | ||
|
||
import org.elasticsearch.common.io.stream.NamedWriteable; | ||
import org.elasticsearch.transport.TransportRequest; | ||
|
||
import java.util.function.Predicate; | ||
|
||
/** | ||
* A ConditionalClusterPrivilege is a composition of a {@link ClusterPrivilege} (that determines which actions may be executed) | ||
* with a {@link Predicate} for a {@link TransportRequest} (that determines which requests may be executed). | ||
* The a given execution of an action is considered to be permitted if both the action and the request are permitted. | ||
*/ | ||
public interface ConditionalClusterPrivilege extends NamedWriteable { | ||
|
||
/** | ||
* The action-level privilege that is required by this conditional privilege. | ||
*/ | ||
ClusterPrivilege getPrivilege(); | ||
|
||
/** | ||
* The request-level privilege (as a {@link Predicate}) that is required by this conditional privilege. | ||
*/ | ||
Predicate<TransportRequest> getRequestPredicate(); | ||
|
||
} |
39 changes: 39 additions & 0 deletions
39
...a/org/elasticsearch/xpack/core/security/authz/privilege/ConditionalClusterPrivileges.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,39 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.core.security.authz.privilege; | ||
|
||
import org.elasticsearch.common.io.stream.StreamInput; | ||
import org.elasticsearch.common.io.stream.StreamOutput; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* Static utility class for working with {@link ConditionalClusterPrivilege} instances | ||
*/ | ||
public final class ConditionalClusterPrivileges { | ||
|
||
public static final ConditionalClusterPrivilege[] EMPTY_ARRAY = new ConditionalClusterPrivilege[0]; | ||
|
||
private ConditionalClusterPrivileges() { | ||
} | ||
|
||
/** | ||
* Utility method to read an array of {@link ConditionalClusterPrivilege} objects from a {@link StreamInput} | ||
*/ | ||
public static ConditionalClusterPrivilege[] readArray(StreamInput in) throws IOException { | ||
return in.readArray(in1 -> | ||
in1.readNamedWriteable(ConditionalClusterPrivilege.class), ConditionalClusterPrivilege[]::new); | ||
} | ||
|
||
/** | ||
* Utility method to write an array of {@link ConditionalClusterPrivilege} objects to a {@link StreamOutput} | ||
*/ | ||
public static void writeArray(StreamOutput out, ConditionalClusterPrivilege[] privileges) throws IOException { | ||
out.writeArray((out1, value) -> out1.writeNamedWriteable(value), privileges); | ||
} | ||
|
||
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. This class is small and seems a bit redundant right now, but it will handle the XContent parsing/building when we add that. |
||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
We currently have special handling for same user privileges. I wonder if it is worth a refactor to change this to a
BiPredicate
, which would cover that case as well. I'm tossing this out there as an idea and we can always defer this to later onThere 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.
This is a good idea - I'll see about adding it in a followup.