Skip to content

Commit 0b5af27

Browse files
authored
Allow system privilege to execute proxied actions (#37508)
Currently all proxied actions are denied for the `SystemPrivilege`. Unfortunately, there are use cases (CCR) where we would like to proxy actions to a remote node that are normally performed by the system context. This commit allows the system context to perform proxy actions if they are actions that the system context is normally allowed to execute.
1 parent 86697f2 commit 0b5af27

File tree

3 files changed

+31
-13
lines changed

3 files changed

+31
-13
lines changed

server/src/main/java/org/elasticsearch/transport/TransportActionProxy.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,14 @@ public static TransportRequest unwrapRequest(TransportRequest request) {
175175
return request;
176176
}
177177

178+
/**
179+
* Unwraps a proxy action and returns the underlying action
180+
*/
181+
public static String unwrapAction(String action) {
182+
assert isProxyAction(action) : "Attempted to unwrap non-proxy action: " + action;
183+
return action.substring(PROXY_ACTION_PREFIX.length());
184+
}
185+
178186
/**
179187
* Returns <code>true</code> iff the given action is a proxy action
180188
*/

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

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
package org.elasticsearch.xpack.core.security.authz.privilege;
77

8+
import org.elasticsearch.transport.TransportActionProxy;
89
import org.elasticsearch.xpack.core.security.support.Automatons;
910

1011
import java.util.Collections;
@@ -14,19 +15,27 @@ public final class SystemPrivilege extends Privilege {
1415

1516
public static SystemPrivilege INSTANCE = new SystemPrivilege();
1617

17-
private static final Predicate<String> PREDICATE = Automatons.predicate(Automatons.
18-
minusAndMinimize(Automatons.patterns(
19-
"internal:*",
20-
"indices:monitor/*", // added for monitoring
21-
"cluster:monitor/*", // added for monitoring
22-
"cluster:admin/bootstrap/*", // for the bootstrap service
23-
"cluster:admin/reroute", // added for DiskThresholdDecider.DiskListener
24-
"indices:admin/mapping/put", // needed for recovery and shrink api
25-
"indices:admin/template/put", // needed for the TemplateUpgradeService
26-
"indices:admin/template/delete", // needed for the TemplateUpgradeService
27-
"indices:admin/seq_no/global_checkpoint_sync*", // needed for global checkpoint syncs
28-
"indices:admin/settings/update" // needed for DiskThresholdMonitor.markIndicesReadOnly
29-
), Automatons.patterns("internal:transport/proxy/*"))); // no proxy actions for system user!
18+
private static final Predicate<String> ALLOWED_ACTIONS = Automatons.predicate(
19+
"internal:*",
20+
"indices:monitor/*", // added for monitoring
21+
"cluster:monitor/*", // added for monitoring
22+
"cluster:admin/bootstrap/*", // for the bootstrap service
23+
"cluster:admin/reroute", // added for DiskThresholdDecider.DiskListener
24+
"indices:admin/mapping/put", // needed for recovery and shrink api
25+
"indices:admin/template/put", // needed for the TemplateUpgradeService
26+
"indices:admin/template/delete", // needed for the TemplateUpgradeService
27+
"indices:admin/seq_no/global_checkpoint_sync*", // needed for global checkpoint syncs
28+
"indices:admin/settings/update" // needed for DiskThresholdMonitor.markIndicesReadOnly
29+
);
30+
31+
private static final Predicate<String> PREDICATE = (action) -> {
32+
// Only allow a proxy action if the underlying action is allowed
33+
if (TransportActionProxy.isProxyAction(action)) {
34+
return ALLOWED_ACTIONS.test(TransportActionProxy.unwrapAction(action));
35+
} else {
36+
return ALLOWED_ACTIONS.test(action);
37+
}
38+
};
3039

3140
private SystemPrivilege() {
3241
super(Collections.singleton("internal"));

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ public void testSystem() throws Exception {
123123
assertThat(predicate.test("indices:admin/mapping/put"), is(true));
124124
assertThat(predicate.test("indices:admin/mapping/whatever"), is(false));
125125
assertThat(predicate.test("internal:transport/proxy/indices:data/read/query"), is(false));
126+
assertThat(predicate.test("internal:transport/proxy/indices:monitor/whatever"), is(true));
126127
assertThat(predicate.test("indices:admin/seq_no/global_checkpoint_sync"), is(true));
127128
assertThat(predicate.test("indices:admin/seq_no/global_checkpoint_sync[p]"), is(true));
128129
assertThat(predicate.test("indices:admin/seq_no/global_checkpoint_sync[r]"), is(true));

0 commit comments

Comments
 (0)