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

Implement Vagrantfile for generic testing environment #474

Merged
merged 6 commits into from
Oct 18, 2024

Conversation

QU3B1M
Copy link
Member

@QU3B1M QU3B1M commented Oct 17, 2024

Description

Adds a Vagrantfile that provides and configure two VMs to be used as testing environment.

It generates the required certificates using the corresponding values of the nodes and copy them to each node's user home directory.


Update

Due to libvirt limitations with shared folders, we discovered that provisioning failed when trying to copy generated certificates from the indexer_1 system to the indexer_2 system. To work around this, I added a pre-start.sh script that generates the certificates locally and copies them to the corresponding systems

Related Issues

Check List

  • Functionality includes testing.
  • API changes companion pull request created, if applicable.
  • Public documentation issue/PR created, if applicable.

@QU3B1M QU3B1M self-assigned this Oct 17, 2024
@QU3B1M QU3B1M requested a review from a team as a code owner October 17, 2024 16:24
@QU3B1M QU3B1M linked an issue Oct 17, 2024 that may be closed by this pull request
Copy link
Member

@f-galland f-galland 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
Member

@AlexRuiz7 AlexRuiz7 left a comment

Choose a reason for hiding this comment

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

Vagrant failed to start

@alex-GL66 ➜ test-tools git:(enhancement/459-vagrantfile-for-testing) ✗ vagrant up
Bringing machine 'indexer_1' up with 'libvirt' provider...
Bringing machine 'indexer_2' up with 'libvirt' provider...
==> indexer_2: Checking if box 'generic/ubuntu2204' version '4.3.12' is up to date...
==> indexer_1: Checking if box 'generic/rhel9' version '4.3.12' is up to date...
==> indexer_2: Creating image (snapshot of base box volume).
==> indexer_1: Creating image (snapshot of base box volume).
==> indexer_2: Creating domain with the following settings...
==> indexer_1: Creating domain with the following settings...
==> indexer_2:  -- Name:              test-tools_indexer_2
==> indexer_1:  -- Name:              test-tools_indexer_1
==> indexer_2:  -- Description:       Source: /home/alex/wazuh/wazuh-indexer/test-tools/Vagrantfile
==> indexer_2:  -- Domain type:       kvm
==> indexer_2:  -- Cpus:              4
==> indexer_1:  -- Description:       Source: /home/alex/wazuh/wazuh-indexer/test-tools/Vagrantfile
==> indexer_2:  -- Feature:           acpi
==> indexer_2:  -- Feature:           apic
==> indexer_1:  -- Domain type:       kvm
==> indexer_2:  -- Feature:           pae
==> indexer_1:  -- Cpus:              4
==> indexer_2:  -- Clock offset:      utc
==> indexer_2:  -- Memory:            6144M
==> indexer_1:  -- Feature:           acpi
==> indexer_2:  -- Base box:          generic/ubuntu2204
==> indexer_1:  -- Feature:           apic
==> indexer_2:  -- Storage pool:      default
==> indexer_1:  -- Feature:           pae
==> indexer_2:  -- Image(vda):        /var/lib/libvirt/images/test-tools_indexer_2.img, virtio, 128G
==> indexer_1:  -- Clock offset:      utc
==> indexer_2:  -- Disk driver opts:  cache='default'
==> indexer_1:  -- Memory:            6144M
==> indexer_2:  -- Graphics Type:     vnc
==> indexer_1:  -- Base box:          generic/rhel9
==> indexer_2:  -- Video Type:        cirrus
==> indexer_1:  -- Storage pool:      default
==> indexer_2:  -- Video VRAM:        256
==> indexer_1:  -- Image(vda):        /var/lib/libvirt/images/test-tools_indexer_1.img, virtio, 128G
==> indexer_1:  -- Disk driver opts:  cache='default'
==> indexer_2:  -- Video 3D accel:    false
==> indexer_1:  -- Graphics Type:     vnc
==> indexer_2:  -- Keymap:            en-us
==> indexer_1:  -- Video Type:        cirrus
==> indexer_2:  -- TPM Backend:       passthrough
==> indexer_1:  -- Video VRAM:        256
==> indexer_2:  -- INPUT:             type=mouse, bus=ps2
==> indexer_1:  -- Video 3D accel:    false
==> indexer_1:  -- Keymap:            en-us
==> indexer_1:  -- TPM Backend:       passthrough
==> indexer_1:  -- INPUT:             type=mouse, bus=ps2
==> indexer_2: Creating shared folders metadata...
==> indexer_1: Creating shared folders metadata...
==> indexer_2: Starting domain.
==> indexer_1: Starting domain.
==> indexer_2: Domain launching with graphics connection settings...
==> indexer_1: Domain launching with graphics connection settings...
==> indexer_2:  -- Graphics Port:      5900
==> indexer_1:  -- Graphics Port:      5901
==> indexer_2:  -- Graphics IP:        127.0.0.1
==> indexer_1:  -- Graphics IP:        127.0.0.1
==> indexer_2:  -- Graphics Password:  Not defined
==> indexer_1:  -- Graphics Password:  Not defined
==> indexer_2:  -- Graphics Websocket: 5700
==> indexer_1:  -- Graphics Websocket: 5701
==> indexer_2: Waiting for domain to get an IP address...
==> indexer_1: Waiting for domain to get an IP address...
==> indexer_2: Waiting for machine to boot. This may take a few minutes...
    indexer_2: SSH address: 192.168.121.225:22
    indexer_2: SSH username: vagrant
    indexer_2: SSH auth method: private key
    indexer_2: Warning: Connection refused. Retrying...
==> indexer_1: Waiting for machine to boot. This may take a few minutes...
    indexer_1: SSH address: 192.168.121.52:22
    indexer_1: SSH username: vagrant
    indexer_1: SSH auth method: private key
    indexer_1: 
    indexer_1: Vagrant insecure key detected. Vagrant will automatically replace
    indexer_1: this with a newly generated keypair for better security.
    indexer_1: 
    indexer_1: Inserting generated public key within guest...
    indexer_2: Warning: Connection refused. Retrying...
    indexer_1: Removing insecure key from the guest if it's present...
    indexer_1: Key inserted! Disconnecting and reconnecting using new SSH key...
==> indexer_1: Machine booted and ready!
==> indexer_1: Setting hostname...
==> indexer_1: Rsyncing folder: /home/alex/wazuh/wazuh-indexer/test-tools/ => /vagrant
    indexer_2: Warning: Connection refused. Retrying...
==> indexer_1: Configuring and enabling network interfaces...
==> indexer_1: Running provisioner: shell...
    indexer_1: Running: inline script
    indexer_1: Removed "/etc/systemd/system/multi-user.target.wants/firewalld.service".
    indexer_1: Removed "/etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service".
    indexer_1: 0 files removed
    indexer_1: 18/10/2024 10:53:55 INFO: Verbose logging redirected to /home/vagrant/wazuh-certificates-tool.log
    indexer_1: 18/10/2024 10:53:55 INFO: Generating the root certificate.
    indexer_1: 18/10/2024 10:53:55 INFO: Generating Admin certificates.
    indexer_1: 18/10/2024 10:53:55 INFO: Admin certificates created.
    indexer_1: 18/10/2024 10:53:55 INFO: Generating Wazuh indexer certificates.
    indexer_1: 18/10/2024 10:53:56 INFO: Wazuh indexer certificates created.
    indexer_1: ./
    indexer_1: ./root-ca.key
    indexer_1: ./root-ca.pem
    indexer_1: ./admin-key.pem
    indexer_1: ./admin.pem
    indexer_1: ./node-1-key.pem
    indexer_1: ./node-1.pem
    indexer_1: ./node-2-key.pem
    indexer_1: ./node-2.pem
    indexer_2: Warning: Connection refused. Retrying...
    indexer_2: Warning: Connection refused. Retrying...
    indexer_2: Warning: Connection refused. Retrying...
    indexer_2: Warning: Connection refused. Retrying...
    indexer_2: Warning: Connection refused. Retrying...
    indexer_2: Warning: Connection refused. Retrying...
    indexer_2: Warning: Connection refused. Retrying...
    indexer_2: Warning: Connection refused. Retrying...
    indexer_2: Warning: Connection refused. Retrying...
    indexer_2: 
    indexer_2: Vagrant insecure key detected. Vagrant will automatically replace
    indexer_2: this with a newly generated keypair for better security.
    indexer_2: 
    indexer_2: Inserting generated public key within guest...
    indexer_2: Removing insecure key from the guest if it's present...
    indexer_2: Key inserted! Disconnecting and reconnecting using new SSH key...
==> indexer_2: Machine booted and ready!
==> indexer_2: Setting hostname...
==> indexer_2: Rsyncing folder: /home/alex/wazuh/wazuh-indexer/test-tools/ => /vagrant
==> indexer_2: Configuring and enabling network interfaces...
==> indexer_2: Running provisioner: shell...
    indexer_2: Running: inline script
    indexer_2: Synchronizing state of ufw.service with SysV service script with /lib/systemd/systemd-sysv-install.
    indexer_2: Executing: /lib/systemd/systemd-sysv-install disable ufw
    indexer_2: Removed /etc/systemd/system/multi-user.target.wants/ufw.service.
    indexer_2: cp: cannot stat '/vagrant/wazuh-vertificates.tar': No such file or directory
==> indexer_2: An error occurred. The error will be shown after all tasks complete.
An error occurred while executing multiple actions in parallel.
Any errors that occurred are shown below.

An error occurred while executing the action on the 'indexer_2'
machine. Please handle this error then try again:

The SSH command responded with a non-zero exit status. Vagrant
assumes that this means the command failed. The output for this command
should be in the log above. Please read the output to determine what
went wrong.

@QU3B1M QU3B1M force-pushed the enhancement/459-vagrantfile-for-testing branch from 63eab84 to 8e98fbe Compare October 18, 2024 14:08
@QU3B1M QU3B1M requested review from AlexRuiz7 and f-galland October 18, 2024 14:26
@QU3B1M
Copy link
Member Author

QU3B1M commented Oct 18, 2024

Fixed the error at the provision stage on the vagrant start, it was caused by a libvirt limitation when interacting with shared folders, it only reads the shared folder in the state previous to the initial startup, so the newly generated certificates cannot be found by the VMs.
As workaround I've made a bash script that generates the certificates locally before the initial startup, so both virtual machines can access it at the provision stage.

Copy link
Member

@AlexRuiz7 AlexRuiz7 left a comment

Choose a reason for hiding this comment

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

LGTM

@alex-GL66 ➜ test-tools git:(enhancement/459-vagrantfile-for-testing) ✗ vagrant ssh indexer_2
vagrant@node-2:~$ ls
wazuh-certificates.tar
vagrant@node-2:~$ md5sum wazuh-certificates.tar 
d41d8cd98f00b204e9800998ecf8427e  wazuh-certificates.tar
vagrant@node-2:~$ ls -l
total 0
-rw-r--r-- 1 root root 0 Oct 18 15:39 wazuh-certificates.tar
vagrant@node-2:~$ exit
logout
@alex-GL66 ➜ test-tools git:(enhancement/459-vagrantfile-for-testing) ✗ vagrant ssh indexer_1
Register this system with Red Hat Insights: insights-client --register
Create an account or view all your systems at https://red.ht/insights-dashboard
Last login: Fri Oct 18 15:43:08 2024 from 192.168.121.1
[vagrant@node-1 ~]$ md5sum wazuh-certificates.tar 
d41d8cd98f00b204e9800998ecf8427e  wazuh-certificates.tar

@AlexRuiz7 AlexRuiz7 merged commit e6b3128 into master Oct 18, 2024
8 checks passed
@AlexRuiz7 AlexRuiz7 deleted the enhancement/459-vagrantfile-for-testing branch October 18, 2024 15:44
AlexRuiz7 added a commit that referenced this pull request Oct 22, 2024
* Add Vagrantfile and config.yml for generic testing environment setup

* Rename vagrantfile storing directory

* Add vagrant basic environment README.md

* Remove basic_env folder

* Fix typo on Vagrantfile

* Add pre-start bash script to generate the certificates

---------

Co-authored-by: Álex Ruiz <alejandro.ruiz.becerra@wazuh.com>
AlexRuiz7 added a commit that referenced this pull request Nov 8, 2024
* Add Vagrantfile and config.yml for generic testing environment setup

* Rename vagrantfile storing directory

* Add vagrant basic environment README.md

* Remove basic_env folder

* Fix typo on Vagrantfile

* Add pre-start bash script to generate the certificates

---------

Co-authored-by: Álex Ruiz <alejandro.ruiz.becerra@wazuh.com>
AlexRuiz7 added a commit that referenced this pull request Nov 18, 2024
* Add Vagrantfile and config.yml for generic testing environment setup

* Rename vagrantfile storing directory

* Add vagrant basic environment README.md

* Remove basic_env folder

* Fix typo on Vagrantfile

* Add pre-start bash script to generate the certificates

---------

Co-authored-by: Álex Ruiz <alejandro.ruiz.becerra@wazuh.com>
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.

Vagrantfile for testing purposes
3 participants