wazuh / wazuh-dashboard

Wazuh dashboard, the Wazuh UI platform
https://wazuh.com
Apache License 2.0
36 stars 57 forks source link

POC engine UX - security policy management #216

Closed asteriscos closed 2 months ago

asteriscos commented 4 months ago

Description

We have to create a new proof of concept plugin that allows the user to manage the new engine.

The engine has the following object types:

Related to the security policy management the engine defines:

These concepts are defined in the engine user manual

Based on this, we need to propose a UI to manage these concepts.

We need to provide an intuitive interface for the engine configuration changes, allowing users to easily adjust settings. It should list the engine configuration and provide a form to edit each setting, ideally using different controls for different configuration data types, validanting the user input.

Also, we need to provide a way to manage KVDBs which is the replacement of the current CDBs. The main difference is that KVDBs are dynamic and can be updated while the policy is running. KVDBs will not be stored in the indexer, so these operations should assume it will be accessed using the API.

References

Plan

Desvelao commented 4 months ago

Plugin

A plugin with ID wazuhEngine was created in the plugins/wazuh-engine.

This plugin defines and exposes the UI components to manage the Engine.

The plugin does not register any application as we would want, because this would need some services that are defined on the main plugin, so the render of the view of Engine application is rendered by the main plugin to simplify the POC. But this should be done as desirable in the final implementation.

So, a new app is registered on the side menu called Engine: image

Accessing to the Engine app displays a layout based on the side menu and body. The side menu has access to the different entities of the engine: decoders, rules, filters, outputs, integrations, policies and KVDBs.

image

Clicking on the menu items changing the view to manage that entity of the engine with the CRUD actions: TODO

Desvelao commented 4 months ago

Reserved

Desvelao commented 4 months ago

Research - Rule relationship visualization

I was exploring the idea to represent the rule relationships through a Vega visualization.

I don't know what is the final document schema of a rule definition, but I defined a simple schema to test the representation of rule relationship storing in the rules data:

Reviewing the chart types, I decided to test with the Tree layout.

:information_source: From my tests, the Tree layout chart needs only one root of the data to build the tree. It could not get to work with multiple tree roots. So this could mean one restriction depending on the use case.

Following this approach I store some data on an index on Wazuh indexer I created an index where I store some mocked documents related to rules. ``` PUT /wazuh-rules { "settings": { "number_of_shards": 1, "number_of_replicas": 0 }, "mappings": { "properties": { "id": { "type": "keyword" }, "parent": { "type": "keyword" } } } } ``` Then I indexed some documents: ``` POST /wazuh-rules/_doc { "id": "1" } POST /wazuh-rules/_doc { "id": "2", "parent": "1" } POST /wazuh-rules/_doc { "id": "3", "parent": "1" } POST /wazuh-rules/_doc { "id": "4" } ```

With the data rule on the Wazuh indexer, I created a visualization of Vega type.

Notes:

Vega visualization definition ``` { $schema: https://vega.github.io/schema/vega/v5.json description: An example of Cartesian layouts for a node-link diagram of hierarchical data. padding: 5 signals: [ { name: labels value: true bind: { input: checkbox } } { name: layout value: tidy bind: { input: radio options: [ tidy cluster ] } } { name: links value: diagonal bind: { input: select options: [ line curve diagonal orthogonal ] } } { name: separation value: false bind: { input: checkbox } } ] data: [ { name: tree url: { /* An object instead of a string for the "url" param is treated as an OpenSearch query. Anything inside this object is not part of the Vega language, but only understood by OpenSearch Dashboards and OpenSearch server. This query counts the number of documents per time interval, assuming you have a @timestamp field in your data. OpenSearch Dashboards has a special handling for the fields surrounded by "%". They are processed before the the query is sent to OpenSearch. This way the query becomes context aware, and can use the time range and the dashboard filters. */ // Apply dashboard context filters when set // %context%: true // Filter the time picker (upper right corner) with this field // %timefield%: @timestamp /* See .search() documentation for : https://opensearch.org/docs/latest/clients/javascript/ */ // Which index to search index: wazuh-rules // If "data_source.enabled: true", optionally set the data source name to query from (omit field if querying from local cluster) // data_source_name: Example US Cluster // Aggregate data by the time field into time buckets, counting the number of documents in each bucket. body: { query: { bool: { should: [ { match_phrase: { id: 1 } } { match_phrase: { parent: 1 } } ] minimum_should_match: 1 } } /* query: { match_all: { } } */ size: 1000 } } /* } For our graph, we only need the list of bucket values. Use the format.property to discard everything else. */ format: { property: hits.hits } transform: [ { type: stratify key: _source.id parentKey: _source.parent } { type: tree method: { signal: layout } size: [ { signal: height } { signal: width - 100 } ] separation: { signal: separation } as: [ y x depth children ] } ] } { name: links source: tree transform: [ { type: treelinks } { type: linkpath orient: horizontal shape: { signal: links } } ] } ] scales: [ { name: color type: linear range: { scheme: magma } domain: { data: tree field: depth } zero: true } ] marks: [ { type: path from: { data: links } encode: { update: { path: { field: path } stroke: { value: "#ccc" } } } } { type: symbol from: { data: tree } encode: { enter: { size: { value: 100 } stroke: { value: "#fff" } } update: { x: { field: x } y: { field: y } fill: { scale: color field: depth } } } } { type: text from: { data: tree } encode: { enter: { text: { field: _source.id } fontSize: { value: 15 } baseline: { value: middle } } update: { x: { field: x } y: { field: y } dx: { signal: datum.children ? -7 : 7 } align: { signal: datum.children ? 'right' : 'left' } opacity: { signal: labels ? 1 : 0 } } } } ] } ```

image

Then, I got the visualization definition and used the same mechanism to render a dashboard used on the main plugin, and I got the visualization: image

JuanGarriuz commented 4 months ago

Mocked API response and flyout added

https://github.com/wazuh/wazuh-dashboard/assets/124377319/f1d1352d-5df2-4d30-a9cc-a483c98ae471

Update 08/07

https://github.com/wazuh/wazuh-dashboard/assets/124377319/dcc9786b-9743-4d12-8c5a-165224198637

Desvelao commented 4 months ago

POC - Rules

This section has the following capabilities:

Cotain information about the rules (table and JSON), its relation with other rules and related events.

It allows the creation of a rule using a visual editor or (through a form) or a file editor. All views allow importing from file. image image image

updates - 2024/07/24 - add ability to remove field form arrayOf form field - Create component to select the configuration method - Replace the creator with configuration method switch - Create paths for editors or rules and outputs - Enhance spec of rule and outputs - Enhance render of arrayOf form fields on form editor - 2024/08/09 - update screenshots
JuanGarriuz commented 4 months ago

Update KVDB 10/07

image image

image

Work on

ToDo

JuanGarriuz commented 4 months ago

Update 15/07

image image

ToDo

JuanGarriuz commented 3 months ago

Update 02/08

Decoders

image image image image

Forms

localhost_5601_app_wz-engine

JuanGarriuz commented 3 months ago

Update 07/08

Policies

image

Decoders

image

Desvelao commented 3 months ago

POC - Outputs