Skip to content

Commit 43b53b0

Browse files
committed
Test unauthorised access to system failure store
1 parent b9ba285 commit 43b53b0

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

x-pack/plugin/security/src/internalClusterTest/java/org/elasticsearch/integration/DataStreamLifecycleServiceRuntimeSecurityIT.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,12 @@
5959
import static org.elasticsearch.cluster.metadata.DataStreamTestHelper.dataStreamIndexEqualTo;
6060
import static org.elasticsearch.cluster.metadata.MetadataIndexTemplateService.DEFAULT_TIMESTAMP_FIELD;
6161
import static org.elasticsearch.xpack.security.support.SecuritySystemIndices.SECURITY_MAIN_ALIAS;
62+
import static org.hamcrest.Matchers.allOf;
6263
import static org.hamcrest.Matchers.anyOf;
6364
import static org.hamcrest.Matchers.containsString;
6465
import static org.hamcrest.Matchers.equalTo;
66+
import static org.hamcrest.Matchers.hasItem;
67+
import static org.hamcrest.Matchers.is;
6568
import static org.hamcrest.Matchers.not;
6669
import static org.hamcrest.Matchers.nullValue;
6770
import static org.hamcrest.Matchers.startsWith;
@@ -151,6 +154,16 @@ public void testUnauthorized() throws Exception {
151154
// lifecycle will therefore fail at runtime with an authz exception
152155
prepareDataStreamAndIndex(SECURITY_MAIN_ALIAS, null);
153156
indexFailedDoc(SECURITY_MAIN_ALIAS);
157+
158+
assertBusy(() -> {
159+
Map<String, String> indicesAndErrors = collectErrorsFromStoreAsMap();
160+
// Both the backing and failures indices should have errors
161+
assertThat(indicesAndErrors.size(), is(2));
162+
assertThat(
163+
indicesAndErrors.values(),
164+
hasItem(allOf(containsString("security_exception"), containsString("unauthorized for user [_data_stream_lifecycle]")))
165+
);
166+
});
154167
}
155168

156169
public void testRolloverAndRetentionWithSystemDataStreamAuthorized() throws Exception {
@@ -166,6 +179,18 @@ public void testRolloverAndRetentionWithSystemDataStreamAuthorized() throws Exce
166179
String writeIndex = backingIndices.get(0).getName();
167180
assertThat(writeIndex, backingIndexEqualTo(dataStreamName, 2));
168181
});
182+
183+
// test failure store too, we index the failure later to have predictable generation suffixes
184+
indexFailedDoc(dataStreamName);
185+
assertBusy(() -> {
186+
assertNoAuthzErrors();
187+
List<String> failureIndices = getDataStreamBackingIndexNames(dataStreamName, true);
188+
assertThat(failureIndices.size(), equalTo(1));
189+
// we expect the data stream to have only one backing index, the write one, with generation 2
190+
// as generation 1 would've been deleted by the data stream lifecycle given the lifecycle configuration
191+
String writeIndex = failureIndices.get(0);
192+
assertThat(writeIndex, dataStreamIndexEqualTo(dataStreamName, 4, true));
193+
});
169194
}
170195

171196
private static String randomDataStreamName() {

0 commit comments

Comments
 (0)