Skip to content

Commit 80e904a

Browse files
adjust IT tests
1 parent a2e1b9e commit 80e904a

File tree

2 files changed

+22
-17
lines changed

2 files changed

+22
-17
lines changed

x-pack/plugin/security/qa/security-trial/src/javaRestTest/java/org/elasticsearch/xpack/security/failurestore/FailureStoreSecurityRestIT.java

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import java.util.stream.Collectors;
4848

4949
import static org.hamcrest.Matchers.containsInAnyOrder;
50+
import static org.hamcrest.Matchers.containsString;
5051
import static org.hamcrest.Matchers.equalTo;
5152
import static org.hamcrest.Matchers.hasItem;
5253
import static org.hamcrest.Matchers.is;
@@ -1388,12 +1389,8 @@ public void testDlsFls() throws Exception {
13881389
Map.of(dataIndexName, Set.of("@timestamp", "age"))
13891390
);
13901391

1391-
// FLS sort of applies to failure store
1392-
// TODO this will change with FLS handling
1393-
assertSearchResponseContainsExpectedIndicesAndFields(
1394-
performRequest(user, new Search("test1::failures").toSearchRequest()),
1395-
Map.of(failureIndexName, Set.of("@timestamp"))
1396-
);
1392+
// FLS does not apply to failure store
1393+
expectFlsDlsError(() -> performRequest(user, new Search("test1::failures").toSearchRequest()));
13971394

13981395
upsertRole(Strings.format("""
13991396
{
@@ -1422,12 +1419,8 @@ public void testDlsFls() throws Exception {
14221419
Map.of(dataIndexName, Set.of("@timestamp", "age"))
14231420
);
14241421

1425-
// FLS sort of applies to failure store
1426-
// TODO this will change with FLS handling
1427-
assertSearchResponseContainsExpectedIndicesAndFields(
1428-
performRequest(user, new Search("test1::failures").toSearchRequest()),
1429-
Map.of(failureIndexName, Set.of("@timestamp"))
1430-
);
1422+
// FLS does not apply to failure store
1423+
expectFlsDlsError(() -> performRequest(user, new Search("test1::failures").toSearchRequest()));
14311424

14321425
upsertRole("""
14331426
{
@@ -1473,7 +1466,8 @@ public void testDlsFls() throws Exception {
14731466
}""", role);
14741467
// DLS applies and no docs match the query
14751468
expectSearch(user, new Search(randomFrom("test1", "test1::data")));
1476-
expectSearch(user, new Search("test1::failures"));
1469+
// DLS is not applicable to failure store
1470+
expectFlsDlsError(() -> performRequest(user, new Search("test1::failures").toSearchRequest()));
14771471

14781472
upsertRole("""
14791473
{
@@ -1488,7 +1482,8 @@ public void testDlsFls() throws Exception {
14881482
}""", role);
14891483
// DLS applies and doc matches the query
14901484
expectSearch(user, new Search(randomFrom("test1", "test1::data")), dataIndexDocId);
1491-
expectSearch(user, new Search("test1::failures"));
1485+
// DLS is not applicable to failure store
1486+
expectFlsDlsError(() -> performRequest(user, new Search("test1::failures").toSearchRequest()));
14921487

14931488
upsertRole("""
14941489
{
@@ -1827,4 +1822,14 @@ private Tuple<String, String> getSingleDataAndFailureIndices(String dataStreamNa
18271822
assertThat(indices.v2().size(), equalTo(1));
18281823
return new Tuple<>(indices.v1().get(0), indices.v2().get(0));
18291824
}
1825+
1826+
private static void expectFlsDlsError(ThrowingRunnable runnable) {
1827+
var exception = expectThrows(ResponseException.class, runnable);
1828+
assertThat(
1829+
exception.getMessage(),
1830+
containsString(
1831+
"Failure store access is not allowed for users who have field or document level security enabled on one of the indices"
1832+
)
1833+
);
1834+
}
18301835
}

x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authz/interceptor/FailureStoreRequestInterceptor.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ void disableFeatures(
3232
ActionListener<Void> listener
3333
) {
3434
for (var indexAccessControl : indicesAccessControlByIndex.entrySet()) {
35-
if (hasFailureStoreSelectorSuffix(indexAccessControl.getKey()) && hasDlsFlsPermissions(indexAccessControl.getValue())) {
35+
if (hasFailuresSelectorSuffix(indexAccessControl.getKey()) && hasDlsFlsPermissions(indexAccessControl.getValue())) {
3636
listener.onFailure(
3737
new ElasticsearchSecurityException(
3838
"Failure store access is not allowed for users who have "
@@ -50,15 +50,15 @@ void disableFeatures(
5050
boolean supports(IndicesRequest request) {
5151
if (request.indicesOptions().allowSelectors()) {
5252
for (String index : request.indices()) {
53-
if (hasFailureStoreSelectorSuffix(index)) {
53+
if (hasFailuresSelectorSuffix(index)) {
5454
return true;
5555
}
5656
}
5757
}
5858
return false;
5959
}
6060

61-
private boolean hasFailureStoreSelectorSuffix(String name) {
61+
private boolean hasFailuresSelectorSuffix(String name) {
6262
return IndexNameExpressionResolver.hasSelectorSuffix(name)
6363
&& IndexComponentSelector.getByKey(
6464
IndexNameExpressionResolver.splitSelectorExpression(name).v2()

0 commit comments

Comments
 (0)