wazuh / wazuh-packages

Wazuh - Tools for packages creation
https://wazuh.com
GNU General Public License v2.0
105 stars 96 forks source link

Installation in debug mode does not terminate the execution if an error is found #2488

Closed rauldpm closed 1 year ago

rauldpm commented 1 year ago
Wazuh version Install type Action performed Platform
4.5.2 Wazuh installation assistant Install Amazon Linux 2023

Note: AL23 is not listed as recommended, but it should not affect the error reported

It has been found that when performing an AIO deployment using the WIA, the script reports an error related to the installation of curl even though it is already installed on the system

[root@ip-172-31-80-6 ec2-user]# curl -V
curl 8.2.1 (x86_64-amazon-linux-gnu) libcurl/8.2.1 OpenSSL/3.0.8 zlib/1.2.11 libidn2/2.3.2 nghttp2/1.55.1
Release-Date: 2023-07-26
Protocols: file ftp ftps http https
Features: alt-svc AsynchDNS GSS-API HSTS HTTP2 HTTPS-proxy IDN IPv6 Kerberos Largefile libz SPNEGO SSL threadsafe UnixSockets
[root@ip-172-31-80-6 ec2-user]# whereis curl
curl: /usr/bin/curl /usr/share/man/man1/curl.1.gz
[root@ip-172-31-80-6 ec2-user]# curl -sO https://packages.wazuh.com/4.5/wazuh-install.sh && sudo bash ./wazuh-install.sh -a - Yo
09/29/2023 14:50:15 INFO: Starting Wazuh installation assistant. Wazuh version: 4.5.2
09/29/2023 14:50:15 INFO: Verbose logging redirected to /var/log/wazuh-install.log
09/29/2023 14:50:18 INFO: --- Dependencies ---
09/29/2023 14:50:18 INFO: Installing curl.
09/29/2023 14:50:19 ERROR: Cannot install dependency: curl.
[root@ip-172-31-80-6 ec2-user]# curl -V
curl 8.2.1 (x86_64-amazon-linux-gnu) libcurl/8.2.1 OpenSSL/3.0.8 zlib/1.2.11 libidn2/2.3.2 nghttp2/1.55.1
Release-Date: 2023-07-26
Protocols: file ftp ftps http https
Features: alt-svc AsynchDNS GSS-API HSTS HTTP2 HTTPS-proxy IDN IPv6 Kerberos Largefile libz SPNEGO SSL threadsafe UnixSockets
[root@ip-172-31-80-6 ec2-user]# whereis curl
curl: /usr/bin/curl /usr/share/man/man1/curl.1.gz

This is reported in version 4.6.0 of Wazuh: https://github.com/wazuh/wazuh-packages/issues/2432

The main problem comes when running in debug mode since it ignores the error and installs all the components successfully: wazuh-install.log

This assumes the following cases, which should not vary in the behavior of the script, the only difference that the debug should show is the detailed process, but if a step fails, the execution should terminate:

It is also necessary to determine if the curl fix must be incorporated into the next patch (4.5.3) or should be maintained for 4.6.0

davidcr01 commented 1 year ago

Update Report

Investigating the error

The error is related with the following lines: https://github.com/wazuh/wazuh-packages/blob/551ed825724887f223858e629e38fbfdc1eaa1a1/unattended_installer/install_functions/installCommon.sh#L703-L704

Taking into account that the debug variable has the following content if the verbose option is enabled: https://github.com/wazuh/wazuh-packages/blob/8023b94a374010c6f99d81146bcd76d62e9db5ae/unattended_installer/install_functions/installMain.sh#L146-L147

The behavior of this code snippet is the following:

This is why the script continues the execution of the script with the verbose option.

Without the verbose option, the debug variable has the following content: https://github.com/wazuh/wazuh-packages/blob/551ed825724887f223858e629e38fbfdc1eaa1a1/unattended_installer/install_functions/installVariables.sh#L32

This is not a pipeline, but a redirection with >>, so, when the yum command fails, the if [ "${PIPESTATUS[0]}" != 0 ]; then conditional is false and the script execution is stopped.

Development

The functions installCommon_aptInstall and installCommon_yumInstallList have been modified. The strategy is to execute the installation command without the debug variable, and store the code of the command in a variable and the output of command in another variable.

For instance:

yum_output=$(yum install ${dep} -y 2>&1)
yum_code="${PIPESTATUS[0]}"

eval "echo \${yum_output} ${debug}"
if [  "${yum_code}" != 0  ]; then
  ....
fi

Testing

:green_circle: RPM-based (AL2023) with and without verbose Both options do not install the `curl` tool and the script execution is stopped. ```console [root@ip-172-31-66-117 ec2-user]# bash wazuh-install.sh -a 03/10/2023 09:53:49 INFO: Starting Wazuh installation assistant. Wazuh version: 4.5.2 03/10/2023 09:53:49 INFO: Verbose logging redirected to /var/log/wazuh-install.log 03/10/2023 09:53:54 INFO: --- Dependencies --- 03/10/2023 09:53:54 INFO: Installing curl. 03/10/2023 09:53:55 ERROR: Cannot install dependency: curl. [root@ip-172-31-66-117 ec2-user]# bash wazuh-install.sh -a -v 03/10/2023 09:54:03 INFO: Starting Wazuh installation assistant. Wazuh version: 4.5.2 03/10/2023 09:54:03 INFO: Verbose logging redirected to /var/log/wazuh-install.log 03/10/2023 09:54:08 INFO: --- Dependencies --- 03/10/2023 09:54:08 INFO: Installing curl. Last metadata expiration check: 13:16:00 ago on Mon Oct 2 20:38:08 2023. Error: Problem: problem with installed package curl-minimal-8.2.1-1.amzn2023.0.3.x86_64 - package curl-minimal-8.2.1-1.amzn2023.0.3.x86_64 conflicts with curl provided by curl-7.87.0-2.amzn2023.0.2.x86_64 - package curl-minimal-8.0.1-1.amzn2023.0.1.x86_64 conflicts with curl provided by curl-7.87.0-2.amzn2023.0.2.x86_64 - package curl-minimal-7.88.0-1.amzn2023.0.1.x86_64 conflicts with curl provided by curl-7.87.0-2.amzn2023.0.2.x86_64 - package curl-minimal-8.2.1-1.amzn2023.0.2.x86_64 conflicts with curl provided by curl-7.87.0-2.amzn2023.0.2.x86_64 - package curl-minimal-7.87.0-2.amzn2023.0.2.x86_64 conflicts with curl provided by curl-7.87.0-2.amzn2023.0.2.x86_64 - package curl-minimal-7.88.1-1.amzn2023.0.1.x86_64 conflicts with curl provided by curl-7.87.0-2.amzn2023.0.2.x86_64 - package curl-minimal-8.0.1-1.amzn2023.x86_64 conflicts with curl provided by curl-7.87.0-2.amzn2023.0.2.x86_64 - conflicting requests - package curl-minimal-8.2.1-1.amzn2023.0.3.x86_64 conflicts with curl provided by curl-7.88.0-1.amzn2023.0.1.x86_64 - package curl-minimal-8.0.1-1.amzn2023.0.1.x86_64 conflicts with curl provided by curl-7.88.0-1.amzn2023.0.1.x86_64 - package curl-minimal-7.88.0-1.amzn2023.0.1.x86_64 conflicts with curl provided by curl-7.88.0-1.amzn2023.0.1.x86_64 - package curl-minimal-8.2.1-1.amzn2023.0.2.x86_64 conflicts with curl provided by curl-7.88.0-1.amzn2023.0.1.x86_64 - package curl-minimal-7.87.0-2.amzn2023.0.2.x86_64 conflicts with curl provided by curl-7.88.0-1.amzn2023.0.1.x86_64 - package curl-minimal-7.88.1-1.amzn2023.0.1.x86_64 conflicts with curl provided by curl-7.88.0-1.amzn2023.0.1.x86_64 - package curl-minimal-8.0.1-1.amzn2023.x86_64 conflicts with curl provided by curl-7.88.0-1.amzn2023.0.1.x86_64 - package curl-minimal-8.2.1-1.amzn2023.0.3.x86_64 conflicts with curl provided by curl-7.88.1-1.amzn2023.0.1.x86_64 - package curl-minimal-8.0.1-1.amzn2023.0.1.x86_64 conflicts with curl provided by curl-7.88.1-1.amzn2023.0.1.x86_64 - package curl-minimal-7.88.0-1.amzn2023.0.1.x86_64 conflicts with curl provided by curl-7.88.1-1.amzn2023.0.1.x86_64 - package curl-minimal-8.2.1-1.amzn2023.0.2.x86_64 conflicts with curl provided by curl-7.88.1-1.amzn2023.0.1.x86_64 - package curl-minimal-7.87.0-2.amzn2023.0.2.x86_64 conflicts with curl provided by curl-7.88.1-1.amzn2023.0.1.x86_64 - package curl-minimal-7.88.1-1.amzn2023.0.1.x86_64 conflicts with curl provided by curl-7.88.1-1.amzn2023.0.1.x86_64 - package curl-minimal-8.0.1-1.amzn2023.x86_64 conflicts with curl provided by curl-7.88.1-1.amzn2023.0.1.x86_64 - package curl-minimal-8.2.1-1.amzn2023.0.3.x86_64 conflicts with curl provided by curl-8.0.1-1.amzn2023.x86_64 - package curl-minimal-8.0.1-1.amzn2023.0.1.x86_64 conflicts with curl provided by curl-8.0.1-1.amzn2023.x86_64 - package curl-minimal-7.88.0-1.amzn2023.0.1.x86_64 conflicts with curl provided by curl-8.0.1-1.amzn2023.x86_64 - package curl-minimal-8.2.1-1.amzn2023.0.2.x86_64 conflicts with curl provided by curl-8.0.1-1.amzn2023.x86_64 - package curl-minimal-7.87.0-2.amzn2023.0.2.x86_64 conflicts with curl provided by curl-8.0.1-1.amzn2023.x86_64 - package curl-minimal-7.88.1-1.amzn2023.0.1.x86_64 conflicts with curl provided by curl-8.0.1-1.amzn2023.x86_64 - package curl-minimal-8.0.1-1.amzn2023.x86_64 conflicts with curl provided by curl-8.0.1-1.amzn2023.x86_64 - package curl-minimal-8.2.1-1.amzn2023.0.3.x86_64 conflicts with curl provided by curl-8.0.1-1.amzn2023.0.1.x86_64 - package curl-minimal-8.0.1-1.amzn2023.0.1.x86_64 conflicts with curl provided by curl-8.0.1-1.amzn2023.0.1.x86_64 - package curl-minimal-7.88.0-1.amzn2023.0.1.x86_64 conflicts with curl provided by curl-8.0.1-1.amzn2023.0.1.x86_64 - package curl-minimal-8.2.1-1.amzn2023.0.2.x86_64 conflicts with curl provided by curl-8.0.1-1.amzn2023.0.1.x86_64 - package curl-minimal-7.87.0-2.amzn2023.0.2.x86_64 conflicts with curl provided by curl-8.0.1-1.amzn2023.0.1.x86_64 - package curl-minimal-7.88.1-1.amzn2023.0.1.x86_64 conflicts with curl provided by curl-8.0.1-1.amzn2023.0.1.x86_64 - package curl-minimal-8.0.1-1.amzn2023.x86_64 conflicts with curl provided by curl-8.0.1-1.amzn2023.0.1.x86_64 - package curl-minimal-8.2.1-1.amzn2023.0.3.x86_64 conflicts with curl provided by curl-8.2.1-1.amzn2023.0.2.x86_64 - package curl-minimal-8.0.1-1.amzn2023.0.1.x86_64 conflicts with curl provided by curl-8.2.1-1.amzn2023.0.2.x86_64 - package curl-minimal-7.88.0-1.amzn2023.0.1.x86_64 conflicts with curl provided by curl-8.2.1-1.amzn2023.0.2.x86_64 - package curl-minimal-8.2.1-1.amzn2023.0.2.x86_64 conflicts with curl provided by curl-8.2.1-1.amzn2023.0.2.x86_64 - package curl-minimal-7.87.0-2.amzn2023.0.2.x86_64 conflicts with curl provided by curl-8.2.1-1.amzn2023.0.2.x86_64 - package curl-minimal-7.88.1-1.amzn2023.0.1.x86_64 conflicts with curl provided by curl-8.2.1-1.amzn2023.0.2.x86_64 - package curl-minimal-8.0.1-1.amzn2023.x86_64 conflicts with curl provided by curl-8.2.1-1.amzn2023.0.2.x86_64 - package curl-minimal-8.2.1-1.amzn2023.0.3.x86_64 conflicts with curl provided by curl-8.2.1-1.amzn2023.0.3.x86_64 - package curl-minimal-8.0.1-1.amzn2023.0.1.x86_64 conflicts with curl provided by curl-8.2.1-1.amzn2023.0.3.x86_64 - package curl-minimal-7.88.0-1.amzn2023.0.1.x86_64 conflicts with curl provided by curl-8.2.1-1.amzn2023.0.3.x86_64 - package curl-minimal-8.2.1-1.amzn2023.0.2.x86_64 conflicts with curl provided by curl-8.2.1-1.amzn2023.0.3.x86_64 - package curl-minimal-7.87.0-2.amzn2023.0.2.x86_64 conflicts with curl provided by curl-8.2.1-1.amzn2023.0.3.x86_64 - package curl-minimal-7.88.1-1.amzn2023.0.1.x86_64 conflicts with curl provided by curl-8.2.1-1.amzn2023.0.3.x86_64 - package curl-minimal-8.0.1-1.amzn2023.x86_64 conflicts with curl provided by curl-8.2.1-1.amzn2023.0.3.x86_64 (try to add '--allowerasing' to command line to replace conflicting packages or '--skip-broken' to skip uninstallable packages) 03/10/2023 09:54:09 ERROR: Cannot install dependency: curl. ```
:green_circle: DEB-based (Ubuntu 22) with and without verbose Testing with existing packages. Installing `apt-transport-https` package. ```console root@ubuntu22:/home/vagrant# bash wazuh-install.sh -a 03/10/2023 10:21:02 INFO: Starting Wazuh installation assistant. Wazuh version: 4.6.0 03/10/2023 10:21:02 INFO: Verbose logging redirected to /var/log/wazuh-install.log 03/10/2023 10:21:16 INFO: Wazuh web interface port will be 443. 03/10/2023 10:21:20 INFO: --- Dependencies ---- 03/10/2023 10:21:20 INFO: Installing apt-transport-https. 03/10/2023 10:21:24 INFO: Wazuh repository added. 03/10/2023 10:21:24 INFO: --- Configuration files --- 03/10/2023 10:21:24 INFO: Generating configuration files. 03/10/2023 10:21:27 INFO: Created wazuh-install-files.tar. It contains the Wazuh cluster key, certificates, and passwords necessary for installation. ... root@ubuntu22:/home/vagrant# bash wazuh-install.sh -a -v 03/10/2023 10:18:38 INFO: Starting Wazuh installation assistant. Wazuh version: 4.6.0 03/10/2023 10:18:38 INFO: Verbose logging redirected to /var/log/wazuh-install.log Hit:1 https://mirrors.edge.kernel.org/ubuntu jammy InRelease Hit:2 https://mirrors.edge.kernel.org/ubuntu jammy-updates InRelease Hit:3 https://mirrors.edge.kernel.org/ubuntu jammy-backports InRelease Hit:4 https://mirrors.edge.kernel.org/ubuntu jammy-security InRelease Reading package lists... Hit:1 https://mirrors.edge.kernel.org/ubuntu jammy InRelease Hit:2 https://mirrors.edge.kernel.org/ubuntu jammy-updates InRelease Hit:3 https://mirrors.edge.kernel.org/ubuntu jammy-backports InRelease Hit:4 https://mirrors.edge.kernel.org/ubuntu jammy-security InRelease Reading package lists... 03/10/2023 10:18:51 INFO: Wazuh web interface port will be 443. Hit:1 https://mirrors.edge.kernel.org/ubuntu jammy InRelease Hit:2 https://mirrors.edge.kernel.org/ubuntu jammy-updates InRelease Hit:3 https://mirrors.edge.kernel.org/ubuntu jammy-backports InRelease Hit:4 https://mirrors.edge.kernel.org/ubuntu jammy-security InRelease Reading package lists... 03/10/2023 10:18:55 INFO: --- Dependencies ---- 03/10/2023 10:18:55 INFO: Installing apt-transport-https. Reading package lists... Building dependency tree... Reading state information... The following NEW packages will be installed: apt-transport-https 0 upgraded, 1 newly installed, 0 to remove and 142 not upgraded. Need to get 1,510 B of archives. After this operation, 169 kB of additional disk space will be used. Get:1 https://mirrors.edge.kernel.org/ubuntu jammy-updates/universe amd64 apt-transport-https all 2.4.10 [1,510 B] Fetched 1,510 B in 1s (2,852 B/s) Selecting previou NEEDRESTART-VER: 3.5 NEEDRESTART-KCUR: 5.15.0-69-generic NEEDRESTART-KEXP: 5.15.0-69-generic NEEDRESTART-KSTA: 1 03/10/2023 10:18:57 DEBUG: Adding the Wazuh repository. gpg: keyring '/usr/share/keyrings/wazuh.gpg' created gpg: directory '/root/.gnupg' created gpg: /root/.gnupg/trustdb.gpg: trustdb created gpg: key 96B3EE5F29111145: public key "Wazuh.com (Wazuh Signing Key) " imported gpg: Total number processed: 1 gpg: imported: 1 deb [signed-by=/usr/share/keyrings/wazuh.gpg] https://packages.wazuh.com/4.x/apt/ stable main Get:1 https://packages.wazuh.com/4.x/apt stable InRelease [17.3 kB] Get:2 https://packages.wazuh.com/4.x/apt stable/main amd64 Packages [32.1 kB] Hit:3 https://mirrors.edge.kernel.org/ubuntu jammy InRelease Hit:4 https://mirrors.edge.kernel.org/ubuntu jammy-updates InRelease Hit:5 https://mirrors.edge.kernel.org/ubuntu jammy-backports InRelease Hit:6 https://mirrors.edge.kernel.org/ubuntu jammy-security InRelease Fetched 49.4 kB in 1s (46.2 kB/s) Reading package lists... 03/10/2023 10:19:00 INFO: Wazuh repository added. ``` Testing with non-existing packages to test if the package manager fails. Installing `package-test` package. ```console root@ubuntu22:/home/vagrant# bash wazuh-install.sh -a 03/10/2023 10:42:31 INFO: Starting Wazuh installation assistant. Wazuh version: 4.6.0 03/10/2023 10:42:31 INFO: Verbose logging redirected to /var/log/wazuh-install.log 03/10/2023 10:42:44 INFO: Wazuh web interface port will be 443. 03/10/2023 10:42:48 INFO: --- Dependencies ---- 03/10/2023 10:42:48 INFO: Installing package-test. 03/10/2023 10:42:49 ERROR: Cannot install dependency: package-test. root@ubuntu22:/home/vagrant# bash wazuh-install.sh -a -v 03/10/2023 10:43:53 INFO: Starting Wazuh installation assistant. Wazuh version: 4.6.0 03/10/2023 10:43:53 INFO: Verbose logging redirected to /var/log/wazuh-install.log Hit:1 https://mirrors.edge.kernel.org/ubuntu jammy InRelease Hit:2 https://mirrors.edge.kernel.org/ubuntu jammy-updates InRelease Hit:3 https://mirrors.edge.kernel.org/ubuntu jammy-backports InRelease Hit:4 https://mirrors.edge.kernel.org/ubuntu jammy-security InRelease Reading package lists... Hit:1 https://mirrors.edge.kernel.org/ubuntu jammy InRelease Hit:2 https://mirrors.edge.kernel.org/ubuntu jammy-updates InRelease Hit:3 https://mirrors.edge.kernel.org/ubuntu jammy-backports InRelease Hit:4 https://mirrors.edge.kernel.org/ubuntu jammy-security InRelease Reading package lists... 03/10/2023 10:44:05 INFO: Wazuh web interface port will be 443. Hit:1 https://mirrors.edge.kernel.org/ubuntu jammy InRelease Hit:2 https://mirrors.edge.kernel.org/ubuntu jammy-updates InRelease Hit:3 https://mirrors.edge.kernel.org/ubuntu jammy-backports InRelease Hit:4 https://mirrors.edge.kernel.org/ubuntu jammy-security InRelease Reading package lists... 03/10/2023 10:44:09 INFO: --- Dependencies ---- 03/10/2023 10:44:09 INFO: Installing package-test. Reading package lists... Building dependency tree... Reading state information... E: Unable to locate package package-test 03/10/2023 10:44:10 ERROR: Cannot install dependency: package-test. ```