wazuh / wazuh-agent

The Wazuh agent for endpoints.
https://wazuh.com
GNU Affero General Public License v3.0
32 stars 19 forks source link

Change package scaffolding for wazuh-agent #257

Closed MarcelKemp closed 4 weeks ago

MarcelKemp commented 4 weeks ago
Related issue
#242

Description

In this PR, the paths of the package have been modified to comply with the expected scaffolding for the Wazuh agent. The new paths are the ones written in the issue:

In addition, some SPECS have been modified so that it doesn't fail to uninstall the agent if the agent is not running. And so that the binary always finds its respective libraries.

lchico commented 4 weeks ago

Tests

DEB # Install ```bash dpkg -i wazuh-agent_5.0.0-0_amd64_c49b9c862.deb Selecting previously unselected package wazuh-agent. (Reading database ... 4381 files and directories currently installed.) Preparing to unpack wazuh-agent_5.0.0-0_amd64_c49b9c862.deb ... + export INSTALLATION_WAZUH_DIR=/opt/wazuh-agent + BINARY_DIR=/usr/share/wazuh-agent/bin/ + WAZUH_TMP_DIR=/opt/wazuh-agent/tmp + [ ! -d /opt/wazuh-agent/tmp ] + mkdir -p /opt/wazuh-agent/tmp + [ install = upgrade ] + exit 0 Unpacking wazuh-agent (5.0.0-0) ... dpkg: dependency problems prevent configuration of wazuh-agent: wazuh-agent depends on lsb-release; however: Package lsb-release is not installed. wazuh-agent depends on adduser; however: Package adduser is not installed. dpkg: error processing package wazuh-agent (--install): dependency problems - leaving unconfigured Processing triggers for libc-bin (2.39-0ubuntu8.3) ... Errors were encountered while processing: wazuh-agent apt install -f Reading package lists... Done Building dependency tree... Done Reading state information... Done Correcting dependencies... Done The following additional packages will be installed: adduser lsb-release Suggested packages: liblocale-gettext-perl perl cron quota ecryptfs-utils The following NEW packages will be installed: adduser lsb-release 0 upgraded, 2 newly installed, 0 to remove and 3 not upgraded. 1 not fully installed or removed. Need to get 107 kB of archives. After this operation, 480 kB of additional disk space will be used. Do you want to continue? [Y/n] Y Get:1 http://archive.ubuntu.com/ubuntu noble/main amd64 lsb-release all 12.0-2 [6564 B] Get:2 http://archive.ubuntu.com/ubuntu noble/main amd64 adduser all 3.137ubuntu1 [101 kB] Fetched 107 kB in 2s (66.8 kB/s) debconf: delaying package configuration, since apt-utils is not installed Selecting previously unselected package lsb-release. (Reading database ... 4396 files and directories currently installed.) Preparing to unpack .../lsb-release_12.0-2_all.deb ... Unpacking lsb-release (12.0-2) ... Selecting previously unselected package adduser. Preparing to unpack .../adduser_3.137ubuntu1_all.deb ... Unpacking adduser (3.137ubuntu1) ... Setting up adduser (3.137ubuntu1) ... Setting up lsb-release (12.0-2) ... Setting up wazuh-agent (5.0.0-0) ... + export INSTALLATION_WAZUH_DIR=/opt/wazuh-agent + WAZUH_TMP_DIR=/opt/wazuh-agent/tmp + BINARY_DIR=/usr/share/wazuh-agent/bin/ + lsb_release -si + OS=Ubuntu + lsb_release -sr + VER=24.04 + USER=wazuh + GROUP=wazuh + OSMYSHELL=/sbin/nologin + [ ! -f /sbin/nologin ] + getent group wazuh + addgroup --system wazuh + getent passwd wazuh + adduser --system --home /opt/wazuh-agent --shell /sbin/nologin --ingroup wazuh wazuh + [ -f /opt/wazuh-agent/tmp/wazuh.restart ] + touch /etc/ld.so.conf.d/wazuh-agentlibs.conf + echo /usr/share/wazuh-agent/lib + ldconfig + exit 0 Processing triggers for libc-bin (2.39-0ubuntu8.3) ... ``` # Paths: ```bash ls /usr/share/wazuh-agent/bin/ wazuh-agent root@4d8ed406b874:~/Test# ls /usr/share/wazuh-agent/lib/ libdbsync.so libstdc++.so.6 libsysinfo.so root@4d8ed406b874:~/Test# ls /etc/wazuh-agent/ wazuh.conf ``` # Purge ```bash apt purge wazuh-agent Reading package lists... Done Building dependency tree... Done Reading state information... Done The following package was automatically installed and is no longer required: lsb-release Use 'apt autoremove' to remove it. The following packages will be REMOVED: wazuh-agent* 0 upgraded, 0 newly installed, 1 to remove and 3 not upgraded. After this operation, 0 B of additional disk space will be used. Do you want to continue? [Y/n] Y (Reading database ... 6280 files and directories currently installed.) Purging configuration files for wazuh-agent (5.0.0-0) ... + export INSTALLATION_WAZUH_DIR=/opt/wazuh-agent + WAZUH_TMP_DIR=/opt/wazuh-agent/tmp + BINARY_DIR=/usr/share/wazuh-agent/bin/ + BINARY_LIB_DIR=/usr/share/wazuh-agent/lib/ + getent passwd wazuh + getent group wazuh + rm -rf /opt/wazuh-agent + exit 0 dpkg: warning: while removing wazuh-agent, directory '/usr/share/wazuh-agent/bin' not empty so not remov ed root@4d8ed406b874:~/Test# ls /usr/share/wazuh-agent/bin/ var root@4d8ed406b874:~/Test# ls /usr/share/wazuh-agent/lib/ ls: cannot access '/usr/share/wazuh-agent/lib/': No such file or directory root@4d8ed406b874:~/Test# ls /etc/wazuh-agent/ ls: cannot access '/etc/wazuh-agent/': No such file or directory ```
lchico commented 4 weeks ago

Test

RPM ```bash cat /etc/os-release NAME="Amazon Linux" VERSION="2023" ID="amzn" ID_LIKE="fedora" VERSION_ID="2023" PLATFORM_ID="platform:al2023" PRETTY_NAME="Amazon Linux 2023.6.20241010" ANSI_COLOR="0;33" CPE_NAME="cpe:2.3:o:amazon:amazon_linux:2023" HOME_URL="https://aws.amazon.com/linux/amazon-linux-2023/" DOCUMENTATION_URL="https://docs.aws.amazon.com/linux/" SUPPORT_URL="https://aws.amazon.com/premiumsupport/" BUG_REPORT_URL="https://github.com/amazonlinux/amazon-linux-2023" VENDOR_NAME="AWS" VENDOR_URL="https://aws.amazon.com/" SUPPORT_END="2028-03-15" ``` # Install ```bash dnf -i wazuh-agent_5.0.0-0_x86_64_149186843.rpm No such command: wazuh-agent_5.0.0-0_x86_64_149186843.rpm. Please use /usr/bin/dnf --help It could be a DNF plugin command, try: "dnf install 'dnf-command(wazuh-agent_5.0.0-0_x86_64_149186843.rpm)'" bash-5.2# dnf install wazuh-agent_5.0.0-0_x86_64_149186843.rpm Last metadata expiration check: 0:00:58 ago on Mon Oct 28 17:54:57 2024. Dependencies resolved. =================================================================================================================================================================================================================== Package Architecture Version Repository Size =================================================================================================================================================================================================================== Installing: wazuh-agent x86_64 5.0.0-0 @commandline 43 M Installing dependencies: libsemanage x86_64 3.4-5.amzn2023.0.2 amazonlinux 121 k shadow-utils x86_64 2:4.9-12.amzn2023.0.4 amazonlinux 1.1 M Transaction Summary =================================================================================================================================================================================================================== Install 3 Packages Total size: 44 M Total download size: 1.2 M Installed size: 128 M Is this ok [y/N]: y Downloading Packages: (1/2): libsemanage-3.4-5.amzn2023.0.2.x86_64.rpm 190 kB/s | 121 kB 00:00 (2/2): shadow-utils-4.9-12.amzn2023.0.4.x86_64.rpm 858 kB/s | 1.1 MB 00:01 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Total 468 kB/s | 1.2 MB 00:02 Running transaction check Transaction check succeeded. Running transaction test Transaction test succeeded. Running transaction Preparing : 1/1 Installing : libsemanage-3.4-5.amzn2023.0.2.x86_64 1/3 Installing : shadow-utils-2:4.9-12.amzn2023.0.4.x86_64 2/3 Running scriptlet: wazuh-agent-5.0.0-0.x86_64 3/3 Installing : wazuh-agent-5.0.0-0.x86_64 3/3 Running scriptlet: wazuh-agent-5.0.0-0.x86_64 3/3 warning: %posttrans(wazuh-agent-5.0.0-0.x86_64) scriptlet failed, exit status 127 Error in POSTTRANS scriptlet in rpm package wazuh-agent Verifying : libsemanage-3.4-5.amzn2023.0.2.x86_64 1/3 Verifying : shadow-utils-2:4.9-12.amzn2023.0.4.x86_64 2/3 Verifying : wazuh-agent-5.0.0-0.x86_64 3/3 Installed: libsemanage-3.4-5.amzn2023.0.2.x86_64 shadow-utils-2:4.9-12.amzn2023.0.4.x86_64 wazuh-agent-5.0.0-0.x86_64 Complete! ``` # Paths: ```bash bash-5.2# ls /usr/share/wazuh-agent/bin/ wazuh-agent bash-5.2# ls /usr/share/wazuh-agent/lib/ libdbsync.so libstdc++.so.6 libsysinfo.so bash-5.2# ls /etc/wazuh-agent/ wazuh.conf ``` # Purge ```bash yum remove wazuh-agent Dependencies resolved. =================================================================================================================================================================================================================== Package Architecture Version Repository Size =================================================================================================================================================================================================================== Removing: wazuh-agent x86_64 5.0.0-0 @@commandline 124 M Removing unused dependencies: libsemanage x86_64 3.4-5.amzn2023.0.2 @amazonlinux 301 k shadow-utils x86_64 2:4.9-12.amzn2023.0.4 @amazonlinux 3.7 M Transaction Summary =================================================================================================================================================================================================================== Remove 3 Packages Freed space: 128 M Is this ok [y/N]: y Running transaction check Transaction check succeeded. Running transaction test Transaction test succeeded. Running transaction Preparing : 1/1 Running scriptlet: wazuh-agent-5.0.0-0.x86_64 1/3 Erasing : wazuh-agent-5.0.0-0.x86_64 1/3 Running scriptlet: wazuh-agent-5.0.0-0.x86_64 1/3 Erasing : shadow-utils-2:4.9-12.amzn2023.0.4.x86_64 2/3 Erasing : libsemanage-3.4-5.amzn2023.0.2.x86_64 3/3 Verifying : libsemanage-3.4-5.amzn2023.0.2.x86_64 1/3 Verifying : shadow-utils-2:4.9-12.amzn2023.0.4.x86_64 2/3 Verifying : wazuh-agent-5.0.0-0.x86_64 3/3 Removed: libsemanage-3.4-5.amzn2023.0.2.x86_64 shadow-utils-2:4.9-12.amzn2023.0.4.x86_64 wazuh-agent-5.0.0-0.x86_64 Complete! bash-5.2# ls /usr/share/wazuh-agent/bin/ bash-5.2# ls /usr/share/wazuh-agent/lib/ bash-5.2# ls /etc/wazuh-agent/ ls: cannot access '/etc/wazuh-agent/': No such file or directory ```