From 4b440ec9b56cb1703655a9a91160b6d5928ab764 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Sat, 23 Oct 2021 20:35:56 +0200 Subject: [PATCH 1/2] Add basic auth to searx --- roles/searx/defaults/main.yml | 4 ++++ roles/searx/templates/upstream.json.j2 | 15 +++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/roles/searx/defaults/main.yml b/roles/searx/defaults/main.yml index 0165f48..de1cc15 100644 --- a/roles/searx/defaults/main.yml +++ b/roles/searx/defaults/main.yml @@ -8,3 +8,7 @@ searx_use_https: true # the subdomain link searx will be reachable under subdomain_alias: search + +searx_authentication: + - username: mysearxusername + password: JDJhJDE0JFdjUnQ5WWllcU8wa01xS0JBS2dlMy5zMEhRTmxqTXdIZmdjcTN6ZGFwRjJlYUdoSHAwRUhL # mysearxpassword diff --git a/roles/searx/templates/upstream.json.j2 b/roles/searx/templates/upstream.json.j2 index 9966f1a..12fd8f0 100644 --- a/roles/searx/templates/upstream.json.j2 +++ b/roles/searx/templates/upstream.json.j2 @@ -26,6 +26,21 @@ ], {% endif %} "handle": [ +{% if searx_authentication is not undefined and not none %} + { + "handler": "authentication", + "providers": { + "http_basic": { + "accounts": [ + { + "username": "{{ searx_authentication.username }}", + "password": "{{ searx_authentication.password }}" + } + ] + } + } + }, +{% endif %} { "handler": "reverse_proxy", "upstreams": [ From 3b27a5222ad7d7573b31feeff8aa41b97c120636 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Sat, 23 Oct 2021 22:02:48 +0200 Subject: [PATCH 2/2] Allow multiple basic auth accounts to be configured --- roles/searx/templates/upstream.json.j2 | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/roles/searx/templates/upstream.json.j2 b/roles/searx/templates/upstream.json.j2 index 12fd8f0..8b90a71 100644 --- a/roles/searx/templates/upstream.json.j2 +++ b/roles/searx/templates/upstream.json.j2 @@ -32,10 +32,15 @@ "providers": { "http_basic": { "accounts": [ +{% for user in searx_authentication %} { - "username": "{{ searx_authentication.username }}", - "password": "{{ searx_authentication.password }}" + "username": "{{ user.username }}", + "password": "{{ user.password }}" } + {% if not loop.last %} + , + {% endif %} +{% endfor %} ] } }