forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Cloud Security] Graph visualization and API (elastic#195307)
## Summary This PR adds: - Graph visualization component using `xyflow`, and layouts the graph using `dagre`. - API that supports the graph visualization - API tests - Serverless API tests **List of open issues (will be tracked in a different ticket):** - Identify if `related.hosts`, `related.ip` and `related.user` are mapped before the query. (can be fixed by elastic/elasticsearch#112912) - Update nodes rendering to match recent figma changes - Return 404 when feature is not enabled - Add keyboard accessibility - Resolve 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)) ### How to test You can view the graph using storybook's [playground](https://supreme-adventure-8qjmlp1.pages.github.io/graph-storybook/?path=/story/components-graph-components-dagree-layout-graph--graph-stacked-edge-cases). To test this PR you can run ``` yarn storybook cloud_security_posture_packages ``` To test the API you can use the mocked data ```bash node scripts/es_archiver load x-pack/test/cloud_security_posture_api/es_archives/logs_gcp_audit \ --es-url http://elastic:changeme@localhost:9200 \ --kibana-url http://elastic:changeme@localhost:5601 ``` And through dev tools: ``` POST kbn:/internal/cloud_security_posture/graph?apiVersion=1 { "query": { "actorIds": ["[email protected]"], "eventIds": [""], "start": "now-1y/y", "end": "now/d" } } ``` ### Checklist Delete any items that are not applicable to this PR. - [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] [Flaky Test Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was used on any tests changed - [ ] Any UI touched in this PR is usable by keyboard only (learn more about [keyboard accessibility](https://webaim.org/techniques/keyboard/)) - [ ] 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) --------- Co-authored-by: kibanamachine <[email protected]>
- Loading branch information
1 parent
2be7a20
commit be0eadf
Showing
66 changed files
with
4,611 additions
and
27 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
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
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
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
8 changes: 8 additions & 0 deletions
8
x-pack/packages/kbn-cloud-security-posture-common/schema/graph/index.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,8 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
export * as graphV1 from './v1'; |
8 changes: 8 additions & 0 deletions
8
x-pack/packages/kbn-cloud-security-posture-common/schema/graph/latest.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,8 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
export * from './v1'; |
89 changes: 89 additions & 0 deletions
89
x-pack/packages/kbn-cloud-security-posture-common/schema/graph/v1.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,89 @@ | ||
/* | ||
* 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 { schema } from '@kbn/config-schema'; | ||
|
||
export const graphRequestSchema = schema.object({ | ||
query: schema.object({ | ||
actorIds: schema.arrayOf(schema.string()), | ||
eventIds: schema.arrayOf(schema.string()), | ||
// TODO: use zod for range validation instead of config schema | ||
start: schema.oneOf([schema.number(), schema.string()]), | ||
end: schema.oneOf([schema.number(), schema.string()]), | ||
}), | ||
}); | ||
|
||
export const graphResponseSchema = () => | ||
schema.object({ | ||
nodes: schema.arrayOf( | ||
schema.oneOf([entityNodeDataSchema, groupNodeDataSchema, labelNodeDataSchema]) | ||
), | ||
edges: schema.arrayOf(edgeDataSchema), | ||
}); | ||
|
||
export const colorSchema = schema.oneOf([ | ||
schema.literal('primary'), | ||
schema.literal('danger'), | ||
schema.literal('warning'), | ||
]); | ||
|
||
export const nodeShapeSchema = schema.oneOf([ | ||
schema.literal('hexagon'), | ||
schema.literal('pentagon'), | ||
schema.literal('ellipse'), | ||
schema.literal('rectangle'), | ||
schema.literal('diamond'), | ||
schema.literal('label'), | ||
schema.literal('group'), | ||
]); | ||
|
||
export const nodeBaseDataSchema = schema.object({ | ||
id: schema.string(), | ||
label: schema.maybe(schema.string()), | ||
icon: schema.maybe(schema.string()), | ||
}); | ||
|
||
export const entityNodeDataSchema = schema.allOf([ | ||
nodeBaseDataSchema, | ||
schema.object({ | ||
color: colorSchema, | ||
shape: schema.oneOf([ | ||
schema.literal('hexagon'), | ||
schema.literal('pentagon'), | ||
schema.literal('ellipse'), | ||
schema.literal('rectangle'), | ||
schema.literal('diamond'), | ||
]), | ||
}), | ||
]); | ||
|
||
export const groupNodeDataSchema = schema.allOf([ | ||
nodeBaseDataSchema, | ||
schema.object({ | ||
shape: schema.literal('group'), | ||
}), | ||
]); | ||
|
||
export const labelNodeDataSchema = schema.allOf([ | ||
nodeBaseDataSchema, | ||
schema.object({ | ||
source: schema.string(), | ||
target: schema.string(), | ||
shape: schema.literal('label'), | ||
parentId: schema.maybe(schema.string()), | ||
color: colorSchema, | ||
}), | ||
]); | ||
|
||
export const edgeDataSchema = schema.object({ | ||
id: schema.string(), | ||
source: schema.string(), | ||
sourceShape: nodeShapeSchema, | ||
target: schema.string(), | ||
targetShape: nodeShapeSchema, | ||
color: colorSchema, | ||
}); |
8 changes: 8 additions & 0 deletions
8
x-pack/packages/kbn-cloud-security-posture-common/types/graph/index.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,8 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
export * as graphV1 from './v1'; |
8 changes: 8 additions & 0 deletions
8
x-pack/packages/kbn-cloud-security-posture-common/types/graph/latest.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,8 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
export * from './v1'; |
35 changes: 35 additions & 0 deletions
35
x-pack/packages/kbn-cloud-security-posture-common/types/graph/v1.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,35 @@ | ||
/* | ||
* 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 type { TypeOf } from '@kbn/config-schema'; | ||
import { | ||
colorSchema, | ||
edgeDataSchema, | ||
entityNodeDataSchema, | ||
graphRequestSchema, | ||
graphResponseSchema, | ||
groupNodeDataSchema, | ||
labelNodeDataSchema, | ||
nodeShapeSchema, | ||
} from '../../schema/graph/v1'; | ||
|
||
export type GraphRequest = TypeOf<typeof graphRequestSchema>; | ||
export type GraphResponse = TypeOf<typeof graphResponseSchema>; | ||
|
||
export type Color = typeof colorSchema.type; | ||
|
||
export type NodeShape = TypeOf<typeof nodeShapeSchema>; | ||
|
||
export type EntityNodeDataModel = TypeOf<typeof entityNodeDataSchema>; | ||
|
||
export type GroupNodeDataModel = TypeOf<typeof groupNodeDataSchema>; | ||
|
||
export type LabelNodeDataModel = TypeOf<typeof labelNodeDataSchema>; | ||
|
||
export type EdgeDataModel = TypeOf<typeof edgeDataSchema>; | ||
|
||
export type NodeDataModel = EntityNodeDataModel | GroupNodeDataModel | LabelNodeDataModel; |
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
25 changes: 25 additions & 0 deletions
25
x-pack/packages/kbn-cloud-security-posture/graph/README.md
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,25 @@ | ||
# Cloud Security Posture's Graph | ||
|
||
## Motivation | ||
|
||
The idea behind this package is to have a reusable graph component, embedding the features available to alerts flyout in | ||
security solution plugin. | ||
|
||
## How to use this | ||
|
||
Standalone examples will follow. In the meantime checkout storybook to view the graphs progress. | ||
|
||
## The most important public api members | ||
|
||
- GraphComponent itself (comming soon..) | ||
|
||
### Extras | ||
|
||
Be sure to check out provided helpers | ||
|
||
## Storybook | ||
|
||
General look of the component can be checked visually running the following storybook: | ||
`yarn storybook cloud_security_posture_packages` | ||
|
||
Note that all the interactions are mocked. |
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,6 @@ | ||
/* | ||
* 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. | ||
*/ |
12 changes: 12 additions & 0 deletions
12
x-pack/packages/kbn-cloud-security-posture/graph/jest.config.js
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,12 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
module.exports = { | ||
preset: '@kbn/test', | ||
roots: ['<rootDir>/x-pack/packages/kbn-cloud-security-posture/graph'], | ||
rootDir: '../../../..', | ||
}; |
5 changes: 5 additions & 0 deletions
5
x-pack/packages/kbn-cloud-security-posture/graph/kibana.jsonc
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,5 @@ | ||
{ | ||
"type": "shared-browser", | ||
"id": "@kbn/cloud-security-posture-graph", | ||
"owner": "@elastic/kibana-cloud-security-posture" | ||
} |
7 changes: 7 additions & 0 deletions
7
x-pack/packages/kbn-cloud-security-posture/graph/package.json
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,7 @@ | ||
{ | ||
"name": "@kbn/cloud-security-posture-graph", | ||
"private": true, | ||
"version": "1.0.0", | ||
"license": "Elastic License 2.0", | ||
"sideEffects": false | ||
} |
5 changes: 5 additions & 0 deletions
5
x-pack/packages/kbn-cloud-security-posture/graph/src/assets/icons/aws.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions
15
x-pack/packages/kbn-cloud-security-posture/graph/src/assets/icons/aws_ec2.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions
14
x-pack/packages/kbn-cloud-security-posture/graph/src/assets/icons/aws_s3.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.