Skip to content

Commit 0489535

Browse files
committed
Make get all app privs requires "*" permission (#32460)
The default behaviour for "GetPrivileges" is to get all application privileges. This should only be allowed if the user has access to the "*" application.
1 parent 45883a8 commit 0489535

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/privilege/GetPrivilegesRequest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public String application() {
5050

5151
@Override
5252
public Collection<String> getApplicationNames() {
53-
return Collections.singleton(application);
53+
return application == null ? Collections.emptySet() : Collections.singleton(application);
5454
}
5555

5656
public void privileges(String... privileges) {

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,9 @@ public ManageApplicationPrivileges(Set<String> applicationNames) {
135135
this.requestPredicate = request -> {
136136
if (request instanceof ApplicationPrivilegesRequest) {
137137
final ApplicationPrivilegesRequest privRequest = (ApplicationPrivilegesRequest) request;
138-
return privRequest.getApplicationNames().stream().allMatch(application -> applicationPredicate.test(application));
138+
final Collection<String> requestApplicationNames = privRequest.getApplicationNames();
139+
return requestApplicationNames.isEmpty() ? this.applicationNames.contains("*")
140+
: requestApplicationNames.stream().allMatch(application -> applicationPredicate.test(application));
139141
}
140142
return false;
141143
};

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

+14
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
import static org.hamcrest.Matchers.equalTo;
5151
import static org.hamcrest.Matchers.instanceOf;
5252
import static org.hamcrest.Matchers.notNullValue;
53+
import static org.hamcrest.Matchers.nullValue;
5354

5455
public class ManageApplicationPrivilegesTests extends ESTestCase {
5556

@@ -140,6 +141,19 @@ public void testRequestPredicate() {
140141
assertThat(cloudAndSwiftypePredicate, not(predicateMatches(putKibana)));
141142
}
142143

144+
public void testSecurityForGetAllApplicationPrivileges() {
145+
final GetPrivilegesRequest getAll = new GetPrivilegesRequest();
146+
getAll.application(null);
147+
getAll.privileges(new String[0]);
148+
149+
assertThat(getAll.validate(), nullValue());
150+
151+
final ManageApplicationPrivileges kibanaOnly = new ManageApplicationPrivileges(Sets.newHashSet("kibana-*"));
152+
final ManageApplicationPrivileges allApps = new ManageApplicationPrivileges(Sets.newHashSet("*"));
153+
154+
assertThat(kibanaOnly.getRequestPredicate(), not(predicateMatches(getAll)));
155+
assertThat(allApps.getRequestPredicate(), predicateMatches(getAll));
156+
}
143157

144158
private ManageApplicationPrivileges clone(ManageApplicationPrivileges original) {
145159
return new ManageApplicationPrivileges(new LinkedHashSet<>(original.getApplicationNames()));

0 commit comments

Comments
 (0)