From 89e6af0d9ad1b336398f148e89a393454c37d405 Mon Sep 17 00:00:00 2001 From: manuasir Date: Tue, 12 Feb 2019 17:10:46 +0100 Subject: [PATCH] Added authorization to every Elastic request --- elasticsearch/config/load_settings.sh | 8 ++++---- kibana/config/entrypoint.sh | 8 +++++++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/elasticsearch/config/load_settings.sh b/elasticsearch/config/load_settings.sh index d41b5cf9..d78d0f17 100644 --- a/elasticsearch/config/load_settings.sh +++ b/elasticsearch/config/load_settings.sh @@ -21,7 +21,7 @@ else auth="--user ${ELASTICSEARCH_USERNAME}:${ELASTICSEARCH_PASSWORD}" fi -until curl -XGET $el_url; do +until curl ${auth} -XGET $el_url; do >&2 echo "Elastic is unavailable - sleeping" sleep 5 done @@ -41,9 +41,9 @@ API_USER_Q=`echo "$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) +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 ${auth} $el_url/.wazuh/wazuh-configuration/1513629884013 -H 'Content-Type: application/json' -d' + curl -s -XPOST $el_url/.wazuh/wazuh-configuration/1513629884013 ${auth} -H 'Content-Type: application/json' -d' { "api_user": "'"$API_USER_Q"'", "api_password": "'"$API_PASSWORD"'", @@ -72,7 +72,7 @@ else fi sleep 5 -curl -XPUT "$el_url/_cluster/settings" -H 'Content-Type: application/json' -d' +curl -XPUT "$el_url/_cluster/settings" ${auth} -H 'Content-Type: application/json' -d' { "persistent": { "xpack.monitoring.collection.enabled": true diff --git a/kibana/config/entrypoint.sh b/kibana/config/entrypoint.sh index e34029b7..e612bbb3 100644 --- a/kibana/config/entrypoint.sh +++ b/kibana/config/entrypoint.sh @@ -9,7 +9,13 @@ else el_url="${ELASTICSEARCH_URL}" fi -until curl -XGET $el_url; do +if [ "x${ELASTICSEARCH_USERNAME}" = "x"]; then + auth="" +else + auth="--user ${ELASTICSEARCH_USERNAME}:${ELASTICSEARCH_PASSWORD}" +fi + +until curl -XGET $el_url ${auth}; do >&2 echo "Elastic is unavailable - sleeping" sleep 5 done