From 715fb4fdec219c7c8c9826436be6b40292175e56 Mon Sep 17 00:00:00 2001 From: toniMR Date: Fri, 22 Mar 2019 09:52:37 +0100 Subject: [PATCH 1/4] Adding NGINX_CREDENTIALS in nginx/config/entrypoint.sh --- nginx/config/entrypoint.sh | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/nginx/config/entrypoint.sh b/nginx/config/entrypoint.sh index a6eeec9e..ca661412 100644 --- a/nginx/config/entrypoint.sh +++ b/nginx/config/entrypoint.sh @@ -1,5 +1,5 @@ -#!/bin/sh -# Wazuh App Copyright (C) 2019 Wazuh Inc. (License GPLv2) +#!/bin/bash +# Wazuh App Copyright (C) 2018 Wazuh Inc. (License GPLv2) set -e @@ -12,15 +12,27 @@ else echo "SSL certificates already present" fi -# Configuring default credentiales. +# Setting users credentials. if [ ! -f /etc/nginx/conf.d/kibana.htpasswd ]; then - echo "Setting Nginx credentials" - echo $NGINX_PWD|htpasswd -i -c /etc/nginx/conf.d/kibana.htpasswd $NGINX_NAME >/dev/null + echo "Setting users credentials" + if [ ! -z "$NGINX_CREDENTIALS" ]; then + IFS=';' read -r -a users <<< "$NGINX_CREDENTIALS" + for index in "${!users[@]}" + do + IFS=':' read -r -a credentials <<< "${users[index]}" + if [ $index -eq 0 ]; then + echo ${credentials[1]}|htpasswd -i -c /etc/nginx/conf.d/kibana.htpasswd ${credentials[0]} >/dev/null + else + echo ${credentials[1]}|htpasswd -i /etc/nginx/conf.d/kibana.htpasswd ${credentials[0]} >/dev/null + fi + done + else + echo $NGINX_PWD|htpasswd -i -c /etc/nginx/conf.d/kibana.htpasswd $NGINX_NAME >/dev/null + fi else echo "Kibana credentials already configured" fi - if [ "x${NGINX_PORT}" = "x" ]; then NGINX_PORT=443 fi From 12b40b48ee64d36046e73f7971d5b5c46268fe23 Mon Sep 17 00:00:00 2001 From: toniMR Date: Fri, 22 Mar 2019 09:54:32 +0100 Subject: [PATCH 2/4] Adding NGINX_CREDENTIALS in docker-compose.yml --- docker-compose.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/docker-compose.yml b/docker-compose.yml index c4cc56bd..91a0d9fc 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -57,6 +57,7 @@ services: restart: always environment: - NGINX_PORT=443 + - NGINX_CREDENTIALS ports: - "80:80" - "443:443" From f3674ff9d9d1d0841d2f7aa8c0bf71c9abe198db Mon Sep 17 00:00:00 2001 From: toniMR Date: Fri, 22 Mar 2019 09:57:02 +0100 Subject: [PATCH 3/4] Changing comment --- nginx/config/entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nginx/config/entrypoint.sh b/nginx/config/entrypoint.sh index ca661412..1b395c5b 100644 --- a/nginx/config/entrypoint.sh +++ b/nginx/config/entrypoint.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Wazuh App Copyright (C) 2018 Wazuh Inc. (License GPLv2) +# Wazuh App Copyright (C) 2019 Wazuh Inc. (License GPLv2) set -e From 11108631c05bf888890195325c67ae65ad3b6693 Mon Sep 17 00:00:00 2001 From: toniMR Date: Tue, 26 Mar 2019 13:26:09 +0100 Subject: [PATCH 4/4] Adding comments --- nginx/config/entrypoint.sh | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/nginx/config/entrypoint.sh b/nginx/config/entrypoint.sh index 1b395c5b..385d7aa8 100644 --- a/nginx/config/entrypoint.sh +++ b/nginx/config/entrypoint.sh @@ -13,6 +13,15 @@ else fi # Setting users credentials. +# In order to set NGINX_CREDENTIALS, before "docker-compose up -d" run (a or b): +# +# a) export NGINX_CREDENTIALS="user1:pass1;user2:pass2;" or +# export NGINX_CREDENTIALS="user1:pass1;user2:pass2" +# +# b) Set NGINX_CREDENTIALS in docker-compose.yml: +# NGINX_CREDENTIALS=user1:pass1;user2:pass2; or +# NGINX_CREDENTIALS=user1:pass1;user2:pass2 +# if [ ! -f /etc/nginx/conf.d/kibana.htpasswd ]; then echo "Setting users credentials" if [ ! -z "$NGINX_CREDENTIALS" ]; then @@ -27,6 +36,7 @@ if [ ! -f /etc/nginx/conf.d/kibana.htpasswd ]; then fi done else + # NGINX_PWD and NGINX_NAME are declared in nginx/Dockerfile echo $NGINX_PWD|htpasswd -i -c /etc/nginx/conf.d/kibana.htpasswd $NGINX_NAME >/dev/null fi else