Skip to content

Commit dcd9049

Browse files
authored
Fix privilege requirement for QuerySearchApplicationAction (#96179)
This is a manual backport of #96144 and #96176 that ensures that searching a search_application only requires the read privilege on the underlying alias.
1 parent 4cede91 commit dcd9049

File tree

8 files changed

+148
-45
lines changed

8 files changed

+148
-45
lines changed

server/src/main/java/org/elasticsearch/action/support/IndicesOptions.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,10 @@ public enum Option {
144144
EnumSet.of(Option.FORBID_ALIASES_TO_MULTIPLE_INDICES, Option.FORBID_CLOSED_INDICES),
145145
EnumSet.noneOf(WildcardStates.class)
146146
);
147+
public static final IndicesOptions STRICT_NO_EXPAND_FORBID_CLOSED = new IndicesOptions(
148+
EnumSet.of(Option.FORBID_CLOSED_INDICES),
149+
EnumSet.noneOf(WildcardStates.class)
150+
);
147151

148152
/**
149153
* @return Whether specified concrete indices should be ignored when unavailable (missing or closed)
@@ -579,6 +583,13 @@ public static IndicesOptions strictExpandHidden() {
579583
return STRICT_EXPAND_OPEN_CLOSED_HIDDEN;
580584
}
581585

586+
/**
587+
* @return indices option that requires each specified index or alias to exist, doesn't expand wildcards.
588+
*/
589+
public static IndicesOptions strictNoExpandForbidClosed() {
590+
return STRICT_NO_EXPAND_FORBID_CLOSED;
591+
}
592+
582593
/**
583594
* @return indices option that requires each specified index or alias to exist, doesn't expand wildcards and
584595
* throws error if any of the aliases resolves to multiple indices

x-pack/plugin/ent-search/qa/rest/build.gradle

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ testClusters.configureEach {
1616
setting 'xpack.security.enabled', 'true'
1717
setting 'xpack.license.self_generated.type', 'trial'
1818
extraConfigFile 'roles.yml', file('roles.yml')
19-
user username: 'entsearch-admin', password: 'entsearch-admin-password', role: 'superuser'
20-
user username: 'entsearch-user', password: 'entsearch-user-password', role: 'entsearch'
19+
user username: 'entsearch-superuser', password: 'entsearch-superuser-password', role: 'superuser'
20+
user username: 'entsearch-admin', password: 'entsearch-admin-password', role: 'admin'
21+
user username: 'entsearch-user', password: 'entsearch-user-password', role: 'user'
2122
}

x-pack/plugin/ent-search/qa/rest/roles.yml

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
entsearch:
1+
admin:
22
cluster:
33
- manage_search_application
44
- manage_behavioral_analytics
@@ -12,6 +12,8 @@ entsearch:
1212
"test-index3",
1313
"test-index4",
1414
"test-index-does-not-exist",
15+
"test-search-index1",
16+
"test-search-index2",
1517
# Search Applications (needed to create aliases)
1618
"test-search-application",
1719
"test-search-application-1",
@@ -23,10 +25,14 @@ entsearch:
2325
"test-search-application-to-delete",
2426
"test-nonexistent-search-application",
2527
]
26-
privileges: [ "manage" ]
28+
privileges: [ "manage", "write" ]
29+
30+
user:
31+
cluster:
32+
- post_behavioral_analytics_event
33+
indices:
2734
- names: [
28-
# indices used for indexing and searching
29-
"test-search-index1",
30-
"test-search-index2",
35+
"test-search-application"
3136
]
32-
privileges: [ "manage", "read", "write" ]
37+
privileges: [ "read" ]
38+

x-pack/plugin/ent-search/qa/rest/src/yamlRestTest/java/org/elasticsearch/xpack/entsearch/EnterpriseSearchRestIT.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,13 @@ public static Iterable<Object[]> parameters() throws Exception {
3030

3131
@Override
3232
protected Settings restAdminSettings() {
33-
final String value = basicAuthHeaderValue("entsearch-admin", new SecureString("entsearch-admin-password".toCharArray()));
33+
final String value = basicAuthHeaderValue("entsearch-superuser", new SecureString("entsearch-superuser-password".toCharArray()));
3434
return Settings.builder().put(ThreadContext.PREFIX + ".Authorization", value).build();
3535
}
3636

3737
@Override
3838
protected Settings restClientSettings() {
39-
final String value = basicAuthHeaderValue("entsearch-user", new SecureString("entsearch-user-password".toCharArray()));
39+
final String value = basicAuthHeaderValue("entsearch-admin", new SecureString("entsearch-admin-password".toCharArray()));
4040
return Settings.builder().put(ThreadContext.PREFIX + ".Authorization", value).build();
4141
}
42-
4342
}

x-pack/plugin/ent-search/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/entsearch/55_search_application_search.yml

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,11 @@ teardown:
8484

8585
---
8686
"Query Search Application with default parameters":
87+
- skip:
88+
features: headers
8789

8890
- do:
91+
headers: { Authorization: "Basic ZW50c2VhcmNoLXVzZXI6ZW50c2VhcmNoLXVzZXItcGFzc3dvcmQ=" } # user
8992
search_application.search:
9093
name: test-search-application
9194

@@ -95,8 +98,11 @@ teardown:
9598

9699
---
97100
"Query Search Application overriding part of the parameters":
101+
- skip:
102+
features: headers
98103

99104
- do:
105+
headers: { Authorization: "Basic ZW50c2VhcmNoLXVzZXI6ZW50c2VhcmNoLXVzZXItcGFzc3dvcmQ=" } # user
100106
search_application.search:
101107
name: test-search-application
102108
body:
@@ -109,8 +115,11 @@ teardown:
109115

110116
---
111117
"Query Search Application overriding all parameters":
118+
- skip:
119+
features: headers
112120

113121
- do:
122+
headers: { Authorization: "Basic ZW50c2VhcmNoLXVzZXI6ZW50c2VhcmNoLXVzZXItcGFzc3dvcmQ=" } # user
114123
search_application.search:
115124
name: test-search-application
116125
body:
@@ -124,36 +133,15 @@ teardown:
124133

125134
---
126135
"Query Search Application - not found":
136+
- skip:
137+
features: headers
127138

128139
- do:
129-
catch: "missing"
140+
catch: "forbidden"
141+
headers: { Authorization: "Basic ZW50c2VhcmNoLXVzZXI6ZW50c2VhcmNoLXVzZXItcGFzc3dvcmQ=" } # user
130142
search_application.search:
131143
name: nonexisting-test-search-application
132144
body:
133145
params:
134146
field_name: field3
135147
field_value: value3
136-
137-
---
138-
"Query Search Application - no read permissions on index":
139-
140-
- do:
141-
search_application.put:
142-
name: test-search-application
143-
body:
144-
indices: [ "test-search-index1", "test-search-index2", "test-index" ]
145-
analytics_collection_name: "test-analytics"
146-
template:
147-
script:
148-
source:
149-
query:
150-
term:
151-
"{{field_name}}": "{{field_value}}"
152-
params:
153-
field_name: field1
154-
field_value: value1
155-
156-
- do:
157-
catch: "forbidden"
158-
search_application.search:
159-
name: test-search-application

0 commit comments

Comments
 (0)