mirror of
https://github.com/dehydrated-io/dehydrated.git
synced 2026-01-11 22:30:44 +01:00
hooks for starting web server only to get auth/cert #137
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @arekm on GitHub (Aug 14, 2016).
Assume you want to create certificates for some other service, like jabber server. web server is turned off by default there and needs to be started only for letsencrypt auth.
So some hooks for that would be nice. Right now I'm doing it in a bit hacky way:
clean_challenge is not always called AFAIK and deploy_cert is called even if certificate did not change, so these hooks are not best for such job.
@Robby- commented on GitHub (Sep 3, 2016):
I'm making preparations to do something very similar, but with nginx instead.
According to the documentation in
docs/examples/hook.sh, or at least what I make out of it, theclean_challengehook only gets called when there is something to clean. This can explain what you are experiencing when you say that it is not always called.For
deploy_certmy understanding is that it only gets called when a new certificate has been produced/retrieved. Ifdeploy_certalways gets called for you, then that sounds like either a bug inside the letsencrypt.sh script itself (or an error in the documentation), or something is wrong in your setup, although the snippet you pasted looks good.For me, in another setup that I have (also an nginx webserver, but one that is always running and needs certificates for itself) the
deploy_certhook only gets called as described in the documentation (when a new certificate has been produced/retrieved).Anyhow, as I said, I'm making preparations (writing a hook script) to do something very similar, and as it is not ready yet I have yet to test it out against the LE staging server. What I'm going to do is start the nginx server in
deploy_challenge, and then indeploy_certI'm stopping the nginx server and copying the new certificates to where they need to be. Provided the documentation is correct (and my understanding of it is also correct) I should have no problems with this, and also not need any of the other hooks, only the two hooks I mentioned.Edit: I have tested it and it is working as expected. I am however thinking of using
clean_challengeto stop the webserver instead of doing it indeploy_cert, sinceclean_challengeseems to be the better choice as it is always supposed to be called, whether the challenge validation is successful or not.@rpv-tomsk commented on GitHub (Dec 19, 2016):
I.e. there is need in two hooks:
Last hook can be used for webserver reload in common HTTPS tasks (as requested in #316).
@tkaehn commented on GitHub (Jan 16, 2017):
It would be great to have one hook running directly after starting dehydrated to do some initialization (e.g. starting the web server or enabling firewall rules on systems which do not allow incoming connections on port 80 or outgoing connections on port 80 and 443). Additionally one hook should be run just before exiting dehydrated to clean everything up (regardless of new certificates being deployed or an error occured).
@txr13 commented on GitHub (Jan 16, 2017):
So far, I haven't seen any use case outlined here where the existing hooks would not suffice.
deploy_challengeworks for starting a web daemon and/or altering firewall rules.clean_challengeworks for killing the web daemon and/or re-altering firewall rules.deploy_certworks for writing out the cert (in whatever format is required) and reloading whatever daemon needs to know about the new cert.If you expect to be doing a lot of challenges and don't want to be continually starting and stopping the daemon, it seems trivial to write a script which does the needful before and after, and simply calls
dehydratedin the middle.@tkaehn commented on GitHub (Jan 17, 2017):
I agree that deploy_cert is sufficient for restarting the daemons. However setting up firewall rules in deploy_ and clean_challenge is not sufficient for systems which normally do not allow outgoing traffic on port 80 and 443.
Having a generic initialization and cleanup hook would solve this problem and might be helpful in other use cases.
Of course using a wrapper script calling dehydrated in the middle is possible, but this feels like a workaround for missing hooks.
@rpv-tomsk commented on GitHub (Jan 17, 2017):
The same hooks are requested in #331
@lukas2511 commented on GitHub (Jan 29, 2017):
I don't know what exactly you want, the
deploy_challengeandclean_challengehooks would be the ideal place for starting and stopping a web-server as they are really only called when there is work to do and they are always called in that case, only exception is on errors in the communication with Let's Encrypt, and there is a different hook for that (seerequest_failure).What you could also do to maybe spare some start/stop cycles is to just start the server in the
deploy_challengehook if it's not running yet, and just always stop it after dehydrated did its job...And just to make this clear: For me using a wrapper script is not a workaround, it's more or less the intended usage of this tool, that is one of the reasons why there are so many options on this script, hooks should only be for things that can't easily be solved in a different (clean) way.