-
Notifications
You must be signed in to change notification settings - Fork 8.5k
[Security Solution] Generate host isolation exceptions artifact #115160
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
Merged
academo
merged 14 commits into
elastic:master
from
academo:feature/host-isolation-exception-artifact-generation
Oct 19, 2021
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
9c15464
Generate host isolation exceptions artifact
ca37d7e
Add tests for host isolation exceptions artifact generation
9c9cda3
Merge branch 'master' into feature/host-isolation-exception-artifact-…
kibanamachine f521ebb
Merge branch 'master' into feature/host-isolation-exception-artifact-…
kibanamachine 6782222
Merge branch 'master' into feature/host-isolation-exception-artifact-…
kibanamachine 4a8fb22
Remove `s` from the host isolation exceptions artifact
1841b6e
Add missing return type
2531ed1
remove wrong file
9a14580
Merge branch 'master' into feature/host-isolation-exception-artifact-…
kibanamachine 3011e16
Merge branch 'master' into feature/host-isolation-exception-artifact-…
kibanamachine 8cbbbf0
Merge branch 'master' into feature/host-isolation-exception-artifact-…
kibanamachine be7c8bc
Merge branch 'master' into feature/host-isolation-exception-artifact-…
kibanamachine d8b6d86
Merge branch 'master' into feature/host-isolation-exception-artifact-…
kibanamachine 1f42a90
Merge branch 'master' into feature/host-isolation-exception-artifact-…
kibanamachine File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,7 @@ | |
|
|
||
| import { savedObjectsClientMock } from 'src/core/server/mocks'; | ||
| import { | ||
| ENDPOINT_HOST_ISOLATION_EXCEPTIONS_LIST_ID, | ||
| ENDPOINT_LIST_ID, | ||
| ENDPOINT_TRUSTED_APPS_LIST_ID, | ||
| } from '@kbn/securitysolution-list-constants'; | ||
|
|
@@ -66,6 +67,12 @@ describe('ManifestManager', () => { | |
| const ARTIFACT_NAME_EVENT_FILTERS_MACOS = 'endpoint-eventfilterlist-macos-v1'; | ||
| const ARTIFACT_NAME_EVENT_FILTERS_WINDOWS = 'endpoint-eventfilterlist-windows-v1'; | ||
| const ARTIFACT_NAME_EVENT_FILTERS_LINUX = 'endpoint-eventfilterlist-linux-v1'; | ||
| const ARTIFACT_NAME_HOST_ISOLATION_EXCEPTIONS_MACOS = | ||
| 'endpoint-hostisolationexceptionlist-macos-v1'; | ||
| const ARTIFACT_NAME_HOST_ISOLATION_EXCEPTIONS_WINDOWS = | ||
| 'endpoint-hostisolationexceptionlist-windows-v1'; | ||
| const ARTIFACT_NAME_HOST_ISOLATION_EXCEPTIONS_LINUX = | ||
| 'endpoint-hostisolationexceptionlist-linux-v1'; | ||
|
|
||
| let ARTIFACTS: InternalArtifactCompleteSchema[] = []; | ||
| let ARTIFACTS_BY_ID: { [K: string]: InternalArtifactCompleteSchema } = {}; | ||
|
|
@@ -157,31 +164,29 @@ describe('ManifestManager', () => { | |
| const manifestManagerContext = buildManifestManagerContextMock({ savedObjectsClient }); | ||
| const manifestManager = new ManifestManager(manifestManagerContext); | ||
|
|
||
| savedObjectsClient.get = jest | ||
| .fn() | ||
| .mockImplementation(async (objectType: string, id: string) => { | ||
| if (objectType === ManifestConstants.SAVED_OBJECT_TYPE) { | ||
| return { | ||
| attributes: { | ||
| created: '20-01-2020 10:00:00.000Z', | ||
| schemaVersion: 'v2', | ||
| semanticVersion: '1.0.0', | ||
| artifacts: [ | ||
| { artifactId: ARTIFACT_ID_EXCEPTIONS_MACOS, policyId: undefined }, | ||
| { artifactId: ARTIFACT_ID_EXCEPTIONS_WINDOWS, policyId: undefined }, | ||
| { artifactId: ARTIFACT_ID_EXCEPTIONS_LINUX, policyId: undefined }, | ||
| { artifactId: ARTIFACT_ID_EXCEPTIONS_WINDOWS, policyId: TEST_POLICY_ID_1 }, | ||
| { artifactId: ARTIFACT_ID_TRUSTED_APPS_MACOS, policyId: TEST_POLICY_ID_1 }, | ||
| { artifactId: ARTIFACT_ID_TRUSTED_APPS_WINDOWS, policyId: TEST_POLICY_ID_1 }, | ||
| { artifactId: ARTIFACT_ID_TRUSTED_APPS_WINDOWS, policyId: TEST_POLICY_ID_2 }, | ||
| ], | ||
| }, | ||
| version: '2.0.0', | ||
| }; | ||
| } else { | ||
| return null; | ||
| } | ||
| }); | ||
| savedObjectsClient.get = jest.fn().mockImplementation(async (objectType: string) => { | ||
| if (objectType === ManifestConstants.SAVED_OBJECT_TYPE) { | ||
| return { | ||
| attributes: { | ||
| created: '20-01-2020 10:00:00.000Z', | ||
| schemaVersion: 'v2', | ||
| semanticVersion: '1.0.0', | ||
| artifacts: [ | ||
| { artifactId: ARTIFACT_ID_EXCEPTIONS_MACOS, policyId: undefined }, | ||
| { artifactId: ARTIFACT_ID_EXCEPTIONS_WINDOWS, policyId: undefined }, | ||
| { artifactId: ARTIFACT_ID_EXCEPTIONS_LINUX, policyId: undefined }, | ||
| { artifactId: ARTIFACT_ID_EXCEPTIONS_WINDOWS, policyId: TEST_POLICY_ID_1 }, | ||
| { artifactId: ARTIFACT_ID_TRUSTED_APPS_MACOS, policyId: TEST_POLICY_ID_1 }, | ||
| { artifactId: ARTIFACT_ID_TRUSTED_APPS_WINDOWS, policyId: TEST_POLICY_ID_1 }, | ||
| { artifactId: ARTIFACT_ID_TRUSTED_APPS_WINDOWS, policyId: TEST_POLICY_ID_2 }, | ||
| ], | ||
| }, | ||
| version: '2.0.0', | ||
| }; | ||
| } else { | ||
| return null; | ||
| } | ||
| }); | ||
|
|
||
| ( | ||
| manifestManagerContext.artifactClient as jest.Mocked<EndpointArtifactClientInterface> | ||
|
|
@@ -218,31 +223,29 @@ describe('ManifestManager', () => { | |
| const manifestManagerContext = buildManifestManagerContextMock({ savedObjectsClient }); | ||
| const manifestManager = new ManifestManager(manifestManagerContext); | ||
|
|
||
| savedObjectsClient.get = jest | ||
| .fn() | ||
| .mockImplementation(async (objectType: string, id: string) => { | ||
| if (objectType === ManifestConstants.SAVED_OBJECT_TYPE) { | ||
| return { | ||
| attributes: { | ||
| created: '20-01-2020 10:00:00.000Z', | ||
| schemaVersion: 'v2', | ||
| semanticVersion: '1.0.0', | ||
| artifacts: [ | ||
| { artifactId: ARTIFACT_ID_EXCEPTIONS_MACOS, policyId: undefined }, | ||
| { artifactId: ARTIFACT_ID_EXCEPTIONS_WINDOWS, policyId: undefined }, | ||
| { artifactId: ARTIFACT_ID_EXCEPTIONS_LINUX, policyId: undefined }, | ||
| { artifactId: ARTIFACT_ID_EXCEPTIONS_WINDOWS, policyId: TEST_POLICY_ID_1 }, | ||
| { artifactId: ARTIFACT_ID_TRUSTED_APPS_MACOS, policyId: TEST_POLICY_ID_1 }, | ||
| { artifactId: ARTIFACT_ID_TRUSTED_APPS_WINDOWS, policyId: TEST_POLICY_ID_1 }, | ||
| { artifactId: ARTIFACT_ID_TRUSTED_APPS_WINDOWS, policyId: TEST_POLICY_ID_2 }, | ||
| ], | ||
| }, | ||
| version: '2.0.0', | ||
| }; | ||
| } else { | ||
| return null; | ||
| } | ||
| }); | ||
| savedObjectsClient.get = jest.fn().mockImplementation(async (objectType: string) => { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note: the only change in this code is removing the unused |
||
| if (objectType === ManifestConstants.SAVED_OBJECT_TYPE) { | ||
| return { | ||
| attributes: { | ||
| created: '20-01-2020 10:00:00.000Z', | ||
| schemaVersion: 'v2', | ||
| semanticVersion: '1.0.0', | ||
| artifacts: [ | ||
| { artifactId: ARTIFACT_ID_EXCEPTIONS_MACOS, policyId: undefined }, | ||
| { artifactId: ARTIFACT_ID_EXCEPTIONS_WINDOWS, policyId: undefined }, | ||
| { artifactId: ARTIFACT_ID_EXCEPTIONS_LINUX, policyId: undefined }, | ||
| { artifactId: ARTIFACT_ID_EXCEPTIONS_WINDOWS, policyId: TEST_POLICY_ID_1 }, | ||
| { artifactId: ARTIFACT_ID_TRUSTED_APPS_MACOS, policyId: TEST_POLICY_ID_1 }, | ||
| { artifactId: ARTIFACT_ID_TRUSTED_APPS_WINDOWS, policyId: TEST_POLICY_ID_1 }, | ||
| { artifactId: ARTIFACT_ID_TRUSTED_APPS_WINDOWS, policyId: TEST_POLICY_ID_2 }, | ||
| ], | ||
| }, | ||
| version: '2.0.0', | ||
| }; | ||
| } else { | ||
| return null; | ||
| } | ||
| }); | ||
|
|
||
| ( | ||
| manifestManagerContext.artifactClient as jest.Mocked<EndpointArtifactClientInterface> | ||
|
|
@@ -278,6 +281,9 @@ describe('ManifestManager', () => { | |
| ARTIFACT_NAME_EVENT_FILTERS_MACOS, | ||
| ARTIFACT_NAME_EVENT_FILTERS_WINDOWS, | ||
| ARTIFACT_NAME_EVENT_FILTERS_LINUX, | ||
| ARTIFACT_NAME_HOST_ISOLATION_EXCEPTIONS_MACOS, | ||
| ARTIFACT_NAME_HOST_ISOLATION_EXCEPTIONS_WINDOWS, | ||
| ARTIFACT_NAME_HOST_ISOLATION_EXCEPTIONS_LINUX, | ||
| ]; | ||
|
|
||
| const getArtifactIds = (artifacts: InternalArtifactSchema[]) => [ | ||
|
|
@@ -310,7 +316,7 @@ describe('ManifestManager', () => { | |
|
|
||
| context.savedObjectsClient.create = jest | ||
| .fn() | ||
| .mockImplementation((type: string, object: InternalManifestSchema) => ({ | ||
| .mockImplementation((_type: string, object: InternalManifestSchema) => ({ | ||
| attributes: object, | ||
| })); | ||
| const manifest = await manifestManager.buildNewManifest(); | ||
|
|
@@ -321,7 +327,7 @@ describe('ManifestManager', () => { | |
|
|
||
| const artifacts = manifest.getAllArtifacts(); | ||
|
|
||
| expect(artifacts.length).toBe(9); | ||
| expect(artifacts.length).toBe(12); | ||
| expect(getArtifactIds(artifacts)).toStrictEqual(SUPPORTED_ARTIFACT_NAMES); | ||
|
|
||
| for (const artifact of artifacts) { | ||
|
|
@@ -336,16 +342,18 @@ describe('ManifestManager', () => { | |
| test('Builds fully new manifest if no baseline parameter passed and present exception list items', async () => { | ||
| const exceptionListItem = getExceptionListItemSchemaMock({ os_types: ['macos'] }); | ||
| const trustedAppListItem = getExceptionListItemSchemaMock({ os_types: ['linux'] }); | ||
| const hostIsolationExceptionsItem = getExceptionListItemSchemaMock({ os_types: ['linux'] }); | ||
| const context = buildManifestManagerContextMock({}); | ||
| const manifestManager = new ManifestManager(context); | ||
|
|
||
| context.exceptionListClient.findExceptionListItem = mockFindExceptionListItemResponses({ | ||
| [ENDPOINT_LIST_ID]: { macos: [exceptionListItem] }, | ||
| [ENDPOINT_TRUSTED_APPS_LIST_ID]: { linux: [trustedAppListItem] }, | ||
| [ENDPOINT_HOST_ISOLATION_EXCEPTIONS_LIST_ID]: { linux: [hostIsolationExceptionsItem] }, | ||
| }); | ||
| context.savedObjectsClient.create = jest | ||
| .fn() | ||
| .mockImplementation((type: string, object: InternalManifestSchema) => ({ | ||
| .mockImplementation((_type: string, object: InternalManifestSchema) => ({ | ||
| attributes: object, | ||
| })); | ||
| context.packagePolicyService.listIds = mockPolicyListIdsResponse([TEST_POLICY_ID_1]); | ||
|
|
@@ -358,7 +366,7 @@ describe('ManifestManager', () => { | |
|
|
||
| const artifacts = manifest.getAllArtifacts(); | ||
|
|
||
| expect(artifacts.length).toBe(9); | ||
| expect(artifacts.length).toBe(12); | ||
| expect(getArtifactIds(artifacts)).toStrictEqual(SUPPORTED_ARTIFACT_NAMES); | ||
|
|
||
| expect(getArtifactObject(artifacts[0])).toStrictEqual({ | ||
|
|
@@ -374,6 +382,11 @@ describe('ManifestManager', () => { | |
| expect(getArtifactObject(artifacts[6])).toStrictEqual({ entries: [] }); | ||
| expect(getArtifactObject(artifacts[7])).toStrictEqual({ entries: [] }); | ||
| expect(getArtifactObject(artifacts[8])).toStrictEqual({ entries: [] }); | ||
| expect(getArtifactObject(artifacts[9])).toStrictEqual({ entries: [] }); | ||
| expect(getArtifactObject(artifacts[10])).toStrictEqual({ entries: [] }); | ||
| expect(getArtifactObject(artifacts[11])).toStrictEqual({ | ||
| entries: translateToEndpointExceptions([hostIsolationExceptionsItem], 'v1'), | ||
| }); | ||
|
|
||
| for (const artifact of artifacts) { | ||
| expect(manifest.isDefaultArtifact(artifact)).toBe(true); | ||
|
|
@@ -395,7 +408,7 @@ describe('ManifestManager', () => { | |
| context.packagePolicyService.listIds = mockPolicyListIdsResponse([TEST_POLICY_ID_1]); | ||
| context.savedObjectsClient.create = jest | ||
| .fn() | ||
| .mockImplementation((type: string, object: InternalManifestSchema) => ({ | ||
| .mockImplementation((_type: string, object: InternalManifestSchema) => ({ | ||
| attributes: object, | ||
| })); | ||
| const oldManifest = await manifestManager.buildNewManifest(); | ||
|
|
@@ -413,7 +426,7 @@ describe('ManifestManager', () => { | |
|
|
||
| const artifacts = manifest.getAllArtifacts(); | ||
|
|
||
| expect(artifacts.length).toBe(9); | ||
| expect(artifacts.length).toBe(12); | ||
| expect(getArtifactIds(artifacts)).toStrictEqual(SUPPORTED_ARTIFACT_NAMES); | ||
|
|
||
| expect(artifacts[0]).toStrictEqual(oldManifest.getAllArtifacts()[0]); | ||
|
|
@@ -462,7 +475,7 @@ describe('ManifestManager', () => { | |
|
|
||
| context.savedObjectsClient.create = jest | ||
| .fn() | ||
| .mockImplementation((type: string, object: InternalManifestSchema) => ({ | ||
| .mockImplementation((_type: string, object: InternalManifestSchema) => ({ | ||
| attributes: object, | ||
| })); | ||
|
|
||
|
|
@@ -474,7 +487,7 @@ describe('ManifestManager', () => { | |
|
|
||
| const artifacts = manifest.getAllArtifacts(); | ||
|
|
||
| expect(artifacts.length).toBe(10); | ||
| expect(artifacts.length).toBe(13); | ||
| expect(getArtifactIds(artifacts)).toStrictEqual(SUPPORTED_ARTIFACT_NAMES); | ||
|
|
||
| expect(getArtifactObject(artifacts[0])).toStrictEqual({ | ||
|
|
@@ -653,7 +666,7 @@ describe('ManifestManager', () => { | |
|
|
||
| context.savedObjectsClient.create = jest | ||
| .fn() | ||
| .mockImplementation((type: string, object: InternalManifestSchema) => object); | ||
| .mockImplementation((_type: string, object: InternalManifestSchema) => object); | ||
|
|
||
| await expect(manifestManager.commit(manifest)).resolves.toBeUndefined(); | ||
|
|
||
|
|
@@ -690,7 +703,7 @@ describe('ManifestManager', () => { | |
|
|
||
| context.savedObjectsClient.update = jest | ||
| .fn() | ||
| .mockImplementation((type: string, id: string, object: InternalManifestSchema) => object); | ||
| .mockImplementation((_type: string, _id: string, object: InternalManifestSchema) => object); | ||
|
|
||
| await expect(manifestManager.commit(manifest)).resolves.toBeUndefined(); | ||
|
|
||
|
|
@@ -1023,7 +1036,7 @@ describe('ManifestManager', () => { | |
|
|
||
| context.savedObjectsClient.create = jest | ||
| .fn() | ||
| .mockImplementation((type: string, object: InternalManifestSchema) => ({ | ||
| .mockImplementation((_type: string, object: InternalManifestSchema) => ({ | ||
| attributes: object, | ||
| })); | ||
| const manifest = await manifestManager.buildNewManifest(); | ||
|
|
@@ -1046,7 +1059,7 @@ describe('ManifestManager', () => { | |
|
|
||
| context.savedObjectsClient.create = jest | ||
| .fn() | ||
| .mockImplementation((type: string, object: InternalManifestSchema) => ({ | ||
| .mockImplementation((_type: string, object: InternalManifestSchema) => ({ | ||
| attributes: object, | ||
| })); | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: the only change in this code is removing the unused
idparameter. The big change is due to eslint formatting the code to its new size.