Нема описа

entrypoint.sh 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #!/usr/bin/env bash
  2. # Wazuh Docker Copyright (C) 2017, Wazuh Inc. (License GPLv2)
  3. set -e
  4. umask 0002
  5. export USER=wazuh-indexer
  6. export INSTALLATION_DIR=/usr/share/wazuh-indexer
  7. export OPENSEARCH_PATH_CONF=${INSTALLATION_DIR}/config
  8. export JAVA_HOME=${INSTALLATION_DIR}/jdk
  9. export DISCOVERY=$(grep -oP "(?<=discovery.type: ).*" ${OPENSEARCH_PATH_CONF}/opensearch.yml)
  10. export CACERT=$(grep -oP "(?<=plugins.security.ssl.transport.pemtrustedcas_filepath: ).*" ${OPENSEARCH_PATH_CONF}/opensearch.yml)
  11. export CERT="${OPENSEARCH_PATH_CONF}/certs/admin.pem"
  12. export KEY="${OPENSEARCH_PATH_CONF}/certs/admin-key.pem"
  13. run_as_other_user_if_needed() {
  14. if [[ "$(id -u)" == "0" ]]; then
  15. # If running as root, drop to specified UID and run command
  16. exec chroot --userspec=1000:0 / "${@}"
  17. else
  18. # Either we are running in Openshift with random uid and are a member of the root group
  19. # or with a custom --user
  20. exec "${@}"
  21. fi
  22. }
  23. # Allow user specify custom CMD, maybe bin/opensearch itself
  24. # for example to directly specify `-E` style parameters for opensearch on k8s
  25. # or simply to run /bin/bash to check the image
  26. if [[ "$1" != "opensearchwrapper" ]]; then
  27. if [[ "$(id -u)" == "0" && $(basename "$1") == "opensearch" ]]; then
  28. # Rewrite CMD args to replace $1 with `opensearch` explicitly,
  29. # Without this, user could specify `opensearch -E x.y=z` but
  30. # `bin/opensearch -E x.y=z` would not work.
  31. set -- "opensearch" "${@:2}"
  32. # Use chroot to switch to UID 1000 / GID 0
  33. exec chroot --userspec=1000:0 / "$@"
  34. else
  35. # User probably wants to run something else, like /bin/bash, with another uid forced (Openshift?)
  36. exec "$@"
  37. fi
  38. fi
  39. # Allow environment variables to be set by creating a file with the
  40. # contents, and setting an environment variable with the suffix _FILE to
  41. # point to it. This can be used to provide secrets to a container, without
  42. # the values being specified explicitly when running the container.
  43. #
  44. # This is also sourced in opensearch-env, and is only needed here
  45. # as well because we use INDEXER_PASSWORD below. Sourcing this script
  46. # is idempotent.
  47. source /usr/share/wazuh-indexer/bin/opensearch-env-from-file
  48. if [[ -f bin/opensearch-users ]]; then
  49. # Check for the INDEXER_PASSWORD environment variable to set the
  50. # bootstrap password for Security.
  51. #
  52. # This is only required for the first node in a cluster with Security
  53. # enabled, but we have no way of knowing which node we are yet. We'll just
  54. # honor the variable if it's present.
  55. if [[ -n "$INDEXER_PASSWORD" ]]; then
  56. [[ -f /usr/share/wazuh-indexer/opensearch.keystore ]] || (run_as_other_user_if_needed opensearch-keystore create)
  57. if ! (run_as_other_user_if_needed opensearch-keystore has-passwd --silent) ; then
  58. # keystore is unencrypted
  59. if ! (run_as_other_user_if_needed opensearch-keystore list | grep -q '^bootstrap.password$'); then
  60. (run_as_other_user_if_needed echo "$INDEXER_PASSWORD" | opensearch-keystore add -x 'bootstrap.password')
  61. fi
  62. else
  63. # keystore requires password
  64. if ! (run_as_other_user_if_needed echo "$KEYSTORE_PASSWORD" \
  65. | opensearch-keystore list | grep -q '^bootstrap.password$') ; then
  66. COMMANDS="$(printf "%s\n%s" "$KEYSTORE_PASSWORD" "$INDEXER_PASSWORD")"
  67. (run_as_other_user_if_needed echo "$COMMANDS" | opensearch-keystore add -x 'bootstrap.password')
  68. fi
  69. fi
  70. fi
  71. fi
  72. if [[ "$(id -u)" == "0" ]]; then
  73. # If requested and running as root, mutate the ownership of bind-mounts
  74. if [[ -n "$TAKE_FILE_OWNERSHIP" ]]; then
  75. chown -R 1000:0 /usr/share/wazuh-indexer/{data,logs}
  76. fi
  77. fi
  78. #if [[ "$DISCOVERY" == "single-node" ]] && [[ ! -f "/var/lib/wazuh-indexer/.flag" ]]; then
  79. # run securityadmin.sh for single node with CACERT, CERT and KEY parameter
  80. # nohup /securityadmin.sh &
  81. # touch "/var/lib/wazuh-indexer/.flag"
  82. #fi
  83. run_as_other_user_if_needed /usr/share/wazuh-indexer/bin/opensearch <<<"$KEYSTORE_PASSWORD"