From c66cdea2569be380024727869bd42c13e16bcccf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gonzalo=20Acu=C3=B1a?= Date: Tue, 15 Mar 2022 11:13:36 -0300 Subject: [PATCH] Tools download logic updated --- indexer_certs_creator/Dockerfile | 4 +- indexer_certs_creator/config/entrypoint.sh | 30 ++++++++---- .../wazuh_indexer_ssl_certs/certs.yml | 2 +- wazuh-indexer/config/config.sh | 48 +++++++++++++++++-- wazuh-manager/config/wazuh.repo | 2 +- 5 files changed, 68 insertions(+), 18 deletions(-) diff --git a/indexer_certs_creator/Dockerfile b/indexer_certs_creator/Dockerfile index e2e22598..d9ac2941 100644 --- a/indexer_certs_creator/Dockerfile +++ b/indexer_certs_creator/Dockerfile @@ -5,10 +5,8 @@ RUN apt-get update && apt-get install openssl curl -y WORKDIR / -#RUN curl -o wazuh-cert-tool.sh https://s3.us-west-1.amazonaws.com/packages.wazuh.com/4.x/wazuh-cert-tool.sh - COPY config/entrypoint.sh / -RUN chmod 700 /entrypoint.sh && chmod 700 /wazuh-cert-tool.sh +RUN chmod 700 /entrypoint.sh ENTRYPOINT ["/entrypoint.sh"] \ No newline at end of file diff --git a/indexer_certs_creator/config/entrypoint.sh b/indexer_certs_creator/config/entrypoint.sh index 30df30d7..1aae8d99 100644 --- a/indexer_certs_creator/config/entrypoint.sh +++ b/indexer_certs_creator/config/entrypoint.sh @@ -5,22 +5,36 @@ # Downloading Cert Gen Tool ############################################################################## -FILE=wazuh-cert-tool.sh +## Variables +CERT_TOOL=wazuh-certs-tool.sh +PASSWORD_TOOL=wazuh-passwords-tool.sh +PACKAGES_URL=https://packages.wazuh.com/resources/4.3/ +PACKAGES_DEV_URL=https://packages-dev.wazuh.com/resources/4.3/ -#Download from packages.wazuh.com with first parameter -curl -o $FILE https://packages.wazuh.com/4.x/wazuh-cert-tool.sh -var=`grep NoSuchKey $FILE` +## Check if the cert tool exists in S3 buckets +CERT_TOOL_PACKAGES=$(curl --silent -I $PACKAGES_URL$CERT_TOOL | grep -E "^HTTP" | awk '{print $2}') +CERT_TOOL_PACKAGES_DEV=$(curl --silent -I $PACKAGES_DEV_URL$CERT_TOOL | grep -E "^HTTP" | awk '{print $2}') -#If the content of the file contains NoSuchKey, download from packages-dev.wazuh.com -if [ ! -z "$var" ]; then - curl -o $FILE https://packages-dev.wazuh.com/4.3/wazuh-certs-tool.sh +## If cert tool exists in some bucket, download it, if not exit 1 +if [ "$CERT_TOOL_PACKAGES" = "200" ]; then + curl -o $CERT_TOOL $PACKAGES_URL$CERT_TOOL + echo "Cert tool exists in Packages bucket" +elif [ "$CERT_TOOL_PACKAGES_DEV" = "200" ]; then + curl -o $CERT_TOOL $PACKAGES_DEV_URL$CERT_TOOL + echo "Cert tool exists in Packages-dev bucket" +else + echo "Cert tool does not exist in any bucket" + echo "ERROR: certificates were not created" + exit 1 fi +chmod 700 /$CERT_TOOL + ############################################################################## # Creating Cluster certificates ############################################################################## -/wazuh-cert-tool.sh +/$CERT_TOOL echo "Moving created certificates to destination directory" cp /certs/* /certificates/ echo "changing certificate permissions" diff --git a/production_cluster/wazuh_indexer_ssl_certs/certs.yml b/production_cluster/wazuh_indexer_ssl_certs/certs.yml index 86f92925..984a96a2 100644 --- a/production_cluster/wazuh_indexer_ssl_certs/certs.yml +++ b/production_cluster/wazuh_indexer_ssl_certs/certs.yml @@ -10,7 +10,7 @@ nodes: # Wazuh server nodes # Use node_type only with more than one Wazuh manager - wazuh_servers: + server: name: wazuh.master ip: wazuh.master node_type: master diff --git a/wazuh-indexer/config/config.sh b/wazuh-indexer/config/config.sh index 5b858632..ab2d40cf 100644 --- a/wazuh-indexer/config/config.sh +++ b/wazuh-indexer/config/config.sh @@ -25,10 +25,48 @@ rm -rf ${INSTALLATION_DIR}/ curl -o ${INDEXER_FILE} https://packages.wazuh.com/stack/indexer/base/${BASE_FILE} tar -xf ${INDEXER_FILE} -curl -o wazuh-cert-tool.sh https://packages.wazuh.com/4.x/wazuh-cert-tool.sh -curl -o wazuh-password-tool.sh https://packages.wazuh.com/4.x/wazuh-passwords-tool.sh +## TOOLS -chmod 755 wazuh-cert-tool.sh && bash /wazuh-cert-tool.sh +## Variables +CERT_TOOL=wazuh-certs-tool.sh +PASSWORD_TOOL=wazuh-passwords-tool.sh +PACKAGES_URL=https://packages.wazuh.com/resources/4.3/ +PACKAGES_DEV_URL=https://packages-dev.wazuh.com/resources/4.3/ + +## Check if the cert tool exists in S3 buckets +CERT_TOOL_PACKAGES=$(curl --silent -I $PACKAGES_URL$CERT_TOOL | grep -E "^HTTP" | awk '{print $2}') +CERT_TOOL_PACKAGES_DEV=$(curl --silent -I $PACKAGES_DEV_URL$CERT_TOOL | grep -E "^HTTP" | awk '{print $2}') + +## If cert tool exists in some bucket, download it, if not exit 1 +if [ "$CERT_TOOL_PACKAGES" = "200" ]; then + curl -o $CERT_TOOL $PACKAGES_URL$CERT_TOOL + echo "Cert tool exists in Packages bucket" +elif [ "$CERT_TOOL_PACKAGES_DEV" = "200" ]; then + curl -o $CERT_TOOL $PACKAGES_DEV_URL$CERT_TOOL + echo "Cert tool exists in Packages-dev bucket" +else + echo "Cert tool does not exist in any bucket" + exit 1 +fi + + +## Check if the password tool exists in S3 buckets +PASSWORD_TOOL_PACKAGES=$(curl --silent -I $PACKAGES_URL$PASSWORD_TOOL | grep -E "^HTTP" | awk '{print $2}') +PASSWORD_TOOL_PACKAGES_DEV=$(curl --silent -I $PACKAGES_DEV_URL$PASSWORD_TOOL | grep -E "^HTTP" | awk '{print $2}') + +## If password tool exists in some bucket, download it, if not exit 1 +if [ "$PASSWORD_TOOL_PACKAGES" = "200" ]; then + curl -o $PASSWORD_TOOL $PACKAGES_URL$PASSWORD_TOOL + echo "Password tool exists in Packages bucket" +elif [ "$PASSWORD_TOOL_PACKAGES_DEV" = "200" ]; then + curl -o $PASSWORD_TOOL $PACKAGES_DEV_URL$PASSWORD_TOOL + echo "Password tool exists in Packages-dev bucket" +else + echo "Password tool does not exist in any bucket" + exit 1 +fi + +chmod 755 $CERT_TOOL && bash /$CERT_TOOL # copy to target mkdir -p ${TARGET_DIR}${INSTALLATION_DIR} @@ -52,8 +90,8 @@ rm -rf ${BASE_DIR}/usr # Copy installation files to final location cp -pr ${BASE_DIR}/* ${TARGET_DIR}${INSTALLATION_DIR} # Copy the security tools -cp /wazuh-cert-tool.sh ${TARGET_DIR}${INSTALLATION_DIR}/plugins/opensearch-security/tools/ -cp /wazuh-password-tool.sh ${TARGET_DIR}${INSTALLATION_DIR}/plugins/opensearch-security/tools/ +cp /$CERT_TOOL ${TARGET_DIR}${INSTALLATION_DIR}/plugins/opensearch-security/tools/ +cp /$PASSWORD_TOOL ${TARGET_DIR}${INSTALLATION_DIR}/plugins/opensearch-security/tools/ # Copy Wazuh's config files for the security plugin cp -pr /roles_mapping.yml ${TARGET_DIR}${INSTALLATION_DIR}/plugins/opensearch-security/securityconfig/ cp -pr /roles.yml ${TARGET_DIR}${INSTALLATION_DIR}/plugins/opensearch-security/securityconfig/ diff --git a/wazuh-manager/config/wazuh.repo b/wazuh-manager/config/wazuh.repo index ec15e1e3..e230d6a9 100644 --- a/wazuh-manager/config/wazuh.repo +++ b/wazuh-manager/config/wazuh.repo @@ -3,5 +3,5 @@ gpgcheck=1 gpgkey=https://packages.wazuh.com/key/GPG-KEY-WAZUH enabled=1 name=Wazuh repository -baseurl=https://packages.wazuh.com/pre-release/yum/ +baseurl=https://packages.wazuh.com/4.x/yum/ protect=1