]> git.immae.eu Git - perso/Immae/Config/Nix.git/blob - virtual/eldiron.nix
Add ldap configuration for httpd
[perso/Immae/Config/Nix.git] / virtual / eldiron.nix
1 {
2 network = {
3 description = "Immae's network";
4 enableRollback = true;
5 };
6
7 eldiron = { config, pkgs, ... }:
8 let mypkgs = import ./packages.nix;
9 in
10 {
11 networking = {
12 firewall = {
13 enable = true;
14 allowedTCPPorts = [ 22 80 443 3306 5432 ];
15 };
16 };
17
18 deployment = {
19 targetEnv = "hetzner";
20 hetzner = {
21 #robotUser = "defined in HETZNER_ROBOT_USER";
22 #robotPass = "defined in HETZNER_ROBOT_PASS";
23 mainIPv4 = "176.9.151.89";
24 partitions = ''
25 clearpart --all --initlabel --drives=sda,sdb
26
27 part swap1 --recommended --label=swap1 --fstype=swap --ondisk=sda
28 part swap2 --recommended --label=swap2 --fstype=swap --ondisk=sdb
29
30 part raid.1 --grow --ondisk=sda
31 part raid.2 --grow --ondisk=sdb
32
33 raid / --level=1 --device=md0 --fstype=ext4 --label=root raid.1 raid.2
34 '';
35 };
36 };
37
38 # FIXME: how to run it? currently set as timer
39 security.acme.certs = {
40 "eldiron" = {
41 webroot = "/var/lib/acme/acme-challenge";
42 email = "ismael@bouya.org";
43 domain = "eldiron.immae.eu";
44 plugins = [ "cert.pem" "chain.pem" "fullchain.pem" "full.pem" "key.pem" "account_key.json" ];
45 postRun = ''
46 "systemctl reload httpd.service"
47 '';
48 extraDomains = {
49 "db-1.immae.eu" = null;
50 "tools.immae.eu" = null;
51 };
52 };
53 };
54
55 # FIXME: open_basedir
56 services.phpfpm = {
57 extraConfig = ''
58 log_level = notice
59 '';
60 poolConfigs = {
61 adminer = mypkgs.adminer.phpFpm.pool;
62 www = ''
63 listen = /var/run/phpfpm/www.sock
64 user = wwwrun
65 group = wwwrun
66 listen.owner = wwwrun
67 listen.group = wwwrun
68 pm = ondemand
69 pm.max_children = 5
70 pm.process_idle_timeout = 60
71 ;php_admin_flag[log_errors] = on
72 php_admin_value[open_basedir] = "/var/www"
73 '';
74 };
75 };
76
77 services.httpd = let
78 withSSL = domain: {
79 enableSSL = true;
80 sslServerCert = "/var/lib/acme/${domain}/full.pem"; # FIXME: cert only?
81 sslServerKey = "/var/lib/acme/${domain}/key.pem";
82 sslServerChain = "/var/lib/acme/${domain}/fullchain.pem";
83 };
84 in rec {
85 enable = true;
86 logPerVirtualHost = true;
87 multiProcessingModule = "worker";
88 adminAddr = "httpd@immae.eu";
89 extraModules = [
90 "proxy_fcgi" # for PHP
91 "macro"
92 "ldap"
93 "authnz_ldap"
94 ];
95 extraConfig = ''
96 <IfModule ldap_module>
97 LDAPSharedCacheSize 500000
98 LDAPCacheEntries 1024
99 LDAPCacheTTL 600
100 LDAPOpCacheEntries 1024
101 LDAPOpCacheTTL 600
102 </IfModule>
103
104 <Macro LDAPConnect>
105 <IfModule authnz_ldap_module>
106 AuthLDAPURL ldap://ldap.immae.eu:389/dc=immae,dc=eu
107 AuthLDAPBindDN cn=httpd,ou=services,dc=immae,dc=eu
108 AuthLDAPBindPassword "${builtins.getEnv "NIXOPS_HTTP_LDAP_PASSWORD"}"
109 AuthType Basic
110 AuthName "Authentification requise (Acces LDAP)"
111 AuthBasicProvider ldap
112 </IfModule>
113 </Macro>
114 '';
115 virtualHosts = [
116 (withSSL "eldiron" // {
117 listen = [ { ip = "*"; port = 443; } ];
118 hostName = "eldiron.immae.eu";
119 # FIXME: directory needs to exist
120 documentRoot = "/var/www";
121 })
122 (withSSL "eldiron" // {
123 listen = [ { ip = "*"; port = 443; } ];
124 hostName = "db-1.immae.eu";
125 documentRoot = null;
126 extraConfig = builtins.concatStringsSep "\n" [
127 mypkgs.adminer.apache.vhostConf
128 ];
129 })
130 (withSSL "eldiron" // {
131 listen = [ { ip = "*"; port = 443; } ];
132 hostName = "tools.immae.eu";
133 documentRoot = null;
134 extraConfig = builtins.concatStringsSep "\n" [
135 mypkgs.adminer.apache.vhostConf
136 ];
137 })
138 { # Should go last, default fallback
139 listen = [ { ip = "*"; port = 80; } ];
140 hostName = "redirectSSL";
141 serverAliases = [ "*" ];
142 enableSSL = false;
143 # FIXME: directory needs to exist
144 documentRoot = "/var/lib/acme/acme-challenge";
145 extraConfig = ''
146 RewriteEngine on
147 RewriteCond "%{REQUEST_URI}" "!^/\.well-known"
148 RewriteRule ^(.+) https://%{HTTP_HOST}$1 [R=301]
149 # To redirect in specific "VirtualHost *:80", do
150 # RedirectMatch 301 ^/((?!\.well-known.*$).*)$ https://host/$1
151 # rather than rewrite
152 '';
153 }
154 ];
155 };
156
157 # FIXME: environment variables ?
158 security.pam.services = let
159 pam_ldap = pkgs.pam_ldap;
160 pam_ldap_mysql = pkgs.writeText "mysql.conf" ''
161 host ldap.immae.eu
162 base dc=immae,dc=eu
163 binddn cn=mysql,cn=pam,ou=services,dc=immae,dc=eu
164 bindpw ${builtins.getEnv "NIXOPS_MYSQL_PAM_PASSWORD"}
165 pam_filter memberOf=cn=users,cn=mysql,cn=pam,ou=services,dc=immae,dc=eu
166 '';
167 in [
168 {
169 name = "mysql";
170 text = ''
171 # https://mariadb.com/kb/en/mariadb/pam-authentication-plugin/
172 auth required ${pam_ldap}/lib/security/pam_ldap.so config=${pam_ldap_mysql}
173 account required ${pam_ldap}/lib/security/pam_ldap.so config=${pam_ldap_mysql}
174 '';
175 }
176 ];
177
178 # FIXME: initial sync
179 # FIXME: backup
180 # FIXME: restart after pam
181 # FIXME: pam access doesn’t work (because of php module)
182 # FIXME: ssl
183 services.mysql = rec {
184 enable = true;
185 package = pkgs.mariadb.overrideAttrs(old: rec {
186 cmakeFlags = old.cmakeFlags ++ [ "-DWITH_AUTHENTICATION_PAM=ON" ];
187 buildInputs = old.buildInputs ++ [ pkgs.pam ];
188 });
189 };
190
191 # FIXME: initial sync
192 # FIXME: backup
193 # FIXME: ssl
194 services.postgresql = rec {
195 enable = true;
196 package = pkgs.postgresql100.overrideAttrs(old: rec {
197 passthru = old.passthru // { psqlSchema = "11.0"; };
198 name = "postgresql-11.1";
199 src = pkgs.fetchurl {
200 url = "mirror://postgresql/source/v11.1/${name}.tar.bz2";
201 sha256 = "026v0sicsh7avzi45waf8shcbhivyxmi7qgn9fd1x0vl520mx0ch";
202 };
203 });
204 enableTCPIP = true;
205 extraConfig = ''
206 max_connections = 100
207 wal_level = logical
208 shared_buffers = 128MB
209 max_wal_size = 1GB
210 min_wal_size = 80MB
211 log_timezone = 'Europe/Paris'
212 datestyle = 'iso, mdy'
213 timezone = 'Europe/Paris'
214 lc_messages = 'en_US.UTF-8'
215 lc_monetary = 'en_US.UTF-8'
216 lc_numeric = 'en_US.UTF-8'
217 lc_time = 'en_US.UTF-8'
218 default_text_search_config = 'pg_catalog.english'
219 # ssl = on
220 # ssl_cert_file = '/var/lib/acme/eldiron/fullchain.pem'
221 # ssl_key_file = '/var/lib/acme/eldiron/key.pem'
222 '';
223 authentication = ''
224 local all postgres ident
225 local all all md5
226 host all all 178.33.252.96/32 md5
227 host all all 188.165.209.148/32 md5
228 #host all all all pam
229 '';
230 };
231 };
232 }