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 filebeat local install unify unattended #1046

Merged
merged 3 commits into from
Dec 2, 2021

Conversation

rauldpm
Copy link
Member

@rauldpm rauldpm commented Dec 2, 2021

Related issue
#1036

Description

This PR fixes the unattended installation using local files. The current installation does not fail if there is a file that is not found, so as there is no debug mode it is not detected.

The problem is in the directory from where we want to copy files, in the last phase of Elasticsearch configuration, it enter in (/usr/share/elasticsearch/plugins/opendistro_security/tools/) directory but it does not restore the previous path when finished

This PR changes the copy command to use an absolute path $(pwd) instead of relative one (./), so that if there is ever a problem in a path it is detectable if debug mode is used. To correct the path a cd - has been incorporated in the last phase of Elasticsarch configuration

Logs example

centos.log

@rauldpm rauldpm self-assigned this Dec 2, 2021
@@ -3,7 +3,7 @@ repobaseurl="https://packages.wazuh.com/4.x"

getConfig() {
if [ -n "${local}" ]; then
cp ./$config_path/$1 $2
cp "$(pwd)/$config_path/$1" $2
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe it will be better to use realpath $0 to obtain the path to the script and remove the script name with sed.

Copy link
Member Author

Choose a reason for hiding this comment

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

Used a variable to store the base path of the main script, this allow to run the unattended from different paths

Done in cb80bbe

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.

Requested changes.

@@ -79,6 +79,7 @@ configureElasticsearchAIO() {

eval "cd /usr/share/elasticsearch/plugins/opendistro_security/tools/ ${debug}"
eval "./securityadmin.sh -cd ../securityconfig/ -icl -nhnv -cacert /etc/elasticsearch/certs/root-ca.pem -cert /etc/elasticsearch/certs/admin.pem -key /etc/elasticsearch/certs/admin-key.pem ${debug}"
eval "cd - ${debug}"
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove this line

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 in cb80bbe

@@ -79,6 +79,7 @@ configureElasticsearchAIO() {

eval "cd /usr/share/elasticsearch/plugins/opendistro_security/tools/ ${debug}"
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove this line

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 in cb80bbe

@@ -79,6 +79,7 @@ configureElasticsearchAIO() {

eval "cd /usr/share/elasticsearch/plugins/opendistro_security/tools/ ${debug}"
eval "./securityadmin.sh -cd ../securityconfig/ -icl -nhnv -cacert /etc/elasticsearch/certs/root-ca.pem -cert /etc/elasticsearch/certs/admin.pem -key /etc/elasticsearch/certs/admin-key.pem ${debug}"
Copy link
Contributor

Choose a reason for hiding this comment

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

Use absolute path

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 in cb80bbe

@rauldpm rauldpm requested review from alberpilot and DFolchA December 2, 2021 18:11
@rauldpm
Copy link
Member Author

rauldpm commented Dec 2, 2021

The changes made allow the AIO to be installed from any path, in addition, now all the files will be created in the same folder where the main script is. Before the changes, the instances.yml file and the certs folder were created in the directory from where it was run

Unattended script location: /vagrant/

Unattended runned from /home/vagrant/: unattended_home.log
Unattended runned inside /vagrant/ folder: unattended.log

Pytests
[root@centos7 wazuh-packages]# /usr/testing/bin/pytest --tb=long /test_unattended.py -v
============================================================================================================ test session starts ============================================================================================================
platform linux -- Python 3.8.2, pytest-5.4.1, py-1.11.0, pluggy-0.13.1 -- /usr/testing/bin/python3.8
cachedir: .pytest_cache
rootdir: /vagrant/wazuh-packages
collected 17 items                                                                                                                                                                                                                          

::test_check_wazuh_manager_authd PASSED                                                                                                                                                                                               [  5%]
::test_check_wazuh_manager_db PASSED                                                                                                                                                                                                  [ 11%]
::test_check_wazuh_manager_execd PASSED                                                                                                                                                                                               [ 17%]
::test_check_wazuh_manager_analysisd PASSED                                                                                                                                                                                           [ 23%]
::test_check_wazuh_manager_syscheckd PASSED                                                                                                                                                                                           [ 29%]
::test_check_wazuh_manager_remoted PASSED                                                                                                                                                                                             [ 35%]
::test_check_wazuh_manager_logcollec PASSED                                                                                                                                                                                           [ 41%]
::test_check_wazuh_manager_monitord PASSED                                                                                                                                                                                            [ 47%]
::test_check_wazuh_manager_modulesd PASSED                                                                                                                                                                                            [ 52%]
::test_check_wazuh_manager_apid PASSED                                                                                                                                                                                                [ 58%]
::test_check_filebeat_process PASSED                                                                                                                                                                                                  [ 64%]
::test_check_elasticsearch_process PASSED                                                                                                                                                                                             [ 70%]
::test_check_kibana_process PASSED                                                                                                                                                                                                    [ 76%]
::test_check_elasticsearch_cluster_status PASSED                                                                                                                                                                                      [ 82%]
::test_check_kibana_status PASSED                                                                                                                                                                                                     [ 88%]
::test_test_check_wazuh_api_status PASSED                                                                                                                                                                                             [ 94%]
::test_check_log_errors PASSED                                                                                                                                                                                                        [100%]

============================================================================================================= warnings summary ==============================================================================================================
::test_check_elasticsearch_cluster_status
::test_check_kibana_status
::test_test_check_wazuh_api_status
  /usr/testing/lib/python3.8/site-packages/urllib3/connectionpool.py:1013: InsecureRequestWarning: Unverified HTTPS request is being made to host 'localhost'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings
    warnings.warn(

-- Docs: https://docs.pytest.org/en/latest/warnings.html
====================================================================================================== 17 passed, 3 warnings in 0.61s =======================================================================================================

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 5eda12e into unify-unattended Dec 2, 2021
@alberpilot alberpilot deleted the fix_filebeat_install_local-unify branch December 2, 2021 18:26
Copy link
Contributor

@myu1d157h0u54nd myu1d157h0u54nd left a comment

Choose a reason for hiding this comment

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

LGTM

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.

4 participants