Piotr Dobrowolski | 9c5d866 | 2022-05-08 02:17:41 +0200 | [diff] [blame] | 1 | { config, pkgs, lib, ... }: |
| 2 | |
| 3 | let |
| 4 | beyondspaceDomains = { |
| 5 | "inventory.waw.hackerspace.pl" = "https"; |
| 6 | "vending.waw.hackerspace.pl" = "https"; |
Piotr Dobrowolski | a7af16d | 2023-09-19 20:10:57 +0200 | [diff] [blame] | 7 | "label.waw.hackerspace.pl" = "http"; |
Piotr Dobrowolski | 9c5d866 | 2022-05-08 02:17:41 +0200 | [diff] [blame] | 8 | }; |
| 9 | |
| 10 | in with lib; { |
| 11 | services.oauth2_proxy = { |
| 12 | enable = true; |
| 13 | provider = "oidc"; |
| 14 | keyFile = "/var/beyondspace.secrets"; |
| 15 | clientID = "1e0a7ba0-5a15-477a-8d96-690ebbe6e720"; |
| 16 | extraConfig = { |
| 17 | oidc-issuer-url = "https://sso.hackerspace.pl"; |
| 18 | email-domain = "*"; |
Piotr Dobrowolski | 8abe202 | 2023-11-11 16:24:43 +0100 | [diff] [blame] | 19 | provider-display-name = "sso.hackerspace.pl"; |
| 20 | |
| 21 | # We use HTTP basic authentication for programmatic access to LAN services |
Piotr Dobrowolski | a7af16d | 2023-09-19 20:10:57 +0200 | [diff] [blame] | 22 | htpasswd-file = "/var/beyondspace.htpasswd"; |
Piotr Dobrowolski | 8abe202 | 2023-11-11 16:24:43 +0100 | [diff] [blame] | 23 | display-htpasswd-form = false; |
| 24 | |
| 25 | custom-sign-in-logo = builtins.path { path = ./default-vhost/beyondspace.png; }; |
| 26 | footer = "This page is only accessible to <a href='https://hackerspace.pl'>Warsaw Hackerspace</a> members (or directly from within Warsaw Hackerspace LAN)."; |
Piotr Dobrowolski | 9c5d866 | 2022-05-08 02:17:41 +0200 | [diff] [blame] | 27 | }; |
| 28 | }; |
| 29 | |
| 30 | |
| 31 | services.nginx.commonHttpConfig = '' |
| 32 | map $http_host $beyondspace_upstream_proto { |
| 33 | hostnames; |
| 34 | |
| 35 | default http; |
| 36 | |
| 37 | ${concatStringsSep "\n" (mapAttrsToList (key: value: "${key} ${value};") beyondspaceDomains)} |
| 38 | } |
| 39 | ''; |
| 40 | |
| 41 | services.nginx.virtualHosts."beyond.waw.hackerspace.pl" = { |
| 42 | forceSSL = true; |
| 43 | enableACME = true; |
| 44 | |
| 45 | serverAliases = attrNames beyondspaceDomains; |
| 46 | |
| 47 | locations."/oauth2/" = { |
| 48 | extraConfig = '' |
| 49 | proxy_pass http://127.0.0.1:4180; |
| 50 | proxy_set_header Host $host; |
| 51 | proxy_set_header X-Real-IP $remote_addr; |
| 52 | proxy_set_header X-Scheme $scheme; |
| 53 | proxy_set_header X-Auth-Request-Redirect $request_uri; |
| 54 | ''; |
| 55 | }; |
| 56 | |
| 57 | locations."= /oauth2/auth" = { |
| 58 | extraConfig = '' |
| 59 | proxy_pass http://127.0.0.1:4180; |
| 60 | proxy_set_header Host $host; |
| 61 | proxy_set_header X-Real-IP $remote_addr; |
| 62 | proxy_set_header X-Scheme $scheme; |
| 63 | |
| 64 | # nginx auth_request includes headers but not body |
| 65 | proxy_set_header Content-Length ""; |
| 66 | proxy_pass_request_body off; |
| 67 | ''; |
| 68 | }; |
| 69 | |
| 70 | locations."/" = { |
| 71 | extraConfig = '' |
| 72 | auth_request /oauth2/auth; |
| 73 | error_page 401 = /oauth2/sign_in; |
| 74 | |
| 75 | # if you enabled --cookie-refresh, this is needed for it to work with auth_request |
| 76 | auth_request_set $auth_cookie $upstream_http_set_cookie; |
| 77 | add_header Set-Cookie $auth_cookie; |
| 78 | |
| 79 | proxy_pass $beyondspace_upstream_proto://$host$request_uri; |
| 80 | ''; |
| 81 | }; |
| 82 | }; |
Piotr Dobrowolski | 8abe202 | 2023-11-11 16:24:43 +0100 | [diff] [blame] | 83 | |
| 84 | services.nginx.virtualHosts."*.waw.hackerspace.pl" = { |
| 85 | default = true; |
| 86 | locations."/".root = ./default-vhost; |
| 87 | }; |
Piotr Dobrowolski | 9c5d866 | 2022-05-08 02:17:41 +0200 | [diff] [blame] | 88 | } |