Merge wazuh container from 3.10-refactor

This commit is contained in:
Manuel Gutierrez
2020-01-09 18:07:33 +01:00
parent 370c59dbe7
commit 6038525d4b
16 changed files with 102 additions and 153 deletions
+113
View File
@@ -0,0 +1,113 @@
#!/usr/bin/with-contenv bash
# Wazuh Docker Copyright (C) 2019 Wazuh Inc. (License GPLv2)
# Wazuh container bootstrap. See the README for information of the environment
# variables expected by this script.
# Startup the services
source /data_dirs.env
FIRST_TIME_INSTALLATION=true
WAZUH_INSTALL_PATH=/var/ossec
DATA_PATH=${WAZUH_INSTALL_PATH}/data
WAZUH_CONFIG_MOUNT=/wazuh-config-mount
print() {
echo -e $1
}
error_and_exit() {
echo "Error executing command: '$1'."
echo 'Exiting.'
exit 1
}
exec_cmd() {
eval $1 > /dev/null 2>&1 || error_and_exit "$1"
}
exec_cmd_stdout() {
eval $1 2>&1 || error_and_exit "$1"
}
edit_configuration() { # $1 -> setting, $2 -> value
sed -i "s/^config.$1\s=.*/config.$1 = \"$2\";/g" "${DATA_PATH}/api/configuration/config.js" || error_and_exit "sed (editing configuration)"
}
for ossecdir in "${DATA_DIRS[@]}"; do
if [ ! -e "${DATA_PATH}/${ossecdir}" ]
then
print "Installing ${ossecdir}"
exec_cmd "mkdir -p $(dirname ${DATA_PATH}/${ossecdir})"
exec_cmd "cp -pr /var/ossec/${ossecdir}-template ${DATA_PATH}/${ossecdir}"
FIRST_TIME_INSTALLATION=true
fi
done
if [ -e ${WAZUH_INSTALL_PATH}/etc-template ]
then
cp -p /var/ossec/etc-template/internal_options.conf /var/ossec/etc/internal_options.conf
fi
rm /var/ossec/queue/db/.template.db
touch ${DATA_PATH}/process_list
chgrp ossec ${DATA_PATH}/process_list
chmod g+rw ${DATA_PATH}/process_list
AUTO_ENROLLMENT_ENABLED=${AUTO_ENROLLMENT_ENABLED:-true}
API_GENERATE_CERTS=${API_GENERATE_CERTS:-true}
##############################################################################
# Copy all files from $WAZUH_CONFIG_MOUNT to $DATA_PATH and respect
# destination files permissions
#
# For example, to mount the file /var/ossec/data/etc/ossec.conf, mount it at
# $WAZUH_CONFIG_MOUNT/etc/ossec.conf in your container and this code will
# replace the ossec.conf file in /var/ossec/data/etc with yours.
##############################################################################
if [ -e "$WAZUH_CONFIG_MOUNT" ]
then
print "Identified Wazuh configuration files to mount..."
exec_cmd_stdout "cp --verbose -r $WAZUH_CONFIG_MOUNT/* $DATA_PATH"
else
print "No Wazuh configuration files to mount..."
fi
function ossec_shutdown(){
${WAZUH_INSTALL_PATH}/bin/ossec-control stop;
}
# Trap exit signals and do a proper shutdown
trap "ossec_shutdown; exit" SIGINT SIGTERM
chmod -R g+rw ${DATA_PATH}
##############################################################################
# Interpret any passed arguments (via docker command to this entrypoint) as
# paths or commands, and execute them.
#
# This can be useful for actions that need to be run before the services are
# started, such as "/var/ossec/bin/ossec-control enable agentless".
##############################################################################
for CUSTOM_COMMAND in "$@"
do
echo "Executing command \`${CUSTOM_COMMAND}\`"
exec_cmd_stdout "${CUSTOM_COMMAND}"
done
##############################################################################
# Change Wazuh API user credentials.
##############################################################################
pushd /var/ossec/api/configuration/auth/
env
echo "Change Wazuh API user credentials"
change_user="node htpasswd -b -c user $API_USER $API_PASS"
eval $change_user
popd
@@ -0,0 +1,31 @@
#!/usr/bin/with-contenv bash
# Wazuh App Copyright (C) 2019 Wazuh Inc. (License GPLv2)
set -e
WAZUH_FILEBEAT_MODULE=wazuh-filebeat-0.1.tar.gz
if [ "$ELASTICSEARCH_URL" != "" ]; then
>&2 echo "Customize Elasticsearch ouput IP"
sed -i 's|http://elasticsearch:9200|'$ELASTICSEARCH_URL'|g' /etc/filebeat/filebeat.yml
fi
# Configure filebeat.yml security settings
if [ "$SSL_CERTIFICATE_AUTHORITIES" != "" ]; then
>&2 echo "Configuring Certificate Authorities."
sed -i 's|#ssl.certificate_authorities:|'ssl.certificate_authorities:\ [\"$SSL_CERTIFICATE_AUTHORITIES\"]'|g' /etc/filebeat/filebeat.yml
fi
if [ "$USERNAME" != "" ]; then
>&2 echo "Configuring username."
sed -i 's|#username:|'username:\ \"$USERNAME\"'|g' /etc/filebeat/filebeat.yml
fi
if [ "$PASSWORD" != "" ]; then
>&2 echo "Configuring password."
sed -i 's|#password:|'password:\ \"$PASSWORD\"'|g' /etc/filebeat/filebeat.yml
fi
chmod go-w /etc/filebeat/filebeat.yml || true
chown root: /etc/filebeat/filebeat.yml || true
+3
View File
@@ -0,0 +1,3 @@
#!/usr/bin/with-contenv bash
/var/ossec/bin/ossec-control start
+6
View File
@@ -0,0 +1,6 @@
#!/usr/bin/env sh
echo >&2 "API exited. code=${1}"
# terminate other services to exit from the container
exec s6-svscanctl -t /var/run/s6/services
+4
View File
@@ -0,0 +1,4 @@
#!/usr/bin/with-contenv sh
echo >&2 "starting API"
exec /bin/node /var/ossec/api/app.js
@@ -0,0 +1,6 @@
#!/usr/bin/env sh
echo >&2 "Filebeat exited. code=${1}"
# terminate other services to exit from the container
exec s6-svscanctl -t /var/run/s6/services
+4
View File
@@ -0,0 +1,4 @@
#!/usr/bin/with-contenv sh
echo >&2 "starting Filebeat"
exec /usr/share/filebeat/bin/filebeat -e -c /etc/filebeat/filebeat.yml -path.home /usr/share/filebeat -path.config /etc/filebeat -path.data /var/lib/filebeat -path.logs /var/log/filebeat