blob: a10e98c82239209656afaaf1f2053bc3c3cd4e9b [file] [log] [blame]
Piotr Dobrowolski9c5d8662022-05-08 02:17:41 +02001{ config, pkgs, lib, ... }:
2
3let
4 beyondspaceDomains = {
5 "inventory.waw.hackerspace.pl" = "https";
6 "vending.waw.hackerspace.pl" = "https";
Piotr Dobrowolskia7af16d2023-09-19 20:10:57 +02007 "label.waw.hackerspace.pl" = "http";
Piotr Dobrowolski9c5d8662022-05-08 02:17:41 +02008 };
9
10in 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 Dobrowolski8abe2022023-11-11 16:24:43 +010019 provider-display-name = "sso.hackerspace.pl";
20
21 # We use HTTP basic authentication for programmatic access to LAN services
Piotr Dobrowolskia7af16d2023-09-19 20:10:57 +020022 htpasswd-file = "/var/beyondspace.htpasswd";
Piotr Dobrowolski8abe2022023-11-11 16:24:43 +010023 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 Dobrowolski9c5d8662022-05-08 02:17:41 +020027 };
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" = {
Piotr Dobrowolski13e60522023-11-12 01:07:46 +010042 # NOTE: we *can't* use forceSSL here for services that do not use HTTPS in
43 # local network setups, since this will pollute browser's redirect cache...
44 addSSL = true;
Piotr Dobrowolski9c5d8662022-05-08 02:17:41 +020045 enableACME = true;
46
47 serverAliases = attrNames beyondspaceDomains;
48
49 locations."/oauth2/" = {
50 extraConfig = ''
Piotr Dobrowolski13e60522023-11-12 01:07:46 +010051 if ($scheme != https) {
52 return 302 https://$host$request_uri;
53 }
54
Piotr Dobrowolski9c5d8662022-05-08 02:17:41 +020055 proxy_pass http://127.0.0.1:4180;
56 proxy_set_header Host $host;
57 proxy_set_header X-Real-IP $remote_addr;
58 proxy_set_header X-Scheme $scheme;
59 proxy_set_header X-Auth-Request-Redirect $request_uri;
60 '';
61 };
62
63 locations."= /oauth2/auth" = {
64 extraConfig = ''
Piotr Dobrowolski13e60522023-11-12 01:07:46 +010065 if ($scheme != https) {
66 return 302 https://$host$request_uri;
67 }
68
Piotr Dobrowolski9c5d8662022-05-08 02:17:41 +020069 proxy_pass http://127.0.0.1:4180;
70 proxy_set_header Host $host;
71 proxy_set_header X-Real-IP $remote_addr;
72 proxy_set_header X-Scheme $scheme;
73
74 # nginx auth_request includes headers but not body
75 proxy_set_header Content-Length "";
76 proxy_pass_request_body off;
77 '';
78 };
79
80 locations."/" = {
81 extraConfig = ''
Piotr Dobrowolski13e60522023-11-12 01:07:46 +010082 if ($scheme != https) {
83 return 302 https://$host$request_uri;
84 }
85
Piotr Dobrowolski9c5d8662022-05-08 02:17:41 +020086 auth_request /oauth2/auth;
87 error_page 401 = /oauth2/sign_in;
88
89 # if you enabled --cookie-refresh, this is needed for it to work with auth_request
90 auth_request_set $auth_cookie $upstream_http_set_cookie;
91 add_header Set-Cookie $auth_cookie;
92
93 proxy_pass $beyondspace_upstream_proto://$host$request_uri;
94 '';
95 };
96 };
Piotr Dobrowolski8abe2022023-11-11 16:24:43 +010097
98 services.nginx.virtualHosts."*.waw.hackerspace.pl" = {
99 default = true;
100 locations."/".root = ./default-vhost;
101 };
Piotr Dobrowolski9c5d8662022-05-08 02:17:41 +0200102}