Skip to content

Commit 5712246

Browse files
author
Amir H Movahed
authored
Add new 'maintenance' index privilege (#50643)
This commit creates a new index privilege named `maintenance`. The privilege grants the following actions: `refresh`, `flush` (also synced-`flush`), and `force-merge`. Previously the actions were only under the `manage` privilege which in some situations was too permissive. Co-authored-by: arhd83@gmail.com
1 parent f891a0d commit 5712246

File tree

6 files changed

+71
-34
lines changed

6 files changed

+71
-34
lines changed

client/rest-high-level/src/main/java/org/elasticsearch/client/security/user/privileges/Role.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,8 +350,9 @@ public static class IndexPrivilegeName {
350350
public static final String MANAGE_FOLLOW_INDEX = "manage_follow_index";
351351
public static final String MANAGE_ILM = "manage_ilm";
352352
public static final String CREATE_DOC = "create_doc";
353+
public static final String MAINTENANCE = "maintenance";
353354
public static final String[] ALL_ARRAY = new String[] { NONE, ALL, READ, READ_CROSS, CREATE, INDEX, DELETE, WRITE, MONITOR, MANAGE,
354-
DELETE_INDEX, CREATE_INDEX, VIEW_INDEX_METADATA, MANAGE_FOLLOW_INDEX, MANAGE_ILM, CREATE_DOC };
355+
DELETE_INDEX, CREATE_INDEX, VIEW_INDEX_METADATA, MANAGE_FOLLOW_INDEX, MANAGE_ILM, CREATE_DOC, MAINTENANCE };
355356
}
356357

357358
}

x-pack/docs/en/rest-api/security/get-builtin-privileges.asciidoc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ available in this version of {es}.
1212
[[security-api-get-builtin-privileges-request]]
1313
==== {api-request-title}
1414

15-
`GET /_security/privilege/_builtin`
15+
`GET /_security/privilege/_builtin`
1616

1717

1818
[[security-api-get-builtin-privileges-prereqs]]
@@ -104,6 +104,7 @@ A successful call returns an object with "cluster" and "index" fields.
104104
"delete",
105105
"delete_index",
106106
"index",
107+
"maintenance",
107108
"manage",
108109
"manage_follow_index",
109110
"manage_ilm",

x-pack/docs/en/security/authorization/privileges.asciidoc

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ Privileges to list and view details on existing repositories and snapshots.
2121

2222
`manage`::
2323
Builds on `monitor` and adds cluster operations that change values in the cluster.
24-
This includes snapshotting, updating settings, and rerouting. It also includes
25-
obtaining snapshot and restore status. This privilege does not include the
24+
This includes snapshotting, updating settings, and rerouting. It also includes
25+
obtaining snapshot and restore status. This privilege does not include the
2626
ability to manage security.
2727

2828
`manage_api_key`::
29-
All security-related operations on {es} API keys including
29+
All security-related operations on {es} API keys including
3030
<<security-api-create-api-key,creating new API keys>>,
3131
<<security-api-get-api-key,retrieving information about API keys>>, and
3232
<<security-api-invalidate-api-key,invalidating API keys>>.
@@ -45,10 +45,10 @@ owned by other users.
4545
--
4646

4747
`manage_ccr`::
48-
All {ccr} operations related to managing follower indices and auto-follow
49-
patterns. It also includes the authority to grant the privileges necessary to
50-
manage follower indices and auto-follow patterns. This privilege is necessary
51-
only on clusters that contain follower indices.
48+
All {ccr} operations related to managing follower indices and auto-follow
49+
patterns. It also includes the authority to grant the privileges necessary to
50+
manage follower indices and auto-follow patterns. This privilege is necessary
51+
only on clusters that contain follower indices.
5252

5353
`manage_transform`::
5454
All operations related to managing {transforms}.
@@ -83,7 +83,7 @@ to initiate and manage OpenID Connect authentication on behalf of other users.
8383

8484
`manage_own_api_key`::
8585
All security-related operations on {es} API keys that are owned by the current
86-
authenticated user. The operations include
86+
authenticated user. The operations include
8787
<<security-api-create-api-key,creating new API keys>>,
8888
<<security-api-get-api-key,retrieving information about API keys>>, and
8989
<<security-api-invalidate-api-key,invalidating API keys>>.
@@ -119,7 +119,7 @@ security roles of the user who created or updated them.
119119
--
120120

121121
`monitor`::
122-
All cluster read-only operations, like cluster health and state, hot threads,
122+
All cluster read-only operations, like cluster health and state, hot threads,
123123
node info, node and cluster stats, and pending cluster tasks.
124124

125125
`monitor_transform`::
@@ -131,16 +131,16 @@ model snapshots, or results.
131131

132132
`monitor_rollup`::
133133
All read-only rollup operations, such as viewing the list of historical and
134-
currently running rollup jobs and their capabilities.
134+
currently running rollup jobs and their capabilities.
135135

136136
`monitor_watcher`::
137137
All read-only watcher operations, such as getting a watch and watcher stats.
138138

139139
`read_ccr`::
140-
All read-only {ccr} operations, such as getting information about indices and
141-
metadata for leader indices in the cluster. It also includes the authority to
142-
check whether users have the appropriate privileges to follow leader indices.
143-
This privilege is necessary only on clusters that contain leader indices.
140+
All read-only {ccr} operations, such as getting information about indices and
141+
metadata for leader indices in the cluster. It also includes the authority to
142+
check whether users have the appropriate privileges to follow leader indices.
143+
This privilege is necessary only on clusters that contain leader indices.
144144

145145
`read_ilm`::
146146
All read-only {Ilm} operations, such as getting policies and checking the
@@ -204,15 +204,19 @@ Privilege to delete an index.
204204
Privilege to index and update documents. Also grants access to the update
205205
mapping action.
206206

207+
`maintenance`::
208+
Permits refresh, flush, synced flush and force merge index administration operations.
209+
No privilege to read or write index data or otherwise manage the index.
210+
207211
`manage`::
208212
All `monitor` privileges plus index administration (aliases, analyze, cache clear,
209213
close, delete, exists, flush, mapping, open, force merge, refresh, settings,
210214
search shards, templates, validate).
211215

212216
`manage_follow_index`::
213217
All actions that are required to manage the lifecycle of a follower index, which
214-
includes creating a follower index, closing it, and converting it to a regular
215-
index. This privilege is necessary only on clusters that contain follower indices.
218+
includes creating a follower index, closing it, and converting it to a regular
219+
index. This privilege is necessary only on clusters that contain follower indices.
216220

217221
`manage_ilm`::
218222
All {Ilm} operations relating to managing the execution of policies of an index
@@ -225,7 +229,7 @@ includes <<ccr-post-forget-follower,forgetting a follower>>. This
225229
privilege is necessary only on clusters that contain leader indices.
226230

227231
`monitor`::
228-
All actions that are required for monitoring (recovery, segments info, index
232+
All actions that are required for monitoring (recovery, segments info, index
229233
stats and status).
230234

231235
`read`::
@@ -258,14 +262,14 @@ sequence.) For more information, see
258262
[[application-privileges]]
259263
==== Application privileges
260264

261-
Application privileges are managed within {es} and can be retrieved with the
262-
<<security-api-has-privileges,has privileges API>> and the
263-
<<security-api-get-privileges,get application privileges API>>. They do
264-
not, however, grant access to any actions or resources within {es}. Their
265-
purpose is to enable applications to represent and store their own privilege
266-
models within {es} roles.
267-
268-
To create application privileges, use the
269-
<<security-api-put-privileges,add application privileges API>>. You can
270-
then associate these application privileges with roles, as described in
271-
<<defining-roles>>.
265+
Application privileges are managed within {es} and can be retrieved with the
266+
<<security-api-has-privileges,has privileges API>> and the
267+
<<security-api-get-privileges,get application privileges API>>. They do
268+
not, however, grant access to any actions or resources within {es}. Their
269+
purpose is to enable applications to represent and store their own privilege
270+
models within {es} roles.
271+
272+
To create application privileges, use the
273+
<<security-api-put-privileges,add application privileges API>>. You can
274+
then associate these application privileges with roles, as described in
275+
<<defining-roles>>.

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/privilege/IndexPrivilege.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ public final class IndexPrivilege extends Privilege {
6666
CloseIndexAction.NAME + "*");
6767
private static final Automaton MANAGE_LEADER_INDEX_AUTOMATON = patterns(ForgetFollowerAction.NAME + "*");
6868
private static final Automaton MANAGE_ILM_AUTOMATON = patterns("indices:admin/ilm/*");
69+
private static final Automaton MAINTENANCE_AUTOMATON = patterns("indices:admin/refresh*", "indices:admin/flush*",
70+
"indices:admin/synced_flush", "indices:admin/forcemerge*");
6971

7072
public static final IndexPrivilege NONE = new IndexPrivilege("none", Automatons.EMPTY);
7173
public static final IndexPrivilege ALL = new IndexPrivilege("all", ALL_AUTOMATON);
@@ -83,7 +85,8 @@ public final class IndexPrivilege extends Privilege {
8385
public static final IndexPrivilege VIEW_METADATA = new IndexPrivilege("view_index_metadata", VIEW_METADATA_AUTOMATON);
8486
public static final IndexPrivilege MANAGE_FOLLOW_INDEX = new IndexPrivilege("manage_follow_index", MANAGE_FOLLOW_INDEX_AUTOMATON);
8587
public static final IndexPrivilege MANAGE_LEADER_INDEX = new IndexPrivilege("manage_leader_index", MANAGE_LEADER_INDEX_AUTOMATON);
86-
public static final IndexPrivilege MANAGE_ILM = new IndexPrivilege("manage_ilm", MANAGE_ILM_AUTOMATON);
88+
public static final IndexPrivilege MANAGE_ILM = new IndexPrivilege("manage_ilm", MANAGE_ILM_AUTOMATON);
89+
public static final IndexPrivilege MAINTENANCE = new IndexPrivilege("maintenance", MAINTENANCE_AUTOMATON);
8790

8891
private static final Map<String, IndexPrivilege> VALUES = Map.ofEntries(
8992
entry("none", NONE),
@@ -102,7 +105,8 @@ public final class IndexPrivilege extends Privilege {
102105
entry("read_cross_cluster", READ_CROSS_CLUSTER),
103106
entry("manage_follow_index", MANAGE_FOLLOW_INDEX),
104107
entry("manage_leader_index", MANAGE_LEADER_INDEX),
105-
entry("manage_ilm", MANAGE_ILM));
108+
entry("manage_ilm", MANAGE_ILM),
109+
entry("maintenance", MAINTENANCE));
106110

107111
public static final Predicate<String> ACTION_MATCHER = ALL.predicate();
108112
public static final Predicate<String> CREATE_INDEX_MATCHER = CREATE_INDEX.predicate();

x-pack/plugin/security/src/test/java/org/elasticsearch/integration/IndexPrivilegeTests.java

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ public class IndexPrivilegeTests extends AbstractPrivilegeTestCase {
6969
" indices:\n" +
7070
" - names: 'b'\n" +
7171
" privileges: [ monitor ]\n" +
72+
"maintenance_a_role:\n" +
73+
" indices:\n" +
74+
" - names: 'a'\n" +
75+
" privileges: [ maintenance ]\n" +
7276
"read_write_a_role:\n" +
7377
" indices:\n" +
7478
" - names: 'a'\n" +
@@ -96,6 +100,7 @@ public class IndexPrivilegeTests extends AbstractPrivilegeTestCase {
96100
"read_write_all_role:u12\n" +
97101
"create_c_role:u11\n" +
98102
"monitor_b_role:u14\n" +
103+
"maintenance_a_role:u15\n" +
99104
"read_write_a_role:u12\n" +
100105
"delete_b_role:u11\n" +
101106
"index_a_role:u13\n";
@@ -129,7 +134,8 @@ protected String configUsers() {
129134
"u11:" + usersPasswdHashed + "\n" +
130135
"u12:" + usersPasswdHashed + "\n" +
131136
"u13:" + usersPasswdHashed + "\n" +
132-
"u14:" + usersPasswdHashed + "\n";
137+
"u14:" + usersPasswdHashed + "\n" +
138+
"u15:" + usersPasswdHashed + "\n" ;
133139
}
134140

135141
@Override
@@ -308,12 +314,14 @@ public void testUserU11() throws Exception {
308314
assertUserIsDenied("u11", "manage", "b");
309315
assertUserIsDenied("u11", "index", "b");
310316
assertUserIsDenied("u11", "search", "b");
317+
assertUserIsDenied("u11", "maintenance", "b");
311318
assertUserIsAllowed("u11", "delete", "b");
312319

313320
assertAccessIsAllowed("admin", "DELETE", "/c");
314321
assertUserIsAllowed("u11", "create_index", "c");
315322
assertUserIsDenied("u11", "data_access", "c");
316323
assertUserIsDenied("u11", "monitor", "c");
324+
assertUserIsDenied("u11", "maintenance", "c");
317325

318326
assertAccessIsDenied("u11",
319327
"GET", "/" + randomIndex() + "/_msearch", "{}\n{ \"query\" : { \"match_all\" : {} } }\n");
@@ -385,6 +393,11 @@ public void testUserU14() throws Exception {
385393
"GET", "/" + randomIndex() + "/_mtermvectors", "{ \"docs\" : [ { \"_id\": \"1\" }, { \"_id\": \"2\" } ] }");
386394
}
387395

396+
public void testUserU15() throws Exception {
397+
assertUserIsAllowed("u15", "maintenance", "a");
398+
assertUserIsDenied("u15", "crud", "a");
399+
}
400+
388401
public void testThatUnknownUserIsRejectedProperly() throws Exception {
389402
try {
390403
Request request = new Request("GET", "/");
@@ -419,6 +432,20 @@ private void assertUserExecutes(String user, String action, String index, boolea
419432
}
420433
break;
421434

435+
case "maintenance" :
436+
if (userIsAllowed) {
437+
assertAccessIsAllowed(user, "POST", "/" + index + "/_refresh");
438+
assertAccessIsAllowed(user, "POST", "/" + index + "/_flush");
439+
assertAccessIsAllowed(user, "POST", "/" + index + "/_flush/synced");
440+
assertAccessIsAllowed(user, "POST", "/" + index + "/_forcemerge");
441+
} else {
442+
assertAccessIsDenied(user, "POST", "/" + index + "/_refresh");
443+
assertAccessIsDenied(user, "POST", "/" + index + "/_flush");
444+
assertAccessIsDenied(user, "POST", "/" + index + "/_flush/synced");
445+
assertAccessIsDenied(user, "POST", "/" + index + "/_forcemerge");
446+
}
447+
break;
448+
422449
case "manage" :
423450
if (userIsAllowed) {
424451
assertAccessIsAllowed(user, "DELETE", "/" + index);

x-pack/plugin/src/test/resources/rest-api-spec/test/privileges/11_builtin.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ setup:
1616
# I would much prefer we could just check that specific entries are in the array, but we don't have
1717
# an assertion for that
1818
- length: { "cluster" : 34 }
19-
- length: { "index" : 17 }
19+
- length: { "index" : 18 }

0 commit comments

Comments
 (0)