blob: 02e677d8f10af9427af5d2bdbd7b96a663eba88b [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 Dobrowolskia7af16d2023-09-19 20:10:57 +020019 htpasswd-file = "/var/beyondspace.htpasswd";
Piotr Dobrowolski9c5d8662022-05-08 02:17:41 +020020 };
21 };
22
23
24 services.nginx.commonHttpConfig = ''
25 map $http_host $beyondspace_upstream_proto {
26 hostnames;
27
28 default http;
29
30 ${concatStringsSep "\n" (mapAttrsToList (key: value: "${key} ${value};") beyondspaceDomains)}
31 }
32 '';
33
34 services.nginx.virtualHosts."beyond.waw.hackerspace.pl" = {
35 forceSSL = true;
36 enableACME = true;
37
38 serverAliases = attrNames beyondspaceDomains;
39
40 locations."/oauth2/" = {
41 extraConfig = ''
42 proxy_pass http://127.0.0.1:4180;
43 proxy_set_header Host $host;
44 proxy_set_header X-Real-IP $remote_addr;
45 proxy_set_header X-Scheme $scheme;
46 proxy_set_header X-Auth-Request-Redirect $request_uri;
47 '';
48 };
49
50 locations."= /oauth2/auth" = {
51 extraConfig = ''
52 proxy_pass http://127.0.0.1:4180;
53 proxy_set_header Host $host;
54 proxy_set_header X-Real-IP $remote_addr;
55 proxy_set_header X-Scheme $scheme;
56
57 # nginx auth_request includes headers but not body
58 proxy_set_header Content-Length "";
59 proxy_pass_request_body off;
60 '';
61 };
62
63 locations."/" = {
64 extraConfig = ''
65 auth_request /oauth2/auth;
66 error_page 401 = /oauth2/sign_in;
67
68 # if you enabled --cookie-refresh, this is needed for it to work with auth_request
69 auth_request_set $auth_cookie $upstream_http_set_cookie;
70 add_header Set-Cookie $auth_cookie;
71
72 proxy_pass $beyondspace_upstream_proto://$host$request_uri;
73 '';
74 };
75 };
76}