5959import static org .elasticsearch .cluster .metadata .DataStreamTestHelper .dataStreamIndexEqualTo ;
6060import static org .elasticsearch .cluster .metadata .MetadataIndexTemplateService .DEFAULT_TIMESTAMP_FIELD ;
6161import static org .elasticsearch .xpack .security .support .SecuritySystemIndices .SECURITY_MAIN_ALIAS ;
62+ import static org .hamcrest .Matchers .allOf ;
6263import static org .hamcrest .Matchers .anyOf ;
6364import static org .hamcrest .Matchers .containsString ;
6465import static org .hamcrest .Matchers .equalTo ;
66+ import static org .hamcrest .Matchers .hasItem ;
67+ import static org .hamcrest .Matchers .is ;
6568import static org .hamcrest .Matchers .not ;
6669import static org .hamcrest .Matchers .nullValue ;
6770import 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