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

Change cert-tool to use only one wazuh-certificates folder. #87

Merged
merged 2 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ All notable changes to this project will be documented in this file.

### Changed

- Change cert-tool to use only one wazuh-certificates folder. ([#87](https://github.com/wazuh/wazuh-installation-assistant/pull/87))
- Solve bugs when changing passwords in the manager, indexer and dashboard services. ([#86](https://github.com/wazuh/wazuh-installation-assistant/pull/86))
- Fixed typo in Wazuh Installation Assistant. ([#85](https://github.com/wazuh/wazuh-installation-assistant/pull/85))
- Print on console the wazuh user's password when installing Wazuh server. ([#84](https://github.com/wazuh/wazuh-installation-assistant/pull/84))
Expand Down
30 changes: 22 additions & 8 deletions cert_tool/certFunctions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


function cert_cleanFiles() {

common_logger -d "Cleaning certificate files."
eval "rm -f ${cert_tmp_path}/*.csr ${debug}"
eval "rm -f ${cert_tmp_path}/*.srl ${debug}"
Expand Down Expand Up @@ -227,7 +227,7 @@ function cert_parseYaml() {

local s='[[:space:]]*' sm='[ \t]*' w='[a-zA-Z0-9_]*' fs=${fs:-$(echo @|tr @ '\034')} i=${i:- }
cat $1 2>/dev/null | \
awk -F$fs "{multi=0;
awk -F$fs "{multi=0;
if(match(\$0,/$sm\|$sm$/)){multi=1; sub(/$sm\|$sm$/,\"\");}
if(match(\$0,/$sm>$sm$/)){multi=2; sub(/$sm>$sm$/,\"\");}
while(multi>0){
Expand Down Expand Up @@ -327,7 +327,7 @@ function cert_parseYaml() {
}

function cert_checkPrivateIp() {

local ip=$1
common_logger -d "Checking if ${ip} is private."

Expand Down Expand Up @@ -382,25 +382,25 @@ function cert_readConfig() {
done

unique_names=($(echo "${indexer_node_names[@]}" | tr ' ' '\n' | sort -u | tr '\n' ' '))
if [ "${#unique_names[@]}" -ne "${#indexer_node_names[@]}" ]; then
if [ "${#unique_names[@]}" -ne "${#indexer_node_names[@]}" ]; then
common_logger -e "Duplicated indexer node names."
exit 1
fi

unique_ips=($(echo "${indexer_node_ips[@]}" | tr ' ' '\n' | sort -u | tr '\n' ' '))
if [ "${#unique_ips[@]}" -ne "${#indexer_node_ips[@]}" ]; then
if [ "${#unique_ips[@]}" -ne "${#indexer_node_ips[@]}" ]; then
common_logger -e "Duplicated indexer node ips."
exit 1
fi

unique_names=($(echo "${server_node_names[@]}" | tr ' ' '\n' | sort -u | tr '\n' ' '))
if [ "${#unique_names[@]}" -ne "${#server_node_names[@]}" ]; then
if [ "${#unique_names[@]}" -ne "${#server_node_names[@]}" ]; then
common_logger -e "Duplicated Wazuh server node names."
exit 1
fi

unique_ips=($(echo "${server_node_ips[@]}" | tr ' ' '\n' | sort -u | tr '\n' ' '))
if [ "${#unique_ips[@]}" -ne "${#server_node_ips[@]}" ]; then
if [ "${#unique_ips[@]}" -ne "${#server_node_ips[@]}" ]; then
common_logger -e "Duplicated Wazuh server node ips."
exit 1
fi
Expand Down Expand Up @@ -456,7 +456,21 @@ function cert_readConfig() {
}

function cert_setpermisions() {
eval "chmod -R 744 ${cert_tmp_path} ${debug}"
eval "chmod -R 744 ${1} ${debug}"
}

function cert_setDirectory() {

if [ -d "${base_path}/wazuh-certificates" ]; then
eval "cp -f ${cert_tmp_path}/* ${base_path}/wazuh-certificates ${debug}"
eval "rm -R ${cert_tmp_path}"
cert_setpermisions "${base_path}/wazuh-certificates"
common_logger -d "Wazuh-certificates directory exists. Copied files from '${cert_tmp_path}' to '${base_path}/wazuh-certificates' and removed '${cert_tmp_path}'."
else
cert_setpermisions "${cert_tmp_path}"
eval "mv ${cert_tmp_path} ${base_path}/wazuh-certificates ${debug}"
common_logger -d "Moved '${cert_tmp_path}' to '${base_path}/wazuh-certificates'."
fi
}

function cert_convertCRLFtoLF() {
Expand Down
24 changes: 6 additions & 18 deletions cert_tool/certMain.sh
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ function main() {
common_logger -e "You have not entered a root-ca.pem"
exit 1
else
common_logger -e "You have not entered a root-ca.key"
common_logger -e "You have not entered a root-ca.key"
exit 1
fi
fi
Expand Down Expand Up @@ -160,13 +160,6 @@ function main() {

common_logger "Verbose logging redirected to ${logfile}"

if [[ -d "${base_path}"/wazuh-certificates ]]; then
if [ -n "$(ls -A "${base_path}"/wazuh-certificates)" ]; then
common_logger -e "Directory wazuh-certificates already exists in the same path as the script. Please, remove the certs directory to create new certificates."
exit 1
fi
fi

if [[ ! -d "${cert_tmp_path}" ]]; then
mkdir -p "${cert_tmp_path}"
chmod 744 "${cert_tmp_path}"
Expand All @@ -183,8 +176,7 @@ function main() {
cert_generateAdmincertificate
common_logger "Admin certificates created."
cert_cleanFiles
cert_setpermisions
eval "mv ${cert_tmp_path} ${base_path}/wazuh-certificates ${debug}"
cert_setDirectory
fi

if [[ -n "${all}" ]]; then
Expand All @@ -208,8 +200,7 @@ function main() {
if [[ -n "${ca}" ]]; then
cert_generateRootCAcertificate
common_logger "Authority certificates created."
cert_cleanFiles
eval "mv ${cert_tmp_path} ${base_path}/wazuh-certificates ${debug}"
cert_setDirectory
fi

if [[ -n "${cindexer}" ]]; then
Expand All @@ -218,8 +209,7 @@ function main() {
cert_generateIndexercertificates
common_logger "Wazuh indexer certificates created."
cert_cleanFiles
cert_setpermisions
eval "mv ${cert_tmp_path} ${base_path}/wazuh-certificates ${debug}"
cert_setDirectory
else
common_logger -e "Indexer node not present in config.yml."
exit 1
Expand All @@ -232,8 +222,7 @@ function main() {
cert_generateFilebeatcertificates
common_logger "Wazuh Filebeat certificates created."
cert_cleanFiles
cert_setpermisions
eval "mv ${cert_tmp_path} ${base_path}/wazuh-certificates ${debug}"
cert_setDirectory
else
common_logger -e "Server node not present in config.yml."
exit 1
Expand All @@ -246,8 +235,7 @@ function main() {
cert_generateDashboardcertificates
common_logger "Wazuh dashboard certificates created."
cert_cleanFiles
cert_setpermisions
eval "mv ${cert_tmp_path} ${base_path}/wazuh-certificates ${debug}"
cert_setDirectory
else
common_logger -e "Dashboard node not present in config.yml."
exit 1
Expand Down
Loading