-
-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[WIP] nixos/acme: switch to lego and support DNS challenge #63613
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
Conversation
CC @arianvp |
@petabyteboy Could you show some examples of different dns providers? I'm specifically interested in an example for https://go-acme.github.io/lego/dns/httpreq/ if you don't mind. Thanks for taking this on. As you mentioned, a much requested feature. |
My configuration for an Amazon Route53 domain looks like this:
/var/src/secrets/route53-api-keys contains something like this:
For the httpreq provider it might look like this:
with lego-httpreq-credentials containing:
|
Thanks for the information @petabyteboy. Great work as usual. I hope to test this over the next week or so. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to be pretty incompatible with existing setups. How are we going to migrate users of the existing module over to this new one, preferably without causing them any pain?
I have listed some of the breaking changes in the initial post. Some of them might be fixable, but this needs work. If there is no way to make it compatible, I would suggest using lego only for installations with a recent stateVersion. |
@petabyteboy you mind if I cherry-pick this into https://github.com/NixOS/nixpkgs/pull/60219/commits ? I'm pretty heavily rewriting the letsencrypt module, and having two diverging branches might cause trouble . Might be better to integrate this into my PR so that we won't have issues merging later on. Keeping both Another option: |
Also, perhaps we want to be able to specify the provider right from the |
@petabyteboy are you still working on this, or how is it? :) I might test this out, and see how it works! |
By enabling the services the user has agreed. I guess it would be worth mentioning that in the documentation... 🤷♂️ |
I'm not actively working on it currently, but I haven't abandoned it. |
Does that work from a legal standpoint? Also, I have made two improvements so far
Don't know the best way to apply them, or add them to the PR.. :) --- acme.nix.bak 2019-09-14 13:11:59.084248039 +0200
+++ acme.nix 2019-09-14 13:16:50.411259892 +0200
@@ -213,7 +213,7 @@
lpath = "${cfg.directory}/${cert}";
rights = if data.allowKeysForGroup then "750" else "700";
renewHook = pkgs.writeScript "lego-renew-hook" ''
- touch /tmp/success
+ touch ${cpath}/renewed
'';
globalOpts = optionals (!cfg.production) ["--server" "https://acme-staging-v02.api.letsencrypt.org/directory"]
++ concatLists (mapAttrsToList (name: root: [ "--domains" name ]) data.extraDomains)
@@ -243,10 +243,13 @@
fi
chmod ${rights} '${cpath}'
chown -R '${data.user}:${data.group}' '${cpath}'
- ${optionalString (data.dnsProvider != null) ''
+ ${optionalString (data.dnsProvider == null) ''
mkdir -p '${data.webroot}/.well-known/acme-challenge'
chown -R '${data.user}:${data.group}' '${data.webroot}/.well-known/acme-challenge'
''}
+ if [ -e ${cpath}/renewed ]; then
+ rm ${cpath}/renewed
+ fi
'';
script = ''
cd '${cpath}'
@@ -262,7 +265,7 @@
postStop = ''
cd '${cpath}'
- if [ -e /tmp/success ]; then
+ if [ -e ${cpath}/renewed ]; then
cp .lego/certificates/${data.domain}.crt cert.pem
cp .lego/certificates/${data.domain}.issuer.crt chain.pem
cp .lego/certificates/${data.domain}.key key.pem EDIT: Wrong patch |
|
Started using this in my own production to generate wildcard certificates. It works but there was a few things I had to modify:
@@ -207,11 +207,11 @@ in {
cd '${cpath}'
if [ -e ${cpath}/renewed ]; then
- cp .lego/certificates/${data.domain}.crt cert.pem
- cp .lego/certificates/${data.domain}.issuer.crt chain.pem
- cp .lego/certificates/${data.domain}.key key.pem
- cat .lego/certificates/${data.domain}.crt .lego/certificates/${data.domain}.issuer.crt > fullchain.pem
- cat .lego/certificates/${data.domain}.key .lego/certificates/${data.domain}.crt .lego/certificates/${data.domain}.issuer.crt > full.pem
+ cp .lego/certificates/*${data.domain}.crt cert.pem
+ cp .lego/certificates/*${data.domain}.issuer.crt chain.pem
+ cp .lego/certificates/*${data.domain}.key key.pem
+ cat .lego/certificates/*${data.domain}.crt .lego/certificates/*${data.domain}.issuer.crt > fullchain.pem
+ cat .lego/certificates/*${data.domain}.key .lego/certificates/*${data.domain}.crt .lego/certificates/*${data.domain}.issuer.crt > full.pem
chmod ${rights} "${cpath}/"{key,fullchain,full,chain,cert}.pem
chown '${data.user}:${data.group}' "${cpath}/"{key,fullchain,full,chain,cert}.pem |
@m1cr0man Are your improvements publicly available? |
@m1cr0man Your module worked for me (with one caveat, see below). The The only problem I experienced was that the acme module in NixOS specifies We should really think about how to integrate this module into NixOS, as the DNS challenge is an extremely useful feature. I subscribe to @arianvp's opinion that it's not ideal to maintain two modules that almost do the same thing, but I also don't like breaking existing installations. If we're deprecating things, I'd also vote to change the |
@wizeman making it a new module and then marking the original as deprecated seems like a reasonable thing to do, but I would suggest only doing it, if we cannot make the current module backwards compatible (which should be possible, right?). Also, is @petabyteboy still working on this? Would be lovely to see some of these changes in the PR. |
No, it will not be possible to make it fully backwards-compatible, because lego does not provide some options, for example using a seperate webdir per domain with the HTTP challenge and multi-domain certs. |
For some reason I just remember both of these things being part of lego as is, but I might remember wrong. But can't this be fixed using the following ways?
|
globalOpts = optionals (!cfg.production) ["--server" "https://acme-staging-v02.api.letsencrypt.org/directory"] | ||
++ concatLists (mapAttrsToList (name: root: [ "--domains" name ]) data.extraDomains) | ||
++ [ "--domains" data.domain "--email" data.email "--accept-tos" ] | ||
++ (if data.dnsProvider != null then [ "--dns" data.dnsProvider ] else [ "--http.webroot" data.webroot ]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pretty sure it should be:
else [ "--http" "--http.webroot" data.webroot ]
}; | ||
path = with pkgs; [ simp_le systemd ]; | ||
path = with pkgs; [ lego systemd ]; | ||
preStart = '' | ||
mkdir -p '${cfg.directory}' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this be: mkdir -p '${cfg.cpath}'
?
Thanks for the feedback @wizeman , I must fix that validMin in my version. I think it would be possible to make this backwards compatible. With regards to the custom webdirs - symlinks could be used to achieve this, and I don't see what would be wrong with doing so in the preStart hook for each domain's certs service. |
Let's take extra care not to complicate the module code too much. Also keep in mind that the existing module runs as a non root user now, so it would be great to continue that way. |
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/what-are-your-goals-for-20-03/4773/3 |
I'll be so sad if this functionality isn't added to I believe the correct path forward is to replace If anyone disagrees can they please speak up. @petabyteboy if there is agreement (or at least no disagreement) with what I have said are you motivated to continue on with this PR as described? |
FWIW, I am still up for taking this on to see if I can make it compatible with the existing setup. I am using in this prod for DNS and HTTP verified certs, but I haven't had time to clean it up to submit here. |
@m1cr0man that would be fantastic. Would you be willing to push your branch in its current state just so we can take a look? What do you think your timeline might be like for cleaning it up? Realistic to have in place well before |
Hi @aanderse all my current work is here and so will any updates I am doing. I'm currently writing a bit of Nix to map a list of vhosts to some HTTP certs. After I've succeeded with that I will immediately try standardising my setup so I can PR it back into nixpkgs and remove it from my repo. This is actually quite high priority for me and I'd be aiming to get it done before the end of the year, although maintaining this infra is a part time job for me at the same time ;) |
@m1cr0man fantastic news! Thank you very much for your efforts. |
If someone else is working on this, feel free to open a PR. I have tried to rebase this multiple times but never with an acceptable result, and since the backwards-compatibility requirements are higher than expected I will probably not make it work in time. |
Over the weekend I deployed a new web host which now serves 28 different domains. 1 of them is using wildcard LE certs, the other 27 are using HTTP-01 challenge. I had to make a few changes to the Lego based cert service to achieve this:
This summary is just a TL;DR, I will open a PR very soon to merge this in to nixpkgs. I'm eager to do so since this is in production now. I have 2 things to do:
|
Fantastic news! Thanks for the update @m1cr0man 🎉 |
I just enabled |
@m1cr0man happy new year! Any news on this? |
@aanderse All I can really say is yes, but I was set back by the death of my main NixOS server over the weekend. I'll be testing the lego based certs ontop of a machine currently running the old cert setup this weekend and I'll likely have the PR in this weekend too. |
Replaced by #77578 |
Motivation for this change
We use Let's Encrypt with DNS-based ACME challenges at work, so I needed this. I have seen multiple other people request DNS challenge support (#34941, #35168).
The following changes would be breaking:
Things done
sandbox
innix.conf
on non-NixOS)nix-shell -p nix-review --run "nix-review wip"
./result/bin/
)nix path-info -S
before and after)