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

Removing root requirement for download option from Wazuh installation assistant and other improvements #1465

Merged
merged 7 commits into from
Apr 20, 2022

Conversation

c-bordon
Copy link
Member

Related issue
closes #1459

Description

  • Removed root user validation for options: -h, -V, and -dw
  • Fixed only valid argument validation for -dw option
  • Fixed directory permissions
  • The result of running -dw is a .tar.gz file with all the necessary files

Logs example

root tests:

[vagrant@centos72 unattended_installer]$ ./wazuh-install.sh -a
This script must be run as root.
[vagrant@centos72 unattended_installer]$ ./wazuh-install.sh -c
This script must be run as root.
[vagrant@centos72 unattended_installer]$ ./wazuh-install.sh -F
This script must be run as root.
[vagrant@centos72 unattended_installer]$ ./wazuh-install.sh -g
This script must be run as root.
[vagrant@centos72 unattended_installer]$ ./wazuh-install.sh -h

NAME
        wazuh-install.sh - Install and configure Wazuh central components: Wazuh manager, Wazuh indexer and Wazuh dashboard.

SYNOPSIS
        wazuh-install.sh [OPTIONS] -a | -c | -s | -wi <indexer-node-name> | -wd <dashboard-node-name> | -ws <wazuh-node-name>
...
[vagrant@centos72 unattended_installer]$ ./wazuh-install.sh -i
This script must be run as root.
[vagrant@centos72 unattended_installer]$ ./wazuh-install.sh -o
This script must be run as root.
[vagrant@centos72 unattended_installer]$ ./wazuh-install.sh -s
This script must be run as root.
[vagrant@centos72 unattended_installer]$ ./wazuh-install.sh -t
This script must be run as root.
[vagrant@centos72 unattended_installer]$ ./wazuh-install.sh -u
This script must be run as root.
[vagrant@centos72 unattended_installer]$ ./wazuh-install.sh -V
19/04/2022 14:53:37 INFO: Wazuh version: 4.3.0
19/04/2022 14:53:37 INFO: Filebeat version: 7.10.2
19/04/2022 14:53:37 INFO: Wazuh installation assistant version: 0.1
[vagrant@centos72 unattended_installer]$ ./wazuh-install.sh -wd
This script must be run as root.
[vagrant@centos72 unattended_installer]$ ./wazuh-install.sh -wi
This script must be run as root.
[vagrant@centos72 unattended_installer]$ ./wazuh-install.sh -ws
This script must be run as root.
[vagrant@centos72 unattended_installer]$ ./wazuh-install.sh -dw
19/04/2022 14:53:50 ERROR: Error on arguments. Probably missing <deb|rpm> after -dw|--download-wazuh

NAME

Tests

Ubuntu: https://devel.ci.wazuh.info/view/Tests/job/Test_unattended/523/console
Centos: https://devel.ci.wazuh.info/view/Tests/job/Test_unattended/526/console
Distributed: https://devel.ci.wazuh.info/view/Tests/job/Test_unattended_distributed/442/console

@c-bordon c-bordon self-assigned this Apr 19, 2022
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 requested changes


curl -so ${DEST_PATH}/wazuh-filebeat-module.tar.gz ${BASE_URL}/filebeat/wazuh-filebeat-0.1.tar.gz
eval "chmod 500 ${BASE_DEST_FOLDER}"

common_logger "The Configuration Files are in ${DEST_PATH}"
Copy link
Contributor

Choose a reason for hiding this comment

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

Why uppercase?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done: c77ab55

Comment on lines 39 to 46
if [ "$EUID" -eq 0 ]; then
if [ -z "${debugLogger}" ] || ( [ -n "${debugLogger}" ] && [ -n "${debugEnabled}" ] ); then
printf "${now} ${mtype} ${message}\n" | tee -a ${logfile}
fi
else
if [ -z "${debugLogger}" ] || ( [ -n "${debugLogger}" ] && [ -n "${debugEnabled}" ] ); then
printf "${now} ${mtype} ${message}\n"
fi
Copy link
Contributor

Choose a reason for hiding this comment

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

This code can be simplified by:

        if [ -z "${debugLogger}" ] || ( [ -n "${debugLogger}" ] && [ -n "${debugEnabled}" ] ); then
	    if [ "$EUID" -eq 0 ]; then
                printf "${now} ${mtype} ${message}\n" | tee -a ${logfile}
	    else 
		printf "${now} ${mtype} ${message}\n"
	    fi
        fi

Copy link
Member Author

Choose a reason for hiding this comment

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

Done: c77ab55

@@ -85,13 +83,15 @@ function main() {
case "${1}" in
"-a"|"--all-in-one")
AIO=1
common_checkRoot
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of repeat common_checkRoot make a function with a loop that finds the option -dw inside the arguments array. If it doesn't exist, then make the common_checkRoot call.
This option has to be attached with a flag check: -V, -h has to be used alone, and probably -dw too.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done: c77ab55

@@ -35,18 +35,18 @@ debug=">> ${logfile} 2>&1"
## Offline Installation vars
readonly BASE_DEST_FOLDER="wazuh-offline"
readonly WAZUH_DEB_BASE_URL="${BASE_URL}/apt/pool/main/w/wazuh-manager"
readonly WAZUH_DEB_PACKAGES=( "wazuh-manager_${wazuh_version}-${wazuh_revision}_amd64.deb" )
readonly WAZUH_DEB_PACKAGES="wazuh-manager_${wazuh_version}-${wazuh_revision}_amd64.deb"
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead WAZUH_DEB_PACKAGES it should be MANAGER_DEB_PACKAGE, right?
Also, it could be a good idea to remove the plural of variable names that only have one element.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done: c77ab55

@c-bordon
Copy link
Member Author

New tests:

[vagrant@centos72 unattended_installer]$ ./wazuh-install.sh -a
This script must be run as root.
[vagrant@centos72 unattended_installer]$ ./wazuh-install.sh -c
This script must be run as root.
[vagrant@centos72 unattended_installer]$ ./wazuh-install.sh -F
This script must be run as root.
[vagrant@centos72 unattended_installer]$ ./wazuh-install.sh -g
This script must be run as root.
[vagrant@centos72 unattended_installer]$ ./wazuh-install.sh -i
This script must be run as root.
[vagrant@centos72 unattended_installer]$ ./wazuh-install.sh -o
This script must be run as root.
[vagrant@centos72 unattended_installer]$ ./wazuh-install.sh -s
This script must be run as root.
[vagrant@centos72 unattended_installer]$ ./wazuh-install.sh -t
This script must be run as root.
[vagrant@centos72 unattended_installer]$ ./wazuh-install.sh -u
This script must be run as root.
[vagrant@centos72 unattended_installer]$ ./wazuh-install.sh -wd
This script must be run as root.
[vagrant@centos72 unattended_installer]$ ./wazuh-install.sh -wi
This script must be run as root.
[vagrant@centos72 unattended_installer]$ ./wazuh-install.sh -ws
This script must be run as root.
[vagrant@centos72 unattended_installer]$ ./wazuh-install.sh -V
19/04/2022 19:37:32 INFO: Wazuh version: 4.3.0
19/04/2022 19:37:32 INFO: Filebeat version: 7.10.2
19/04/2022 19:37:32 INFO: Wazuh installation assistant version: 0.1
[vagrant@centos72 unattended_installer]$ ./wazuh-install.sh -h

NAME
        wazuh-install.sh - Install and configure Wazuh central components: Wazuh manager, Wazuh indexer and Wazuh dashboard.
...
[vagrant@centos72 unattended_installer]$ ./wazuh-install.sh -dw
19/04/2022 19:37:42 ERROR: Error on arguments. Probably missing <deb|rpm> after -dw|--download-wazuh

NAME
        wazuh-install.sh - Install and configure Wazuh central components: Wazuh manager, Wazuh indexer and Wazuh dashboard.

@alberpilot alberpilot changed the title Some Changes in Offline Installator Removing root requirement for download option from Wazuh installation assistant and other improvements Apr 20, 2022
@c-bordon c-bordon requested a review from alberpilot April 20, 2022 10:04
@c-bordon
Copy link
Member Author

New Tests:

cbordon@cbordon-MS-7C88:~/Documents/wazuh/repositorios/wazuh-packages/unattended_installer$ ./wazuh-install.sh -dw rpm                   
20/04/2022 08:32:59 INFO: Starting Wazuh installation assistant. Wazuh version: 4.3.0
20/04/2022 08:32:59 INFO: Verbose logging redirected to /var/log/wazuh-install.log
20/04/2022 08:33:01 INFO: --- Download Packages ---
20/04/2022 08:33:01 INFO: Starting Wazuh packages download.
20/04/2022 08:33:01 INFO: Downloading Wazuh rpm packages for x86_64.
20/04/2022 08:33:13 INFO: The manager package was downloaded.
20/04/2022 08:33:16 INFO: The filebeat package was downloaded.
20/04/2022 08:33:53 INFO: The indexer package was downloaded.
20/04/2022 08:34:13 INFO: The dashboard package was downloaded.
20/04/2022 08:34:13 INFO: The packages are in wazuh-offline/wazuh-packages
20/04/2022 08:34:13 INFO: Downloading configuration files and assets.
20/04/2022 08:34:14 INFO: The resource https://packages-dev.wazuh.com/key/GPG-KEY-WAZUH was downloaded.
20/04/2022 08:34:15 INFO: The resource https://packages-dev.wazuh.com/4.3/tpl/wazuh/filebeat/filebeat.yml was downloaded.
20/04/2022 08:34:16 INFO: The resource https://raw.githubusercontent.com/wazuh/wazuh/4.3/extensions/elasticsearch/7.x/wazuh-template.json was downloaded.
20/04/2022 08:34:17 INFO: The resource https://packages-dev.wazuh.com/pre-release/filebeat/wazuh-filebeat-0.1.tar.gz was downloaded.
20/04/2022 08:34:17 INFO: The configuration files and assets are in wazuh-offline/wazuh-files
20/04/2022 08:34:34 INFO: You can follow the installation guide here https://documentation.wazuh.com/current/installation-guide/more-installation-alternatives/offline-installation.html

Copy link
Contributor

@okynos okynos 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.

LGTM

@alberpilot alberpilot merged commit 9d70e29 into 4.3 Apr 20, 2022
@alberpilot alberpilot deleted the 1459-FixOffline-to4.3 branch April 20, 2022 15:18
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.

3 participants