-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[D4C] policy schema/UI refactored to support process and file selecto…
…rs (network soon) (#153126) ## Summary This PR refactors alot of the interface/type definitions around "cloud_defend/control" selectors and responses. A lot of refactoring went into ensuring the interfaces and types that represent file and process selector/responses in the UI is as type safe as possible. It should take fewer changes to add new conditions, and compile time checks should ensure most code paths are updated correctly. Updates to policy_schema.json (json-schema) made to support the following yaml schema format: ``` file: selectors: - name: nginxBinMods operation: - createExecutable - modifyExecutable targetFilePath: - /usr/bin/** containerImageName: - nginx - name: excludeTestServers containerImageTag: - staging - preprod responses: - match: - nginxBinMods exclude: - excludeTestServers actions: - alert process: selectors: - name: allProcesses operation: - fork - exec responses: - match: - allProcesses actions: - log ``` Both selectors and responses now ask for a "type" to be selected when adding. This locks it into either a process or file selector/response type. Certain conditions are available to specfiic types. ### TODOS - more unit tests to cover new UX features - cloud_defend integration package needs to be updated with new defaults for configuration - i18n copy could use PM/Techwriter review ### Screenshot ![image](https://user-images.githubusercontent.com/16198204/224398453-e41d8bf7-e952-46f4-9cd9-340c4928ad7e.png) ### Checklist - [x] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md) - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios - [x] Any UI touched in this PR is usable by keyboard only (learn more about [keyboard accessibility](https://webaim.org/techniques/keyboard/)) - [x] Any UI touched in this PR does not create any new axe failures (run axe in browser: [FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/), [Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US)) - [x] This renders correctly on smaller devices using a responsive layout. (You can test this [in your browser](https://www.browserstack.com/guide/responsive-testing-on-local-server)) - [x] This was checked for [cross-browser compatibility](https://www.elastic.co/support/matrix#matrix_browsers)
- Loading branch information
1 parent
15f1f64
commit 6552165
Showing
17 changed files
with
1,528 additions
and
653 deletions.
There are no files selected for viewing
This file contains 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
108 changes: 108 additions & 0 deletions
108
x-pack/plugins/cloud_defend/public/common/utils.test.ts
This file contains 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 |
---|---|---|
@@ -0,0 +1,108 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { | ||
getSelectorsAndResponsesFromYaml, | ||
getYamlFromSelectorsAndResponses, | ||
getSelectorConditions, | ||
conditionCombinationInvalid, | ||
getRestrictedValuesForCondition, | ||
} from './utils'; | ||
import { MOCK_YAML_CONFIGURATION, MOCK_YAML_INVALID_CONFIGURATION } from '../test/mocks'; | ||
|
||
describe('getSelectorsAndResponsesFromYaml', () => { | ||
it('converts yaml into arrays of selectors and responses', () => { | ||
const { selectors, responses } = getSelectorsAndResponsesFromYaml(MOCK_YAML_CONFIGURATION); | ||
|
||
expect(selectors).toHaveLength(3); | ||
expect(responses).toHaveLength(2); | ||
}); | ||
|
||
it('returns empty arrays if bad yaml', () => { | ||
const { selectors, responses } = getSelectorsAndResponsesFromYaml( | ||
MOCK_YAML_INVALID_CONFIGURATION | ||
); | ||
|
||
expect(selectors).toHaveLength(0); | ||
expect(responses).toHaveLength(0); | ||
}); | ||
}); | ||
|
||
describe('getYamlFromSelectorsAndResponses', () => { | ||
it('converts arrays of selectors and responses into yaml', () => { | ||
const { selectors, responses } = getSelectorsAndResponsesFromYaml(MOCK_YAML_CONFIGURATION); | ||
const yaml = getYamlFromSelectorsAndResponses(selectors, responses); | ||
expect(yaml).toEqual(MOCK_YAML_CONFIGURATION); | ||
}); | ||
}); | ||
|
||
describe('getSelectorConditions', () => { | ||
it('grabs file conditions for file selectors', () => { | ||
const options = getSelectorConditions('file'); | ||
|
||
// check at least one common condition present | ||
expect(options.includes('containerImageName')).toBeTruthy(); | ||
|
||
// check file specific conditions present | ||
expect(options.includes('ignoreVolumeFiles')).toBeTruthy(); | ||
expect(options.includes('ignoreVolumeMounts')).toBeTruthy(); | ||
expect(options.includes('targetFilePath')).toBeTruthy(); | ||
|
||
// check that process specific conditions are not included | ||
expect(options.includes('processExecutable')).toBeFalsy(); | ||
expect(options.includes('processName')).toBeFalsy(); | ||
}); | ||
|
||
it('grabs process conditions for process selectors', () => { | ||
const options = getSelectorConditions('process'); | ||
|
||
// check at least one common condition present | ||
expect(options.includes('containerImageName')).toBeTruthy(); | ||
|
||
// check file specific conditions present | ||
expect(options.includes('ignoreVolumeFiles')).toBeFalsy(); | ||
expect(options.includes('ignoreVolumeMounts')).toBeFalsy(); | ||
expect(options.includes('targetFilePath')).toBeFalsy(); | ||
|
||
// check that process specific conditions are not included | ||
expect(options.includes('processExecutable')).toBeTruthy(); | ||
expect(options.includes('processName')).toBeTruthy(); | ||
expect(options.includes('processUserName')).toBeTruthy(); | ||
expect(options.includes('processUserId')).toBeTruthy(); | ||
expect(options.includes('sessionLeaderInteractive')).toBeTruthy(); | ||
}); | ||
}); | ||
|
||
describe('conditionCombinationInvalid', () => { | ||
it('returns true when conditions cannot be combined', () => { | ||
const result = conditionCombinationInvalid(['ignoreVolumeMounts'], 'ignoreVolumeFiles'); | ||
|
||
expect(result).toBeTruthy(); | ||
}); | ||
|
||
it('returns false when they can', () => { | ||
const result = conditionCombinationInvalid(['containerImageName'], 'ignoreVolumeFiles'); | ||
|
||
expect(result).toBeFalsy(); | ||
}); | ||
}); | ||
|
||
describe('getRestrictedValuesForCondition', () => { | ||
it('works', () => { | ||
let values = getRestrictedValuesForCondition('file', 'operation'); | ||
expect(values).toEqual([ | ||
'createExecutable', | ||
'modifyExecutable', | ||
'createFile', | ||
'modifyFile', | ||
'deleteFile', | ||
]); | ||
|
||
values = getRestrictedValuesForCondition('process', 'operation'); | ||
expect(values).toEqual(['fork', 'exec']); | ||
}); | ||
}); |
This file contains 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 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
Oops, something went wrong.