Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Security][Network] Exclude glob-only (*) Index Pattern from map layers #69736

Merged
merged 2 commits into from
Jun 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -475,3 +475,12 @@ export const mockGlobIndexPattern: IndexPatternSavedObject = {
title: '*',
},
};

export const mockCCSGlobIndexPattern: IndexPatternSavedObject = {
id: '*:*',
type: 'index-pattern',
_version: 'abc',
attributes: {
title: '*:*',
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
mockAuditbeatIndexPattern,
mockFilebeatIndexPattern,
mockGlobIndexPattern,
mockCCSGlobIndexPattern,
} from './__mocks__/mock';

const mockEmbeddable = embeddablePluginMock.createStartContract();
Expand Down Expand Up @@ -106,12 +107,20 @@ describe('embedded_map_helpers', () => {
]);
});

test('finds glob-only index patterns ', () => {
test('excludes glob-only index patterns', () => {
const matchingIndexPatterns = findMatchingIndexPatterns({
kibanaIndexPatterns: [mockGlobIndexPattern, mockFilebeatIndexPattern],
siemDefaultIndices,
});
expect(matchingIndexPatterns).toEqual([mockGlobIndexPattern, mockFilebeatIndexPattern]);
expect(matchingIndexPatterns).toEqual([mockFilebeatIndexPattern]);
});

test('excludes glob-only CCS index patterns', () => {
const matchingIndexPatterns = findMatchingIndexPatterns({
kibanaIndexPatterns: [mockCCSGlobIndexPattern, mockFilebeatIndexPattern],
siemDefaultIndices,
});
expect(matchingIndexPatterns).toEqual([mockFilebeatIndexPattern]);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ export const createEmbeddable = async (
return embeddableObject;
};

// These patterns are overly greedy and must be excluded when matching against Security indexes.
const ignoredIndexPatterns = ['*', '*:*'];

/**
* Returns kibanaIndexPatterns that wildcard match at least one of siemDefaultIndices
*
Expand All @@ -142,9 +145,13 @@ export const findMatchingIndexPatterns = ({
siemDefaultIndices: string[];
}): IndexPatternSavedObject[] => {
try {
return kibanaIndexPatterns.filter((kip) =>
siemDefaultIndices.some((sdi) => minimatch(sdi, kip.attributes.title))
);
return kibanaIndexPatterns.filter((kip) => {
const pattern = kip.attributes.title;
return (
!ignoredIndexPatterns.includes(pattern) &&
siemDefaultIndices.some((sdi) => minimatch(sdi, pattern))
);
});
} catch {
return [];
}
Expand Down