No Description

entrypoint.sh 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #!/bin/bash
  2. # Wazuh Docker Copyright (C) 2017, Wazuh Inc. (License GPLv2)
  3. ##############################################################################
  4. # Downloading Cert Gen Tool
  5. ##############################################################################
  6. ## Variables
  7. CERT_TOOL=wazuh-certs-tool.sh
  8. PASSWORD_TOOL=wazuh-passwords-tool.sh
  9. PACKAGES_URL=https://packages.wazuh.com/$CERT_TOOL_VERSION/
  10. PACKAGES_DEV_URL=https://packages-dev.wazuh.com/$CERT_TOOL_VERSION/
  11. OUTPUT_FILE="/$CERT_TOOL"
  12. download_package() {
  13. local url=$1
  14. echo "Checking $url$CERT_TOOL ..."
  15. if curl -fsL "$url$CERT_TOOL" -o "$OUTPUT_FILE"; then
  16. echo "Downloaded $CERT_TOOL from $url"
  17. return 0
  18. else
  19. return 1
  20. fi
  21. }
  22. # Try first the prod URL, if it fails try the dev URL
  23. if download_package "$PACKAGES_URL"; then
  24. :
  25. elif download_package "$PACKAGES_DEV_URL"; then
  26. :
  27. else
  28. echo "The tool to create the certificates does not exist in any bucket"
  29. echo "ERROR: certificates were not created"
  30. exit 1
  31. fi
  32. cp /config/certs.yml /config.yml
  33. chmod 700 "$OUTPUT_FILE"
  34. ##############################################################################
  35. # Creating Cluster certificates
  36. ##############################################################################
  37. ## Execute cert tool and parsin cert.yml to set UID permissions
  38. source /$CERT_TOOL -A
  39. nodes_server=$( cert_parseYaml /config.yml | grep -E "nodes[_]+server[_]+[0-9]+=" | sed -e 's/nodes__server__[0-9]=//' | sed 's/"//g' )
  40. node_names=($nodes_server)
  41. echo "Moving created certificates to the destination directory"
  42. cp /wazuh-certificates/* /certificates/
  43. echo "Changing certificate permissions"
  44. chmod -R 500 /certificates
  45. chmod -R 400 /certificates/*
  46. echo "Setting UID indexer and dashboard"
  47. chown 1000:1000 /certificates/*
  48. echo "Setting UID for wazuh manager and worker"
  49. cp /certificates/root-ca.pem /certificates/root-ca-manager.pem
  50. cp /certificates/root-ca.key /certificates/root-ca-manager.key
  51. chown 999:999 /certificates/root-ca-manager.pem
  52. chown 999:999 /certificates/root-ca-manager.key
  53. for i in ${node_names[@]};
  54. do
  55. chown 999:999 "/certificates/${i}.pem"
  56. chown 999:999 "/certificates/${i}-key.pem"
  57. done