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
@@ -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