Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nginx: make enabling SSL port-specific #27426

Merged
merged 1 commit into from
Aug 7, 2017
Merged

Conversation

rnhmjoj
Copy link
Contributor

@rnhmjoj rnhmjoj commented Jul 16, 2017

Motivation for this change

Fix issues #27338, #27442, #25533 and possibly #23711

This PR implements @globin's suggestion about SSL:

  • addSSL: add a listen port on *:443 keeping *:80 and every other address/port
  • onlySSL: listen only on *:443
  • forceSSL: redirects *:80 (and every other non-ssl port) to *:443

addSSL and onlySSL are mutually exclusive while forceSSL needs addSSL.

Moreover one can freely configure the virtual host using the listen option directly.

Things done
  • Tested via one or more NixOS test (nixos/tests/nginx.nix)
  • Tested addSSL, onlySSL and forceSSL
  • Tested enableACME
  • Fits CONTRIBUTING.md.

I had to move out the default value for config.nginx.virtualHost.<name>.listen because I don't know how to access the configuration inside a submodule. Is there a way? I would like to see what's the default from man configuration.nix when possible.

cc @globin @fpletz

@mention-bot
Copy link

@rnhmjoj, thanks for your PR! By analyzing the history of the files in this pull request, we identified @abbradar, @roconnor and @globin to be potential reviewers.

@wmertens
Copy link
Contributor

wmertens commented Jul 17, 2017

LGTM, but would it not be better to remain backwards-compatible by making enableSSL an alias for onlySSL? You can use visible: false to make it invisible https://github.com/NixOS/nixpkgs/blob/master/lib/options.nix#L21

@rnhmjoj
Copy link
Contributor Author

rnhmjoj commented Jul 17, 2017

Ok, a deprecation warning could be useful too. Is there a way?

edit: I have found about mkRenamedOptionModule but I can't get it right.

@rnhmjoj
Copy link
Contributor Author

rnhmjoj commented Jul 17, 2017

(mkRenamedOptionModule [ "services" "nginx" "virtualHosts" "<name>" "enableSSL" ] [ "services" "nginx" "virtualHosts" "<name>" "onySSL" ])

gives this error:

error: The option `services.nginx.virtualHosts' in `src/nixpkgs/nixos/modules/services/web-servers/nginx/default.nix' is a prefix of options in `src/nixpkgs/nixos/modules/rename.nix'.

@globin
Copy link
Member

globin commented Jul 17, 2017

@edolstra, @nbp, do you know how to specify a mkRenamedOptionModule with submodules?

@wmertens
Copy link
Contributor

I don't think it's possible, but you could just keep enableSSL a hidden setting that you logically OR with forceSSL to decide to force…

@nbp
Copy link
Member

nbp commented Jul 22, 2017

@globin @rnhmjoj To make it work within a submodule you would have to make a new option named warnings which accumulate the messages, and the definitions of these options (multiple instances of submodules) should be forwarded to the top-level warnings option.

https://github.com/NixOS/nixpkgs/blob/master/lib/modules.nix#L669

@rnhmjoj
Copy link
Contributor Author

rnhmjoj commented Jul 22, 2017

Sorry but I don't understand. Can you show me an example?

@wmertens
Copy link
Contributor

👌 LGTM, let's merge?

@rnhmjoj
Copy link
Contributor Author

rnhmjoj commented Jul 26, 2017

Currently .enableSSL = true; doesn't do anything besides triggering the warning. Is it ok?

@wmertens
Copy link
Contributor

wmertens commented Jul 26, 2017 via email

@rnhmjoj
Copy link
Contributor Author

rnhmjoj commented Jul 26, 2017

Done.

Copy link
Member

@fpletz fpletz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot! LGTM overall but see my comments.

+ ";";

redirectListen = filter (x: !x.ssl) defaultListen;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need another assertion that there is a listen statement with and without ssl enabled. Otherwise there won't be any listen directives in either the redirect or host server block.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I understand. forceSSL implies addSSL so at least hostListen should have an entry. How can they be both empty?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ping

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rnhmjoj Hmm, you can set forceSSL but not addSSL right? That would be wrong of course, but why not make addSSL be true if forceSSL is true? Or assert it at least?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is an assert:

       assertion = all (conf: with conf; forceSSL -> addSSL) (attrValues virtualHosts);
       message = ''
          Option services.nginx.virtualHosts.<name>.forceSSL requires
          services.nginx.virtualHosts.<name>.addSSL set to true.
        '';

@@ -70,12 +66,24 @@ with lib;
'';
};

enableSSL = mkOption {
addSSL = mkOption {
type = types.bool;
default = false;
description = "Whether to enable SSL (https) support.";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Description proposal:

Whether to enable HTTPS in addition to plain HTTP. This will set defaults
for <literal>listen</literal> to listen on all interfaces on the
respective default ports (80, 443).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you.

visible = false;
default = false;
};

forceSSL = mkOption {
type = types.bool;
default = false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Description proposal:

Whether to add a separate nginx server block that permanently redirects (301) all
plain HTTP traffic to HTTPS. This option needs <literal>addSSL</literal> to be
set to true.

onlySSL = mkOption {
type = types.bool;
default = false;
description = "Whether to enable SSL (https) support and reject plain (http) connections.";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Description proposal:

Whether to add a separate nginx server block that permanently redirects (301)
all plain HTTP traffic to HTTPS. This will set defaults for <literal>listen</literal>
to listen on all interfaces on port 443.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you mixed up this one.

@wmertens
Copy link
Contributor

wmertens commented Aug 1, 2017 via email

@wmertens wmertens merged commit 339330b into NixOS:master Aug 7, 2017
@wmertens
Copy link
Contributor

wmertens commented Aug 7, 2017

Merged since no further comments, thanks!

@rnhmjoj
Copy link
Contributor Author

rnhmjoj commented Aug 7, 2017

Issues #27338 #25533 should be closed. I'm not sure about #23711.

florianjacob added a commit to florianjacob/nixpkgs that referenced this pull request Aug 30, 2017
instead of redeclaring part of the options. Backward-compatible change.
This gives the same flexibility to the user as nginx itself.
This also resolves the piwik module break from nginx' enableSSL introduction from NixOS#27426.
@rnhmjoj rnhmjoj deleted the nginx branch September 12, 2017 23:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants