forked from wazuh/wazuh-docker
Elastic 7-x cloud adaption (#255)
This commit is contained in:
committed by
Jesús Linares
parent
7a8b332c93
commit
6d9595327d
+17
-13
@@ -1,8 +1,9 @@
|
||||
# Wazuh App Copyright (C) 2019 Wazuh Inc. (License GPLv2)
|
||||
FROM docker.elastic.co/elasticsearch/elasticsearch:6.8.2
|
||||
# Wazuh Docker Copyright (C) 2019 Wazuh Inc. (License GPLv2)
|
||||
ARG ELASTIC_VERSION=7.2.1
|
||||
FROM docker.elastic.co/elasticsearch/elasticsearch:${ELASTIC_VERSION}
|
||||
ARG TEMPLATE_VERSION=v3.9.5
|
||||
|
||||
ENV ALERTS_SHARDS="1" \
|
||||
ALERTS_REPLICAS="0"
|
||||
ENV ELASTICSEARCH_URL="http://elasticsearch:9200"
|
||||
|
||||
ENV API_USER="foo" \
|
||||
API_PASS="bar"
|
||||
@@ -11,8 +12,10 @@ ENV XPACK_ML="true"
|
||||
|
||||
ENV ENABLE_CONFIGURE_S3="false"
|
||||
|
||||
ENV TEMPLATE_VERSION=v3.9.4
|
||||
ENV WAZUH_ALERTS_SHARDS="1" \
|
||||
WAZUH_ALERTS_REPLICAS="0"
|
||||
|
||||
ADD https://raw.githubusercontent.com/wazuh/wazuh/$TEMPLATE_VERSION/extensions/elasticsearch/7.x/wazuh-template.json /usr/share/elasticsearch/config
|
||||
|
||||
# This CA is created for testing. Please set your own CA zip containing the key and the signed certificate.
|
||||
# command: $ docker build <elasticsearch_directory> --build-arg SECURITY_CA_PEM_LOCATION=<CA_PEM_LOCATION> --build-arg SECURITY_CA_KEY_LOCATION=<CA_KEY_LOCATION>
|
||||
@@ -29,19 +32,19 @@ ARG SECURITY_CA_TRUST_LOCATION=""
|
||||
|
||||
# Elasticearch cluster configuration environment variables
|
||||
# If ELASTIC_CLUSTER is set to "true" the following variables will be added to the Elasticsearch configuration
|
||||
# CLUSTER_INITIAL_MASTER_NODES set to own node by default.
|
||||
ENV ELASTIC_CLUSTER="false" \
|
||||
CLUSTER_NAME="wazuh" \
|
||||
CLUSTER_NODE_MASTER="true" \
|
||||
CLUSTER_NODE_MASTER="false" \
|
||||
CLUSTER_NODE_DATA="true" \
|
||||
CLUSTER_NODE_INGEST="true" \
|
||||
CLUSTER_NODE_NAME="wazuh-elasticsearch" \
|
||||
CLUSTER_MEMORY_LOCK="true" \
|
||||
CLUSTER_DISCOVERY_SERVICE="wazuh-elasticsearch" \
|
||||
CLUSTER_NUMBER_OF_MASTERS="2" \
|
||||
CLUSTER_MAX_NODES="1" \
|
||||
CLUSTER_DELAYED_TIMEOUT="1m"
|
||||
|
||||
ADD https://raw.githubusercontent.com/wazuh/wazuh/$TEMPLATE_VERSION/extensions/elasticsearch/6.x/wazuh-template.json /usr/share/elasticsearch/config
|
||||
CLUSTER_DELAYED_TIMEOUT="1m" \
|
||||
CLUSTER_INITIAL_MASTER_NODES="wazuh-elasticsearch" \
|
||||
CLUSTER_DISCOVERY_SEED="elasticsearch"
|
||||
|
||||
# CA cert for Transport SSL
|
||||
ADD $SECURITY_CA_PEM_LOCATION /usr/share/elasticsearch/config
|
||||
@@ -49,7 +52,8 @@ ADD $SECURITY_CA_KEY_LOCATION /usr/share/elasticsearch/config
|
||||
ADD $SECURITY_OPENSSL_CONF_LOCATION /usr/share/elasticsearch/config
|
||||
ADD $SECURITY_CA_TRUST_LOCATION /usr/share/elasticsearch/config
|
||||
|
||||
RUN yum install openssl -y
|
||||
RUN yum install openssl -y && \
|
||||
yum install unzip -y
|
||||
|
||||
RUN mkdir /entrypoint-scripts
|
||||
|
||||
@@ -61,7 +65,7 @@ COPY --chown=elasticsearch:elasticsearch ./config/load_settings.sh ./
|
||||
|
||||
RUN chmod +x ./load_settings.sh
|
||||
|
||||
RUN bin/elasticsearch-plugin install --batch https://artifacts.elastic.co/downloads/elasticsearch-plugins/repository-s3/repository-s3-6.8.2.zip
|
||||
RUN bin/elasticsearch-plugin install repository-s3 -b
|
||||
|
||||
COPY config/configure_s3.sh ./config/configure_s3.sh
|
||||
RUN chmod 755 ./config/configure_s3.sh
|
||||
@@ -70,7 +74,7 @@ COPY --chown=elasticsearch:elasticsearch ./config/10-config_cluster.sh /entrypoi
|
||||
RUN chmod +x /entrypoint-scripts/10-config_cluster.sh
|
||||
|
||||
COPY --chown=elasticsearch:elasticsearch ./config/20-config_secure.sh /entrypoint-scripts/20-config_secure.sh
|
||||
RUN chmod +x /entrypoint-scripts/10-config_cluster.sh
|
||||
RUN chmod +x /entrypoint-scripts/20-config_cluster.sh
|
||||
|
||||
COPY --chown=elasticsearch:elasticsearch ./config/30-entrypoint.sh /entrypoint-scripts/30-entrypoint.sh
|
||||
RUN chmod +x /entrypoint-scripts/30-entrypoint.sh
|
||||
|
||||
@@ -1,36 +1,93 @@
|
||||
#!/bin/bash
|
||||
# Wazuh App Copyright (C) 2019 Wazuh Inc. (License GPLv2)
|
||||
# Wazuh Docker Copyright (C) 2019 Wazuh Inc. (License GPLv2)
|
||||
|
||||
elastic_config_file="/usr/share/elasticsearch/config/elasticsearch.yml"
|
||||
|
||||
original_file="/usr/share/elasticsearch/config/original-elasticsearch.yml"
|
||||
ELASTIC_HOSTAME=`hostname`
|
||||
|
||||
echo "CLUSTER: - Prepare Configuration"
|
||||
echo "CLUSTER: - Hostname"
|
||||
echo $ELASTIC_HOSTAME
|
||||
echo "CLUSTER: - Security main node"
|
||||
echo $SECURITY_MAIN_NODE
|
||||
echo "CLUSTER: - Discovery seed"
|
||||
echo $CLUSTER_DISCOVERY_SEED
|
||||
echo "CLUSTER: - Elastic cluster flag"
|
||||
echo $ELASTIC_CLUSTER
|
||||
echo "CLUSTER: - Node Master"
|
||||
echo $CLUSTER_NODE_MASTER
|
||||
echo "CLUSTER: - Node Data"
|
||||
echo $CLUSTER_NODE_DATA
|
||||
echo "CLUSTER: - Node Ingest"
|
||||
echo $CLUSTER_NODE_INGEST
|
||||
|
||||
cp $elastic_config_file $original_file
|
||||
|
||||
# If Elasticsearch cluster is enable
|
||||
if [[ $ELASTIC_CLUSTER == "true" ]]
|
||||
then
|
||||
|
||||
# Set the cluster.name and discovery.zen.minimun_master_nodes variables
|
||||
sed -i 's:cluster.name\: "docker-cluster":cluster.name\: "'$CLUSTER_NAME'":g' $elastic_config_file
|
||||
remove_single_node_conf(){
|
||||
if grep -Fq "discovery.type" $1; then
|
||||
sed -i '/discovery.type\: /d' $1
|
||||
fi
|
||||
}
|
||||
|
||||
# Add the cluster configuration
|
||||
echo "
|
||||
#cluster node
|
||||
node:
|
||||
master: ${CLUSTER_NODE_MASTER}
|
||||
data: ${CLUSTER_NODE_DATA}
|
||||
ingest: ${CLUSTER_NODE_INGEST}
|
||||
name: ${CLUSTER_NODE_NAME}
|
||||
max_local_storage_nodes: ${CLUSTER_MAX_NODES}
|
||||
remove_cluster_config(){
|
||||
sed -i '/# cluster node/,/# end cluster config/d' $1
|
||||
}
|
||||
|
||||
bootstrap:
|
||||
memory_lock: ${CLUSTER_MEMORY_LOCK}
|
||||
# If Elasticsearch cluster is enable, then set up the elasticsearch.yml
|
||||
if [[ $ELASTIC_CLUSTER == "true" && $CLUSTER_NODE_MASTER != "" && $CLUSTER_NODE_DATA != "" && $CLUSTER_NODE_INGEST != "" && $ELASTIC_HOSTAME != "" ]]; then
|
||||
# Remove the old configuration
|
||||
remove_single_node_conf $elastic_config_file
|
||||
remove_cluster_config $elastic_config_file
|
||||
echo "CLUSTER: - Remove old configuration"
|
||||
|
||||
discovery:
|
||||
zen:
|
||||
ping.unicast.hosts: ${CLUSTER_DISCOVERY_SERVICE}
|
||||
minimum_master_nodes: ${CLUSTER_NUMBER_OF_MASTERS}
|
||||
|
||||
" >> $elastic_config_file
|
||||
if [[ $ELASTIC_HOSTAME == $SECURITY_MAIN_NODE ]]; then
|
||||
# Add the master configuration
|
||||
# cluster.initial_master_nodes for bootstrap the cluster
|
||||
echo "CLUSTER: - Add the master configuration"
|
||||
|
||||
cat > $elastic_config_file << EOF
|
||||
# cluster node
|
||||
cluster.name: $CLUSTER_NAME
|
||||
bootstrap.memory_lock: $CLUSTER_MEMORY_LOCK
|
||||
network.host: 0.0.0.0
|
||||
node.name: $ELASTIC_HOSTAME
|
||||
node.master: $CLUSTER_NODE_MASTER
|
||||
node.data: $CLUSTER_NODE_DATA
|
||||
node.ingest: $CLUSTER_NODE_INGEST
|
||||
node.max_local_storage_nodes: $CLUSTER_MAX_NODES
|
||||
cluster.initial_master_nodes:
|
||||
- $ELASTIC_HOSTAME
|
||||
# end cluster config"
|
||||
EOF
|
||||
|
||||
elif [[ $CLUSTER_DISCOVERY_SEED != "" ]]; then
|
||||
# Remove the old configuration
|
||||
remove_single_node_conf $elastic_config_file
|
||||
remove_cluster_config $elastic_config_file
|
||||
echo "CLUSTER: - Add standard cluster configuration."
|
||||
|
||||
cat > $elastic_config_file << EOF
|
||||
# cluster node
|
||||
cluster.name: $CLUSTER_NAME
|
||||
bootstrap.memory_lock: $CLUSTER_MEMORY_LOCK
|
||||
network.host: 0.0.0.0
|
||||
node.name: $ELASTIC_HOSTAME
|
||||
node.master: $CLUSTER_NODE_MASTER
|
||||
node.data: $CLUSTER_NODE_DATA
|
||||
node.ingest: $CLUSTER_NODE_INGEST
|
||||
node.max_local_storage_nodes: $CLUSTER_MAX_NODES
|
||||
discovery.seed_hosts:
|
||||
- $CLUSTER_DISCOVERY_SEED
|
||||
# end cluster config"
|
||||
EOF
|
||||
fi
|
||||
# If the cluster is disabled, then set a single-node configuration
|
||||
else
|
||||
# Remove the old configuration
|
||||
remove_single_node_conf $elastic_config_file
|
||||
remove_cluster_config $elastic_config_file
|
||||
echo "discovery.type: single-node" >> $elastic_config_file
|
||||
echo "CLUSTER: - Discovery type: single-node"
|
||||
fi
|
||||
|
||||
echo "CLUSTER: - Configured"
|
||||
@@ -16,14 +16,21 @@ if [[ $SECURITY_ENABLED == "yes" ]]; then
|
||||
|
||||
echo "Setting configuration options."
|
||||
|
||||
ELASTIC_HOSTNAME=`hostname`
|
||||
POD_DNS="$ELASTIC_HOSTNAME.$NAMESPACE.pod.cluster.local"
|
||||
SVC_DNS="elasticsearch.$NAMESPACE.svc.cluster.local"
|
||||
|
||||
# Create instances.yml for elasticsearch .p12 certificate and key
|
||||
echo "
|
||||
instances:
|
||||
- name: \"elasticsearch\"
|
||||
dns:
|
||||
- $SECURITY_CERTIFICATE_DNS
|
||||
dns:
|
||||
- \"$POD_DNS\"
|
||||
- \"$SVC_DNS\"
|
||||
" > instances.yml
|
||||
|
||||
cp instances.yml /usr/share/elasticsearch
|
||||
|
||||
# Change permissions and owner of ca
|
||||
chown elasticsearch: /usr/share/elasticsearch/config/$SECURITY_CA_PEM
|
||||
chmod 440 /usr/share/elasticsearch/config/$SECURITY_CA_PEM
|
||||
@@ -32,6 +39,7 @@ instances:
|
||||
# Genereate .p12 certificate and key
|
||||
SECURITY_KEY_PASSPHRASE=`date +%s | sha256sum | base64 | head -c 32 ; echo`
|
||||
/usr/share/elasticsearch/bin/elasticsearch-certutil csr --in instances.yml --out certs.zip --pass $SECURITY_KEY_PASSPHRASE
|
||||
mv /usr/share/elasticsearch/certs.zip /usr/share/elasticsearch/config/certs.zip
|
||||
unzip certs.zip
|
||||
rm certs.zip
|
||||
|
||||
@@ -108,4 +116,3 @@ xpack.security.http.ssl.certificate_authorities: [\"/usr/share/elasticsearch/con
|
||||
echo -e "$SECURITY_KEY_PASSPHRASE" | /usr/share/elasticsearch/bin/elasticsearch-keystore add xpack.security.http.ssl.secure_key_passphrase --stdin
|
||||
|
||||
fi
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#!/bin/bash
|
||||
# Wazuh Docker Copyright (C) 2019 Wazuh Inc. (License GPLv2)
|
||||
|
||||
set -e
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#!/bin/bash
|
||||
# Wazuh App Copyright (C) 2019 Wazuh Inc. (License GPLv2)
|
||||
# Wazuh Docker Copyright (C) 2019 Wazuh Inc. (License GPLv2)
|
||||
|
||||
# It will run every .sh script located in entrypoint-scripts folder in lexicographical order
|
||||
for script in `ls /entrypoint-scripts/*.sh | sort -n`; do
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#!/bin/bash
|
||||
# Wazuh App Copyright (C) 2019 Wazuh Inc. (License GPLv2)
|
||||
# Wazuh Docker Copyright (C) 2019 Wazuh Inc. (License GPLv2)
|
||||
|
||||
set -e
|
||||
|
||||
@@ -84,7 +84,7 @@ fi
|
||||
|
||||
if [ ${SECURITY_ENABLED} != "no" ]; then
|
||||
auth="-uelastic:${ELASTIC_PASS} -k"
|
||||
elif [ ${ENABLED_XPACK} != "true" || "x${ELASTICSEARCH_USERNAME}" = "x" || "x${ELASTICSEARCH_PASSWORD}" = "x" ]; then
|
||||
elif [[ ${ENABLED_XPACK} != "true" || "x${ELASTICSEARCH_USERNAME}" = "x" || "x${ELASTICSEARCH_PASSWORD}" = "x" ]]; then
|
||||
auth=""
|
||||
else
|
||||
auth="--user ${ELASTICSEARCH_USERNAME}:${ELASTICSEARCH_PASSWORD}"
|
||||
@@ -160,22 +160,24 @@ if [[ $SECURITY_ENABLED == "yes" ]]; then
|
||||
fi
|
||||
fi
|
||||
|
||||
#Insert default templates
|
||||
|
||||
sed -i 's| "index.refresh_interval": "5s"| "index.refresh_interval": "5s", "number_of_shards" : '"${ALERTS_SHARDS}"', "number_of_replicas" : '"${ALERTS_REPLICAS}"'|' /usr/share/elasticsearch/config/wazuh-template.json
|
||||
# Modify wazuh-alerts template shards and replicas
|
||||
sed -i 's:"index.number_of_shards"\: "3":"index.number_of_shards"\: "'$WAZUH_ALERTS_SHARDS'":g' /usr/share/elasticsearch/config/wazuh-template.json
|
||||
sed -i 's:"index.number_of_replicas"\: "0":"index.number_of_replicas"\: "'$WAZUH_ALERTS_REPLICAS'":g' /usr/share/elasticsearch/config/wazuh-template.json
|
||||
|
||||
# Insert default templates
|
||||
cat /usr/share/elasticsearch/config/wazuh-template.json | curl -XPUT "$el_url/_template/wazuh" ${auth} -H 'Content-Type: application/json' -d @-
|
||||
sleep 5
|
||||
|
||||
|
||||
# Prepare Wazuh API credentials
|
||||
API_PASS_Q=`echo "$WAZH_API_PASS" | tr -d '"'`
|
||||
API_USER_Q=`echo "$WAZH_API_USER" | tr -d '"'`
|
||||
API_PASSWORD=`echo -n $API_PASS_Q | base64`
|
||||
|
||||
echo "Setting API credentials into Wazuh APP"
|
||||
CONFIG_CODE=$(curl -s -o /dev/null -w "%{http_code}" -XGET $el_url/.wazuh/wazuh-configuration/1513629884013 ${auth})
|
||||
if [ "x$CONFIG_CODE" = "x404" ]; then
|
||||
curl -s -XPOST $el_url/.wazuh/wazuh-configuration/1513629884013 ${auth} -H 'Content-Type: application/json' -d'
|
||||
CONFIG_CODE=$(curl -s -o /dev/null -w "%{http_code}" -XGET $el_url/.wazuh/_doc/1513629884013 ${auth})
|
||||
|
||||
if [ "x$CONFIG_CODE" != "x200" ]; then
|
||||
curl -s -XPOST $el_url/.wazuh/_doc/1513629884013 ${auth} -H 'Content-Type: application/json' -d'
|
||||
{
|
||||
"api_user": "'"$API_USER_Q"'",
|
||||
"api_password": "'"$API_PASSWORD"'",
|
||||
|
||||
Reference in New Issue
Block a user