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

Fixed a routes loop when reinstalling Wazuh indexer #4373

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ All notable changes to the Wazuh app project will be documented in this file.
- Fixed an error of an undefined username hash related to reporting when using Kibana with X-Pack and security was disabled [#4358](https://github.com/wazuh/wazuh-kibana-app/pull/4358)
- Fixed persistence of the plugin registry file between updates [#4359](https://github.com/wazuh/wazuh-kibana-app/pull/4359)
- Fixed searchbar error on SCA Inventory table [#4367](https://github.com/wazuh/wazuh-kibana-app/pull/4367)
- Fixed a routes loop when reinstalling Wazuh indexer [#4373](https://github.com/wazuh/wazuh-kibana-app/pull/4373)
- Fixed Wazuh restart UI [#4365](https://github.com/wazuh/wazuh-kibana-app/pull/4365)

# Removed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ export const checkIndexPatternObjectService = async (appConfig, checkLogger: Ch
listValidIndexPatterns = await SavedObject.getListOfWazuhValidIndexPatterns(defaultIndexPatterns, HEALTH_CHECK);
checkLogger.info(`Valid index patterns found: ${listValidIndexPatterns.length || 0}`);
if(!AppState.getCurrentPattern()){
// Check the index pattern saved objects can be found using `GET /api/saved_objects/_find` endpoint.
// Related issue: https://github.com/wazuh/wazuh-kibana-app/issues/4293
await validateIntegritySavedObjects([defaultPatternId], checkLogger);

AppState.setCurrentPattern(defaultPatternId);
checkLogger.info(`Index pattern set in cookie: [${defaultPatternId}]`);
}
Expand All @@ -69,8 +73,14 @@ export const checkIndexPatternObjectService = async (appConfig, checkLogger: Ch
if (AppState.getCurrentPattern() && listValidIndexPatterns.length) {
const indexPatternToSelect = listValidIndexPatterns.find(item => item.id === AppState.getCurrentPattern());
if (!indexPatternToSelect){
AppState.setCurrentPattern(listValidIndexPatterns[0].id);
checkLogger.action(`Set index pattern id in cookie: [${listValidIndexPatterns[0].id}]`);
const indexPatternID = listValidIndexPatterns[0].id;

// Check the index pattern saved objects can be found using `GET /api/saved_objects/_find` endpoint.
// Related issue: https://github.com/wazuh/wazuh-kibana-app/issues/4293
await validateIntegritySavedObjects([indexPatternID], checkLogger);

AppState.setCurrentPattern(indexPatternID);
checkLogger.action(`Set index pattern id in cookie: [${indexPatternID}]`);
}
}

Expand All @@ -91,6 +101,10 @@ export const checkIndexPatternObjectService = async (appConfig, checkLogger: Ch
const indexPatternDefaultFound = listValidIndexPatterns.find((indexPattern) => indexPattern.title === defaultPatternId);
checkLogger.info(`Index pattern id exists [${defaultPatternId}]: ${indexPatternDefaultFound ? 'yes': 'no'}`);
if(indexPatternDefaultFound){
// Check the index pattern saved objects can be found using `GET /api/saved_objects/_find` endpoint.
// Related issue: https://github.com/wazuh/wazuh-kibana-app/issues/4293
await validateIntegritySavedObjects([indexPatternDefaultFound.id], checkLogger);

AppState.setCurrentPattern(indexPatternDefaultFound.id);
checkLogger.action(`Index pattern set in cookie: [${indexPatternDefaultFound.id}]`);
}
Expand All @@ -101,3 +115,11 @@ export const checkIndexPatternObjectService = async (appConfig, checkLogger: Ch
}
}
};

// Check the index pattern saved objects can be found using `GET /api/saved_objects/_find` endpoint.
// Related issue: https://github.com/wazuh/wazuh-kibana-app/issues/4293
const validateIntegritySavedObjects = async (indexPatternSavedObjectIDs: string[], checkLogger: CheckLogger): Promise<void> => {
checkLogger.info(`Checking the integrity of saved objects. Validating ${indexPatternSavedObjectIDs.join(',')} can be found...`);
await SavedObject.validateIndexPatternSavedObjectCanBeFound(indexPatternSavedObjectIDs);
checkLogger.info('Integrity of saved objects: [ok]');
};
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,11 @@ export const checkPatternSupportService = (pattern: string, indexType : string)
checkLogger.error(`Error creating index pattern id [${pattern}]: ${error.message || error}`);
}
};

const indexPatternSavedObjectIDs = [pattern];
// Check the index pattern saved objects can be found using `GET /api/saved_objects/_find` endpoint.
// Related issue: https://github.com/wazuh/wazuh-kibana-app/issues/4293
checkLogger.info(`Checking the integrity of saved objects. Validating ${indexPatternSavedObjectIDs.join(',')} can be found...`);
await SavedObject.validateIndexPatternSavedObjectCanBeFound(indexPatternSavedObjectIDs);
checkLogger.info('Integrity of saved objects: [ok]');
}
25 changes: 24 additions & 1 deletion public/react-services/saved-objects.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@ import { FieldsStatistics } from '../utils/statistics-fields';
import { FieldsMonitoring } from '../utils/monitoring-fields';
import {
HEALTH_CHECK,
PLUGIN_PLATFORM_NAME,
WAZUH_INDEX_TYPE_ALERTS,
WAZUH_INDEX_TYPE_MONITORING,
WAZUH_INDEX_TYPE_STATISTICS,
} from '../../common/constants';
import { getSavedObjects } from '../kibana-services';
import { webDocumentationLink } from '../../common/services/web_documentation';

export class SavedObject {
/**
Expand Down Expand Up @@ -279,4 +282,24 @@ export class SavedObject {
}
}
};
}

/**
* Check if it exists the index pattern saved objects using the `GET /api/saved_objects/_find` endpoint.
* It is usefull to validate if the endpoint works as expected. Related issue: https://github.com/wazuh/wazuh-kibana-app/issues/4293
* @param {string[]} indexPatternIDs
*/
static async validateIndexPatternSavedObjectCanBeFound(indexPatternIDs){
const indexPatternsSavedObjects = await getSavedObjects().client.find({
type: 'index-pattern',
fields: ['title'],
perPage: 10000
});
const indexPatternsSavedObjectsCanBeFound = indexPatternIDs
.every(indexPatternID => indexPatternsSavedObjects.savedObjects.some(savedObject => savedObject.id === indexPatternID));

if (!indexPatternsSavedObjectsCanBeFound) {
throw new Error(`Saved object for index pattern not found.
Restart the ${PLUGIN_PLATFORM_NAME} service to initialize the index. More information in <a href="${webDocumentationLink('user-manual/wazuh-dashboard/troubleshooting.html#saved-object-for-index-pattern-not-found')}" target="_blank">troubleshooting</a>.`
)};
}
}
2 changes: 1 addition & 1 deletion server/start/initialize/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { pluginPlatformTemplate } from '../../integration-files/kibana-template'
import { getConfiguration } from '../../lib/get-configuration';
import { totalmem } from 'os';
import fs from 'fs';
import { WAZUH_ALERTS_PATTERN, WAZUH_DATA_CONFIG_REGISTRY_PATH, WAZUH_PLUGIN_PLATFORM_TEMPLATE_NAME, WAZUH_DATA_PLUGIN_PLATFORM_BASE_ABSOLUTE_PATH, PLUGIN_PLATFORM_NAME, PLUGIN_PLATFORM_INSTALLATION_USER_GROUP, PLUGIN_PLATFORM_INSTALLATION_USER, WAZUH_DEFAULT_APP_CONFIG } from '../../../common/constants';
import { WAZUH_ALERTS_PATTERN, WAZUH_DATA_CONFIG_REGISTRY_PATH, WAZUH_PLUGIN_PLATFORM_TEMPLATE_NAME, WAZUH_DATA_PLUGIN_PLATFORM_BASE_ABSOLUTE_PATH, PLUGIN_PLATFORM_NAME, PLUGIN_PLATFORM_INSTALLATION_USER_GROUP, PLUGIN_PLATFORM_INSTALLATION_USER, WAZUH_DEFAULT_APP_CONFIG, PLUGIN_APP_NAME } from '../../../common/constants';
import { createDataDirectoryIfNotExists } from '../../lib/filesystem';
import _ from 'lodash';

Expand Down