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

Make get all app privs requires "*" permission #32460

Merged
merged 1 commit into from
Jul 30, 2018
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 @@ -50,7 +50,7 @@ public String application() {

@Override
public Collection<String> getApplicationNames() {
return Collections.singleton(application);
return application == null ? Collections.emptySet() : Collections.singleton(application);
}

public void privileges(String... privileges) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,9 @@ public ManageApplicationPrivileges(Set<String> applicationNames) {
this.requestPredicate = request -> {
if (request instanceof ApplicationPrivilegesRequest) {
final ApplicationPrivilegesRequest privRequest = (ApplicationPrivilegesRequest) request;
return privRequest.getApplicationNames().stream().allMatch(application -> applicationPredicate.test(application));
final Collection<String> requestApplicationNames = privRequest.getApplicationNames();
return requestApplicationNames.isEmpty() ? this.applicationNames.contains("*")
: requestApplicationNames.stream().allMatch(application -> applicationPredicate.test(application));
}
return false;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;

public class ManageApplicationPrivilegesTests extends ESTestCase {

Expand Down Expand Up @@ -140,6 +141,19 @@ public void testRequestPredicate() {
assertThat(cloudAndSwiftypePredicate, not(predicateMatches(putKibana)));
}

public void testSecurityForGetAllApplicationPrivileges() {
final GetPrivilegesRequest getAll = new GetPrivilegesRequest();
getAll.application(null);
getAll.privileges(new String[0]);

assertThat(getAll.validate(), nullValue());

final ManageApplicationPrivileges kibanaOnly = new ManageApplicationPrivileges(Sets.newHashSet("kibana-*"));
final ManageApplicationPrivileges allApps = new ManageApplicationPrivileges(Sets.newHashSet("*"));

assertThat(kibanaOnly.getRequestPredicate(), not(predicateMatches(getAll)));
assertThat(allApps.getRequestPredicate(), predicateMatches(getAll));
}

private ManageApplicationPrivileges clone(ManageApplicationPrivileges original) {
return new ManageApplicationPrivileges(new LinkedHashSet<>(original.getApplicationNames()));
Expand Down