Skip to content

Commit

Permalink
Create plugin wazuh check updates (#5897)
Browse files Browse the repository at this point in the history
* Add wazuh_check_updates plugin

Signed-off-by: Luciano Gorza <lucianogorza@gmail.com>

* Manage saved object for plugin configurations

Signed-off-by: Luciano Gorza <lucianogorza@gmail.com>

* New componente UpToDateStatus and improvements

Signed-off-by: Luciano Gorza <lucianogorza@gmail.com>

* Current update component and improvements

Signed-off-by: Luciano Gorza <lucianogorza@gmail.com>

* CurrentUpdateDetails improvements and others

Signed-off-by: Luciano Gorza <lucianogorza@gmail.com>

* Improvements with unit tests

Signed-off-by: Luciano Gorza <lucianogorza@gmail.com>

* Complete public unit tests

Signed-off-by: Luciano Gorza <lucianogorza@gmail.com>

* Unit test updatesNotification component

Signed-off-by: Luciano Gorza <lucianogorza@gmail.com>

* Backend unit tests

Signed-off-by: Luciano Gorza <lucianogorza@gmail.com>

* Add current update details to currentUpdateDetails component

Signed-off-by: Luciano Gorza <lucianogorza@gmail.com>

* Add translation to show details message

Signed-off-by: Luciano Gorza <lucianogorza@gmail.com>

* Add DismissNotificationCheck component

Signed-off-by: Luciano Gorza <lucianogorza@gmail.com>

* Modify styles

Signed-off-by: Luciano Gorza <lucianogorza@gmail.com>

* Expose new component

Signed-off-by: Luciano Gorza <lucianogorza@gmail.com>

* Update DismissNotificationCheck component

Signed-off-by: Luciano Gorza <lucianogorza@gmail.com>

* Add getCurrentUser implementation

Signed-off-by: Luciano Gorza <lucianogorza@gmail.com>

* Fix plugin start types

Signed-off-by: Luciano Gorza <lucianogorza@gmail.com>

* Fix checks ids

Signed-off-by: Luciano Gorza <lucianogorza@gmail.com>

* Delete console.log in component

Signed-off-by: Luciano Gorza <lucianogorza@gmail.com>

* Fixes in PR

Signed-off-by: Luciano Gorza <lucianogorza@gmail.com>

* Modify README

Signed-off-by: Luciano Gorza <lucianogorza@gmail.com>

* Delete unused files

Signed-off-by: Luciano Gorza <lucianogorza@gmail.com>

* Delete commented code

Signed-off-by: Luciano Gorza <lucianogorza@gmail.com>

* Removing unnecessary packages

Signed-off-by: Luciano Gorza <lucianogorza@gmail.com>

* Clear available updates value on error

Signed-off-by: Luciano Gorza <lucianogorza@gmail.com>

* Change constant name

Signed-off-by: Luciano Gorza <lucianogorza@gmail.com>

* Change message on new update

Signed-off-by: Luciano Gorza <lucianogorza@gmail.com>

* Change camelCase to kebab-case

Signed-off-by: Luciano Gorza <lucianogorza@gmail.com>

* Change plugin name using kebab-case

Signed-off-by: Luciano Gorza <lucianogorza@gmail.com>

* Add useEffect to component UpToDateStatus

Signed-off-by: Luciano Gorza <lucianogorza@gmail.com>

* Improve return errors in routes

Signed-off-by: Luciano Gorza <lucianogorza@gmail.com>

* Show update description in lines

Signed-off-by: Luciano Gorza <lucianogorza@gmail.com>

* Add Logger

Signed-off-by: Luciano Gorza <lucianogorza@gmail.com>

* Improve constant name

Signed-off-by: Luciano Gorza <lucianogorza@gmail.com>

* Improve check texts and links icons

Signed-off-by: Luciano Gorza <lucianogorza@gmail.com>

* Fix if statements

Signed-off-by: Luciano Gorza <lucianogorza@gmail.com>

* Change folder name in dev.yml using kebab-case

Signed-off-by: Luciano Gorza <lucianogorza@gmail.com>

* Update test snapshots

Signed-off-by: Luciano Gorza <lucianogorza@gmail.com>

* Add I18nProvider wrapper to components

Signed-off-by: Luciano Gorza <lucianogorza@gmail.com>

* Unit test for routes and kebab case fixes

Signed-off-by: Luciano Gorza <lucianogorza@gmail.com>

* Add toast when on get updates error

Signed-off-by: Luciano Gorza <lucianogorza@gmail.com>

* Omit username property on GET user preferences

Signed-off-by: Luciano Gorza <lucianogorza@gmail.com>

* Improve try catch finally

Signed-off-by: Luciano Gorza <lucianogorza@gmail.com>

* Add mock html_id_generator to component unit tests

Signed-off-by: Luciano Gorza <lucianogorza@gmail.com>

* Fix unit test get-user-preferences

Signed-off-by: Luciano Gorza <lucianogorza@gmail.com>

* Fix route unit tests port by adding a random port

Signed-off-by: Luciano Gorza <lucianogorza@gmail.com>

* Improved user preferences saved object

Signed-off-by: Luciano Gorza <lucianogorza@gmail.com>

* Fix toast message

Signed-off-by: Luciano Gorza <lucianogorza@gmail.com>

* Change port in route unit tests

Signed-off-by: Luciano Gorza <lucianogorza@gmail.com>

---------

Signed-off-by: Luciano Gorza <lucianogorza@gmail.com>
  • Loading branch information
lucianogorza authored Sep 25, 2023
1 parent 0da782f commit 20e61a7
Show file tree
Hide file tree
Showing 84 changed files with 4,360 additions and 29 deletions.
59 changes: 30 additions & 29 deletions docker/osd-dev/dev.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
version: "2.2"
version: '2.2'

x-logging: &logging
logging:
driver: loki
options:
loki-url: "http://host.docker.internal:3100/loki/api/v1/push"
loki-url: 'http://host.docker.internal:3100/loki/api/v1/push'

services:
exporter:
image: quay.io/prometheuscommunity/elasticsearch-exporter:latest
<<: *logging
hostname: exporter-osd-${OS_VERSION}
profiles:
- "saml"
- "standard"
- 'saml'
- 'standard'
networks:
- os-dev
- mon
command:
- "--es.uri=https://admin:${PASSWORD}@os1:9200"
- "--es.ssl-skip-verify"
- "--es.all"
- '--es.uri=https://admin:${PASSWORD}@os1:9200'
- '--es.ssl-skip-verify'
- '--es.all'

imposter:
image: outofcoffee/imposter
Expand All @@ -39,8 +39,8 @@ services:
image: cfssl/cfssl
<<: *logging
profiles:
- "saml"
- "standard"
- 'saml'
- 'standard'
volumes:
- wi_certs:/certs/wi
- wd_certs:/certs/wd
Expand Down Expand Up @@ -117,7 +117,7 @@ services:
sleep 300
'
healthcheck:
test: ["CMD-SHELL", "[ -r /certs/wi/os1.pem ]"]
test: ['CMD-SHELL', '[ -r /certs/wi/os1.pem ]']
interval: 2s
timeout: 5s
retries: 10
Expand All @@ -129,15 +129,15 @@ services:
image: opensearchproject/opensearch:${OS_VERSION}
<<: *logging
profiles:
- "saml"
- "standard"
- 'saml'
- 'standard'
environment:
- cluster.name=os-dev-cluster
- node.name=os1
- discovery.seed_hosts=os1
- cluster.initial_master_nodes=os1
- bootstrap.memory_lock=true # along with the memlock settings below, disables swapping
- "OPENSEARCH_JAVA_OPTS=-Xms512m -Xmx512m" # minimum and maximum Java heap size, recommend setting both to 50% of system RAM
- 'OPENSEARCH_JAVA_OPTS=-Xms512m -Xmx512m' # minimum and maximum Java heap size, recommend setting both to 50% of system RAM
- OPENSEARCH_PATH_CONF=/usr/share/opensearch/config/
ulimits:
memlock:
Expand All @@ -162,7 +162,7 @@ services:
healthcheck:
test:
[
"CMD-SHELL",
'CMD-SHELL',
"curl -v --cacert config/certs/ca.pem https://os1:9200 2>&1 | grep -q '401 Unauthorized'",
]
interval: 1s
Expand All @@ -175,17 +175,17 @@ services:
condition: service_healthy
image: elastic/filebeat:7.10.2
profiles:
- "saml"
- "standard"
- 'saml'
- 'standard'
hostname: filebeat
user: "0:0"
user: '0:0'
networks:
- os-dev
- mon
<<: *logging
# restart: always
entrypoint:
- "/bin/bash"
- '/bin/bash'
command: >
-c '
mkdir -p /etc/filebeat
Expand All @@ -211,23 +211,24 @@ services:
condition: service_healthy
image: quay.io/wazuh/osd-dev:${OSD_VERSION}
profiles:
- "saml"
- "standard"
- 'saml'
- 'standard'
hostname: osd
networks:
- os-dev
- devel
- mon
user: "1000:1000"
user: '1000:1000'
<<: *logging
ports:
- ${OSD_PORT}:5601
environment:
- "LOGS=/proc/1/fd/1"
entrypoint: ["tail", "-f", "/dev/null"]
- 'LOGS=/proc/1/fd/1'
entrypoint: ['tail', '-f', '/dev/null']
volumes:
- osd_cache:/home/node/.cache
- "${SRC}:/home/node/kbn/plugins/wazuh"
- '${SRC}/main:/home/node/kbn/plugins/wazuh'
- '${SRC}/wazuh-check-updates:/home/node/kbn/plugins/wazuh-check-updates'
- wd_certs:/home/node/kbn/certs/
- ${WAZUH_DASHBOARD_CONF}:/home/node/kbn/config/opensearch_dashboards.yml
- ./config/${OSD_MAJOR}/osd/wazuh.yml:/home/node/kbn/data/wazuh/config/wazuh.yml
Expand All @@ -238,7 +239,7 @@ services:
generator:
condition: service_healthy
profiles:
- "saml"
- 'saml'
volumes:
- wi_certs:/certs/wi
- wd_certs:/certs/wd
Expand All @@ -258,7 +259,7 @@ services:
sleep 300
'
healthcheck:
test: ["CMD-SHELL", "[ -r /certs/idp/truststore.jks ]"]
test: ['CMD-SHELL', '[ -r /certs/idp/truststore.jks ]']
interval: 2s
timeout: 5s
retries: 10
Expand All @@ -269,14 +270,14 @@ services:
idpsec:
condition: service_healthy
profiles:
- "saml"
- 'saml'
hostname: idp
<<: *logging
networks:
- os-dev
- mon
ports:
- "8080:8080"
- '8080:8080'
environment:
- KEYCLOAK_ADMIN=admin
- KEYCLOAK_ADMIN_PASSWORD=admin
Expand All @@ -298,7 +299,7 @@ services:
idp:
condition: service_healthy
profiles:
- "saml"
- 'saml'
hostname: idpsetup
<<: *logging
networks:
Expand Down
7 changes: 7 additions & 0 deletions plugins/wazuh-check-updates/.i18nrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"prefix": "wazuhCheckUpdates",
"paths": {
"wazuhCheckUpdates": "."
},
"translations": ["translations/en-US.json"]
}
24 changes: 24 additions & 0 deletions plugins/wazuh-check-updates/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Wazuh Check Updates Plugin

The **Wazuh Check Updates Plugin** is a extension for Wazuh that allows you to seamlessly query an external service to retrieve information about the latest available updates and their corresponding features. This dedicated plugin has been designed to work in conjunction with the primary Wazuh plugin, enhancing its capabilities to notify users whenever new updates become accessible. With a focus on modularity, the Check Updates Plugin provides various components to manage updates and notification preferences.

## Features

### 1. Notification of New Updates

The core functionality of the plugin is to notify users about the availability of new updates. It continuously queries an external service to check for updates and sends notifications to users when new updates are detected.

### 2. Deployment Status

Stay informed about the deployment status of updates. The plugin offers a component that allows you to easily view the status of updates.

### 3. Update Details

Get detailed information about the latest update, including links to release notes and updagrade guide, as well as the update description.

## Software and libraries used

- [OpenSearch](https://opensearch.org/)
- [Elastic UI Framework](https://eui.elastic.co/)
- [Node.js](https://nodejs.org)
- [React](https://reactjs.org)
47 changes: 47 additions & 0 deletions plugins/wazuh-check-updates/common/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import path from 'path';

export const PLUGIN_ID = 'wazuhCheckUpdates';
export const PLUGIN_NAME = 'wazuh_check_updates';

export const SAVED_OBJECT_UPDATES = 'wazuh-check-updates-available-updates';
export const SAVED_OBJECT_SETTINGS = 'wazuh-check-updates-settings';
export const SAVED_OBJECT_USER_PREFERENCES = 'wazuh-check-updates-user-preferences';

export const DEFAULT_SCHEDULE = '* */12 * * *';

export enum routes {
checkUpdates = '/api/wazuh-check-updates/updates',
userPreferences = '/api/wazuh-check-updates/user-preferences',
}

// Security
export const WAZUH_SECURITY_PLUGIN_OPENSEARCH_DASHBOARDS_SECURITY =
'OpenSearch Dashboards Security';

// Default Elasticsearch user name context
export const ELASTIC_NAME = 'elastic';

// Wazuh data path
const WAZUH_DATA_PLUGIN_PLATFORM_BASE_PATH = 'data';
export const WAZUH_DATA_PLUGIN_PLATFORM_BASE_ABSOLUTE_PATH = path.join(
__dirname,
'../../../',
WAZUH_DATA_PLUGIN_PLATFORM_BASE_PATH
);
export const WAZUH_DATA_ABSOLUTE_PATH = path.join(
WAZUH_DATA_PLUGIN_PLATFORM_BASE_ABSOLUTE_PATH,
'wazuh'
);

// Wazuh data path - config
export const WAZUH_DATA_CONFIG_DIRECTORY_PATH = path.join(WAZUH_DATA_ABSOLUTE_PATH, 'config');
export const WAZUH_DATA_CONFIG_APP_PATH = path.join(WAZUH_DATA_CONFIG_DIRECTORY_PATH, 'wazuh.yml');

// Wazuh data path - logs
export const MAX_MB_LOG_FILES = 100;
export const WAZUH_DATA_LOGS_DIRECTORY_PATH = path.join(WAZUH_DATA_ABSOLUTE_PATH, 'logs');
export const WAZUH_DATA_LOGS_PLAIN_FILENAME = 'wazuhapp-plain.log';
export const WAZUH_DATA_LOGS_RAW_FILENAME = 'wazuhapp.log';

// App configuration
export const WAZUH_CONFIGURATION_CACHE_TIME = 10000; // time in ms;
29 changes: 29 additions & 0 deletions plugins/wazuh-check-updates/common/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
export interface AvailableUpdates {
mayor: Update[];
minor: Update[];
patch: Update[];
last_check?: Date | string | undefined;
}

export interface Update {
description: string;
published_date: string;
semver: {
mayor: number;
minor: number;
patch: number;
};
tag: string;
title: string;
}

export interface UserPreferences {
last_dismissed_update?: string;
hide_update_notifications?: boolean;
}

export interface CheckUpdatesSettings {
schedule?: string;
}

export type savedObjectType = AvailableUpdates | UserPreferences | CheckUpdatesSettings;
9 changes: 9 additions & 0 deletions plugins/wazuh-check-updates/opensearch_dashboards.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"id": "wazuhCheckUpdates",
"version": "1.0.0",
"opensearchDashboardsVersion": "opensearchDashboards",
"server": true,
"ui": true,
"requiredPlugins": ["navigation", "opensearchDashboardsUtils"],
"optionalPlugins": ["securityDashboards"]
}
28 changes: 28 additions & 0 deletions plugins/wazuh-check-updates/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "wazuh-check-updates",
"version": "0.0.0",
"private": true,
"scripts": {
"build": "yarn plugin-helpers build",
"plugin-helpers": "node ../../scripts/plugin_helpers",
"osd": "node ../../scripts/osd",
"test:ui:runner": "node ../../scripts/functional_test_runner.js",
"test:server": "plugin-helpers test:server",
"test:browser": "plugin-helpers test:browser",
"test:jest": "node scripts/jest",
"test:jest:runner": "node scripts/runner test"
},
"dependencies": {
"axios": "^1.5.0",
"axios-mock-adapter": "^1.21.5",
"md5": "^2.3.0",
"node-cron": "^3.0.2",
"winston": "^3.10.0"
},
"devDependencies": {
"@testing-library/user-event": "^14.5.0",
"@types/": "testing-library/user-event",
"@types/md5": "^2.3.2",
"@types/node-cron": "^3.0.8"
}
}
Loading

0 comments on commit 20e61a7

Please sign in to comment.