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

Change apt to dpkg for better performance #3004

Merged

Conversation

Enaraque
Copy link
Member

Related issue
#2983

Description

The purpose of this PR is to improve the speed of checking packages installed with APT.
APT has been changed to dpkg due to better performance.

Speed tests

If we compare the execution results when checking the installed wazuh components we get the following data:

Check with APT
root@ubuntu-focal:/home/vagrant# bash wazuh-install.sh -a
13/06/2024 09:34:46 INFO: Starting Wazuh installation assistant. Wazuh version: 4.8.0
13/06/2024 09:34:46 INFO: Verbose logging redirected to /var/log/wazuh-install.log
Total time for apt: 1699 ms
Check with dpkg
root@ubuntu-focal:/home/vagrant# bash wazuh-install.sh -a
13/06/2024 09:30:00 INFO: Starting Wazuh installation assistant. Wazuh version: 4.8.0
13/06/2024 09:30:00 INFO: Verbose logging redirected to /var/log/wazuh-install.log
Total time for dpkg: 115 ms

With this we check how the improvement when using dpkg is 93.23%

Install components tests

To check that the components are installed correctly when changing apt to dpkg, an AIO has been installed.

AIO installation
root@ubuntu-focal:/home/vagrant# bash wazuh-install.sh -a
13/06/2024 09:47:22 INFO: Starting Wazuh installation assistant. Wazuh version: 4.8.0
13/06/2024 09:47:22 INFO: Verbose logging redirected to /var/log/wazuh-install.log
13/06/2024 09:47:22 INFO: Verifying that your system meets the recommended minimum hardware requirements.
13/06/2024 09:47:31 INFO: Wazuh web interface port will be 443.
13/06/2024 09:47:43 INFO: Wazuh development repository added.
13/06/2024 09:47:43 INFO: --- Configuration files ---
13/06/2024 09:47:43 INFO: Generating configuration files.
13/06/2024 09:47:44 INFO: Generating the root certificate.
13/06/2024 09:47:44 INFO: Generating Admin certificates.
13/06/2024 09:47:44 INFO: Generating Wazuh indexer certificates.
13/06/2024 09:47:44 INFO: Generating Filebeat certificates.
13/06/2024 09:47:44 INFO: Generating Wazuh dashboard certificates.
13/06/2024 09:47:45 INFO: Created wazuh-install-files.tar. It contains the Wazuh cluster key, certificates, and passwords necessary for installation.
13/06/2024 09:47:45 INFO: --- Wazuh indexer ---
13/06/2024 09:47:45 INFO: Starting Wazuh indexer installation.
13/06/2024 09:51:13 INFO: Wazuh indexer installation finished.
13/06/2024 09:51:13 INFO: Wazuh indexer post-install configuration finished.
13/06/2024 09:51:13 INFO: Starting service wazuh-indexer.
13/06/2024 09:51:57 INFO: wazuh-indexer service started.
13/06/2024 09:51:57 INFO: Initializing Wazuh indexer cluster security settings.
13/06/2024 09:52:08 INFO: Wazuh indexer cluster security configuration initialized.
13/06/2024 09:52:08 INFO: Wazuh indexer cluster initialized.
13/06/2024 09:52:08 INFO: --- Wazuh server ---
13/06/2024 09:52:08 INFO: Starting the Wazuh manager installation.
13/06/2024 09:56:19 INFO: Wazuh manager installation finished.
13/06/2024 09:56:20 INFO: Wazuh manager vulnerability detection configuration finished.
13/06/2024 09:56:20 INFO: Starting service wazuh-manager.
13/06/2024 09:56:46 INFO: wazuh-manager service started.
13/06/2024 09:56:46 INFO: Starting Filebeat installation.
13/06/2024 09:59:32 INFO: Filebeat installation finished.
13/06/2024 10:00:10 INFO: Filebeat post-install configuration finished.
13/06/2024 10:00:10 INFO: Starting service filebeat.
13/06/2024 10:00:21 INFO: filebeat service started.
13/06/2024 10:00:21 INFO: --- Wazuh dashboard ---
13/06/2024 10:00:21 INFO: Starting Wazuh dashboard installation.
13/06/2024 10:09:49 INFO: Wazuh dashboard installation finished.
13/06/2024 10:09:50 INFO: Wazuh dashboard post-install configuration finished.
13/06/2024 10:09:50 INFO: Starting service wazuh-dashboard.
13/06/2024 10:09:56 INFO: wazuh-dashboard service started.
13/06/2024 10:09:57 INFO: Updating the internal users.
13/06/2024 10:10:33 INFO: A backup of the internal users has been saved in the /etc/wazuh-indexer/internalusers-backup folder.
13/06/2024 10:12:18 INFO: Initializing Wazuh dashboard web application.
13/06/2024 10:15:39 INFO: Wazuh dashboard web application initialized.
13/06/2024 10:15:39 INFO: --- Summary ---

If we try to reinstall it, we can see that the components are already installed.

Try to reinstall wazuh components
root@ubuntu-focal:/home/vagrant# bash wazuh-install.sh -a
13/06/2024 10:39:08 INFO: Starting Wazuh installation assistant. Wazuh version: 4.8.0
13/06/2024 10:39:09 INFO: Verbose logging redirected to /var/log/wazuh-install.log
13/06/2024 10:39:44 ERROR: Wazuh manager already installed.
13/06/2024 10:39:44 ERROR: Wazuh indexer already installed.
13/06/2024 10:39:44 ERROR: Wazuh dashboard already installed.
13/06/2024 10:39:44 ERROR: Filebeat already installed.
13/06/2024 10:39:44 INFO: If you want to overwrite the current installation, run this script adding the option -o/--overwrite. This will erase all the existing configuration and data.

It has also been tested to try uninstalling the components. Both when they are installed and when they do not exist:

Uninstalling wazuh components when they are installed
oot@ubuntu-focal:/home/vagrant# bash wazuh-install.sh -u
13/06/2024 10:55:27 INFO: Starting Wazuh installation assistant. Wazuh version: 4.8.0
13/06/2024 10:55:27 INFO: Verbose logging redirected to /var/log/wazuh-install.log
13/06/2024 10:55:27 INFO: Removing Wazuh manager.
13/06/2024 10:56:17 INFO: Wazuh manager removed.
13/06/2024 10:56:17 INFO: Removing Wazuh indexer.
13/06/2024 10:56:29 INFO: Wazuh indexer removed.
13/06/2024 10:56:29 INFO: Removing Filebeat.
13/06/2024 10:56:36 INFO: Filebeat removed.
13/06/2024 10:56:36 INFO: Removing Wazuh dashboard.
13/06/2024 10:57:27 INFO: Wazuh dashboard removed.

We see how to uninstall them correctly

Try to uninstall wazuh components when they are not installed
root@ubuntu-focal:/home/vagrant# bash wazuh-install.sh -u
13/06/2024 11:14:25 INFO: Starting Wazuh installation assistant. Wazuh version: 4.8.0
13/06/2024 11:14:25 INFO: Verbose logging redirected to /var/log/wazuh-install.log
13/06/2024 11:14:25 INFO: Wazuh manager not found in the system so it was not uninstalled.
13/06/2024 11:14:25 INFO: Filebeat not found in the system so it was not uninstalled.
13/06/2024 11:14:25 INFO: Wazuh indexer not found in the system so it was not uninstalled.
13/06/2024 11:14:25 INFO: Wazuh dashboard not found in the system so it was not uninstalled.
13/06/2024 11:14:25 INFO: Wazuh GPG key not found in the system

We can see how the installed packages are detected correctly.

Offline installation tests

In the offline installation section, check that the necessary packages are installed.

Offline installation packages installed
root@ubuntu-focal:/home/vagrant# bash wazuh-install.sh -of -a -v
13/06/2024 11:02:09 DEBUG: Checking root permissions.
13/06/2024 11:02:09 DEBUG: Checking sudo package.
13/06/2024 11:02:09 INFO: Starting Wazuh installation assistant. Wazuh version: 4.8.0
13/06/2024 11:02:09 INFO: Verbose logging redirected to /var/log/wazuh-install.log
13/06/2024 11:02:09 DEBUG: APT package manager will be used.
13/06/2024 11:02:09 DEBUG: Checking system distribution.
13/06/2024 11:02:09 DEBUG: Detected distribution name: ubuntu
13/06/2024 11:02:09 DEBUG: Detected distribution version: 20
13/06/2024 11:02:09 INFO: Checking installed dependencies for Offline installation.
13/06/2024 11:02:09 DEBUG: Offline dependencies are installed.

@Enaraque Enaraque requested a review from a team June 13, 2024 12:05
@Enaraque Enaraque self-assigned this Jun 13, 2024
@Enaraque Enaraque linked an issue Jun 13, 2024 that may be closed by this pull request
4 tasks
Copy link
Contributor

@davidcr01 davidcr01 left a comment

Choose a reason for hiding this comment

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

Please, add one more test, performing any kind of installation. But, in this test, make sure that some dependencies are not installed. Try removing some dependencies like openssl, lsof, grep...etc, in order to see if the new development fetches the not-installed dependencies correctly.

@Enaraque
Copy link
Member Author

Update Report

I removed openssl from my machine. When I try to install an offline installation, I get the error ERROR: openssl is necessary for the offline installation. showing that the new deployment fetch the not-installed dependencies correctly.

Test output

root@ubuntu-focal:/home/vagrant# openssl version

Command 'openssl' not found, but can be installed with:

apt install openssl

root@ubuntu-focal:/home/vagrant# bash wazuh-install.sh -of -a -v
14/06/2024 11:19:38 DEBUG: Checking root permissions.
14/06/2024 11:19:38 DEBUG: Checking sudo package.
14/06/2024 11:19:38 INFO: Starting Wazuh installation assistant. Wazuh version: 4.8.0
14/06/2024 11:19:38 INFO: Verbose logging redirected to /var/log/wazuh-install.log
14/06/2024 11:19:38 DEBUG: APT package manager will be used.
14/06/2024 11:19:38 DEBUG: Checking system distribution.
14/06/2024 11:19:38 DEBUG: Detected distribution name: ubuntu
14/06/2024 11:19:38 DEBUG: Detected distribution version: 20
14/06/2024 11:19:38 INFO: Checking installed dependencies for Offline installation.
14/06/2024 11:19:39 ERROR: openssl is necessary for the offline installation.

@Enaraque Enaraque requested a review from davidcr01 June 14, 2024 11:27
@c-bordon c-bordon merged commit 19a2bff into master Jun 14, 2024
6 of 9 checks passed
@c-bordon c-bordon deleted the change/2983-improve-apt-package-check-in-the-assistant branch June 14, 2024 14:29
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.

Improve APT package check in the Assistant
3 participants