Skip to content

Commit

Permalink
Ensure view_index_metadata is fully covered by manage
Browse files Browse the repository at this point in the history
In elastic#80984, a new action is added to the "view_index_privilege" index
privilege. This PR adds it under "manage" as well and also adds test to
ensure "view_index_metadata" is always a subset of "manage".
  • Loading branch information
ywangd committed Mar 1, 2022
1 parent e1202dd commit a22a1ff
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,12 @@ public final class IndexPrivilege extends Privilege {
private static final Automaton MANAGE_AUTOMATON = unionAndMinimize(
Arrays.asList(
MONITOR_AUTOMATON,
patterns("indices:admin/*", FieldCapabilitiesAction.NAME + "*", GetRollupIndexCapsAction.NAME + "*")
patterns(
"indices:admin/*",
FieldCapabilitiesAction.NAME + "*",
GetRollupIndexCapsAction.NAME + "*",
GetCheckpointAction.NAME + "*" // transform internal action
)
)
);
private static final Automaton CREATE_INDEX_AUTOMATON = patterns(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

package org.elasticsearch.xpack.core.security.authz.privilege;

import org.apache.lucene.util.automaton.Operations;
import org.elasticsearch.action.admin.indices.refresh.RefreshAction;
import org.elasticsearch.action.admin.indices.shrink.ShrinkAction;
import org.elasticsearch.action.admin.indices.stats.IndicesStatsAction;
Expand All @@ -24,6 +25,7 @@

import static org.elasticsearch.xpack.core.security.authz.privilege.IndexPrivilege.findPrivilegesThatGrant;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.lessThan;

public class IndexPrivilegeTests extends ESTestCase {
Expand All @@ -40,16 +42,18 @@ public void testOrderingOfPrivilegeNames() throws Exception {
final int read = Iterables.indexOf(names, "read"::equals);
final int write = Iterables.indexOf(names, "write"::equals);
final int index = Iterables.indexOf(names, "index"::equals);
final int create_doc = Iterables.indexOf(names, "create_doc"::equals);
final int createDoc = Iterables.indexOf(names, "create_doc"::equals);
final int delete = Iterables.indexOf(names, "delete"::equals);
final int viewIndexMetadata = Iterables.indexOf(names, "view_index_metadata"::equals);

assertThat(read, lessThan(all));
assertThat(manage, lessThan(all));
assertThat(monitor, lessThan(manage));
assertThat(write, lessThan(all));
assertThat(index, lessThan(write));
assertThat(create_doc, lessThan(index));
assertThat(createDoc, lessThan(index));
assertThat(delete, lessThan(write));
assertThat(viewIndexMetadata, lessThan(manage));
}

public void testFindPrivilegesThatGrant() {
Expand All @@ -67,4 +71,13 @@ public void testPrivilegesForRollupFieldCapsAction() {
assertThat(Set.copyOf(privileges), equalTo(Set.of("read", "view_index_metadata", "manage", "all")));
}

public void testViewIndexMetadataIsCoveredByManage() {
assertThat(
Operations.subsetOf(
IndexPrivilege.get(Set.of("view_index_metadata")).automaton,
IndexPrivilege.get(Set.of("manage")).automaton
),
is(true)
);
}
}

0 comments on commit a22a1ff

Please sign in to comment.