-
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
Permission for restricted indices #37577
Permission for restricted indices #37577
Conversation
Pinging @elastic/es-security |
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.
This is looking pretty good
@Nullable String query) { | ||
super(indices, privileges); | ||
private IndicesPrivileges(Collection<String> indices, Collection<String> privileges, boolean allowRestrictedIndices, | ||
@Nullable FieldSecurity fieldSecurity, @Nullable String query) { |
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: can you align the fields so that the @
on this line aligns with the C
return check(action) && (indexNameMatcher.test(index) | ||
&& ((false == RestrictedIndicesNames.NAMES_SET.contains(index)) // if it is not restricted no more checks are required | ||
|| IndexPrivilege.MONITOR.predicate().test(action) // allow monitor as a special case, even for restricted | ||
|| allowRestrictedIndices) |
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.
I suggest we reorder this check to:
(indexNameMatcher.test(index) && (allowRestrictedIndices || false == RestrictedIndicesNames.NAMES_SET.contains(index) || IndexPrivilege.MONITOR.predicate().test(action))
} | ||
} | ||
} | ||
return indexMatcher(restrictedIndices) |
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.
I think it might be worth checking if we have any restricted or any ordinary
final Predicate<String> predicate;
if (restricted.isEmpty()) {
predicate = indexMatcher(ordinaryIndices)
.and(index -> false == RestrictedIndicesNames.NAMES_SET.contains(index));
} else if (ordinary.isEmpty()) {
predicate = indexMatcher(restrictedIndices);
} else {
predicate = indexMatcher(restrictedIndices)
.or(indexMatcher(ordinaryIndices)
.and(index -> false == RestrictedIndicesNames.NAMES_SET.contains(index)));
}
also, shouldn't we take into account the monitor action case?
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.
I think it might be worth checking if we have any restricted or any ordinary
Agreed will do!
shouldn't we take into account the monitor action case?
Ha! I noticed this too, but I decided to keep the original behavior. In the original behavior, monitoring for wildcards will not work, indices have to be named explicitly.
Out of the three options:
- remove support all together
- keep it as is
- extend monitoring priv to wildcards
I am leaning towards 1, but only slightly. Maintaining the status quo was chosen so that this PR sail smoothly.
I think we can make any such change in a different PR (if it's breaking I'll take good care of it to catch the train!)
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.
Let's maintain status quo in this PR and then do 1 in a followup targeted towards 7.0
import java.util.Collections; | ||
import java.util.Set; | ||
|
||
public class RestrictedIndicesNames { |
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.
make the class final and add private constructor
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.
I'll learn, I'll learn, thanks for the patience!
Thanks for the speedy feedback @jaymode ! I have pushed the fixes. |
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.
LGTM. Hopefully CI will agree
run gradle build tests 1 |
This grants the capability to grant privileges over certain restricted indices (.security and .security-6 at the moment). It also removes the special status of the superuser role. IndicesPermission.Group is extended by adding the `allow_restricted_indices` boolean flag. By default the flag is false. When it is toggled, you acknowledge that the indices under the scope of the permission group can cover the restricted indices as well. Otherwise, by default, restricted indices are ignored when granting privileges, thus rendering them hidden for authorization purposes. This effectively adds a confirmation "check-box" for roles that might grant privileges to restricted indices. The "special status" of the superuser role has been removed and coded as any other role: ``` new RoleDescriptor("superuser", new String[] { "all" }, new RoleDescriptor.IndicesPrivileges[] { RoleDescriptor.IndicesPrivileges.builder() .indices("*") .privileges("all") .allowRestrictedIndices(true) // this ----^ .build() }, new RoleDescriptor.ApplicationResourcePrivileges[] { RoleDescriptor.ApplicationResourcePrivileges.builder() .application("*") .privileges("*") .resources("*") .build() }, null, new String[] { "*" }, MetadataUtils.DEFAULT_RESERVED_METADATA, Collections.emptyMap()); ``` In the context of the Backup .security work, this allows the creation of a "curator role" that would permit listing (get settings) for all indices (including the restricted ones). That way the curator role would be able to ist and snapshot all indices, but not read or restore any of them. Supersedes #36765 Relates #34454
* elastic/master: (104 commits) Permission for restricted indices (elastic#37577) Remove Watcher Account "unsecure" settings (elastic#36736) Add cache cleaning task for ML snapshot (elastic#37505) Update jdk used by the docker builds (elastic#37621) Remove an unused constant in PutMappingRequest. Update get users to allow unknown fields (elastic#37593) Do not add index event listener if CCR disabled (elastic#37432) Add local session timeouts to leader node (elastic#37438) Add some deprecation optimizations (elastic#37597) refactor inner geogrid classes to own class files (elastic#37596) Remove obsolete deprecation checks (elastic#37510) ML: Add support for single bucket aggs in Datafeeds (elastic#37544) ML: creating ML State write alias and pointing writes there (elastic#37483) Deprecate types in the put mapping API. (elastic#37280) [ILM] Add unfollow action (elastic#36970) Packaging: Update marker used to allow ELASTIC_PASSWORD (elastic#37243) Fix setting openldap realm ssl config Document the need for JAVA11_HOME (elastic#37589) SQL: fix object extraction from sources (elastic#37502) Nit in settings.gradle for Eclipse ...
allowRestrictedIndices was only added in ES6.7 (see elastic#37577). For randomised testing we should not set that field if we are generating a role descriptor that will be serialized into an older version stream. Resolves: elastic#82216
allowRestrictedIndices was only added in ES6.7 (see elastic#37577). For randomised testing we should not set that field if we are generating a role descriptor that will be serialized into an older version stream. Resolves: elastic#82216
Supersedes #36765 .
This grants the capability to grant privileges over certain restricted indices (
.security
and.security-6
at the moment) . It also removes the special status of thesuperuser
role.IndicesPermission.Group
is extended by adding theallow_restricted_indices
boolean flag. By default the flag isfalse
. When it is toggled, you acknowledge that the indices under the scope of the permission group can cover the restricted indices as well. Otherwise, by default, restricted indices are ignored when granting privileges, thus rendering them hidden for authorization purposes.This effectively adds a confirmation "check-box" for roles that might grant privileges to restricted indices.
The "special status" of the
superuser
role has been removed and coded as any other role:In the context of the Backup .security work, this would allow the creation of a curator role that would permit listing (get settings) for all indices (including the restricted ones). That way the curator role would be able to list and snapshot all indices, but not read or restore any of them.
Relates #34454