Skip to content

Commit

Permalink
Allow system privilege to execute proxied actions (#37508)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Tim-Brooks authored Jan 16, 2019
1 parent 86697f2 commit 0b5af27
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,14 @@ public static TransportRequest unwrapRequest(TransportRequest request) {
return request;
}

/**
* Unwraps a proxy action and returns the underlying action
*/
public static String unwrapAction(String action) {
assert isProxyAction(action) : "Attempted to unwrap non-proxy action: " + action;
return action.substring(PROXY_ACTION_PREFIX.length());
}

/**
* Returns <code>true</code> iff the given action is a proxy action
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
package org.elasticsearch.xpack.core.security.authz.privilege;

import org.elasticsearch.transport.TransportActionProxy;
import org.elasticsearch.xpack.core.security.support.Automatons;

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

public static SystemPrivilege INSTANCE = new SystemPrivilege();

private static final Predicate<String> PREDICATE = Automatons.predicate(Automatons.
minusAndMinimize(Automatons.patterns(
"internal:*",
"indices:monitor/*", // added for monitoring
"cluster:monitor/*", // added for monitoring
"cluster:admin/bootstrap/*", // for the bootstrap service
"cluster:admin/reroute", // added for DiskThresholdDecider.DiskListener
"indices:admin/mapping/put", // needed for recovery and shrink api
"indices:admin/template/put", // needed for the TemplateUpgradeService
"indices:admin/template/delete", // needed for the TemplateUpgradeService
"indices:admin/seq_no/global_checkpoint_sync*", // needed for global checkpoint syncs
"indices:admin/settings/update" // needed for DiskThresholdMonitor.markIndicesReadOnly
), Automatons.patterns("internal:transport/proxy/*"))); // no proxy actions for system user!
private static final Predicate<String> ALLOWED_ACTIONS = Automatons.predicate(
"internal:*",
"indices:monitor/*", // added for monitoring
"cluster:monitor/*", // added for monitoring
"cluster:admin/bootstrap/*", // for the bootstrap service
"cluster:admin/reroute", // added for DiskThresholdDecider.DiskListener
"indices:admin/mapping/put", // needed for recovery and shrink api
"indices:admin/template/put", // needed for the TemplateUpgradeService
"indices:admin/template/delete", // needed for the TemplateUpgradeService
"indices:admin/seq_no/global_checkpoint_sync*", // needed for global checkpoint syncs
"indices:admin/settings/update" // needed for DiskThresholdMonitor.markIndicesReadOnly
);

private static final Predicate<String> PREDICATE = (action) -> {
// Only allow a proxy action if the underlying action is allowed
if (TransportActionProxy.isProxyAction(action)) {
return ALLOWED_ACTIONS.test(TransportActionProxy.unwrapAction(action));
} else {
return ALLOWED_ACTIONS.test(action);
}
};

private SystemPrivilege() {
super(Collections.singleton("internal"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ public void testSystem() throws Exception {
assertThat(predicate.test("indices:admin/mapping/put"), is(true));
assertThat(predicate.test("indices:admin/mapping/whatever"), is(false));
assertThat(predicate.test("internal:transport/proxy/indices:data/read/query"), is(false));
assertThat(predicate.test("internal:transport/proxy/indices:monitor/whatever"), is(true));
assertThat(predicate.test("indices:admin/seq_no/global_checkpoint_sync"), is(true));
assertThat(predicate.test("indices:admin/seq_no/global_checkpoint_sync[p]"), is(true));
assertThat(predicate.test("indices:admin/seq_no/global_checkpoint_sync[r]"), is(true));
Expand Down

0 comments on commit 0b5af27

Please sign in to comment.