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 handling of configuration files in packages #310

Closed
Tostti opened this issue Sep 13, 2024 · 6 comments
Closed

Change handling of configuration files in packages #310

Tostti opened this issue Sep 13, 2024 · 6 comments
Assignees
Labels
level/task Task issue type/change Change performed in a Wazuh Cloud environment issue

Comments

@Tostti
Copy link
Member

Tostti commented Sep 13, 2024

Description

We have to modify the deb and rpm packages to detect old configuration files and automatically prevent from overwriting them, removing the need for user inputs and thus reducing the possibility of issues that can occur after upgrades

@Tostti Tostti added type/change Change performed in a Wazuh Cloud environment issue level/task Task issue labels Sep 13, 2024
@Tostti Tostti self-assigned this Sep 13, 2024
@wazuhci wazuhci moved this to In progress in Release 4.9.1 Sep 16, 2024
@Tostti
Copy link
Member Author

Tostti commented Sep 17, 2024

Update

Worked in new packages with the required behavior

Deb

For the deb packages, the rules file was modified to add the opensearch_dashboard.yml as opensearch_dashboard.yml.new.

Then, on the postinst file, the following line was added

cp -n "${TARGET_DIR}""${CONFIG_DIR}"/opensearch_dashboards.yml.new "${TARGET_DIR}""${CONFIG_DIR}"/opensearch_dashboards.yml

That creates an opensearch_dashboard.yml if it doesn't exist. Otherwise, it doesn't do anything.

Additional discovery

While creating the package, an error in a route was discovered. This caused the installation script always to create a new keystore, even if it already existed. That also required input from the user, which was why the terminal freezed on the upgrades (#301).

RPM

The RPM packages already have a mechanism to save the new configuration file as rpmnew and don't overwrite the existing one.
Using this approach, a warning is shown in the terminal letting the user know there's a different file. We tried several approaches to get rid of that warning but had no success.

@Tostti
Copy link
Member Author

Tostti commented Sep 18, 2024

We have decided to keep the default behavior of dpkg, but forcing it to keep the user modified files over ours.

This can be done using the --force-confdef and --force-confold options. The deb package will remain without changes.

We need to ensure that the files in the RPM package contain the noreplace directive

@wazuhci wazuhci moved this from In progress to In review in Release 4.9.1 Sep 18, 2024
@Tostti
Copy link
Member Author

Tostti commented Sep 18, 2024

Tests

RPM

New installation 🟢

  1. Install a new 4.9.1 package in an environment without any version of Wazuh dashboard installed.
  2. Verify that the configuration files are in its place
[root@localhost vagrant]# ls -l /etc/wazuh-dashboard/
total 12
-rw-r-----. 1 wazuh-dashboard wazuh-dashboard 312 Sep 18 17:01 node.options
-rw-r--r--. 1 wazuh-dashboard wazuh-dashboard 226 Sep 18 17:27 opensearch_dashboards.keystore
-rw-r-----. 1 wazuh-dashboard wazuh-dashboard 634 Sep 18 17:28 opensearch_dashboards.yml

Upgrade 🟢

  1. Install a 4.8.2 version of Wazuh dashboard and modify the configuration files.
  2. Install a new 4.9.1 package on top of it.
  3. Verify that a rpmnew file appeared and the changes made were not overwritten.
[root@localhost vagrant]# ls -l /etc/wazuh-dashboard/
total 16
-rw-r-----. 1 wazuh-dashboard wazuh-dashboard 312 Sep 18 17:01 node.options
-rw-r-----. 1 wazuh-dashboard wazuh-dashboard 226 Sep 18 18:43 opensearch_dashboards.keystore
-rw-r-----. 1 wazuh-dashboard wazuh-dashboard 635 Sep 18 18:44 opensearch_dashboards.yml
-rw-r-----. 1 wazuh-dashboard wazuh-dashboard 634 Sep 18 17:01 opensearch_dashboards.yml.rpmnew

DEB

New installation 🟢

  1. Install a new 4.9.1 package in an environment without any version of Wazuh dashboard installed.
  2. Verify that the configuration files are in its place.
root@vagrant:/home/vagrant# ls -l /etc/wazuh-dashboard/
total 12
-rw-r----- 1 wazuh-dashboard wazuh-dashboard 312 May  5  2023 node.options
-rw-r--r-- 1 wazuh-dashboard wazuh-dashboard 226 Sep 18 18:04 opensearch_dashboards.keystore
-rw-r----- 1 wazuh-dashboard wazuh-dashboard 634 May  5  2023 opensearch_dashboards.yml

Upgrade 1🟢

  1. Install a 4.8 version of Wazuh dashboard and modify the configuration files.
  2. Install a new 4.9.1 package on top of it.
  3. A message telling that a new configuration file version is in the package should appear, and will ask to select which file to keep.
Configuration file '/etc/wazuh-dashboard/opensearch_dashboards.yml'
 ==> Modified (by you or by a script) since installation.
 ==> Package distributor has shipped an updated version.
   What would you like to do about it ?  Your options are:
    Y or I  : install the package maintainer's version
    N or O  : keep your currently-installed version
      D     : show the differences between the versions
      Z     : start a shell to examine the situation
 The default action is to keep your current version.
*** opensearch_dashboards.yml (Y/I/N/O/D/Z) [default=N] ? 

Upgrade 2🟢

  1. Install a previous version of Wazuh dashboard and modify the configuration files.
  2. Install a new 4.9.1 package on top of it but using the --force-confdef and --force-confold parameters
dpkg --force-confdef --force-confold -i <package>
  1. No interaction should be required.
  2. Verify that the configuration files are in its place and the changes made were not overwritten.

@wazuhci wazuhci moved this from In review to Pending final review in Release 4.9.1 Sep 18, 2024
@JuanGarriuz
Copy link
Member

JuanGarriuz commented Sep 19, 2024

Test

RPM

New installation 🟢

[root@fedora37 vagrant]# ls -l /etc/wazuh-dashboard/
total 12
-rw-r-----. 1 wazuh-dashboard wazuh-dashboard 312 Sep  6 20:28 node.options
-rw-r--r--. 1 wazuh-dashboard wazuh-dashboard 226 Sep 19 10:33 opensearch_dashboards.keystore
-rw-r-----. 1 wazuh-dashboard wazuh-dashboard 634 Sep  6 20:28 opensearch_dashboards.yml

Upgrade 🟢

[root@fedora37 vagrant]# ls -l /etc/wazuh-dashboard/
total 16
-rw-r-----. 1 wazuh-dashboard wazuh-dashboard 312 Sep 18 17:01 node.options
-rw-r-----. 1 wazuh-dashboard wazuh-dashboard 226 Sep 19 10:23 opensearch_dashboards.keystore
-rw-r-----. 1 wazuh-dashboard wazuh-dashboard 643 Sep 19 10:23 opensearch_dashboards.yml
-rw-r-----. 1 wazuh-dashboard wazuh-dashboard 634 Sep 18 17:01 opensearch_dashboards.yml.rpmnew
[root@fedora37 vagrant]#

DEB

New installation 🟢

root@vagrant:/vagrant# ls -l /etc/wazuh-dashboard/
total 12
-rw-r----- 1 wazuh-dashboard wazuh-dashboard 312 May  5  2023 node.options
-rw-r--r-- 1 wazuh-dashboard wazuh-dashboard 226 Sep 19 09:18 opensearch_dashboards.keystore
-rw-r----- 1 wazuh-dashboard wazuh-dashboard 634 May  5  2023 opensearch_dashboards.yml

Upgrade 1 🟢

Configuration file '/etc/wazuh-dashboard/opensearch_dashboards.yml'
 ==> Modified (by you or by a script) since installation.
 ==> Package distributor has shipped an updated version.
   What would you like to do about it ?  Your options are:
    Y or I  : install the package maintainer's version
    N or O  : keep your currently-installed version
      D     : show the differences between the versions
      Z     : start a shell to examine the situation
 The default action is to keep your current version.
*** opensearch_dashboards.yml (Y/I/N/O/D/Z) [default=N] ?
root@vagrant:/vagrant# ls -l /etc/wazuh-dashboard/
total 16
-rw-r----- 1 wazuh-dashboard wazuh-dashboard 312 May  5  2023 node.options
-rw-r----- 1 wazuh-dashboard wazuh-dashboard 226 Sep 19 09:22 opensearch_dashboards.keystore
-rw-r----- 1 wazuh-dashboard wazuh-dashboard 643 Sep 19 09:23 opensearch_dashboards.yml
-rw-r----- 1 wazuh-dashboard wazuh-dashboard 634 May  5  2023 opensearch_dashboards.yml.dpkg-dist

image

Upgrade 2 🟢

Configuration file '/etc/wazuh-dashboard/opensearch_dashboards.yml'
 ==> Modified (by you or by a script) since installation.
 ==> Package distributor has shipped an updated version.
 ==> Keeping old config file as default.
root@vagrant:/home/vagrant# cat /etc/wazuh-dashboard/opensearch_dashboards.yml
[...]
#opensearch.username:1234
#opensearch.password:1234
[...]

@asteriscos
Copy link
Member

Tests

RPM 🟢

New installation 🟢

[root@localhost wazuh-dashboard]# yum localinstall /vagrant/packages/wazuh-dashboard_4.9.1-1_x86_64_24c454efa8.rpm 
Failed to set locale, defaulting to C.UTF-8
Last metadata expiration check: 0:09:31 ago on Thu Sep 19 09:51:17 2024.
Dependencies resolved.
======================================================================================================================================
 Package                             Architecture               Version                        Repository                        Size
======================================================================================================================================
Installing:
 wazuh-dashboard                     x86_64                     4.9.1-1                        @commandline                     253 M

Transaction Summary
======================================================================================================================================
Install  1 Package

Total size: 253 M
Installed size: 849 M
Is this ok [y/N]: y
Downloading Packages:
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                              1/1 
  Running scriptlet: wazuh-dashboard-4.9.1-1.x86_64                                                                               1/1 
  Installing       : wazuh-dashboard-4.9.1-1.x86_64                                                                               1/1 
  Running scriptlet: wazuh-dashboard-4.9.1-1.x86_64                                                                               1/1 
  Verifying        : wazuh-dashboard-4.9.1-1.x86_64                                                                               1/1 

Installed:
  wazuh-dashboard-4.9.1-1.x86_64                                                                                                      

Complete!
[root@localhost wazuh-dashboard]# ls -l /etc/wazuh-dashboard/
total 12
-rw-r-----. 1 wazuh-dashboard wazuh-dashboard 312 Sep 18 17:01 node.options
-rw-r--r--. 1 wazuh-dashboard wazuh-dashboard 226 Sep 19 10:01 opensearch_dashboards.keystore
-rw-r-----. 1 wazuh-dashboard wazuh-dashboard 634 Sep 18 17:01 opensearch_dashboards.yml

Upgrade 🟢

The configuration file opensearch_dashboard.yml was not overwritten.

[root@localhost wazuh-dashboard]# yum localinstall /vagrant/packages/wazuh-dashboard_4.9.1-1_x86_64_24c454efa8.rpm 
Failed to set locale, defaulting to C.UTF-8
Last metadata expiration check: 0:18:45 ago on Thu Sep 19 09:51:17 2024.
Dependencies resolved.
======================================================================================================================================
 Package                             Architecture               Version                        Repository                        Size
======================================================================================================================================
Upgrading:
 wazuh-dashboard                     x86_64                     4.9.1-1                        @commandline                     253 M

Transaction Summary
======================================================================================================================================
Upgrade  1 Package

Total size: 253 M
Is this ok [y/N]: y
Downloading Packages:
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                              1/1 
  Running scriptlet: wazuh-dashboard-4.9.1-1.x86_64                                                                               1/1 
  Running scriptlet: wazuh-dashboard-4.9.1-1.x86_64                                                                               1/2 
  Upgrading        : wazuh-dashboard-4.9.1-1.x86_64                                                                               1/2 
warning: /etc/wazuh-dashboard/opensearch_dashboards.yml created as /etc/wazuh-dashboard/opensearch_dashboards.yml.rpmnew

  Running scriptlet: wazuh-dashboard-4.9.1-1.x86_64                                                                               1/2 
  Running scriptlet: wazuh-dashboard-4.8.2-1.x86_64                                                                               2/2 
  Cleanup          : wazuh-dashboard-4.8.2-1.x86_64                                                                               2/2 
  Running scriptlet: wazuh-dashboard-4.8.2-1.x86_64                                                                               2/2 
  Running scriptlet: wazuh-dashboard-4.9.1-1.x86_64                                                                               2/2 
  Running scriptlet: wazuh-dashboard-4.8.2-1.x86_64                                                                               2/2 
  Verifying        : wazuh-dashboard-4.9.1-1.x86_64                                                                               1/2 
  Verifying        : wazuh-dashboard-4.8.2-1.x86_64                                                                               2/2 

Upgraded:
  wazuh-dashboard-4.9.1-1.x86_64                                                                                                      

Complete!

@asteriscos
Copy link
Member

asteriscos commented Sep 19, 2024

Tests

DEB

New installation 🟢

root@ubuntu-jammy:/home/vagrant# dpkg -i /vagrant/packages/wazuh-dashboard_4.9.1-1_amd64_24c454efa8.deb 
Selecting previously unselected package wazuh-dashboard.
(Reading database ... 87541 files and directories currently installed.)
Preparing to unpack .../wazuh-dashboard_4.9.1-1_amd64_24c454efa8.deb ...
Creating wazuh-dashboard group... OK
Creating wazuh-dashboard user... OK
Unpacking wazuh-dashboard (4.9.1-1) ...
Setting up wazuh-dashboard (4.9.1-1) ...
root@ubuntu-jammy:/home/vagrant# ls -la /etc/wazuh-dashboard/
node.options                    opensearch_dashboards.keystore  opensearch_dashboards.yml  

Upgrade 1 🟢

Using dpkg -i to install the package the user is asked to overwrite the opensearch_dashboards.yml file. If the user chooses to overwrite it, a backup of the old one is generated.

root@ubuntu-jammy:/home/vagrant# dpkg -i /vagrant/packages/wazuh-dashboard_4.9.1-1_amd64_24c454efa8.deb 
(Reading database ... 178533 files and directories currently installed.)
Preparing to unpack .../wazuh-dashboard_4.9.1-1_amd64_24c454efa8.deb ...
Unpacking wazuh-dashboard (4.9.1-1) over (4.8.2-1) ...
Setting up wazuh-dashboard (4.9.1-1) ...
Installing new version of config file /etc/systemd/system/wazuh-dashboard ...
Installing new version of config file /etc/wazuh-dashboard/node.options ...

Configuration file '/etc/wazuh-dashboard/opensearch_dashboards.yml'
 ==> Modified (by you or by a script) since installation.
 ==> Package distributor has shipped an updated version.
   What would you like to do about it ?  Your options are:
    Y or I  : install the package maintainer's version
    N or O  : keep your currently-installed version
      D     : show the differences between the versions
      Z     : start a shell to examine the situation
 The default action is to keep your current version.
*** opensearch_dashboards.yml (Y/I/N/O/D/Z) [default=N] ? y
Installing new version of config file /etc/wazuh-dashboard/opensearch_dashboards.yml ...

root@ubuntu-jammy:/home/vagrant# ls -la /etc/wazuh-dashboard/
certs/                              opensearch_dashboards.keystore      opensearch_dashboards.yml.dpkg-old  
node.options                        opensearch_dashboards.yml  

Upgrade 2 🟢

Using the command dpkg --force-confdef --force-confold -i to install the package no interaction from the user is required. The old configuration files are not overwritten and the new ones are saved with the .dpkg-dist extension.

root@ubuntu-jammy:/home/vagrant# dpkg --force-confdef --force-confold -i /vagrant/packages/wazuh-dashboard_4.9.1-1_amd64_24c454efa8.deb 
(Reading database ... 178533 files and directories currently installed.)
Preparing to unpack .../wazuh-dashboard_4.9.1-1_amd64_24c454efa8.deb ...
Unpacking wazuh-dashboard (4.9.1-1) over (4.8.2-1) ...
Setting up wazuh-dashboard (4.9.1-1) ...
Installing new version of config file /etc/systemd/system/wazuh-dashboard ...
Installing new version of config file /etc/wazuh-dashboard/node.options ...

Configuration file '/etc/wazuh-dashboard/opensearch_dashboards.yml'
 ==> Modified (by you or by a script) since installation.
 ==> Package distributor has shipped an updated version.
 ==> Keeping old config file as default.

root@ubuntu-jammy:/home/vagrant# nano /etc/wazuh-dashboard/opensearch_dashboards.yml
root@ubuntu-jammy:/home/vagrant# ls -la /etc/wazuh-dashboard/
node.options                         opensearch_dashboards.keystore       opensearch_dashboards.yml            opensearch_dashboards.yml.dpkg-dist

@Tostti Tostti closed this as completed Sep 19, 2024
@wazuhci wazuhci moved this from Pending final review to Done in Release 4.9.1 Sep 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
level/task Task issue type/change Change performed in a Wazuh Cloud environment issue
Projects
No open projects
Status: Done
Development

No branches or pull requests

3 participants