blob: ab0c6cf57ee8c5926388aef64a4ee37fe23e25f6 [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" = {
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 Dobrowolski8abe2022023-11-11 16:24:43 +010083
84 services.nginx.virtualHosts."*.waw.hackerspace.pl" = {
85 default = true;
86 locations."/".root = ./default-vhost;
87 };
Piotr Dobrowolski9c5d8662022-05-08 02:17:41 +020088}