Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow system privilege to execute proxied actions #37508

Merged
merged 1 commit into from
Jan 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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