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

Replace the management of plugins configuration #6337

Merged
merged 146 commits into from
Mar 11, 2024

Conversation

Desvelao
Copy link
Member

@Desvelao Desvelao commented Jan 17, 2024

Description

This pull request replaces the management of configuration by the plugins.

Changes:

  • Create new services to manage the configuration
    • Configuration (common)
    • ConfigurationStore (frontend and backend side)
    • Adapt the replacement of configuration services:
      • Frontend:
        • Configure through the App Settings application
      • Backend:
        • Refactor the ReportPrinter service to create the PDF reports, now uses the new Configuration service
        • Jobs
        • services to get the top agents with alerts related to some specific condition
  • Add a new field store in the plugin setting
  • Move some backend services to properties of ManageHosts service:
    • CacheAPIUserAllowRunAs
    • ServerAPIHostEntries
  • Create button components that open a flyout
  • Enhance the useForm hook to allow dynamic inputs
  • Create password input form component
  • Add a new setting type arrayOf
  • Refactor AddAPI component
    • Remove old one
    • Create form to add or edit an API host from Server APIs application
    • Refactor the management to display the new add API view
    • Remove unused controller methods to adding the new API host view
  • Add buttons to edit or delete the API host entry to the table on Server APIs application
  • The table in Server APIs application now displays a message when there are not configured APIs
  • Remove deprecated services related to previous configuration
    • Common:
      • getCategorySettingByTitle
      • getSettingDefaultValue
      • getSettingsDefault
      • getSettingsByCategories
      • getSettingsDefaultList
      • groupSettingsByCategory
      • getPluginSettingDescription
      • getCustomizationSetting: moved to the Configuration instance of the backend side
    • Backend:
      • getConfiguration
      • services related to the creation of the initial file configuration
  • Create new endpoints to manage the configuration
    • POST /utils/configuration/clear: clear the configuration stored in the saved object
    • POST /utils/configuration/import: import the configuration from a configuration file
  • Create new endpoints and controllers to manage the API host entries
    • PUT /hosts/apis/{id}: add or update an existing API host entry
    • DELETE /hosts/apis/{id}: remove an existing API host entry
  • Refactor the validation of endpoints taking into account the dynamic configuration instead of static
    • PUT /utils/configuration
    • PUT /utils/configuration/files/{key}
    • DELETE /utils/configuration/files/{key}
  • Move the API is down view
    - Remove render through AngularJS template
    - Remove properties defined in controller
    - Add a new callout to render in Server APIs
    - Include a button that opens a flyout with a basic troubleshooting
  • Create processes to setup or migrate the previous configuration:
    • Server side
    • Script
  • Replace the consideration of "administrator" user based on API roles to platform permission to use the rest API based on platform roles:
    • Create a new endpoint to get data about the account:
    • GET /utils/account: gives information about if the user is an user considered as "administrator" for the plugins.
    • Refactor the protection of some views with the "administrator" user.
      • Sample data
      • App Settings
    • Refactor the WzButtonPermissions buttons to use the administrator check instead of based on checking the "administrator" API roles.
    • Create a decorator to protect the API routes and protect them
  • Create a frontend service to manage the dashboardSecurity
    • Replace the request to get the current platform by method provided by the service
  • Create a button component that opens a flyout
  • Create a password form input
  • Adapted the unit tests

Issues Resolved

#6201

Evidence

  • Generic view
    image

  • Add API entry
    image
    image

  • Edit and remove buttons
    image
    image
    image

  • Warning about API could be down:
    image
    image

Test

configuration-saved-object

Legend:
⚫: none
🟢: pass
🟡: warning
🔴: fail
⚪: not applicable

UI

Test Chrome Firefox Safari
With no API hosts added, go to Server APIs application and should display an empty table.
With an administrator user, go to Server APIs, click on Add API host and fill the form with a valid API host. The API host should be added and the table should be udpated.
With an administrator user and API hosts added, go to Server APIs, and edit some of them. Try editing some field or multiple fields. The API host entry should be updated and the new values should be displayed in the table.
With an administrator user and API hosts added, go to Server APIs, and remove some of them. The API host entries should be updated.
With API hosts entries added, ensure the host key in the saved object of the configuration is encrypted.
With a stopped API entry, go to Server APIs application and should display a callout about the problem.
Without a stored object of configuration, upload a file through the POST /utils/configuration/import. The configuration should be updated into the saved object.
With a stored object of configuration, upload a file through the POST /utils/configuration/import. The configuration should be updated into the saved object and ensure the previous configuration is not present.
With a non administrator user, go to App Settings, a prompt should display the user has no permissions
With a non administrator user, go to Server APIs, the Add API host, edit and remove button should be disabled displaying a message related to missing permissions.

Details

⚫ With no API hosts added, go to Server APIs application and should display an empty table.

Chrome - ⚫

Firefox - ⚫

Safari - ⚫

⚫ With an administrator user, go to Server APIs, click on Add API host and fill the form with a valid API host. The API host should be added and the table should be udpated.

Chrome - ⚫

Firefox - ⚫

Safari - ⚫

⚫ With an administrator user and API hosts added, go to Server APIs, and edit some of them. Try editing some field or multiple fields. The API host entry should be updated and the new values should be displayed in the table.

Chrome - ⚫

Firefox - ⚫

Safari - ⚫

⚫ With an administrator user and API hosts added, go to Server APIs, and remove some of them. The API host entries should be updated.

Chrome - ⚫

Firefox - ⚫

Safari - ⚫

⚫ With API hosts entries added, ensure the host key in the saved object of the configuration is encrypted.

Chrome - ⚫

Firefox - ⚫

Safari - ⚫

⚫ With a stopped API entry, go to Server APIs application and should display a callout about the problem.

Chrome - ⚫

Firefox - ⚫

Safari - ⚫

⚫ Without a stored object of configuration, upload a file through the POST /utils/configuration/import. The configuration should be updated into the saved object.

Chrome - ⚫

Firefox - ⚫

Safari - ⚫

⚫ With a stored object of configuration, upload a file through the POST /utils/configuration/import. The configuration should be updated into the saved object and ensure the previous configuration is not present.

Chrome - ⚫

Firefox - ⚫

Safari - ⚫

⚫ With a non administrator user, go to App Settings, a prompt should display the user has no permissions

Chrome - ⚫

Firefox - ⚫

Safari - ⚫

⚫ With a non administrator user, go to Server APIs, the Add API host, edit and remove button should be disabled displaying a message related to missing permissions.

Chrome - ⚫

Firefox - ⚫

Safari - ⚫

Other

Test Result
In configuration, change some settings and update the configuration. Ensure the data is stored in the saved object. Try to upload files too.
With a stored saved object of configuration, stop the Wazuh dashboard, change the platform setting wazuh_core.instance. Check the current settings are not using the values of the stored saved object configuration.
With a wazuh.yml configuration file located at data/wazuh/config/wazuh.yml and no stored saved object, should setup the configuration defined in the file into the saved object.

Details

⚫ In configuration, change some settings and update the configuration. Ensure the data is stored in the saved object. Try to upload files too.
⚫ With a stored saved object of configuration, stop the Wazuh dashboard, change the platform setting wazuh_core.instance. Check the current settings are not using the values of the stored saved object configuration.
⚫ With a wazuh.yml configuration file located at data/wazuh/config/wazuh.yml and no stored saved object, should setup the configuration defined in the file into the saved object.

Check List

  • All tests pass
    • yarn test:jest
  • New functionality includes testing.
  • New functionality has been documented.
  • Update CHANGELOG.md
  • Commits are signed per the DCO using --signoff

- Enhance the logging messages
- Minor enhancements
- Replace the logging services
- Move services to core plugin
  - CacheAPIUserAllowRunAs
  - ManageHosts
  - ServerAPIClient (aka api-interceptor)
  - ServerAPIHostEntries (aka )
  - UpdateConfigurationFile
  - UpdateRegistry
- Adapt the usage of services in the main and check updates plugin from
  core plugin
- Remove plugin logger from main and core plugins
- Remove API endpoint
  - GET /utils/logs/ui
- Remove unused code
- Adapt the test suites
…to enhancement/6137-adapt-logging-method
…to enhancement/6137-adapt-logging-method
- Remove GET /utils/logs endpoint
  - Remove related tests
- Remove App logs application
- Create Configuration service
- Create ConfigurationStore (backend and frontend side)
- Register the plugin settings in the configuration services
…ration service

- API endpoints:
  - GET /utils/configuration
  - PUT /utils/configuration
  - PUT /utils/configuration/files/{key}
  - DELETE /utils/configuration/files/{key}
@JuanGarriuz JuanGarriuz self-requested a review March 5, 2024 10:54
Copy link
Contributor

github-actions bot commented Mar 8, 2024

Wazuh Core plugin code coverage (Jest) test % values
Statements 28.94% ( 286 / 988 )
Branches 26.22% ( 107 / 408 )
Functions 26.87% ( 86 / 320 )
Lines 28.68% ( 278 / 969 )

Copy link
Contributor

github-actions bot commented Mar 8, 2024

Wazuh Check Updates plugin code coverage (Jest) test % values
Statements 76.44% ( 172 / 225 )
Branches 58.65% ( 61 / 104 )
Functions 61.7% ( 29 / 47 )
Lines 76.44% ( 172 / 225 )

Copy link
Contributor

github-actions bot commented Mar 8, 2024

Main plugin code coverage (Jest) test % values
Statements 11.55% ( 3979 / 34427 )
Branches 7.32% ( 1651 / 22548 )
Functions 10.31% ( 843 / 8169 )
Lines 11.73% ( 3873 / 32995 )

Copy link
Member

@yenienserrano yenienserrano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CR: ✅
Test: ✅ fixed the problems I had found when adding and editing apis

@asteriscos
Copy link
Member

asteriscos commented Mar 8, 2024

Test Chrome Firefox Safari
With no API hosts added, go to Server APIs application and should display an empty table. 🟢
With an administrator user, go to Server APIs, click on Add API host and fill the form with a valid API host. The API host should be added and the table should be udpated. 🟢
With an administrator user and API hosts added, go to Server APIs, and edit some of them. Try editing some field or multiple fields. The API host entry should be updated and the new values should be displayed in the table. 🟢
With an administrator user and API hosts added, go to Server APIs, and remove some of them. The API host entries should be updated. 🟢
With API hosts entries added, ensure the host key in the saved object of the configuration is encrypted. 🟢
With a stopped API entry, go to Server APIs application and should display a callout about the problem. 🟢
Without a stored object of configuration, upload a file through the POST /utils/configuration/import. The configuration should be updated into the saved object. 🟢
With a stored object of configuration, upload a file through the POST /utils/configuration/import. The configuration should be updated into the saved object and ensure the previous configuration is not present. 🟢
With a non administrator user, go to App Settings, a prompt should display the user has no permissions 🟢
With a non administrator user, go to Server APIs, the Add API host, edit and remove button should be disabled displaying a message related to missing permissions. 🟢

Details

🟢 With no API hosts added, go to Server APIs application and should display an empty table.

Chrome - 🟢

image

Firefox - ⚫

Safari - ⚫

🟢 With an administrator user, go to Server APIs, click on Add API host and fill the form with a valid API host. The API host should be added and the table should be udpated.

Chrome - 🟢

image

Firefox - ⚫

Safari - ⚫

🟢 With an administrator user and API hosts added, go to Server APIs, and edit some of them. Try editing some field or multiple fields. The API host entry should be updated and the new values should be displayed in the table.

Chrome - 🟢

image

Firefox - ⚫

Safari - ⚫

🟢 With an administrator user and API hosts added, go to Server APIs, and remove some of them. The API host entries should be updated.

Chrome - 🟢

Peek 2024-03-11 16-06

Firefox - ⚫

Safari - ⚫

🟢 With API hosts entries added, ensure the host key in the saved object of the configuration is encrypted.

Chrome - 🟢

image

Firefox - ⚫

Safari - ⚫

🟢 With a stopped API entry, go to Server APIs application and should display a callout about the problem.

Chrome - 🟢

image

Firefox - ⚫

Safari - ⚫

🟢 Without a stored object of configuration, upload a file through the POST /utils/configuration/import. The configuration should be updated into the saved object.

Chrome - 🟢

image

Firefox - ⚫

Safari - ⚫

🟢 With a stored object of configuration, upload a file through the POST /utils/configuration/import. The configuration should be updated into the saved object and ensure the previous configuration is not present.

Chrome - 🟢

image

Firefox - ⚫

Safari - ⚫

🟢 With a non administrator user, go to App Settings, a prompt should display the user has no permissions

Chrome - 🟢

image

Firefox - ⚫

Safari - ⚫

🟢 With a non administrator user, go to Server APIs, the Add API host, edit and remove button should be disabled displaying a message related to missing permissions.

Chrome - 🟢

image

Firefox - ⚫

Safari - ⚫

@asteriscos asteriscos merged commit d79db98 into 4.9.0 Mar 11, 2024
4 checks passed
@asteriscos asteriscos deleted the enhancement/6201-replace-plugins-configuration branch March 11, 2024 15:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Move the plugin configuration to stateless
3 participants