diff --git a/order/README.md b/order/README.md index e3067725d1..30a184a04f 100644 --- a/order/README.md +++ b/order/README.md @@ -21,8 +21,10 @@ A small Python service behind nginx on a Debian host. Checkout (an open one is reused) that collects card, email, phone and the shipping address in the quote's country, and shows the price-may-change terms beside Pay. There is no quote page: the quote is only shown in Backplane. Stripe comes back to `/q/{id}/done` or `/q/{id}/cancelled`, one line each. -- `/admin`: paid orders, to place by hand. Takes `?k=$FAB_ADMIN_TOKEN` once, which then - becomes a cookie. +- `/admin`: paid orders, to place by hand. nginx asks for a password first (user `admin`, a bcrypt + line in `/etc/nginx/fab-admin.htpasswd`, made with `mkpasswd -m bcrypt`) and then hands the app its + token from `/etc/fab/nginx-admin.conf`; without that file the page takes `?k=$FAB_ADMIN_TOKEN` once, + which then becomes a cookie. The person sees three lines and a total, four for the US: - manufacturing; diff --git a/order/deploy/nginx.conf b/order/deploy/nginx.conf index 48f53be37e..85347b1cf0 100644 --- a/order/deploy/nginx.conf +++ b/order/deploy/nginx.conf @@ -3,6 +3,7 @@ limit_req_zone $binary_remote_addr zone=fab_api:10m rate=5r/s; limit_req_zone $binary_remote_addr zone=fab_up:10m rate=6r/m; limit_conn_zone $binary_remote_addr zone=fab_conn:10m; +limit_req_zone $binary_remote_addr zone=fab_admin:10m rate=30r/m; # no query strings in the log: they can carry a quote's token log_format fab '$remote_addr [$time_local] "$request_method $uri" $status $body_bytes_sent $request_time'; @@ -45,6 +46,22 @@ server { proxy_set_header X-Forwarded-For $remote_addr; proxy_set_header X-Forwarded-Proto https; } + # The order list: a password (user admin; bcrypt hash in /etc/nginx/fab-admin.htpasswd, readable by + # www-data) and then the app's own admin token, which nginx adds from /etc/fab/nginx-admin*.conf + # (root only; one line: proxy_set_header Cookie "fab_admin=";). With no password + # file every /admin request fails; with no token file the page asks for ?k= as before. + location ^~ /admin { + limit_req zone=fab_admin burst=20 nodelay; + auth_basic "Backplane orders"; + auth_basic_user_file /etc/nginx/fab-admin.htpasswd; + client_max_body_size 256k; + proxy_pass http://127.0.0.1:8090; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $remote_addr; + proxy_set_header X-Forwarded-Proto https; + include /etc/fab/nginx-admin*.conf; + } location / { limit_req zone=fab_api burst=40 nodelay; client_max_body_size 256k;