|
@@ -18,6 +18,7 @@ import org.elasticsearch.common.Strings;
|
|
|
import org.elasticsearch.common.settings.SecureString;
|
|
|
import org.elasticsearch.common.settings.Settings;
|
|
|
import org.elasticsearch.common.util.concurrent.ThreadContext;
|
|
|
+import org.elasticsearch.index.query.QueryBuilders;
|
|
|
import org.elasticsearch.test.MapMatcher;
|
|
|
import org.elasticsearch.test.cluster.ElasticsearchCluster;
|
|
|
import org.elasticsearch.test.cluster.local.distribution.DistributionType;
|
|
@@ -160,7 +161,7 @@ public class EsqlSecurityIT extends ESRestTestCase {
|
|
|
.entry("values", List.of(List.of(72.0d)));
|
|
|
assertMap(entityAsMap(resp), matcher);
|
|
|
}
|
|
|
- for (var index : List.of("index-user2", "index-user1,index-user2", "index-user*", "index*")) {
|
|
|
+ for (var index : List.of("index-user2", "index-user*", "index*")) {
|
|
|
Response resp = runESQLCommand("metadata1_read2", "from " + index + " | stats sum=sum(value)");
|
|
|
assertOK(resp);
|
|
|
MapMatcher matcher = responseMatcher().entry("columns", List.of(Map.of("name", "sum", "type", "double")))
|
|
@@ -170,7 +171,7 @@ public class EsqlSecurityIT extends ESRestTestCase {
|
|
|
}
|
|
|
|
|
|
public void testAliases() throws Exception {
|
|
|
- for (var index : List.of("second-alias", "second-alias,index-user2", "second-*", "second-*,index*")) {
|
|
|
+ for (var index : List.of("second-alias", "second-*", "second-*,index*")) {
|
|
|
Response resp = runESQLCommand(
|
|
|
"alias_user2",
|
|
|
"from " + index + " METADATA _index" + "| stats sum=sum(value), index=VALUES(_index)"
|
|
@@ -185,7 +186,7 @@ public class EsqlSecurityIT extends ESRestTestCase {
|
|
|
}
|
|
|
|
|
|
public void testAliasFilter() throws Exception {
|
|
|
- for (var index : List.of("first-alias", "first-alias,index-user1", "first-alias,index-*", "first-*,index-*")) {
|
|
|
+ for (var index : List.of("first-alias", "first-alias,index-*", "first-*,index-*")) {
|
|
|
Response resp = runESQLCommand("alias_user1", "from " + index + " METADATA _index" + "| KEEP _index, org, value | LIMIT 10");
|
|
|
assertOK(resp);
|
|
|
MapMatcher matcher = responseMatcher().entry(
|
|
@@ -221,19 +222,97 @@ public class EsqlSecurityIT extends ESRestTestCase {
|
|
|
assertThat(error.getMessage(), containsString("Unknown index [index-user1]"));
|
|
|
}
|
|
|
|
|
|
+ public void testIndexPatternErrorMessageComparison_ESQL_SearchDSL() throws Exception {
|
|
|
+ // _search match_all query on the index-user1,index-user2 index pattern
|
|
|
+ XContentBuilder json = JsonXContent.contentBuilder();
|
|
|
+ json.startObject();
|
|
|
+ json.field("query", QueryBuilders.matchAllQuery());
|
|
|
+ json.endObject();
|
|
|
+ Request searchRequest = new Request("GET", "/index-user1,index-user2/_search");
|
|
|
+ searchRequest.setJsonEntity(Strings.toString(json));
|
|
|
+ searchRequest.setOptions(RequestOptions.DEFAULT.toBuilder().addHeader("es-security-runas-user", "metadata1_read2"));
|
|
|
+
|
|
|
+ // ES|QL query on the same index pattern
|
|
|
+ var esqlResp = expectThrows(ResponseException.class, () -> runESQLCommand("metadata1_read2", "FROM index-user1,index-user2"));
|
|
|
+ var srchResp = expectThrows(ResponseException.class, () -> client().performRequest(searchRequest));
|
|
|
+
|
|
|
+ for (ResponseException r : List.of(esqlResp, srchResp)) {
|
|
|
+ assertThat(
|
|
|
+ EntityUtils.toString(r.getResponse().getEntity()),
|
|
|
+ containsString(
|
|
|
+ "unauthorized for user [test-admin] run as [metadata1_read2] with effective roles [metadata1_read2] on indices [index-user1]"
|
|
|
+ )
|
|
|
+ );
|
|
|
+ }
|
|
|
+ assertThat(esqlResp.getResponse().getStatusLine().getStatusCode(), equalTo(srchResp.getResponse().getStatusLine().getStatusCode()));
|
|
|
+ }
|
|
|
+
|
|
|
public void testLimitedPrivilege() throws Exception {
|
|
|
- Response resp = runESQLCommand("metadata1_read2", """
|
|
|
- FROM index-user1,index-user2 METADATA _index
|
|
|
- | STATS sum=sum(value), index=VALUES(_index)
|
|
|
- """);
|
|
|
- assertOK(resp);
|
|
|
- Map<String, Object> respMap = entityAsMap(resp);
|
|
|
+ ResponseException resp = expectThrows(
|
|
|
+ ResponseException.class,
|
|
|
+ () -> runESQLCommand(
|
|
|
+ "metadata1_read2",
|
|
|
+ "FROM index-user1,index-user2 METADATA _index | STATS sum=sum(value), index=VALUES(_index)"
|
|
|
+ )
|
|
|
+ );
|
|
|
assertThat(
|
|
|
- respMap.get("columns"),
|
|
|
- equalTo(List.of(Map.of("name", "sum", "type", "double"), Map.of("name", "index", "type", "keyword")))
|
|
|
+ EntityUtils.toString(resp.getResponse().getEntity()),
|
|
|
+ containsString(
|
|
|
+ "unauthorized for user [test-admin] run as [metadata1_read2] with effective roles [metadata1_read2] on indices [index-user1]"
|
|
|
+ )
|
|
|
+ );
|
|
|
+ assertThat(resp.getResponse().getStatusLine().getStatusCode(), equalTo(HttpStatus.SC_FORBIDDEN));
|
|
|
+
|
|
|
+ resp = expectThrows(
|
|
|
+ ResponseException.class,
|
|
|
+ () -> runESQLCommand("metadata1_read2", "FROM index-user1,index-user2 METADATA _index | STATS index=VALUES(_index)")
|
|
|
);
|
|
|
- assertThat(respMap.get("values"), equalTo(List.of(List.of(72.0, "index-user2"))));
|
|
|
+ assertThat(
|
|
|
+ EntityUtils.toString(resp.getResponse().getEntity()),
|
|
|
+ containsString(
|
|
|
+ "unauthorized for user [test-admin] run as [metadata1_read2] with effective roles [metadata1_read2] on indices [index-user1]"
|
|
|
+ )
|
|
|
+ );
|
|
|
+ assertThat(resp.getResponse().getStatusLine().getStatusCode(), equalTo(HttpStatus.SC_FORBIDDEN));
|
|
|
|
|
|
+ resp = expectThrows(
|
|
|
+ ResponseException.class,
|
|
|
+ () -> runESQLCommand("metadata1_read2", "FROM index-user1,index-user2 | STATS sum=sum(value)")
|
|
|
+ );
|
|
|
+ assertThat(
|
|
|
+ EntityUtils.toString(resp.getResponse().getEntity()),
|
|
|
+ containsString(
|
|
|
+ "unauthorized for user [test-admin] run as [metadata1_read2] with effective roles [metadata1_read2] on indices [index-user1]"
|
|
|
+ )
|
|
|
+ );
|
|
|
+ assertThat(resp.getResponse().getStatusLine().getStatusCode(), equalTo(HttpStatus.SC_FORBIDDEN));
|
|
|
+
|
|
|
+ resp = expectThrows(
|
|
|
+ ResponseException.class,
|
|
|
+ () -> runESQLCommand("alias_user1", "FROM first-alias,index-user1 METADATA _index | KEEP _index, org, value | LIMIT 10")
|
|
|
+ );
|
|
|
+ assertThat(
|
|
|
+ EntityUtils.toString(resp.getResponse().getEntity()),
|
|
|
+ containsString(
|
|
|
+ "unauthorized for user [test-admin] run as [alias_user1] with effective roles [alias_user1] on indices [index-user1]"
|
|
|
+ )
|
|
|
+ );
|
|
|
+ assertThat(resp.getResponse().getStatusLine().getStatusCode(), equalTo(HttpStatus.SC_FORBIDDEN));
|
|
|
+
|
|
|
+ resp = expectThrows(
|
|
|
+ ResponseException.class,
|
|
|
+ () -> runESQLCommand(
|
|
|
+ "alias_user2",
|
|
|
+ "from second-alias,index-user2 METADATA _index | stats sum=sum(value), index=VALUES(_index)"
|
|
|
+ )
|
|
|
+ );
|
|
|
+ assertThat(
|
|
|
+ EntityUtils.toString(resp.getResponse().getEntity()),
|
|
|
+ containsString(
|
|
|
+ "unauthorized for user [test-admin] run as [alias_user2] with effective roles [alias_user2] on indices [index-user2]"
|
|
|
+ )
|
|
|
+ );
|
|
|
+ assertThat(resp.getResponse().getStatusLine().getStatusCode(), equalTo(HttpStatus.SC_FORBIDDEN));
|
|
|
}
|
|
|
|
|
|
public void testDocumentLevelSecurity() throws Exception {
|