Add separate web module
modules/config/web.scm unknown status 1
1 | + | ;;; Tyreunom's system administration and configuration tools. | |
2 | + | ;;; | |
3 | + | ;;; Copyright ?? 2019 Julien Lepiller <julien@lepiller.eu> | |
4 | + | ;;; | |
5 | + | ;;; This program is free software: you can redistribute it and/or modify | |
6 | + | ;;; it under the terms of the GNU General Public License as published by | |
7 | + | ;;; the Free Software Foundation, either version 3 of the License, or | |
8 | + | ;;; (at your option) any later version. | |
9 | + | ;;; | |
10 | + | ;;; This program is distributed in the hope that it will be useful, | |
11 | + | ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | + | ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | + | ;;; GNU General Public License for more details. | |
14 | + | ;;; | |
15 | + | ;;; You should have received a copy of the GNU General Public License | |
16 | + | ;;; along with this program. If not, see <http://www.gnu.org/licenses/>. | |
17 | + | ||
18 | + | (define-module (config web) | |
19 | + | #:export (web-base-policy | |
20 | + | web-html-policy | |
21 | + | default-web-policy)) | |
22 | + | ||
23 | + | (define web-base-policy | |
24 | + | '("add_header Strict-Transport-Security \"max-age=31536000; includeSubDomains\" always;" | |
25 | + | "add_header X-Frame-Options DENY;" | |
26 | + | "add_header X-Content-Type-Options nosniff;" | |
27 | + | "add_header Content-Security-Policy 'default-src \\'none\\'; img-src \\'self\\'; style-src \\'self\\' \\'unsafe-inline\\'; frame-ancestors \\'none\\'';" | |
28 | + | "add_header Referrer-Policy no-referrer;")) | |
29 | + | ||
30 | + | (define (web-html-policy additional-data) | |
31 | + | (append | |
32 | + | '("location ~ \\.html$ {" | |
33 | + | " add_header 'Cache-Control' 'no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0';" | |
34 | + | " add_header Strict-Transport-Security \"max-age=31536000; includeSubDomains\" always;" | |
35 | + | " add_header X-Frame-Options DENY;" | |
36 | + | " add_header X-Content-Type-Options nosniff;" | |
37 | + | " add_header Content-Security-Policy 'default-src \\'none\\'; img-src \\'self\\'; style-src \\'self\\' \\'unsafe-inline\\'; frame-ancestors \\'none\\'';" | |
38 | + | " add_header Referrer-Policy no-referrer;") | |
39 | + | additional-data | |
40 | + | '(" expires off;" | |
41 | + | "}"))) | |
42 | + | ||
43 | + | (define default-web-policy | |
44 | + | (append | |
45 | + | web-base-policy | |
46 | + | (web-html-policy '()))) |
systems/hermes.scm
20 | 20 | (use-modules (gnu bootloader) (gnu bootloader grub)) | |
21 | 21 | (use-modules (gnu services dns)) | |
22 | 22 | (use-modules (gnu services web)) | |
23 | - | (use-modules (config certbot) (config dns) (config mail) (config network) (config os)) | |
23 | + | (use-modules (config certbot) (config dns) (config mail) (config network) (config os) | |
24 | + | (config web)) | |
24 | 25 | ||
25 | 26 | ||
26 | 27 | ;; NOTE: this config contains out-of band files. | |
… | |||
32 | 33 | ;; To (re-)generate /etc/knot/secrets.conf, run: | |
33 | 34 | ;; keymgt -t lepiller-key > /etc/knot/secrets.conf | |
34 | 35 | ||
36 | + | (define lepiller-policy | |
37 | + | (append | |
38 | + | web-base-policy | |
39 | + | '("set $first_language $http_accept_language;" | |
40 | + | "if ($http_accept_language ~* '(en|eo|fr)') {" | |
41 | + | " set $first_language $1;" | |
42 | + | "}" | |
43 | + | "set $language_suffix $first_language;" | |
44 | + | "if ($cookie_language) {" | |
45 | + | " set $language_suffix $cookie_language;" | |
46 | + | "}" | |
47 | + | "if ($uri ~ \\.en.html$) {" | |
48 | + | " set $language_suffix 'en';" | |
49 | + | "}" | |
50 | + | "if ($uri ~ \\.eo.html$) {" | |
51 | + | " set $language_suffix 'eo';" | |
52 | + | "}" | |
53 | + | "if ($uri ~ \\.fr.html$) {" | |
54 | + | " set $language_suffix 'fr';" | |
55 | + | "}" | |
56 | + | "if ($uri ~ (.*).html) {" | |
57 | + | " set $my_uri $1.$language_suffix.html;" | |
58 | + | "}") | |
59 | + | (web-html-policy | |
60 | + | '(" add_header Set-Cookie 'language=$language_suffix;HttpOnly;Secure';" | |
61 | + | " try_files $my_uri $uri $uri/ =404;")) | |
62 | + | '("error_page 404 /404;"))) | |
63 | + | ||
35 | 64 | (operating-system | |
36 | 65 | (inherit (tyreunom-os "hermes")) | |
37 | 66 | (bootloader | |
… | |||
66 | 95 | (root "/srv/http/lepiller/public") | |
67 | 96 | (index '("index.$language_suffix.html" "index.html")) | |
68 | 97 | (try-files '("$uri.$language_suffix.html" "$uri" "$uri/" "=404")) | |
69 | - | (raw-content | |
70 | - | '("add_header Strict-Transport-Security \"max-age=31536000; includeSubDomains\" always;" | |
71 | - | "add_header X-Frame-Options DENY;" | |
72 | - | "add_header X-Content-Type-Options nosniff;" | |
73 | - | "add_header Content-Security-Policy 'default-src \\'none\\'; img-src \\'self\\'; style-src \\'self\\' \\'unsafe-inline\\'; frame-ancestors \\'none\\'';" | |
74 | - | "add_header Referrer-Policy no-referrer;" | |
75 | - | "set $first_language $http_accept_language;" | |
76 | - | "if ($http_accept_language ~* '(en|eo|fr)') {" | |
77 | - | " set $first_language $1;" | |
78 | - | "}" | |
79 | - | "set $language_suffix $first_language;" | |
80 | - | "if ($cookie_language) {" | |
81 | - | " set $language_suffix $cookie_language;" | |
82 | - | "}" | |
83 | - | "if ($uri ~ \\.en.html$) {" | |
84 | - | " set $language_suffix 'en';" | |
85 | - | "}" | |
86 | - | "if ($uri ~ \\.eo.html$) {" | |
87 | - | " set $language_suffix 'eo';" | |
88 | - | "}" | |
89 | - | "if ($uri ~ \\.fr.html$) {" | |
90 | - | " set $language_suffix 'fr';" | |
91 | - | "}" | |
92 | - | "if ($uri ~ (.*).html) {" | |
93 | - | " set $my_uri $1.$language_suffix.html;" | |
94 | - | "}" | |
95 | - | "location ~ \\.html$ {" | |
96 | - | " add_header Set-Cookie 'language=$language_suffix;HttpOnly;Secure';" | |
97 | - | " add_header 'Cache-Control' 'no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0';" | |
98 | - | " add_header Strict-Transport-Security \"max-age=31536000; includeSubDomains\" always;" | |
99 | - | " add_header X-Frame-Options DENY;" | |
100 | - | " add_header X-Content-Type-Options nosniff;" | |
101 | - | " add_header Content-Security-Policy 'default-src \\'none\\'; img-src \\'self\\'; style-src \\'self\\' \\'unsafe-inline\\'; frame-ancestors \\'none\\'';" | |
102 | - | " add_header Referrer-Policy no-referrer;" | |
103 | - | " expires off;" | |
104 | - | " try_files $my_uri $uri $uri/ =404;" | |
105 | - | "}" | |
106 | - | "error_page 404 /404;"))))) | |
98 | + | (raw-content lepiller-policy)))) | |
107 | 99 | (simple-service 'default-http-server nginx-service-type | |
108 | 100 | (list (nginx-server-configuration | |
109 | 101 | (ssl-certificate "/etc/letsencrypt/live/lepiller.eu/fullchain.pem") | |
110 | 102 | (ssl-certificate-key "/etc/letsencrypt/live/lepiller.eu/privkey.pem") | |
111 | 103 | (listen '("443 ssl http2" "[::]:443 ssl http2")) | |
112 | - | (server-name '(default))(root "/srv/http/default"))))) | |
104 | + | (server-name '(default)) | |
105 | + | (root "/srv/http/default") | |
106 | + | (raw-content default-web-policy))))) | |
113 | 107 | (lepiller-mail-services | |
114 | 108 | #:interface "ens18" | |
115 | 109 | #:domain "lepiller.eu") |