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 #2998

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
17 changes: 16 additions & 1 deletion unattended_installer/cert_tool/certFunctions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,22 @@ 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
25 changes: 6 additions & 19 deletions unattended_installer/cert_tool/certMain.sh
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,6 @@ function main() {
done

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}"
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 @@ -201,15 +193,13 @@ function main() {
common_logger "Wazuh dashboard certificates created."
fi
cert_cleanFiles
cert_setpermisions
eval "mv ${cert_tmp_path} ${base_path}/wazuh-certificates ${debug}"
cert_setDirectory
fi

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 +208,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 +221,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 +234,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