Skip to content

Commit

Permalink
Rollback configuration store from saved object to configuration file (#…
Browse files Browse the repository at this point in the history
…6573)

* rollback(configuration-store): rollback the store system to configuration file

- Rollback the store system to configuration file
  - Change WAZUH_CORE_CONFIGURATION_CACHE_SECONDS from 60 to 10
  - Create logic to ensure the configuration file is created else create
    it with default configuration on start
  - Remove task to migrate the configuration file to saved object
- Enhance the Configuration service to include references to categories
  and some utility functions
- Remove plugin settings:
  - wazuh_core.instance
  - wazuh_core.encryption_key

* remove(configuration): remove the migration task of configuration file to saved object

* rollback(configuration): remove references to plugin settings defition

* rollback(configuration): remove enhanceConfiguration from frontend side

* fix(configuration): replace logger methods for noop

* rollback(configuration): display the path to the configuration file on App Settings application

- Display the real path of the configuration file instead of the fixed value on App Settings
- Add configuration_file property to the response of GET /api/setup
- Refactor the ConfigurationStore services
- Minor enhancements typed code

* remove: unused constant PLUGIN_PLATFORM_BASE_INSTALLATION_PATH

* rollback(configuration): remove management of API connections on Server APIs

- Remove buttons to edit and remove from the table
- Change the form to add an API connection by information about editing
  the configuration file

* rollback(configuration): remove management of API connection from the backend side

- Remove API endpoints and related controllers
  - POST /hosts/apis/{id}
  - PUT /hosts/apis/{id}
  - DELETE /hosts/apis/{id}
- Remove methods to manage the API connections in the ManageHosts
  service

* fix: fix innaccesible view of Miscellaneous tab on App Settings

* fix(configuration): fix error when editing some setting from the UI due to an error in the backend side

- Renamed setting properties:
  - validate -> validateUIForm
  - validateBackend -> validate
  - Adapted the validation on the affected API endpoints
- Removed transformation of changed values of useForm hook. This
  transformation is now done externally.

* rollback(configuration): clear entry on configuration file

* rollback(configuration): remove API endpoint POST /utils/configuration/import

* feat(configuration): enhance validation of plugin settings

* feat(configuration): enhance validation of enrollment.dns plugin setting

- Enhance the validation of enrollment.dns setting
- Replace the validation of the server address input on Deploy new agent
  guide by the validation of enrollment.dns plugin setting
  - Remove validateServerAddress method and related tests. Move tests to
    apply to SettingsValidator

* clean: import of non-existent method

* rollback(configuration): remove import configuration from file

* fix(configuration): remove the visibility of default values of customization settings on App Settings

- Create getSettingValueIfNotSet method for Configuration services to
  manage the customization settings
- Adapt the getCustomizationSetting method of Configuration service
  to use getSettingValueIfNotSet
- Change the parameters of getCustomizationSetting of Configuration
  service to support multiple settings
- Adapt printer to the usage of getCustomizationSettings redefinition
- Enhance code typings

* fix(configuration): minimize the references to branding on the configuration file

* rollback(administrator): consideration of administrator user

- Rollback to the consideration of administrator user based on
  the administrator API connection role
  - Create logic to check this consideration to the DashboardSecurity
    services in frontend and backend side
   - Add getAccountFromJWTAPIDecodedToken method to frontend side
   - Adapt the WzAuthentication service to use the
     getAccountFromJWTAPIDecodedToken
  - Add a constant that defines the ID for the administrator role of the
    API connection
  - Remove previous consideration based on the access to the security
    REST API of the platform
    - Remove API endpoint `GET /utils/account` and
      getPluginScopedAccount controller
    - Remove fetch user account data from the frontend side
    - Remove fetchAccount method of DashboardSecurity service on the
      frontend side
    - Adapt routeDecoratorProtectedAdministrator route decorator
- Enhance the message about the administrator missing requirements
- Rename administrator_error_message to administrator_requirements
  related to the consideration of administrator user

* changelog: adapt some entries related to rollback the configuartion store in the backend side

* test: fix reporting tests

* tests: fix of core plugin

* rollback: remove encryption service

* tests: fix tests

* tests: remove references to deprecated validateBackend method of plugin settings

* tests(configuration-store): add tests

* remove: deprecated createLogFileIfNotExists method

* fix: comment

* fix(configuration-store): dirname of configuration file

* rollback(configuration-store): rename logger of ConfigurationStore service

* rollback(configuration): remove API endpoint POST /utils/configuration/clear

- Remove API endpoint POST /utils/configuration/clear
  - Remove route controller

* fix(configuration): fix error removing customization logos in a short period of time

- Add plugin setting category: API_CONNECTION (related to hosts
  setting)
- Replace the category of hosts plugin setting
- Refactor the setting.store.file interface:
  - Remove configurable
  - Add configurableManaged and defaultBlock
  - Adapt the plugin settings defitions with these changes
- Remove the configuration block related to the API connections from the
  ConfigurationStore service to the plugin setting definition through
  the defaultBlock
- Enhance logging on ManageHosts

* tests(configuration-store): adapt to latest changes
  • Loading branch information
Desvelao authored Apr 9, 2024
1 parent 711f798 commit 5efc20f
Show file tree
Hide file tree
Showing 54 changed files with 1,610 additions and 2,109 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ All notable changes to the Wazuh app project will be documented in this file.
- Support for Wazuh 4.9.0
- Added AngularJS dependencies [#6145](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6145)
- Added a migration task to setup the configuration using a configuration file [#6337](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6337)
- Added the ability to manage the API hosts from the Server APIs [#6337](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6337) [#6519](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6519)
- Improve fleet management by adding 'Edit Agent Groups' and 'Upgrade Agents' actions, as well as a filter to show only outdated agents [#6250](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6250) [#6476](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6476) [#6274](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6274) [#6501](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6501) [#6529](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6529)
- Added propagation of updates from the table to dashboard visualizations in Endpoints summary [#6460](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6460)
- Handle index pattern selector on new discover [#6499](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6499)
Expand All @@ -20,7 +19,7 @@ All notable changes to the Wazuh app project will be documented in this file.
- Removed embedded discover [#6120](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6120) [#6235](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6235) [#6254](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6254) [#6285](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6285) [#6288](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6288) [#6290](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6290) [#6289](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6289) [#6286](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6286) [#6275](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6275) [#6287](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6287) [#6297](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6297) [#6287](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6287) [#6291](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6287) [#6459](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6459) [#6434](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6434)
- Develop logic of a new index for the fim module [#6227](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6227)
- Allow editing groups for an agent from Endpoints Summary [#6250](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6250)
- Changed as the configuration is defined and stored [#6337](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6337)
- Change how the configuration is managed in the backend side [#6337](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6337) [#6519](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6519) [#6570](https://github.com/wazuh/wazuh-dashboard-plugins/issues/6570)
- Change the view of API is down and check connection to Server APIs application [#6337](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6337)
- Changed the usage of the endpoint GET /groups/{group_id}/files/{file_name} [#6385](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6385)
- Refactoring and redesign endpoints summary visualizations [#6268](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6268)
Expand All @@ -34,6 +33,7 @@ All notable changes to the Wazuh app project will be documented in this file.
### Fixed

- Fixed the scripted fields disappear when the fields of the events index pattern was refreshed [#6237](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6237)
- Fixed the validation for `enrollment.dns` on App Settings application [#6570](https://github.com/wazuh/wazuh-dashboard-plugins/issues/6570)

### Removed

Expand Down
2 changes: 0 additions & 2 deletions plugins/main/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,6 @@ export const REPORTS_PAGE_HEADER_TEXT = '[email protected]\nhttps://wazuh.com';

// Plugin platform
export const PLUGIN_PLATFORM_NAME = 'dashboard';
export const PLUGIN_PLATFORM_BASE_INSTALLATION_PATH =
'/usr/share/wazuh-dashboard/data/wazuh/';
export const PLUGIN_PLATFORM_INSTALLATION_USER = 'wazuh-dashboard';
export const PLUGIN_PLATFORM_INSTALLATION_USER_GROUP = 'wazuh-dashboard';
export const PLUGIN_PLATFORM_WAZUH_DOCUMENTATION_URL_PATH_UPGRADE_PLATFORM =
Expand Down
8 changes: 0 additions & 8 deletions plugins/main/public/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,6 @@ app.run([
})
.catch(() => {});

// Set user account data in Redux when app starts.
getWazuhCorePlugin()
.dashboardSecurity.fetchAccount()
.then(response => {
store.dispatch(updateUserAccount(response));
})
.catch(() => {});

// Init the process of refreshing the user's token when app start.
checkPluginVersion().finally(WzAuthentication.refresh);

Expand Down
4 changes: 1 addition & 3 deletions plugins/main/public/components/common/form/hooks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,7 @@ export const useForm = (fields: FormConfiguration): UseFormReturn => {
pathFormState: [],
},
({ changed, error, value }, _, { pathFormState, fieldDefinition }) => {
changed &&
(result.changed[pathFormState] =
fieldDefinition?.transformChangedOutputValue?.(value) ?? value);
changed && (result.changed[pathFormState] = value);
error && (result.errors[pathFormState] = error);
},
);
Expand Down
1 change: 0 additions & 1 deletion plugins/main/public/components/common/form/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ interface FieldConfiguration {
initialValue: any;
validate?: (value: any) => string | undefined;
transformChangedInputValue?: (value: any) => any;
transformChangedOutputValue?: (value: any) => any;
}

export interface DefaultFieldConfiguration extends FieldConfiguration {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ import { useSelector } from 'react-redux';
// It retuns user requirements if is is not admin
export const useUserPermissionsIsAdminRequirements = () => {
const account = useSelector(state => state.appStateReducers.userAccount);
return [account.administrator_error_message, account];
return [account.administrator_requirements, account];
};
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,10 @@ import {
} from '../../../../common/hocs';
import GroupInput from '../../components/group-input/group-input';
import { OsCard } from '../../components/os-selector/os-card/os-card';
import {
validateServerAddress,
validateAgentName,
} from '../../utils/validations';
import { validateAgentName } from '../../utils/validations';
import { compose } from 'redux';
import { endpointSummary } from '../../../../../utils/applications';
import { getCore } from '../../../../../kibana-services';
import { getCore, getWazuhCorePlugin } from '../../../../../kibana-services';
import { getErrorOrchestrator } from '../../../../../react-services/common-services';

export const RegisterAgent = compose(
Expand Down Expand Up @@ -80,7 +77,9 @@ export const RegisterAgent = compose(
serverAddress: {
type: 'text',
initialValue: configuration['enrollment.dns'] || '',
validate: validateServerAddress,
validate:
getWazuhCorePlugin().configuration._settings.get('enrollment.dns')
.validate,
},
agentName: {
type: 'text',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,53 +1,6 @@
import { validateServerAddress, validateAgentName } from './validations';
import { validateAgentName } from './validations';

describe('Validations', () => {
it('should return undefined for an empty value', () => {
const result = validateServerAddress('');
expect(result).toBeUndefined();
});

it('should return undefined for a valid FQDN', () => {
const validFQDN = 'example.fqdn.valid';
const result = validateServerAddress(validFQDN);
expect(result).toBeUndefined();
});

it('should return undefined for a valid IPv4', () => {
const validIP = '192.168.1.1';
const result = validateServerAddress(validIP);
expect(result).toBeUndefined();
});

it('should return undefined for a valid IPv6', () => {
const validIP = '2001:0db8:85a3:0000:0000:8a2e:0370:7334';
const result = validateServerAddress(validIP);
expect(result).toBeUndefined();
});

it('should return an error message for an invalid IPv6', () => {
const invalidIPV6 = '2001:db8:85a3::8a2e:370:7334';
const result = validateServerAddress(invalidIPV6);
expect(result).toBe(
'It should be a valid hostname, FQDN, IPv4 or uncompressed IPv6',
);
});

it('should return an error message for a compressed IPv6', () => {
const compressedIPV6 = '2001:0db8:85a3:0000:0000:8a2e:0370:7334:KL12';
const result = validateServerAddress(compressedIPV6);
expect(result).toBe(
'It should be a valid hostname, FQDN, IPv4 or uncompressed IPv6',
);
});

it('should return an error message for an invalid FQDN', () => {
const invalidFQDN = 'example.';
const result = validateServerAddress(invalidFQDN);
expect(result).toBe(
'It should be a valid hostname, FQDN, IPv4 or uncompressed IPv6',
);
});

test('should return undefined for an empty value', () => {
const emptyValue = '';
const result = validateAgentName(emptyValue);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,3 @@
//IPv4: This is a set of four numbers, for example, 192.158.1.38. Each number in the set can range from 0 to 255. Therefore, the full range of IP addresses goes from 0.0.0.0 to 255.255.255.255
//IPv6: This is a set or eight hexadecimal expressions, each from 0000 to FFFF. 2001:0db8:85a3:0000:0000:8a2e:0370:7334

// FQDN: Maximum of 63 characters per label.
// Can only contain numbers, letters and hyphens (-)
// Labels cannot begin or end with a hyphen
// Currently supports multilingual characters, i.e. letters not included in the English alphabet: e.g. á é í ó ú ü ñ.
// Minimum 3 labels
// A label can contain only numbers

// Hostname: Maximum of 63 characters per label. Same rules as FQDN apply.

export const validateServerAddress = (value: string) => {
const isFQDNOrHostname =
/^(?!-)(?!.*--)[a-zA-Z0-9áéíóúüñ-]{0,62}[a-zA-Z0-9áéíóúüñ](?:\.[a-zA-Z0-9áéíóúüñ-]{0,62}[a-zA-Z0-9áéíóúüñ]){0,}$/;
const isIPv6 = /^(?:[0-9a-fA-F]{4}:){7}[0-9a-fA-F]{4}$/;

if (
value.length > 255 ||
(value.length > 0 && !isFQDNOrHostname.test(value) && !isIPv6.test(value))
) {
return 'It should be a valid hostname, FQDN, IPv4 or uncompressed IPv6';
}
return undefined;
};

export const validateAgentName = (value: any) => {
if (value.length === 0) {
return undefined;
Expand Down
Loading

0 comments on commit 5efc20f

Please sign in to comment.