Skip to content

Commit 122857b

Browse files
authored
[Entity Store] Filter out CCS indices (elastic#253644)
1 parent 79e44f3 commit 122857b

2 files changed

Lines changed: 35 additions & 1 deletion

File tree

x-pack/solutions/security/plugins/entity_store/server/domain/logs_extraction_client.test.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,39 @@ describe('LogsExtractionClient', () => {
546546
});
547547
});
548548

549+
it('should filter out cross-cluster search (CCS) remote indices', async () => {
550+
const mockEsqlResponse: ESQLSearchResponse = {
551+
columns: [
552+
{ name: '@timestamp', type: 'date' },
553+
{ name: HASHED_ID_FIELD, type: 'keyword' },
554+
],
555+
values: [['2024-01-02T10:00:00.000Z', 'hash1']],
556+
};
557+
558+
const mockDataView = {
559+
getIndexPattern: jest
560+
.fn()
561+
.mockReturnValue('logs-*,remote_cluster:logs-*,other:filebeat-*,metrics-*'),
562+
};
563+
564+
mockEngineDescriptorClient.findOrThrow.mockResolvedValue(
565+
createMockEngineDescriptor('user') as Awaited<
566+
ReturnType<EngineDescriptorClient['findOrThrow']>
567+
>
568+
);
569+
mockDataViewsService.get.mockResolvedValue(mockDataView as any);
570+
mockExecuteEsqlQuery.mockResolvedValue(mockEsqlResponse);
571+
mockIngestEntities.mockResolvedValue(undefined);
572+
573+
const result = await client.extractLogs('user');
574+
575+
expect(result.success).toBe(true);
576+
expect(result.success && result.scannedIndices).toContain('logs-*');
577+
expect(result.success && result.scannedIndices).toContain('metrics-*');
578+
expect(result.success && result.scannedIndices).not.toContain('remote_cluster:logs-*');
579+
expect(result.success && result.scannedIndices).not.toContain('other:filebeat-*');
580+
});
581+
549582
it('should fallback to logs-* when data view is not found', async () => {
550583
const mockEsqlResponse: ESQLSearchResponse = {
551584
columns: [

x-pack/solutions/security/plugins/entity_store/server/domain/logs_extraction_client.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import type { Logger } from '@kbn/logging';
99
import moment from 'moment';
1010
import { SavedObjectsErrorHelpers, type ElasticsearchClient } from '@kbn/core/server';
1111
import type { DataViewsService } from '@kbn/data-views-plugin/common';
12+
import { isCCSRemoteIndexName } from '@kbn/es-query';
1213
import type {
1314
EntityType,
1415
ManagedEntityDefinition,
@@ -319,7 +320,7 @@ export class LogsExtractionClient {
319320
const cleanIndices = secSolDataView
320321
.getIndexPattern()
321322
.split(',')
322-
.filter((index) => index !== alertsIndex);
323+
.filter((index) => index !== alertsIndex && !isCCSRemoteIndexName(index));
323324
indexPatterns.push(...cleanIndices);
324325
} catch (error) {
325326
this.logger.warn(

0 commit comments

Comments
 (0)