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

security.acme: added reload and restart lists for sytemd targets #34388

Merged
merged 5 commits into from Feb 6, 2018

Conversation

qknight
Copy link
Member

@qknight qknight commented Jan 29, 2018

Motivation for this change
  • added a list for systemd reload and restart targets
  • using the nixos module system to set the default at the domain option (instead of using code in the config = section which duplicates code and makes it not accessible from outside the acme.nix scope)
Things done

reload = mkOption {
type = types.listOf types.str;
default = [];
example = [ "postfix.service" ];
Copy link
Member

Choose a reason for hiding this comment

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

postfix.service is used in both examples. Which one is needed for postfix and can we find a different common example for the other-one?

Copy link
Member Author

Choose a reason for hiding this comment

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

my main goal is postfix.service but maybe there are other use-cases as well.

Copy link
Member Author

Choose a reason for hiding this comment

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

we could use dovecot.service for instance

@@ -193,10 +225,11 @@ in
servicesLists = mapAttrsToList certToServices cfg.certs;
certToServices = cert: data:
let
domain = if data.domain != null then data.domain else cert;
restartJobs = lib.unique data.systemd.restart;
reloadJobs = lib.subtractLists restartJobs (lib.unique data.systemd.reload);
Copy link
Member

@zimbatm zimbatm Jan 29, 2018

Choose a reason for hiding this comment

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

What is the case where a restart jobs is promoted to reload only? It seems like a configuration error.

Reversely, if one wants to change a job from reloading to restarting, how would you do that?

Using a { jobName = "restart" | "reload" } data-structure would guarantee the uniqueness and allow that kind of override.

Copy link
Member Author

Choose a reason for hiding this comment

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

@zimbatm i 'feel' that there are use-cases but can't think of one atm. so maybe it is over-engineered.

Copy link
Member Author

@qknight qknight Jan 29, 2018

Choose a reason for hiding this comment

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

many services as postfix.service and dovecot.service can load new certificates using reload so one does not have to cut connections, reset state and such, which would be the case with a full reload.

but there could be a plugin for dovecot, a plugin like https://pigeonhole.dovecot.org/, which hypotetically would require postfix to restart. i made this up of course, but the code using lib.unique and restart over reload is already there and simple so why not just use it.

@qknight
Copy link
Member Author

qknight commented Jan 29, 2018

i have to fix a issue with the overall design first and then i will reopen the PR

@zimbatm
Copy link
Member

zimbatm commented Jan 29, 2018

sure no problem

@qknight
Copy link
Member Author

qknight commented Jan 29, 2018

ATM i wonder why there is: cert.domain at all. what is the motivation to not just use the attrName as 'domain' key? if no such motivation is there i'd like to rewrite the service and force the attrName to be the domain and get rid of the domain mkOption completely.

@fpletz
Copy link
Member

fpletz commented Jan 29, 2018

The domain option was introduced to make it possible to have different certificates with the same common name (i.e. with different SubjAltNames for different services).

@qknight qknight reopened this Jan 29, 2018
@qknight
Copy link
Member Author

qknight commented Jan 29, 2018

now that @fpletz explained why domain needs to be there i think that this patch is working for both of our use-cases.

@zimbatm
Copy link
Member

zimbatm commented Jan 30, 2018

@qknight I pushed a simplified proposal to your branch that takes into account what we where saying previously. It still needs a bit of testing. Feel free to revert or change it however you like.

@qknight
Copy link
Member Author

qknight commented Jan 30, 2018

@zimbatm happy to use your modified version. i have to find out what has to be done now, do i merge your stuff now and then sqash-merge it?

@zimbatm
Copy link
Member

zimbatm commented Jan 30, 2018

yes or keep adding commits to the branch and I'll squash them during merge

@qknight
Copy link
Member Author

qknight commented Jan 31, 2018

another thing i don't understand is security.acme.certs.<name>.webroot. in nixcloud-webservices i'm using a constant here, which points to /var/lib/acme/acme-challenges for all my security.acme.certs.

i assume this value is closely coupled with the vhost abstraction in nginx you guys wrote, is that correct? i'd like to add a example value and a better description to it, any ideas what that could be?

@zimbatm
Copy link
Member

zimbatm commented Jan 31, 2018

yeah, I didn't build it but I'm pretty sure it's tied to the nginx enableTLS feature. It should work with Apache or any other webserver that can map the .well-known folder to that path. I believe that ACME has other validation methods, in which case this folder would be pretty useless.

@qknight
Copy link
Member Author

qknight commented Feb 1, 2018

@zimbatm if you like it, please merge it. i didn't test 'our' work in production yet, so merge with care. and thanks for your effort, very much appreciated!

@qknight
Copy link
Member Author

qknight commented Feb 2, 2018

@zimbatm @fpletz

regarding default values

at the moment this is the most important patch so that domain is always assigned to a resonable value (not null but a string) by default. this is an important patch, since i want to read the certificates directly and don't have to check if they are null and then "otherwise" use the attrName.

regarding restart/reload

creating the new reload and restart targets was motivated by the idea that one can merge the different configs for a single domain so nixcloud.email could use the same TLS certificates as nixcloud.webservices but since merging does not work our current solution is to use seperate certs for these two use-cases.

this usage still does not exceed the quota of weekly certs of 4.

we could basically drop this from the PR and maybe create a new abstraction: security.TLS which uses security.acme as a backend.

@qknight
Copy link
Member Author

qknight commented Feb 2, 2018

webroot might have to be a unique directory but i'm not sure.

@zimbatm
Copy link
Member

zimbatm commented Feb 4, 2018

How about creating a new PR with just the default values change?

The rest is less obvious to me and I don't have a setup to test it out right now; I think overall the idea is good, it just needs to be fleshed out a bit more.

@qknight
Copy link
Member Author

qknight commented Feb 4, 2018

@zimbatm yes, this seems to be a good idea. let's skip the restart/reload feature completely for the time being.

@qknight
Copy link
Member Author

qknight commented Feb 4, 2018

@zimbatm

  • please check this latest patch and squash merge it.
  • after your merge into master i would like to cherry-pick this into 17.09 later on, agreed?

@zimbatm
Copy link
Member

zimbatm commented Feb 6, 2018

@GrahamcOfBorg test acme

@GrahamcOfBorg
Copy link

Failure on aarch64-linux (full log)

Partial log (click to expand)

Package ‘botan-1.10.17’ in /var/lib/gc-of-borg/nix-test-rs-3/repo/38dca4e3aa6bca43ea96d2fcc04e8229/builder/grahamc-aarch64-community-3/pkgs/development/libraries/botan/generic.nix:46 is not supported on ‘aarch64-linux’, refusing to evaluate.

a) For `nixos-rebuild` you can set
  { nixpkgs.config.allowBroken = true; }
in configuration.nix to override this.

b) For `nix-env`, `nix-build`, `nix-shell` or any other Nix command you can add
  { allowBroken = true; }
to ~/.config/nixpkgs/config.nix.

@GrahamcOfBorg
Copy link

Success on x86_64-linux (full log)

Partial log (click to expand)

webserver: running command: sync
webserver: exit status 0
test script finished in 105.64s
cleaning up
killing client (pid 612)
killing letsencrypt (pid 593)
killing webserver (pid 623)
vde_switch: EOF on stdin, cleaning up and exiting
vde_switch: Could not remove ctl dir '/tmp/nix-build-vm-test-run-acme.drv-0/vde1.ctl': Directory not empty
/nix/store/7f6jj93lgz7klhdsl6kc2gsqn9cfk4rk-vm-test-run-acme

@zimbatm
Copy link
Member

zimbatm commented Feb 6, 2018

@qknight looks good to me. It should be safe to be cherry-picked as well.

Any idea on what to name the commit?

@qknight
Copy link
Member Author

qknight commented Feb 6, 2018

something like acme_default_value_via_module_system

@zimbatm zimbatm merged commit edeacd0 into NixOS:master Feb 6, 2018
Copy link
Member

@dotlambda dotlambda left a comment

Choose a reason for hiding this comment

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

This breaks the build of the manual:

options-db.xml:6594: parser error : Opening and ending tag mismatch: name line 6594 and option
(<option>security.acme.cert.<name>.group</option>) to read SSL private certifica

@dotlambda
Copy link
Member

Fixed XML in #34683

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

5 participants