x-pack/solutions/security/packages/kbn-cloud-security-posture/graph/README.md
The idea behind this package is to have a reusable graph component, embedding the features available to the alert's flyout in security solution plugin.
Graph Visualization requires specific license tiers depending on your deployment type:
The feature will not be available if the required license tier is not met.
First, import the Graph component into your desired file.
import { Graph } from '@kbn/cloud-security-posture-graph';
Create the nodes and edges data models. These should follow the NodeViewModel and EdgeViewModel interfaces.
const nodes: NodeViewModel[] = [
{
id: 'node1',
label: 'Node 1',
color: 'primary',
shape: 'ellipse',
icon: 'user',
},
{
id: 'node2',
label: 'Node 2',
color: 'primary',
shape: 'hexagon',
icon: 'question',
},
];
const edges: EdgeViewModel[] = [
{
id: 'edge1',
source: 'node1',
target: 'node2',
color: 'primary',
},
];
Use the Graph component in your JSX/TSX, passing the nodes, edges, and interactivity flag as props.
<Graph nodes={nodes} edges={edges} interactive={true} />
Here is a complete example of how to use the Graph component in a React component.
import React from 'react';
import { Graph } from '@kbn/cloud-security-posture-graph';
import type { NodeViewModel, EdgeViewModel } from '@kbn/cloud-security-posture-graph';
const App: React.FC = () => {
const nodes: NodeViewModel[] = [
{
id: 'node1',
label: 'Node 1',
color: 'primary',
shape: 'ellipse',
icon: 'user',
},
{
id: 'node2',
label: 'Node 2',
color: 'primary',
shape: 'hexagon',
icon: 'question',
},
];
const edges: EdgeViewModel[] = [
{
id: 'edge1',
source: 'node1',
target: 'node2',
color: 'primary',
},
];
return (
<div>
<h1>Graph Visualization</h1>
<Graph nodes={nodes} edges={edges} interactive={true} />
</div>
);
};
export default App;
You can also see how the Graph component is used in the Storybook file graph_layout.stories.tsx.
Be sure to check out provided helpers
General look of the component can be checked visually running the following storybook:
yarn storybook cloud_security_posture_graph
Note that all the interactions are mocked.
When using GraphGroupedNodePreviewPanel the list of grouped entities / events renders clickable titles. Instead of wiring an onOpenItem callback (which would break URL serialization for flyout state) the package exposes an RxJS Subject:
import { groupedItemClick$, emitGroupedItemClick } from '@kbn/cloud-security-posture-graph';
useEffect(() => {
const sub = groupedItemClick$.subscribe((item) => {
// Decide how to open your own preview panel here
});
return () => sub.unsubscribe();
}, []);
The Security Solution plugin, for example, maps:
DOCUMENT_TYPE_ENTITY -> Generic entity flyoutDOCUMENT_TYPE_EVENT -> Event document detailsDOCUMENT_TYPE_ALERT -> Alert document detailsRapid double clicks on the same item id (within 250ms) are ignored to prevent accidental duplicate flyout openings. For testing there is a private helper __resetGroupedItemClickDedupe().
useGroupedItemClick convenience hook.