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

Fix init.d file installation for Alma Linux and Rocky Linux #2053

Merged
merged 183 commits into from
Feb 6, 2023

Conversation

verdx
Copy link
Contributor

@verdx verdx commented Jan 19, 2023

Related issue
#1626

Description

In this PR we propose a fix to the matter of enabling Wazuh service in RHEL 9 derived systems:

  • Alma Linux 9
  • Rocky Linux 9

Logs example

Error:

# systemctl enable wazuh-agent
Synchronizing state of wazuh-agent.service with SysV service script with /usr/lib/systemd/systemd-sysv-install.
Executing: /usr/lib/systemd/systemd-sysv-install enable wazuh-agent
Failed to execute /usr/lib/systemd/systemd-sysv-install: No such file or directory

Fixed:

# systemctl enable wazuh-agent
Created symlink /etc/systemd/system/multi-user.target.wants/wazuh-agent.service → /usr/lib/systemd/system/wazuh-agent.service.

Tests

  • Tests for Linux RPM
    • Build the package for x86_64

RHEL 9

  • Agent
    • Install
    • Upgrade
    • Remove
    • Systemctl enable
    • Systemctl disable
    • Systemctl start
    • Systemctl stop
    • Systemctl restart
  • Manager
    • Install
    • Upgrade
    • Remove
    • Systemctl enable
    • Systemctl disable
    • Systemctl start
    • Systemctl stop
    • Systemctl restart

Rocky Linux 9

  • Install
  • Upgrade
  • Remove
  • Systemctl enable
  • Systemctl disable
  • Systemctl start
  • Systemctl stop
  • Systemctl restart

Alma Linux 9

  • Install
  • Upgrade
  • Remove
  • Systemctl enable
  • Systemctl disable
  • Systemctl start
  • Systemctl stop
  • Systemctl restart

Oracle Linux 9

  • Install
  • Upgrade
  • Remove
  • Systemctl enable
  • Systemctl disable
  • Systemctl start
  • Systemctl stop
  • Systemctl restart

CentOS 7

  • Agent
    • Install
    • Upgrade
    • Remove
    • Systemctl enable
    • Systemctl disable
    • Systemctl start
    • Systemctl stop
    • Systemctl restart
  • Manager
    • Install
    • Upgrade
    • Remove
    • Systemctl enable
    • Systemctl disable
    • Systemctl start
    • Systemctl stop
    • Systemctl restart

…or RHEL 9

Signed-off-by: Miguel Verdaguer Velázquez <verdx@riseup.net>
@verdx verdx self-assigned this Jan 19, 2023
@verdx verdx requested review from DFolchA and removed request for DFolchA January 19, 2023 18:21
@verdx verdx linked an issue Jan 19, 2023 that may be closed by this pull request
Signed-off-by: Miguel Verdaguer Velázquez <verdx@riseup.net>
@verdx verdx changed the title Fix init.d file installation for Alma Linux, Rocky Linux and Oracle Linux Fix init.d file installation for Alma Linux and Rocky Linux Jan 20, 2023
Signed-off-by: Miguel Verdaguer Velázquez <verdx@riseup.net>
DFolchA
DFolchA previously approved these changes Jan 20, 2023
davidcr01
davidcr01 previously approved these changes Jan 20, 2023
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.

LGTM

verdx added 2 commits January 20, 2023 13:10
Signed-off-by: Miguel Verdaguer Velázquez <verdx@riseup.net>
Signed-off-by: Miguel Verdaguer Velázquez <verdx@riseup.net>
@verdx
Copy link
Contributor Author

verdx commented Jan 20, 2023

In addition to the fix changed in this PR, a test is being added to Github Actions to check for this error from now onwards. Even though other systemctl commands cannot be used inside a docker container, systemctl enable does work as expected.

Tests

Alma Linux 9
> sudo docker run --privileged -it almalinux:9.1 bash
[root@97a20a2d6415 /]# curl https://packages-dev.wazuh.com/pre-release/yum/wazuh-agent-4.4.0-1.x86_64.rpm -O -J && yum install -y wazuh-agent-4.4.0-1.x86_64.rpm
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 8743k  100 8743k    0     0  4788k      0  0:00:01  0:00:01 --:--:-- 4785k
AlmaLinux 9 - AppStream                                                                                                                                                            4.0 MB/s | 7.1 MB     00:01    
AlmaLinux 9 - BaseOS                                                                                                                                                               2.1 MB/s | 2.0 MB     00:00    
AlmaLinux 9 - Extras                                                                                                                                                                19 kB/s |  17 kB     00:00    
Dependencies resolved.
===================================================================================================================================================================================================================
 Package                                                  Architecture                                Version                                              Repository                                         Size
===================================================================================================================================================================================================================
Installing:
 wazuh-agent                                              x86_64                                      4.4.0-1                                              @commandline                                      8.5 M
Installing dependencies:
 initscripts-service                                      noarch                                      10.11.5-1.el9                                        baseos                                             13 k

Transaction Summary
===================================================================================================================================================================================================================
Install  2 Packages

Total size: 8.6 M
Total download size: 13 k
Installed size: 25 M
Downloading Packages:
initscripts-service-10.11.5-1.el9.noarch.rpm                                                                                                                                       221 kB/s |  13 kB     00:00    
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                                                               22 kB/s |  13 kB     00:00     
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                                                                                           1/1 
  Installing       : initscripts-service-10.11.5-1.el9.noarch                                                                                                                                                  1/2 
  Running scriptlet: wazuh-agent-4.4.0-1.x86_64                                                                                                                                                                2/2 
  Installing       : wazuh-agent-4.4.0-1.x86_64                                                                                                                                                                2/2 
  Running scriptlet: wazuh-agent-4.4.0-1.x86_64                                                                                                                                                                2/2 
  Verifying        : initscripts-service-10.11.5-1.el9.noarch                                                                                                                                                  1/2 
  Verifying        : wazuh-agent-4.4.0-1.x86_64                                                                                                                                                                2/2 

Installed:
  initscripts-service-10.11.5-1.el9.noarch                                                                        wazuh-agent-4.4.0-1.x86_64                                                                       

Complete!
[root@97a20a2d6415 /]# systemctl enable wazuh-agent
Synchronizing state of wazuh-agent.service with SysV service script with /usr/lib/systemd/systemd-sysv-install.
Executing: /usr/lib/systemd/systemd-sysv-install enable wazuh-agent
Failed to execute /usr/lib/systemd/systemd-sysv-install: No such file or directory
[root@97a20a2d6415 /]# exit
exit
Red Hat Enterprise Linux 9
>sudo docker run --privileged -it redhat/ubi9 bash
[root@c50fd29636a4 /]# curl https://packages-dev.wazuh.com/pre-release/yum/wazuh-agent-4.4.0-1.x86_64.rpm -O -J && yum install -y wazuh-agent-4.4.0-1.x86_64.rpm
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 8743k  100 8743k    0     0  5495k      0  0:00:01  0:00:01 --:--:-- 5495k
Updating Subscription Management repositories.
Unable to read consumer identity
Subscription Manager is operating in container mode.

This system is not registered with an entitlement server. You can use subscription-manager to register.

Red Hat Universal Base Image 9 (RPMs) - BaseOS                                                                                                                                     261 kB/s | 577 kB     00:02    
Red Hat Universal Base Image 9 (RPMs) - AppStream                                                                                                                                  824 kB/s | 1.7 MB     00:02    
Red Hat Universal Base Image 9 (RPMs) - CodeReady Builder                                                                                                                           48 kB/s | 102 kB     00:02    
Dependencies resolved.
===================================================================================================================================================================================================================
 Package                                                 Architecture                               Version                                            Repository                                             Size
===================================================================================================================================================================================================================
Installing:
 wazuh-agent                                             x86_64                                     4.4.0-1                                            @commandline                                          8.5 M
Installing dependencies:
 initscripts-service                                     noarch                                     10.11.5-1.el9                                      ubi-9-baseos-rpms                                      15 k

Transaction Summary
===================================================================================================================================================================================================================
Install  2 Packages

Total size: 8.6 M
Total download size: 15 k
Installed size: 25 M
Downloading Packages:
initscripts-service-10.11.5-1.el9.noarch.rpm                                                                                                                                        95 kB/s |  15 kB     00:00    
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                                                               94 kB/s |  15 kB     00:00     
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                                                                                           1/1 
  Installing       : initscripts-service-10.11.5-1.el9.noarch                                                                                                                                                  1/2 
  Running scriptlet: wazuh-agent-4.4.0-1.x86_64                                                                                                                                                                2/2 
  Installing       : wazuh-agent-4.4.0-1.x86_64                                                                                                                                                                2/2 
  Running scriptlet: wazuh-agent-4.4.0-1.x86_64                                                                                                                                                                2/2 
  Verifying        : initscripts-service-10.11.5-1.el9.noarch                                                                                                                                                  1/2 
  Verifying        : wazuh-agent-4.4.0-1.x86_64                                                                                                                                                                2/2 
Installed products updated.

Installed:
  initscripts-service-10.11.5-1.el9.noarch                                                                        wazuh-agent-4.4.0-1.x86_64                                                                       

Complete!
[root@c50fd29636a4 /]# systemctl enable wazuh-agent
Created symlink /etc/systemd/system/multi-user.target.wants/wazuh-agent.service → /usr/lib/systemd/system/wazuh-agent.service.
[root@c50fd29636a4 /]# 
Rocky Linux 9
sudo docker run --privileged -it rockylinux:9 bash
[root@684eb3080b47 /]# curl https://packages-dev.wazuh.com/pre-release/yum/wazuh-agent-4.4.0-1.x86_64.rpm -O -J && yum install -y wazuh-agent-4.4.0-1.x86_64.rpm
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 8743k  100 8743k    0     0  4788k      0  0:00:01  0:00:01 --:--:-- 4785k
Rocky Linux 9 - BaseOS                                                                                                                                                             637 kB/s | 1.7 MB     00:02    
Rocky Linux 9 - AppStream                                                                                                                                                          2.1 MB/s | 6.4 MB     00:03    
Rocky Linux 9 - Extras                                                                                                                                                              24 kB/s | 8.5 kB     00:00    
Dependencies resolved.
===================================================================================================================================================================================================================
 Package                                                  Architecture                                Version                                              Repository                                         Size
===================================================================================================================================================================================================================
Installing:
 wazuh-agent                                              x86_64                                      4.4.0-1                                              @commandline                                      8.5 M
Installing dependencies:
 initscripts-service                                      noarch                                      10.11.5-1.el9                                        baseos                                             13 k

Transaction Summary
===================================================================================================================================================================================================================
Install  2 Packages

Total size: 8.6 M
Total download size: 13 k
Installed size: 25 M
Downloading Packages:
initscripts-service-10.11.5-1.el9.noarch.rpm                                                                                                                                        89 kB/s |  13 kB     00:00    
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                                                               30 kB/s |  13 kB     00:00     
Rocky Linux 9 - BaseOS                                                                                                                                                             151 kB/s | 1.7 kB     00:00    
Importing GPG key 0x350D275D:
 Userid     : "Rocky Enterprise Software Foundation - Release key 2022 <releng@rockylinux.org>"
 Fingerprint: 21CB 256A E16F C54C 6E65 2949 702D 426D 350D 275D
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-Rocky-9
Key imported successfully
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                                                                                           1/1 
  Installing       : initscripts-service-10.11.5-1.el9.noarch                                                                                                                                                  1/2 
  Running scriptlet: wazuh-agent-4.4.0-1.x86_64                                                                                                                                                                2/2 
  Installing       : wazuh-agent-4.4.0-1.x86_64                                                                                                                                                                2/2 
  Running scriptlet: wazuh-agent-4.4.0-1.x86_64                                                                                                                                                                2/2 
  Verifying        : initscripts-service-10.11.5-1.el9.noarch                                                                                                                                                  1/2 
  Verifying        : wazuh-agent-4.4.0-1.x86_64                                                                                                                                                                2/2 

Installed:
  initscripts-service-10.11.5-1.el9.noarch                                                                        wazuh-agent-4.4.0-1.x86_64                                                                       

Complete!
[root@684eb3080b47 /]# systemctl enable wazuh-agent
Synchronizing state of wazuh-agent.service with SysV service script with /usr/lib/systemd/systemd-sysv-install.
Executing: /usr/lib/systemd/systemd-sysv-install enable wazuh-agent
Failed to execute /usr/lib/systemd/systemd-sysv-install: No such file or directory
[root@684eb3080b47 /]# 

verdx added 5 commits January 20, 2023 14:50
Signed-off-by: Miguel Verdaguer Velázquez <verdx@riseup.net>
Signed-off-by: Miguel Verdaguer Velázquez <verdx@riseup.net>
Signed-off-by: Miguel Verdaguer Velázquez <verdx@riseup.net>
Signed-off-by: Miguel Verdaguer Velázquez <verdx@riseup.net>
Signed-off-by: Miguel Verdaguer Velázquez <verdx@riseup.net>
@verdx verdx force-pushed the 1626-fix-rhel9-derived-services branch from 8c71106 to 8d49c5a Compare January 23, 2023 12:27
verdx added 2 commits January 23, 2023 13:29
Signed-off-by: Miguel Verdaguer Velázquez <verdx@riseup.net>
@@ -0,0 +1,28 @@
name: Test the enabling of the Wazuh agent - AlmaLinux 9 - RPM
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we define an array of RPM manager-supported operating systems and loop into it? And another one for the agent? Could you please add all manager-supported RPM operating systems?
In addition, it could be great if we test Debian too.

Signed-off-by: Miguel Verdaguer Velázquez <verdx@riseup.net>
verdx added 2 commits February 2, 2023 10:33
Signed-off-by: Miguel Verdaguer Velázquez <verdx@riseup.net>
Signed-off-by: Miguel Verdaguer Velázquez <verdx@riseup.net>
@verdx
Copy link
Contributor Author

verdx commented Feb 2, 2023

GitHub Actions Update

@@ -332,7 +332,7 @@ fi

if [ -f /etc/os-release ]; then
source /etc/os-release
if [ "${NAME}" = "Red Hat Enterprise Linux" ] && [ "$((${VERSION_ID:0:1}))" -ge 9 ]; then
if ( [ "${NAME}" = "Red Hat Enterprise Linux" ] || [ "${NAME}" = "Rocky Linux" ] || [ "${NAME}" = "AlmaLinux" ] ) && [ "$((${VERSION_ID:0:1}))" -ge 9 ]; then
Copy link
Contributor

Choose a reason for hiding this comment

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

This should also cover the corespondent versions of CentOS and Fedora, if possible we should use a generic command to determine these systems.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The generic command would be useful but the only common variable in /etc/os-release is ID_LIKE, which function is this type of things. The problem is it is also the same for Oracle Linux 9, which doesn't have this problem.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

CentOS 9 Stream and Fedora 34 added in 08bd107

verdx added 2 commits February 2, 2023 17:07
Signed-off-by: Miguel Verdaguer Velázquez <verdx@riseup.net>
Signed-off-by: Miguel Verdaguer Velázquez <verdx@riseup.net>
apt-get update
apt-get install -y systemd
else
common_logger -e "Couldn'd find type of system"
Copy link
Contributor

Choose a reason for hiding this comment

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

Please change Couldn'd to Couldn't.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in 24734fb

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.

Signed-off-by: Miguel Verdaguer Velázquez <verdx@riseup.net>
@verdx verdx requested a review from davidcr01 February 3, 2023 12:08
Copy link
Contributor

@DFolchA DFolchA left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@alberpilot alberpilot left a comment

Choose a reason for hiding this comment

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

Please review the comments

macos/generate_wazuh_packages.sh Show resolved Hide resolved
.github/workflows/upload-deb-images.yml Show resolved Hide resolved
.github/workflows/upload-deb-images.yml Show resolved Hide resolved
.github/workflows/upload-deb-images.yml Show resolved Hide resolved
.github/workflows/upload-deb-images.yml Show resolved Hide resolved
.github/workflows/upload-deb-images.yml Show resolved Hide resolved
.github/workflows/upload-rpm-images.yml Show resolved Hide resolved
verdx added 6 commits February 3, 2023 16:54
Signed-off-by: Miguel Verdaguer Velázquez <verdx@riseup.net>
Signed-off-by: Miguel Verdaguer Velázquez <verdx@riseup.net>
Signed-off-by: Miguel Verdaguer Velázquez <verdx@riseup.net>
Signed-off-by: Miguel Verdaguer Velázquez <verdx@riseup.net>
Signed-off-by: Miguel Verdaguer Velázquez <verdx@riseup.net>
Signed-off-by: Miguel Verdaguer Velázquez <verdx@riseup.net>
Copy link
Contributor

@alberpilot alberpilot left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@DFolchA DFolchA left a comment

Choose a reason for hiding this comment

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

LGTM

@DFolchA DFolchA merged commit ccb2072 into 4.5 Feb 6, 2023
@DFolchA DFolchA deleted the 1626-fix-rhel9-derived-services branch February 6, 2023 15:46
@vikman90 vikman90 added type/bug Bug issue and removed type: bug labels Jun 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Investigate RHEL9 service installation error
5 participants