From 80f61576923bb9950c2c738fd67f095b86b12847 Mon Sep 17 00:00:00 2001 From: Marcin Mielnicki Date: Tue, 12 Feb 2019 13:32:11 +0100 Subject: [PATCH] Support for configuration of basic authentication (#99) * Support for basic authentication --- README.md | 4 ++++ defaults/main.yml | 4 ++++ templates/http/default.conf.j2 | 12 ++++++++++++ 3 files changed, 20 insertions(+) diff --git a/README.md b/README.md index 616a0e9..295cc7b 100644 --- a/README.md +++ b/README.md @@ -344,6 +344,8 @@ nginx_http_template: html_file_location: /usr/share/nginx/html html_file_name: index.html autoindex: false + auth_basic: null + auth_basic_file: null http_demo_conf: false reverse_proxy: locations: @@ -351,6 +353,8 @@ nginx_http_template: location: / proxy_pass: http://backend websocket: false + auth_basic: null + auth_basic_file: null health_check_plus: false upstreams: upstream1: diff --git a/defaults/main.yml b/defaults/main.yml index 26afd1e..f4f306a 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -175,6 +175,8 @@ nginx_http_template: html_file_location: /usr/share/nginx/html html_file_name: index.html autoindex: false + auth_basic: null + auth_basic_file: null http_demo_conf: false reverse_proxy: locations: @@ -182,6 +184,8 @@ nginx_http_template: location: / proxy_pass: http://backend websocket: false + auth_basic: null + auth_basic_file: null health_check_plus: false upstreams: upstream1: diff --git a/templates/http/default.conf.j2 b/templates/http/default.conf.j2 index e6de25c..14c1bde 100644 --- a/templates/http/default.conf.j2 +++ b/templates/http/default.conf.j2 @@ -33,6 +33,12 @@ server { {% if item.value.reverse_proxy is defined %} {% for location in item.value.reverse_proxy.locations %} location {{ item.value.reverse_proxy.locations[location].location }} { +{% if item.value.reverse_proxy.locations[location].auth_basic is defined and item.value.reverse_proxy.locations[location].auth_basic %} + auth_basic "{{ item.value.reverse_proxy.locations[location].auth_basic }}"; +{% endif %} +{% if item.value.reverse_proxy.locations[location].auth_basic_file is defined and item.value.reverse_proxy.locations[location].auth_basic_file %} + auth_basic_user_file {{ item.value.reverse_proxy.locations[location].auth_basic_file }}; +{% endif %} proxy_pass {{ item.value.reverse_proxy.locations[location].proxy_pass }}; {% if item.value.reverse_proxy.health_check_plus is defined and item.value.reverse_proxy.health_check_plus %} health_check; @@ -56,6 +62,12 @@ server { index {{ item.value.web_server.locations[location].html_file_name }}; {% if item.value.web_server.locations[location].autoindex %} autoindex on; +{% endif %} +{% if item.value.web_server.locations[location].auth_basic is defined and item.value.web_server.locations[location].auth_basic %} + auth_basic "{{ item.value.web_server.locations[location].auth_basic }}"; +{% endif %} +{% if item.value.web_server.locations[location].auth_basic_file is defined and item.value.web_server.locations[location].auth_basic_file %} + auth_basic_user_file {{ item.value.web_server.locations[location].auth_basic_file }}; {% endif %} } {% endfor %}