Skip to content

Commit 80860ee

Browse files
bizybotkcm
authored andcommitted
[Authz] Allow update settings action for system user (#34030)
When the cluster.routing.allocation.disk.watermark.flood_stage watermark is breached, DiskThresholdMonitor marks the indices as read-only. This failed when x-pack security was present as system user does not have the privilege for update settings action("indices:admin/settings/update"). This commit adds the required privilege for the system user. Also added missing debug logs when access is denied to help future debugging. An assert statement is added to catch any missed privileges required for system user. Closes #33119
1 parent a768830 commit 80860ee

File tree

4 files changed

+23
-18
lines changed

4 files changed

+23
-18
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ public final class SystemPrivilege extends Privilege {
2323
"indices:admin/mapping/put", // needed for recovery and shrink api
2424
"indices:admin/template/put", // needed for the TemplateUpgradeService
2525
"indices:admin/template/delete", // needed for the TemplateUpgradeService
26-
"indices:admin/seq_no/global_checkpoint_sync*" // needed for global checkpoint syncs
26+
"indices:admin/seq_no/global_checkpoint_sync*", // needed for global checkpoint syncs
27+
"indices:admin/settings/update" // needed for DiskThresholdMonitor.markIndicesReadOnly
2728
), Automatons.patterns("internal:transport/proxy/*"))); // no proxy actions for system user!
2829

2930
private SystemPrivilege() {

x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/security/authz/privilege/PrivilegeTests.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ public void testSystem() throws Exception {
126126
assertThat(predicate.test("indices:admin/seq_no/global_checkpoint_sync"), is(true));
127127
assertThat(predicate.test("indices:admin/seq_no/global_checkpoint_sync[p]"), is(true));
128128
assertThat(predicate.test("indices:admin/seq_no/global_checkpoint_sync[r]"), is(true));
129+
assertThat(predicate.test("indices:admin/settings/update"), is(true));
130+
assertThat(predicate.test("indices:admin/settings/foo"), is(false));
129131
}
130132

131133
public void testManageCcrPrivilege() {

x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authz/AuthorizationService.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,9 +568,12 @@ private ElasticsearchSecurityException denialException(Authentication authentica
568568
}
569569
// check for run as
570570
if (authentication.getUser().isRunAs()) {
571+
logger.debug("action [{}] is unauthorized for user [{}] run as [{}]", action, authUser.principal(),
572+
authentication.getUser().principal());
571573
return authorizationError("action [{}] is unauthorized for user [{}] run as [{}]", action, authUser.principal(),
572574
authentication.getUser().principal());
573575
}
576+
logger.debug("action [{}] is unauthorized for user [{}]", action, authUser.principal());
574577
return authorizationError("action [{}] is unauthorized for user [{}]", action, authUser.principal());
575578
}
576579

x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authz/AuthorizationServiceTests.java

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -240,22 +240,23 @@ private void authorize(Authentication authentication, String action, TransportRe
240240
future.actionGet();
241241
}
242242

243-
public void testActionsSystemUserIsAuthorized() {
244-
TransportRequest request = mock(TransportRequest.class);
243+
public void testActionsForSystemUserIsAuthorized() {
244+
final TransportRequest request = mock(TransportRequest.class);
245245

246246
// A failure would throw an exception
247-
Authentication authentication = createAuthentication(SystemUser.INSTANCE);
248-
authorize(authentication, "indices:monitor/whatever", request);
249-
verify(auditTrail).accessGranted(authentication, "indices:monitor/whatever", request,
250-
new String[]{SystemUser.ROLE_NAME});
251-
252-
authentication = createAuthentication(SystemUser.INSTANCE);
253-
authorize(authentication, "internal:whatever", request);
254-
verify(auditTrail).accessGranted(authentication, "internal:whatever", request, new String[]{SystemUser.ROLE_NAME});
247+
final Authentication authentication = createAuthentication(SystemUser.INSTANCE);
248+
final String[] actions = { "indices:monitor/whatever", "internal:whatever", "cluster:monitor/whatever", "cluster:admin/reroute",
249+
"indices:admin/mapping/put", "indices:admin/template/put", "indices:admin/seq_no/global_checkpoint_sync",
250+
"indices:admin/settings/update" };
251+
for (String action : actions) {
252+
authorize(authentication, action, request);
253+
verify(auditTrail).accessGranted(authentication, action, request, new String[] { SystemUser.ROLE_NAME });
254+
}
255+
255256
verifyNoMoreInteractions(auditTrail);
256257
}
257258

258-
public void testIndicesActionsAreNotAuthorized() {
259+
public void testIndicesActionsForSystemUserWhichAreNotAuthorized() {
259260
final TransportRequest request = mock(TransportRequest.class);
260261
final Authentication authentication = createAuthentication(SystemUser.INSTANCE);
261262
assertThrowsAuthorizationException(
@@ -265,25 +266,23 @@ public void testIndicesActionsAreNotAuthorized() {
265266
verifyNoMoreInteractions(auditTrail);
266267
}
267268

268-
public void testClusterAdminActionsAreNotAuthorized() {
269+
public void testClusterAdminActionsForSystemUserWhichAreNotAuthorized() {
269270
final TransportRequest request = mock(TransportRequest.class);
270271
final Authentication authentication = createAuthentication(SystemUser.INSTANCE);
271272
assertThrowsAuthorizationException(
272273
() -> authorize(authentication, "cluster:admin/whatever", request),
273274
"cluster:admin/whatever", SystemUser.INSTANCE.principal());
274-
verify(auditTrail).accessDenied(authentication, "cluster:admin/whatever", request,
275-
new String[]{SystemUser.ROLE_NAME});
275+
verify(auditTrail).accessDenied(authentication, "cluster:admin/whatever", request, new String[] { SystemUser.ROLE_NAME });
276276
verifyNoMoreInteractions(auditTrail);
277277
}
278278

279-
public void testClusterAdminSnapshotStatusActionIsNotAuthorized() {
279+
public void testClusterAdminSnapshotStatusActionForSystemUserWhichIsNotAuthorized() {
280280
final TransportRequest request = mock(TransportRequest.class);
281281
final Authentication authentication = createAuthentication(SystemUser.INSTANCE);
282282
assertThrowsAuthorizationException(
283283
() -> authorize(authentication, "cluster:admin/snapshot/status", request),
284284
"cluster:admin/snapshot/status", SystemUser.INSTANCE.principal());
285-
verify(auditTrail).accessDenied(authentication, "cluster:admin/snapshot/status", request,
286-
new String[]{SystemUser.ROLE_NAME});
285+
verify(auditTrail).accessDenied(authentication, "cluster:admin/snapshot/status", request, new String[] { SystemUser.ROLE_NAME });
287286
verifyNoMoreInteractions(auditTrail);
288287
}
289288

0 commit comments

Comments
 (0)