Skip to content

Commit 98ec904

Browse files
committed
Apply batch auth to /
1 parent ffad357 commit 98ec904

File tree

2 files changed

+27
-14
lines changed

2 files changed

+27
-14
lines changed

docker/webserver/authentication.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,14 @@ if [ ! "$DEBUG" = "False" ] && [ "$BASIC_AUTH_RAW$ALLOW_LIST" = "" ];then
2323
printf "\nMust have BASIC_AUTH_RAW or ALLOW_LIST authentication configured if DEBUG is not 'False'!\n"
2424
exit 1
2525
fi
26+
27+
if [ "$ENABLE_BATCH" = True ]; then
28+
cat > /etc/nginx/conf.d/batch_auth.include << END
29+
auth_basic "Please enter your batch username and password";
30+
auth_basic_user_file /etc/nginx/htpasswd/external/batch_api.htpasswd;
31+
# pass logged in user to Django
32+
proxy_set_header REMOTE-USER \$remote_user;
33+
END
34+
else
35+
echo > /etc/nginx/conf.d/batch_auth.include
36+
fi

docker/webserver/nginx_templates/app.conf.template

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,22 @@ server {
197197
# make sure to cache separate for languages
198198
proxy_cache_key $scheme$host$uri$is_args$args$http_accept_language;
199199

200+
include /etc/nginx/conf.d/batch_auth.include;
201+
202+
proxy_pass http://${IPV4_IP_APP_INTERNAL}:8080;
203+
}
204+
205+
# openapi.yaml should never have auth, otherwise same as /
206+
location /api/batch/openapi.yaml {
207+
auth_basic off;
208+
allow all;
209+
proxy_set_header Host $host;
210+
proxy_set_header X-Forwarded-Proto $scheme;
211+
proxy_cache ${NGINX_PROXY_CACHE};
212+
proxy_cache_valid 200 1m;
213+
proxy_cache_use_stale updating error timeout invalid_header http_500 http_502 http_503 http_504;
214+
expires 1m;
215+
proxy_cache_key $scheme$host$uri$is_args$args$http_accept_language;
200216
proxy_pass http://${IPV4_IP_APP_INTERNAL}:8080;
201217
}
202218

@@ -255,20 +271,6 @@ server {
255271
return 301 http://${subdomain}conn.${INTERNETNL_DOMAINNAME}/connection/;
256272
}
257273

258-
# batch API, requires authentication and passes basic auth user to Django App via headers
259-
location /api/batch/v2 {
260-
auth_basic "Please enter your batch username and password";
261-
auth_basic_user_file /etc/nginx/htpasswd/external/batch_api.htpasswd;
262-
263-
# pass logged in user to Django
264-
proxy_set_header REMOTE-USER $remote_user;
265-
266-
# pass host for Django's allowed_hosts
267-
proxy_set_header Host $host;
268-
269-
proxy_pass http://${IPV4_IP_APP_INTERNAL}:8080;
270-
}
271-
272274
# monitoring, requires authentication
273275
location /grafana {
274276
auth_basic "Please enter your username and password";

0 commit comments

Comments
 (0)