Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate wazuh.yml configuration to opensearch_dashboards.yml #7175

Merged
merged 38 commits into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
e2ecc3d
Added wazuh configuration in wazuh_core plugin
Machi3mfl Nov 25, 2024
ea8ad34
Add hosts config on opensearch_dashboards.yml
Machi3mfl Nov 27, 2024
4c25766
Merge branch 'master' into enhancement/migrate-wazuh-configuration
Machi3mfl Dec 2, 2024
25886e3
Add advanced settings (ui_settings)
Machi3mfl Dec 4, 2024
0467def
Move all configurations to yml and ui settings
Machi3mfl Dec 4, 2024
c7922d3
Add new configuration providers and repository
Machi3mfl Dec 9, 2024
c933616
Update providers
Machi3mfl Dec 9, 2024
4855482
Update core with new configuration store interface
Machi3mfl Dec 9, 2024
94a9dad
Fix main errores
Machi3mfl Dec 9, 2024
1dacb0b
Create configuration services folder on common
Machi3mfl Dec 12, 2024
634f43d
Update server configuration services and types
Machi3mfl Dec 12, 2024
511b3e5
Create public configuration types
Machi3mfl Dec 12, 2024
d6b66e5
Apply new configuration store implementation on server
Machi3mfl Dec 12, 2024
9a4d2fe
Apply new configuration store implementation on public context
Machi3mfl Dec 12, 2024
3ab5831
Moved ui settings to common
Machi3mfl Dec 13, 2024
e5d0f95
Update providers and configuration types
Machi3mfl Dec 13, 2024
4fc58e2
Use configuration service on public
Machi3mfl Dec 13, 2024
ff50249
Add configuration store unit tests
Machi3mfl Dec 13, 2024
86bc999
Update configuration service unit tests
Machi3mfl Dec 13, 2024
bced596
Adapt the plugin settings to ui settings
Machi3mfl Dec 17, 2024
d6ae59d
Use settings adapter to create plugin config
Machi3mfl Dec 18, 2024
ddea925
Merge branch 'master' into enhancement/migrate-wazuh-configuration
Machi3mfl Dec 19, 2024
da87f62
Fix conflicts with master
Machi3mfl Dec 19, 2024
f8e7b16
Apply prettier
Machi3mfl Dec 20, 2024
2382b23
Apply prettier
Machi3mfl Dec 20, 2024
3d754b2
Merge branch 'master' into enhancement/migrate-wazuh-configuration
Machi3mfl Dec 23, 2024
b3564d4
Fix linter errors
Machi3mfl Dec 23, 2024
42c49c0
Fix linter error
Machi3mfl Dec 23, 2024
6db1a11
Fix linter errors
Machi3mfl Dec 24, 2024
72c36c5
Fix linter errors
Machi3mfl Dec 24, 2024
cd37ed7
Fix linter error
Machi3mfl Dec 24, 2024
f42c941
Fix linter errors
Machi3mfl Dec 24, 2024
1b69592
Fix linter errors
Machi3mfl Dec 24, 2024
7d3ab5f
Apply prettier
Machi3mfl Dec 24, 2024
5fa2c4a
Fix errors and unit tests
Machi3mfl Dec 24, 2024
0b38816
Resolve requested changes
Machi3mfl Dec 26, 2024
473271a
Add port number validation
Machi3mfl Dec 30, 2024
c25b048
Merge branch 'master' into enhancement/migrate-wazuh-configuration
Machi3mfl Dec 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions docker/osd-dev/config/2.x/osd/opensearch_dashboards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,23 @@ opensearch.ssl.verificationMode: certificate
# opensearch.requestHeadersWhitelist: ["securitytenant","Authorization"]
#
# osd 2.0
opensearch.requestHeadersAllowlist: ["securitytenant", "Authorization"]
opensearch.requestHeadersAllowlist: ['securitytenant', 'Authorization']
#
opensearch_security.multitenancy.enabled: false
opensearch_security.readonly_mode.roles: ["kibana_read_only"]
opensearch_security.readonly_mode.roles: ['kibana_read_only']
server.ssl.enabled: true
server.ssl.key: "/home/node/kbn/certs/osd.key"
server.ssl.certificate: "/home/node/kbn/certs/osd.pem"
opensearch.ssl.certificateAuthorities: ["/home/node/kbn/certs/ca.pem"]
server.ssl.key: '/home/node/kbn/certs/osd.key'
server.ssl.certificate: '/home/node/kbn/certs/osd.pem'
opensearch.ssl.certificateAuthorities: ['/home/node/kbn/certs/ca.pem']
uiSettings.overrides.defaultRoute: /app/wz-home
opensearch.username: "kibanaserver"
opensearch.password: "kibanaserver"
opensearch.username: 'kibanaserver'
opensearch.password: 'kibanaserver'
opensearchDashboards.branding:
useExpandedHeader: false

wazuh_core.hosts:
manager:
url: 'https://wazuh.manager'
port: 55000
username: wazuh-wui
password: MyS3cr37P450r.*-
run_as: false
72 changes: 29 additions & 43 deletions plugins/main/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import {
Plugin,
PluginInitializerContext,
} from 'opensearch_dashboards/public';
import { Cookies } from 'react-cookie';
import { euiPaletteColorBlind } from '@elastic/eui';
import { createHashHistory } from 'history';
import {
setDataPlugin,
setHttp,
Expand All @@ -27,61 +30,49 @@ import {
setWazuhEnginePlugin,
setWazuhFleetPlugin,
} from './kibana-services';
import { validate as validateNodeCronInterval } from 'node-cron';
import {
AppPluginStartDependencies,
WazuhSetup,
WazuhSetupPlugins,
WazuhStart,
WazuhStartPlugins,
} from './types';
import { Cookies } from 'react-cookie';
import { AppState } from './react-services/app-state';
import { setErrorOrchestrator } from './react-services/common-services';
import { ErrorOrchestratorService } from './react-services/error-orchestrator/error-orchestrator.service';
import store from './redux/store';
import { updateAppConfig } from './redux/actions/appConfigActions';
import {
initializeInterceptor,
unregisterInterceptor,
} from './services/request-handler';
import { Applications, Categories } from './utils/applications';
import { euiPaletteColorBlind } from '@elastic/eui';
import NavigationService from './react-services/navigation-service';
import { createHashHistory } from 'history';
import { reportingDefinitions } from './react-services/reporting/reporting-definitions';

export class WazuhPlugin
implements
Plugin<WazuhSetup, WazuhStart, WazuhSetupPlugins, WazuhStartPlugins>
{
constructor(private readonly initializerContext: PluginInitializerContext) {}

private hideTelemetryBanner?: () => void;

public async setup(
core: CoreSetup,
plugins: WazuhSetupPlugins,
): Promise<WazuhSetup> {
// Get custom logos configuration to start up the app with the correct logos
let logosInitialState = {};
try {
logosInitialState = await core.http.get(`/api/logos`);
} catch (error) {
console.error('plugin.ts: Error getting logos configuration', error);
}

// Redefine the mapKeys method to change the properties sent to euiPaletteColorBlind.
// This is a workaround until the issue reported in Opensearch Dashboards is fixed.
// https://github.com/opensearch-project/OpenSearch-Dashboards/issues/5422
// This should be reomved when the issue is fixed. Probably in OSD 2.12.0
plugins.charts.colors.mappedColors.mapKeys = function (
keys: Array<string | number>,
keys: (string | number)[],
) {
const configMapping = this.getConfigColorMapping();
const configColors = _.values(configMapping);
const oldColors = _.values(this._oldMap);

let alreadyUsedColors: string[] = [];
const keysToMap: Array<string | number> = [];
const keysToMap: (string | number)[] = [];

_.each(keys, key => {
// If this key is mapped in the config, it's unnecessary to have it mapped here
if (configMapping[key as any]) {
Expand All @@ -90,7 +81,7 @@ export class WazuhPlugin
}

// If this key is mapped to a color used by the config color mapping, we need to remap it
if (_.includes(configColors, this._mapping[key])) keysToMap.push(key);
if (_.includes(configColors, this._mapping[key])) {keysToMap.push(key);}

// if key exist in oldMap, move it to mapping
if (this._oldMap[key]) {
Expand All @@ -99,13 +90,14 @@ export class WazuhPlugin
}

// If this key isn't mapped, we need to map it
if (this.get(key) == null) keysToMap.push(key);
if (this.get(key) === null) {keysToMap.push(key);}
});

alreadyUsedColors.push(...Object.values(this._mapping));
alreadyUsedColors = alreadyUsedColors.map(color =>
color.toLocaleLowerCase(),
);

// Choose colors from euiPaletteColorBlind and filter out any already assigned to keys
const colorPalette = euiPaletteColorBlind({
rotations: Math.ceil(
Expand All @@ -120,57 +112,46 @@ export class WazuhPlugin
};

// Register the applications
Applications.forEach(app => {
for (const app of Applications) {
const { category, id, title, redirectTo, order } = app;

core.application.register({
id,
title,
order,
mount: async (params: AppMountParameters) => {
try {
/* Workaround: Redefine the validation functions of cron.statistics.interval setting.
There is an optimization error of the frontend side source code due to some modules can
not be loaded
*/
const setting = plugins.wazuhCore.configuration._settings.get(
'cron.statistics.interval',
);
!setting.validateUIForm &&
(setting.validateUIForm = function (value) {
return this.validate(value);
});
!setting.validate &&
(setting.validate = function (value: string) {
return validateNodeCronInterval(value)
? undefined
: 'Interval is not valid.';
});
setWzCurrentAppID(id);
// Set the dynamic redirection
setWzMainParams(redirectTo());
initializeInterceptor(core);

// Update redux app state logos with the custom logos
if (logosInitialState?.logos) {
store.dispatch(updateAppConfig(logosInitialState.logos));
}
// hide the telemetry banner.
// Set the flag in the telemetry saved object as the notice was seen and dismissed
this.hideTelemetryBanner && (await this.hideTelemetryBanner());
if (this.hideTelemetryBanner) {
await this.hideTelemetryBanner();
}

setScopedHistory(params.history);
// This allows you to add the selectors to the navbar
setHeaderActionMenuMounter(params.setHeaderActionMenu);
NavigationService.getInstance(createHashHistory());

// Load application bundle
const { renderApp } = await import('./application');

setErrorOrchestrator(ErrorOrchestratorService);
setHttp(core.http);
setCookies(new Cookies());

if (!AppState.checkCookies()) {
NavigationService.getInstance().reload();
}

params.element.classList.add('dscAppWrapper', 'wz-app');

const unmount = await renderApp(params);

return () => {
unmount();
unregisterInterceptor();
Expand All @@ -183,9 +164,11 @@ export class WazuhPlugin
({ id: categoryID }) => categoryID === category,
),
});
});
}

return {};
}

public start(
core: CoreStart,
plugins: AppPluginStartDependencies,
Expand All @@ -194,11 +177,13 @@ export class WazuhPlugin
if (plugins.securityOss) {
plugins.securityOss.insecureCluster.hideAlert(true);
}

if (plugins?.telemetry?.telemetryNotifications?.setOptedInNoticeSeen) {
// assign to a method to hide the telemetry banner used when the app is mounted
this.hideTelemetryBanner = () =>
plugins.telemetry.telemetryNotifications.setOptedInNoticeSeen();
}

setCore(core);
setPlugins(plugins);
setHttp(core.http);
Expand All @@ -215,6 +200,7 @@ export class WazuhPlugin
setWazuhCorePlugin(plugins.wazuhCore);
setWazuhEnginePlugin(plugins.wazuhEngine);
setWazuhFleetPlugin(plugins.wazuhFleet);

return {};
}
}
9 changes: 7 additions & 2 deletions plugins/main/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@
SharedGlobalConfig,
} from 'opensearch_dashboards/server';

import { WazuhPluginSetup, WazuhPluginStart, PluginSetup } from './types';

Check failure on line 29 in plugins/main/server/plugin.ts

View workflow job for this annotation

GitHub Actions / Ensure the code format on the changed files

Unexpected blank line before this statement
import { setupRoutes } from './routes';
import {
jobInitializeRun,
jobMonitoringRun,

Check failure on line 33 in plugins/main/server/plugin.ts

View workflow job for this annotation

GitHub Actions / Ensure the code format on the changed files

'jobMonitoringRun' is defined but never used. Allowed unused vars must match /[iI]gnored$/u
jobSchedulerRun,

Check failure on line 34 in plugins/main/server/plugin.ts

View workflow job for this annotation

GitHub Actions / Ensure the code format on the changed files

'jobSchedulerRun' is defined but never used. Allowed unused vars must match /[iI]gnored$/u
jobQueueRun,
jobMigrationTasksRun,
jobSanitizeUploadedFilesTasksRun,

Check failure on line 37 in plugins/main/server/plugin.ts

View workflow job for this annotation

GitHub Actions / Ensure the code format on the changed files

'jobSanitizeUploadedFilesTasksRun' is defined but never used. Allowed unused vars must match /[iI]gnored$/u
} from './start';
import { first } from 'rxjs/operators';

Check failure on line 39 in plugins/main/server/plugin.ts

View workflow job for this annotation

GitHub Actions / Ensure the code format on the changed files

`rxjs/operators` import should occur before import of `./types`

declare module 'opensearch_dashboards/server' {
interface RequestHandlerContext {
Expand Down Expand Up @@ -82,7 +82,7 @@

const serverInfo = core.http.getServerInfo();

core.http.registerRouteHandlerContext('wazuh', (context, request) => {

Check failure on line 85 in plugins/main/server/plugin.ts

View workflow job for this annotation

GitHub Actions / Ensure the code format on the changed files

Unexpected block statement surrounding arrow body; parenthesize the returned value and move it immediately after the `=>`
return {
// Create a custom logger with a tag composed of HTTP method and path endpoint
logger: this.logger.get(
Expand All @@ -102,12 +102,12 @@
const additionalHeaders = {
'x-frame-options': 'sameorigin',
};
return toolkit.next({ headers: additionalHeaders });

Check failure on line 105 in plugins/main/server/plugin.ts

View workflow job for this annotation

GitHub Actions / Ensure the code format on the changed files

Expected blank line before this statement
});

// Routes
const router = core.http.createRouter();
setupRoutes(router, plugins.wazuhCore);

Check failure on line 110 in plugins/main/server/plugin.ts

View workflow job for this annotation

GitHub Actions / Ensure the code format on the changed files

Expected blank line before this statement

return {};
}
Expand All @@ -118,7 +118,7 @@
.pipe(first())
.toPromise();

const contextServer = {

Check failure on line 121 in plugins/main/server/plugin.ts

View workflow job for this annotation

GitHub Actions / Ensure the code format on the changed files

Unexpected blank line before this statement
config: globalConfiguration,
};

Expand All @@ -134,6 +134,8 @@
});

// Sanitize uploaded files tasks
// error: [error][plugins][sanitize-uploaded-files-task][wazuh] sanitize:sanitizeUploadedSVG: Error: Configuration undefined not found
/*
jobSanitizeUploadedFilesTasksRun({
core,
wazuh: {
Expand All @@ -143,6 +145,7 @@
wazuh_core: plugins.wazuhCore,
server: contextServer,
});
*/

// Migration tasks
jobMigrationTasksRun({
Expand All @@ -155,7 +158,7 @@
server: contextServer,
});

// Monitoring
/* Monitoring
jobMonitoringRun({
core,
wazuh: {
Expand All @@ -165,8 +168,9 @@
wazuh_core: plugins.wazuhCore,
server: contextServer,
});
*/

// Scheduler
/* Scheduler
jobSchedulerRun({
core,
wazuh: {
Expand All @@ -176,6 +180,7 @@
wazuh_core: plugins.wazuhCore,
server: contextServer,
});
*/

// Queue
jobQueueRun({
Expand All @@ -187,7 +192,7 @@
wazuh_core: plugins.wazuhCore,
server: contextServer,
});
return {};

Check failure on line 195 in plugins/main/server/plugin.ts

View workflow job for this annotation

GitHub Actions / Ensure the code format on the changed files

Expected blank line before this statement
}

public stop() {}
Expand Down
4 changes: 3 additions & 1 deletion plugins/main/server/routes/wazuh-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ export function WazuhApiRoutes(router: IRouter) {
ctrl.getSyscollector(context, request, response),
);

// Return app logos configuration
/* Return app logos configuration
ToDo: Change (maybe) to get the opensearch logo settings
router.get(
{
path: '/api/logos',
Expand All @@ -138,6 +139,7 @@ export function WazuhApiRoutes(router: IRouter) {
async (context, request, response) =>
ctrl.getAppLogos(context, request, response),
);
*/

// Return binary dashboard
router.get(
Expand Down
5 changes: 3 additions & 2 deletions plugins/main/server/start/monitoring/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ let MONITORING_ENABLED,
async function initMonitoringConfiguration(context) {
try {
context.wazuh.logger.debug('Reading configuration');
const appConfig = await context.wazuh_core.configuration.get();
const appConfig = await context.wazuh_core.configuration.getAll();
MONITORING_ENABLED =
(appConfig['wazuh.monitoring.enabled'] &&
appConfig['wazuh.monitoring.enabled'] !== 'worker') ||
Expand Down Expand Up @@ -90,6 +90,7 @@ async function initMonitoringConfiguration(context) {
*/
async function init(context) {
try {
const config = await context.wazuh_core.configuration.getAll();
if (MONITORING_ENABLED) {
await checkTemplate(context);
}
Expand Down Expand Up @@ -519,7 +520,7 @@ async function fetchAllAgentsFromApiHost(context, apiHost) {
export async function jobMonitoringRun(context) {
context.wazuh.logger.debug('Task:Monitoring initializing');
// Init the monitoring variables
await initMonitoringConfiguration(context);
//await initMonitoringConfiguration(context);
// Check Kibana index and if it is prepared, start the initialization of Wazuh App.
await checkPluginPlatformStatus(context);
// // Run the cron job only it it's enabled
Expand Down
Loading
Loading