Keine Beschreibung

2-manager 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. #!/usr/bin/with-contenv bash
  2. ##############################################################################
  3. # Migration sequence
  4. # Detect if there is a mounted volume on /wazuh-migration and copy the data
  5. # to /var/ossec, finally it will create a flag ".migration-completed" inside
  6. # the mounted volume
  7. ##############################################################################
  8. function __colortext()
  9. {
  10. echo -e " \e[1;$2m$1\e[0m"
  11. }
  12. function echogreen()
  13. {
  14. echo $(__colortext "$1" "32")
  15. }
  16. function echoyellow()
  17. {
  18. echo $(__colortext "$1" "33")
  19. }
  20. function echored()
  21. {
  22. echo $(__colortext "$1" "31")
  23. }
  24. function_wazuh_migration(){
  25. if [ -d "/wazuh-migration" ]; then
  26. if [ ! -e /wazuh-migration/.migration-completed ]; then
  27. if [ ! -e /wazuh-migration/global.db ]; then
  28. echoyellow "The volume mounted on /wazuh-migration does not contain all the correct files."
  29. return
  30. fi
  31. \cp -f /wazuh-migration/data/etc/ossec.conf /var/ossec/etc/ossec.conf
  32. chown root:wazuh /var/ossec/etc/ossec.conf
  33. chmod 640 /var/ossec/etc/ossec.conf
  34. \cp -f /wazuh-migration/data/etc/client.keys /var/ossec/etc/client.keys
  35. chown wazuh:wazuh /var/ossec/etc/client.keys
  36. chmod 640 /var/ossec/etc/client.keys
  37. \cp -f /wazuh-migration/data/etc/sslmanager.cert /var/ossec/etc/sslmanager.cert
  38. \cp -f /wazuh-migration/data/etc/sslmanager.key /var/ossec/etc/sslmanager.key
  39. chown root:root /var/ossec/etc/sslmanager.cert /var/ossec/etc/sslmanager.key
  40. chmod 640 /var/ossec/etc/sslmanager.cert /var/ossec/etc/sslmanager.key
  41. \cp -f /wazuh-migration/data/etc/shared/default/agent.conf /var/ossec/etc/shared/default/agent.conf
  42. chown wazuh:wazuh /var/ossec/etc/shared/default/agent.conf
  43. chmod 660 /var/ossec/etc/shared/default/agent.conf
  44. \cp -f /wazuh-migration/data/etc/decoders/* /var/ossec/etc/decoders/
  45. chown wazuh:wazuh /var/ossec/etc/decoders/*
  46. chmod 660 /var/ossec/etc/decoders/*
  47. \cp -f /wazuh-migration/data/etc/rules/* /var/ossec/etc/rules/
  48. chown wazuh:wazuh /var/ossec/etc/rules/*
  49. chmod 660 /var/ossec/etc/rules/*
  50. if [ -e /wazuh-migration/data/agentless/.passlist ]; then
  51. \cp -f /wazuh-migration/data/agentless/.passlist /var/ossec/agentless/.passlist
  52. chown root:wazuh /var/ossec/agentless/.passlist
  53. chmod 640 /var/ossec/agentless/.passlist
  54. fi
  55. \cp -f /wazuh-migration/global.db /var/ossec/queue/db/global.db
  56. chown wazuh:wazuh /var/ossec/queue/db/global.db
  57. chmod 640 /var/ossec/queue/db/global.db
  58. # mark volume as migrated
  59. touch /wazuh-migration/.migration-completed
  60. echogreen "Migration completed succesfully"
  61. else
  62. echoyellow "This volume has already been migrated. You may proceed and remove it from the mount point (/wazuh-migration)"
  63. fi
  64. fi
  65. }
  66. function_create_custom_user() {
  67. if [[ ! -z $API_USERNAME ]] && [[ ! -z $API_PASSWORD ]]; then
  68. cat << EOF > /var/ossec/api/configuration/admin.json
  69. {
  70. "username": "$API_USERNAME",
  71. "password": "$API_PASSWORD"
  72. }
  73. EOF
  74. # create or customize API user
  75. if /var/ossec/framework/python/bin/python3 /var/ossec/framework/scripts/create_user.py; then
  76. # remove json if exit code is 0
  77. rm /var/ossec/api/configuration/admin.json
  78. else
  79. echored "There was an error configuring the API user"
  80. # terminate container to avoid unpredictable behavior
  81. exec s6-svscanctl -t /var/run/s6/services
  82. exit 1
  83. fi
  84. fi
  85. }
  86. function_entrypoint_scripts() {
  87. # It will run every .sh script located in entrypoint-scripts folder in lexicographical order
  88. if [ -d "/entrypoint-scripts/" ]
  89. then
  90. for script in `ls /entrypoint-scripts/*.sh | sort -n`; do
  91. bash "$script"
  92. done
  93. fi
  94. }
  95. function_configure_vulnerability_detection() {
  96. if [ "$INDEXER_PASSWORD" != "" ]; then
  97. >&2 echo "Configuring password."
  98. echo "$INDEXER_USERNAME" | /var/ossec/bin/wazuh-keystore -f indexer -k username
  99. echo "$INDEXER_PASSWORD" | /var/ossec/bin/wazuh-keystore -f indexer -k password
  100. fi
  101. }
  102. # Migrate data from /wazuh-migration volume
  103. function_wazuh_migration
  104. # create API custom user
  105. function_create_custom_user
  106. # configure Vulnerabilty detection
  107. function_configure_vulnerability_detection
  108. # run entrypoint scripts
  109. function_entrypoint_scripts
  110. # Start Wazuh
  111. /var/ossec/bin/wazuh-control start