|
6 | 6 | }: |
7 | 7 |
|
8 | 8 | # TODO: Gems includes for Mruby |
9 | | -# TODO: Recommended options |
10 | 9 | let |
11 | 10 | cfg = config.services.h2o; |
12 | 11 | inherit (config.security.acme) certs; |
|
22 | 21 |
|
23 | 22 | mkCertOwnershipAssertion = import ../../../security/acme/mk-cert-ownership-assertion.nix lib; |
24 | 23 |
|
| 24 | + inherit (import ./common.nix { inherit lib; }) tlsRecommendationsOption; |
| 25 | + |
25 | 26 | settingsFormat = pkgs.formats.yaml { }; |
26 | 27 |
|
27 | 28 | getNames = name: vhostSettings: rec { |
|
76 | 77 | all = certNames'.dependent ++ certNames'.independent; |
77 | 78 | }; |
78 | 79 |
|
| 80 | + mozTLSRecs = |
| 81 | + if cfg.defaultTLSRecommendations != null then |
| 82 | + let |
| 83 | + # NOTE: if updating, *do* verify the changes then adjust ciphers & |
| 84 | + # other settings with the tests @ |
| 85 | + # `nixos/tests/web-servers/h2o/tls-recommendations.nix` |
| 86 | + # & run with `nix-build -A nixosTests.h2o.tls-recommendations` |
| 87 | + version = "5.7"; |
| 88 | + git_tag = "v5.7.1"; |
| 89 | + guidelinesJSON = |
| 90 | + lib.pipe |
| 91 | + { |
| 92 | + urls = [ |
| 93 | + "https://ssl-config.mozilla.org/guidelines/${version}.json" |
| 94 | + "https://raw.githubusercontent.com/mozilla/ssl-config-generator/refs/tags/${git_tag}/src/static/guidelines/${version}.json" |
| 95 | + ]; |
| 96 | + sha256 = "sha256:1mj2pcb1hg7q2wpgdq3ac8pc2q64wvwvwlkb9xjmdd9jm4hiyny7"; |
| 97 | + } |
| 98 | + [ |
| 99 | + pkgs.fetchurl |
| 100 | + builtins.readFile |
| 101 | + builtins.fromJSON |
| 102 | + ]; |
| 103 | + in |
| 104 | + guidelinesJSON.configurations |
| 105 | + else |
| 106 | + null; |
| 107 | + |
79 | 108 | hostsConfig = lib.concatMapAttrs ( |
80 | 109 | name: value: |
81 | 110 | let |
@@ -130,23 +159,79 @@ let |
130 | 159 | ] |
131 | 160 | ) |
132 | 161 | { |
133 | | - "${names.server}:${builtins.toString port.TLS}" = value.settings // { |
134 | | - listen = |
135 | | - let |
136 | | - identity = |
137 | | - value.tls.identity |
138 | | - ++ lib.optional (builtins.elem names.cert certNames.all) { |
139 | | - key-file = "${certs.${names.cert}.directory}/key.pem"; |
140 | | - certificate-file = "${certs.${names.cert}.directory}/fullchain.pem"; |
| 162 | + "${names.server}:${builtins.toString port.TLS}" = |
| 163 | + let |
| 164 | + tlsRecommendations = lib.attrByPath [ "tls" "recommendations" ] cfg.defaultTLSRecommendations value; |
| 165 | + |
| 166 | + hasTLSRecommendations = tlsRecommendations != null && mozTLSRecs != null; |
| 167 | + |
| 168 | + # NOTE: Let’s Encrypt has sunset OCSP stapling. Mozilla’s |
| 169 | + # ssl-config-generator is at present still recommending this setting, but |
| 170 | + # this module will skip setting a stapling value as Let’s Encrypt + |
| 171 | + # ACME is the most likely use case. |
| 172 | + # |
| 173 | + # See: https://github.com/mozilla/ssl-config-generator/issues/323 |
| 174 | + tlsRecAttrs = lib.optionalAttrs hasTLSRecommendations ( |
| 175 | + let |
| 176 | + recs = mozTLSRecs.${tlsRecommendations}; |
| 177 | + in |
| 178 | + { |
| 179 | + min-version = builtins.head recs.tls_versions; |
| 180 | + cipher-preference = "server"; |
| 181 | + "cipher-suite-tls1.3" = recs.ciphersuites; |
| 182 | + } |
| 183 | + // lib.optionalAttrs (recs.ciphers.openssl != [ ]) { |
| 184 | + cipher-suite = lib.concatStringsSep ":" recs.ciphers.openssl; |
| 185 | + } |
| 186 | + ); |
| 187 | + |
| 188 | + headerRecAttrs = |
| 189 | + lib.optionalAttrs |
| 190 | + ( |
| 191 | + hasTLSRecommendations |
| 192 | + && value.tls != null |
| 193 | + && builtins.elem value.tls.policy [ |
| 194 | + "force" |
| 195 | + "only" |
| 196 | + ] |
| 197 | + ) |
| 198 | + ( |
| 199 | + let |
| 200 | + headerSet = value.settings."header.set" or [ ]; |
| 201 | + recs = mozTLSRecs.${tlsRecommendations}; |
| 202 | + hsts = "Strict-Transport-Security: max-age=${builtins.toString recs.hsts_min_age}; includeSubDomains; preload"; |
| 203 | + in |
| 204 | + { |
| 205 | + "header.set" = |
| 206 | + if builtins.isString headerSet then |
| 207 | + [ |
| 208 | + headerSet |
| 209 | + hsts |
| 210 | + ] |
| 211 | + else |
| 212 | + headerSet ++ [ hsts ]; |
| 213 | + } |
| 214 | + ); |
| 215 | + in |
| 216 | + value.settings |
| 217 | + // headerRecAttrs |
| 218 | + // { |
| 219 | + listen = |
| 220 | + let |
| 221 | + identity = |
| 222 | + value.tls.identity |
| 223 | + ++ lib.optional (builtins.elem names.cert certNames.all) { |
| 224 | + key-file = "${certs.${names.cert}.directory}/key.pem"; |
| 225 | + certificate-file = "${certs.${names.cert}.directory}/fullchain.pem"; |
| 226 | + }; |
| 227 | + in |
| 228 | + { |
| 229 | + port = port.TLS; |
| 230 | + ssl = (lib.recursiveUpdate tlsRecAttrs value.tls.extraSettings) // { |
| 231 | + inherit identity; |
141 | 232 | }; |
142 | | - in |
143 | | - { |
144 | | - port = port.TLS; |
145 | | - ssl = value.tls.extraSettings // { |
146 | | - inherit identity; |
147 | 233 | }; |
148 | | - }; |
149 | | - }; |
| 234 | + }; |
150 | 235 | }; |
151 | 236 | in |
152 | 237 | # With a high likelihood of HTTP & ACME challenges being on the same port, |
|
184 | 269 | }; |
185 | 270 |
|
186 | 271 | package = lib.mkPackageOption pkgs "h2o" { |
187 | | - example = '' |
188 | | - pkgs.h2o.override { |
189 | | - withMruby = false; |
190 | | - }; |
191 | | - ''; |
| 272 | + example = # nix |
| 273 | + '' |
| 274 | + pkgs.h2o.override { |
| 275 | + withMruby = false; |
| 276 | + openssl = pkgs.openssl_legacy; |
| 277 | + } |
| 278 | + ''; |
192 | 279 | }; |
193 | 280 |
|
194 | 281 | defaultHTTPListenPort = mkOption { |
|
209 | 296 | example = 8443; |
210 | 297 | }; |
211 | 298 |
|
| 299 | + defaultTLSRecommendations = tlsRecommendationsOption; |
| 300 | + |
212 | 301 | settings = mkOption { |
213 | 302 | type = settingsFormat.type; |
214 | 303 | default = { }; |
215 | 304 | description = "Configuration for H2O (see <https://h2o.examp1e.net/configure.html>)"; |
216 | 305 | }; |
217 | 306 |
|
218 | 307 | hosts = mkOption { |
219 | | - type = types.attrsOf ( |
220 | | - types.submodule ( |
221 | | - import ./vhost-options.nix { |
222 | | - inherit config lib; |
223 | | - } |
224 | | - ) |
225 | | - ); |
| 308 | + type = types.attrsOf (types.submodule (import ./vhost-options.nix { inherit config lib; })); |
226 | 309 | default = { }; |
227 | 310 | description = '' |
228 | 311 | The `hosts` config to be merged with the settings. |
|
0 commit comments