From 8e98fbe9de5675609da6f4fa95520074f643b82c Mon Sep 17 00:00:00 2001 From: quebim Date: Fri, 18 Oct 2024 11:08:02 -0300 Subject: [PATCH] Add pre-start bash script to generate the certificates --- test-tools/Vagrantfile | 22 ++++++++++++---------- test-tools/pre-start.sh | 23 +++++++++++++++++++++++ 2 files changed, 35 insertions(+), 10 deletions(-) create mode 100644 test-tools/pre-start.sh diff --git a/test-tools/Vagrantfile b/test-tools/Vagrantfile index d4114c23b408f..dbbeb02976274 100644 --- a/test-tools/Vagrantfile +++ b/test-tools/Vagrantfile @@ -1,3 +1,10 @@ +system(" + if [ #{ARGV[0]} = 'up' ]; then + echo 'Executing pre-start script.' + bash ./pre-start.sh + fi +") + Vagrant.configure("2") do |config| config.vm.define "indexer_1" do |indexer_1| indexer_1.vm.box = "generic/rhel9" @@ -13,15 +20,9 @@ Vagrant.configure("2") do |config| sudo systemctl disable firewalld sudo yum clean all # Add node-2 to /etc/hosts - echo "192.168.56.11 node-2" >> /etc/hosts - # Generate certificates - cp /vagrant/config.yml config.yml - curl -sO https://packages.wazuh.com/4.9/wazuh-certs-tool.sh - bash ./wazuh-certs-tool.sh -A - # Compress and share certificates - tar -cvf ./wazuh-certificates.tar -C ./wazuh-certificates/ . - rm -rf ./wazuh-certificates *.yml *.log *.sh - cp wazuh-certificates.tar /vagrant/wazuh-certificates.tar + sudo echo "192.168.56.11 node-2" >> /etc/hosts + # Copy generated certificates + cp /vagrant/wazuh-certificates.tar /home/vagrant/wazuh-certificates.tar SHELL end config.vm.define "indexer_2" do |indexer_2| @@ -36,10 +37,11 @@ Vagrant.configure("2") do |config| indexer_2.vm.provision "shell", inline: <<-SHELL sudo systemctl stop ufw sudo systemctl disable ufw + sudo apt install sshpass -y # Add node-1 to /etc/hosts echo "192.168.56.10 node-1" >> /etc/hosts # Copy generated certificates - cp /vagrant/wazuh-certificates.tar wazuh-certificates.tar + cp /vagrant/wazuh-certificates.tar /home/vagrant/wazuh-certificates.tar SHELL end end diff --git a/test-tools/pre-start.sh b/test-tools/pre-start.sh new file mode 100644 index 0000000000000..ab8142d32f25d --- /dev/null +++ b/test-tools/pre-start.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +# SPDX-License-Identifier: Apache-2.0 +# The OpenSearch Contributors require contributions made to +# this file be licensed under the Apache-2.0 license or a +# compatible open source license. + +# Download the Wazuh certs tool +curl -sO https://packages.wazuh.com/4.9/wazuh-certs-tool.sh + +# Make the script executable +chmod +x ./wazuh-certs-tool.sh + +# Run the Wazuh certs tool +bash ./wazuh-certs-tool.sh -A + +# Create a tarball of the generated certificates +tar -cvf ./wazuh-certificates.tar -C ./wazuh-certificates/ . + +# Clean up +rm -rf ./wazuh-certificates wazuh-certs-tool.sh *.log + +echo "Setup complete and certificates archived."