Skip to content

Commit 5dad709

Browse files
authored
Merge pull request #217 from wazuh/merge-4.11.0-into-4.11.1
Merge 4.11.0 into 4.11.1
2 parents eeb2d73 + 07668aa commit 5dad709

File tree

11 files changed

+318
-60
lines changed

11 files changed

+318
-60
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ All notable changes to this project will be documented in this file.
3434

3535
### Fixed
3636

37+
- Fix Wazuh dashboard errors in OVA. ([#209](https://github.com/wazuh/wazuh-virtual-machines/pull/209))
38+
- Fixed local build for OVA. ([#208](https://github.com/wazuh/wazuh-virtual-machines/pull/208))
39+
- Fixed Wazuh Dashboard issues when the AMI boots up. ([#205](https://github.com/wazuh/wazuh-virtual-machines/pull/205))
40+
- Fix Wazuh dashboard certificate verification failure ([#198](https://github.com/wazuh/wazuh-virtual-machines/pull/198))
3741
- Fixed Wazuh ASCII art logo display in OVA. ([#192](https://github.com/wazuh/wazuh-virtual-machines/pull/192))
3842
- Fixed video in grub configuration for the OVA. ([#190](https://github.com/wazuh/wazuh-virtual-machines/pull/190))
3943
- Changed ssh config file to allow ssh while FIPS is activated. ([#184](https://github.com/wazuh/wazuh-virtual-machines/pull/184))

ami/playbooks/build_ami_packages.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,12 @@
296296
enabled: yes
297297
daemon_reload: yes
298298

299+
- name: Disable Wazuh Dashboard service
300+
systemd:
301+
name: wazuh-dashboard
302+
enabled: no
303+
state: stopped
304+
299305
- name: Change SSH port to 22
300306
lineinfile:
301307
path: /etc/ssh/sshd_config

ami/wazuh-ami-customizer.sh

Lines changed: 95 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
# Variables
55
logfile="/var/log/wazuh-ami-customizer.log"
66
debug="| tee -a ${logfile}"
7+
8+
###########################################
9+
# Utility Functions
10+
###########################################
711
function logger(){
812
now=$(date +'%d/%m/%Y %H:%M:%S')
913
mtype="INFO:"
@@ -28,20 +32,26 @@ function logger(){
2832
printf "%s\n" "${now} ${mtype} ${message}" | tee -a "${logfile}"
2933
}
3034

31-
logger "Starting Wazuh AMI Customizer"
32-
33-
logger "Stopping SSH service to avoid connections during the configuration"
34-
35-
eval "systemctl stop sshd.service"
35+
function create_certificates() {
36+
logger "Creating certificates"
37+
eval "bash /etc/.wazuh-certs-tool.sh -A ${debug}"
38+
}
3639

37-
logger "Waiting for Wazuh indexer to be ready"
40+
function systemctl_execution(){
41+
eval "systemctl $1 $2 $3"
42+
}
3843

39-
until $(curl -XGET https://localhost:9200/ -uadmin:admin -k --max-time 120 --silent --output /dev/null); do
40-
logger -w "Wazuh indexer is not ready yet, waiting 10 seconds"
41-
sleep 10
42-
done
44+
###########################################
45+
# Configuration Functions
46+
###########################################
4347

4448
function configure_indexer(){
49+
logger "Stopping all services"
50+
systemctl_execution "stop" "filebeat" "${debug}"
51+
systemctl_execution "stop" "wazuh-dashboard" "${debug}"
52+
systemctl_execution "stop" "wazuh-manager" "${debug}"
53+
systemctl_execution "stop" "wazuh-indexer" "${debug}"
54+
eval "sleep 5"
4555
logger "Configuring Wazuh Indexer"
4656
eval "rm -f /etc/wazuh-indexer/certs/* ${debug}"
4757
eval "cp /etc/wazuh-certificates/wazuh-indexer.pem /etc/wazuh-indexer/certs/wazuh-indexer.pem ${debug}"
@@ -52,10 +62,28 @@ function configure_indexer(){
5262
eval "chmod 500 /etc/wazuh-indexer/certs ${debug}"
5363
eval "chmod 400 /etc/wazuh-indexer/certs/* ${debug}"
5464
eval "chown -R wazuh-indexer:wazuh-indexer /etc/wazuh-indexer/certs ${debug}"
55-
eval "systemctl restart wazuh-indexer ${debug}"
65+
systemctl_execution "start" "wazuh-indexer" "${debug}"
5666
eval "/usr/share/wazuh-indexer/bin/indexer-security-init.sh ${debug}"
5767
}
5868

69+
function verify_indexer() {
70+
logger "Waiting for Wazuh indexer to be ready"
71+
indexer_security_admin_comm="curl -XGET https://localhost:9200/ -uadmin:admin -k --max-time 120 --silent -w \"%{http_code}\" --output /dev/null"
72+
http_status=$(eval "${indexer_security_admin_comm}")
73+
retries=0
74+
max_retries=5
75+
while [ "${http_status}" -ne 200 ]; do
76+
logger -w "Wazuh indexer is not ready yet, waiting 5 seconds"
77+
sleep 5
78+
retries=$((retries+1))
79+
if [ "${retries}" -eq "${max_retries}" ]; then
80+
logger -e "Wazuh indexer is not ready yet, trying to configure it again"
81+
configure_indexer
82+
fi
83+
http_status=$(eval "${indexer_security_admin_comm}")
84+
done
85+
}
86+
5987
function configure_filebeat(){
6088
logger "Configuring Filebeat"
6189
eval "rm -f /etc/filebeat/certs/* ${debug}"
@@ -65,14 +93,23 @@ function configure_filebeat(){
6593
eval "chmod 500 /etc/filebeat/certs ${debug}"
6694
eval "chmod 400 /etc/filebeat/certs/* ${debug}"
6795
eval "chown -R root:root /etc/filebeat/certs ${debug}"
68-
eval "systemctl restart filebeat ${debug}"
96+
systemctl_execution "start" "filebeat" "${debug}"
97+
}
98+
99+
function verify_filebeat() {
100+
logger "Waiting for Filebeat to be ready"
101+
if filebeat test output | grep -q -i -w "ERROR"; then
102+
logger -e "Filebeat is not ready yet, trying to configure it again"
103+
eval "filebeat test output x ${debug}"
104+
configure_filebeat
105+
fi
69106
}
70107

71108
function configure_manager(){
72109
logger "Configuring Wazuh Manager"
73110
eval "rm /var/ossec/api/configuration/security/*_key.pem ${debug}"
74111
eval "rm /var/ossec/api/configuration/ssl/server.* ${debug}"
75-
eval "systemctl restart wazuh-manager ${debug}"
112+
systemctl_execution "start" "wazuh-manager" "${debug}"
76113
}
77114

78115
function configure_dashboard(){
@@ -84,9 +121,31 @@ function configure_dashboard(){
84121
eval "chmod 500 /etc/wazuh-dashboard/certs ${debug}"
85122
eval "chmod 400 /etc/wazuh-dashboard/certs/* ${debug}"
86123
eval "chown -R wazuh-dashboard:wazuh-dashboard /etc/wazuh-dashboard/certs ${debug}"
87-
eval "systemctl restart wazuh-dashboard ${debug}"
124+
systemctl_execution "start" "wazuh-dashboard" "${debug}"
88125
}
89126

127+
function verify_dashboard() {
128+
logger "Waiting for Wazuh dashboard to be ready"
129+
dashboard_check_comm="curl -XGET https://localhost:443/status -uadmin:admin -k -w \"%{http_code}\" -s -o /dev/null"
130+
http_code=$(eval "${dashboard_check_comm}")
131+
retries=0
132+
max_dashboard_initialize_retries=20
133+
while [ "${http_code}" -ne "200" ];do
134+
logger -w "Wazuh dashboard is not ready yet, waiting 15 seconds"
135+
retries=$((retries+1))
136+
sleep 15
137+
if [ "${retries}" -eq "${max_dashboard_initialize_retries}" ]; then
138+
logger -e "Wazuh dashboard is not ready yet, trying to configure it again"
139+
configure_dashboard
140+
fi
141+
http_code=$(eval "${dashboard_check_comm}")
142+
done
143+
}
144+
145+
###########################################
146+
# Cleanup and Finalization Functions
147+
###########################################
148+
90149
function clean_configuration(){
91150
logger "Cleaning configuration files"
92151
eval "rm -rf /etc/wazuh-certificates /etc/.wazuh-certs-tool.sh /etc/config.yml /etc/wazuh-certificates-tool.log /var/log/wazuh-ami-customizer.log"
@@ -100,63 +159,43 @@ function change_passwords(){
100159
new_password=$(ec2-metadata | grep "instance-id" | cut -d":" -f2 | tr -d " "| awk '{print toupper(substr($0,1,1)) substr($0,2)}')
101160
eval "sed -i 's/password:.*/password: ${new_password}/g' /etc/.wazuh-install-files/wazuh-passwords.txt ${debug}"
102161
eval "bash /etc/.wazuh-passwords-tool.sh -a -A -au wazuh -ap wazuh -f /etc/.wazuh-install-files/wazuh-passwords.txt >> /dev/null"
103-
eval "systemctl restart wazuh-dashboard ${debug}"
104162
}
105163

106164
function restart_ssh_service(){
107165
logger "Starting SSH service"
108166
eval "systemctl start sshd.service"
109167
}
110168

111-
logger "Creating certificates"
112-
eval "bash /etc/.wazuh-certs-tool.sh -A ${debug}"
169+
###########################################
170+
# Main
171+
###########################################
113172

114-
configure_indexer
173+
logger "Starting Wazuh AMI Customizer"
174+
175+
logger "Stopping SSH service to avoid connections during the configuration"
176+
eval "systemctl stop sshd.service"
115177

116178
logger "Waiting for Wazuh indexer to be ready"
117-
indexer_security_admin_comm="curl -XGET https://localhost:9200/ -uadmin:admin -k --max-time 120 --silent -w \"%{http_code}\" --output /dev/null"
118-
http_status=$(eval "${indexer_security_admin_comm}")
119-
retries=0
120-
max_retries=5
121-
while [ "${http_status}" -ne 200 ]; do
122-
logger -w "Wazuh indexer is not ready yet, waiting 5 seconds"
123-
sleep 5
124-
retries=$((retries+1))
125-
if [ "${retries}" -eq "${max_retries}" ]; then
126-
logger -e "Wazuh indexer is not ready yet, trying to configure it again"
127-
configure_indexer
128-
fi
129-
http_status=$(eval "${indexer_security_admin_comm}")
179+
until $(curl -XGET https://localhost:9200/ -uadmin:admin -k --max-time 120 --silent --output /dev/null); do
180+
logger -w "Wazuh indexer is not ready yet, waiting 10 seconds"
181+
sleep 10
130182
done
131183

132-
configure_filebeat
184+
create_certificates
185+
186+
configure_indexer
187+
verify_indexer
133188

134-
logger "Waiting for Filebeat to be ready"
135-
if filebeat test output | grep -q -i -w "ERROR"; then
136-
logger -e "Filebeat is not ready yet, trying to configure it again"
137-
eval "filebeat test output x ${debug}"
138-
configure_filebeat
139-
fi
189+
configure_filebeat
190+
verify_filebeat
140191

141192
configure_manager
142193

143194
configure_dashboard
195+
verify_dashboard
144196

145-
logger "Waiting for Wazuh dashboard to be ready"
146-
dashboard_check_comm="curl -XGET https://localhost:443/status -uadmin:admin -k -w \"%{http_code}\" -s -o /dev/null"
147-
http_code=$(eval "${dashboard_check_comm}")
148-
retries=0
149-
max_dashboard_initialize_retries=20
150-
while [ "${http_code}" -ne "200" ];do
151-
logger -w "Wazuh dashboard is not ready yet, waiting 15 seconds"
152-
retries=$((retries+1))
153-
sleep 15
154-
if [ "${retries}" -eq "${max_dashboard_initialize_retries}" ]; then
155-
logger -e "Wazuh dashboard is not ready yet, trying to configure it again"
156-
configure_dashboard
157-
fi
158-
http_code=$(eval "${dashboard_check_comm}")
159-
done
197+
systemctl_execution "stop" "wazuh-dashboard" "${debug}"
198+
eval "sleep 5"
160199

161200
change_passwords
162201

@@ -165,6 +204,9 @@ until $(curl -XGET https://localhost:9200/ -uadmin:${new_password} -k --max-time
165204
sleep 10
166205
done
167206

207+
systemctl_execution "start" "wazuh-dashboard" "${debug}"
208+
systemctl_execution "enable" "wazuh-dashboard" "${debug}"
209+
168210
restart_ssh_service
169211

170212
clean_configuration

ova/Vagrantfile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
Vagrant.configure("2") do |config|
55

6-
config.vm.box_url = "https://packages-dev.wazuh.com/vms/ova/amznlinux-2.box"
7-
config.vm.box = "amznlinux-2"
6+
config.vm.box_url = "https://packages-dev.wazuh.com/vms/ova/al2023.box"
7+
config.vm.box = "al2023"
88
config.vm.hostname = "wazuh-server"
99
config.vm.provider "virtualbox" do |vb|
1010
vb.name = "vm_wazuh"
@@ -13,15 +13,15 @@ Vagrant.configure("2") do |config|
1313
end
1414

1515
config.ssh.username = "wazuh-user"
16-
config.ssh.password = "wazuh"
16+
#config.ssh.password = "wazuh"
1717
config.ssh.insert_key = true
1818

1919
# Synced folder configuration
2020
config.vm.synced_folder ".", "/vagrant", disabled: true
2121
config.vm.synced_folder ".", "/tmp", type: "rsync", :rsync__exclude => ['output']
2222

2323
# Provision stage
24-
config.vm.provision :shell, path: "provision.sh", :args => "#{ENV['PACKAGES_REPOSITORY']} #{ENV['DEBUG']}"
24+
config.vm.provision :shell, path: "ova_configurer_caller.sh", :args => "#{ENV['INSTALLATION_ASSISTANT_BRANCH']} #{ENV['WVM_BRANCH']} #{ENV['PACKAGES_REPOSITORY']} #{ENV['DEBUG']}"
2525

2626
# Provision cleanup stage
2727
config.vm.provision :shell, path: "assets/postProvision.sh", :args => "#{ENV['DEBUG']}"
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Wazuh AMI Customizer Service - Used to customize the Wazuh AMI with custom certificates and passwords
2+
# Copyright (C) 2015, Wazuh Inc.
3+
#
4+
# This program is a free software; you can redistribute it
5+
# and/or modify it under the terms of the GNU General Public
6+
# License (version 2) as published by the FSF - Free Software
7+
# Foundation.
8+
#
9+
10+
[Unit]
11+
Description=Starts Wazuh services in order
12+
Wants=wazuh-starter.timer
13+
14+
[Service]
15+
Type=oneshot
16+
ExecStart=/etc/.wazuh-starter.sh
17+
18+
[Install]
19+
WantedBy=multi-user.target

0 commit comments

Comments
 (0)