vert.x icon indicating copy to clipboard operation
vert.x copied to clipboard

Automatic certificate change detection and reload

Open lukehutch opened this issue 5 years ago • 11 comments

Vert.x needs to support automatic change detection and reload for certificates, so that Vert.x servers can be used with certbot.

Currently Vert.x does not have out-of-the-box support for LetsEncrypt.org's ACME. There is an outdated project that implemented support for an older version protocol. However, a better strategy is to rely on certbot, the primary recommended ACME client, set up as a cron job to renew certificates as needed.

When used with a Vert.x server, this would require shutting down the Vert.x server and restarting it when the certificate is renewed, using certbot's --renew-hook option. Server downtime, even if brief, is not ideal.

It would be much better for Vert.x to be able to watch for changes to certificates, and reload certificates if they change.

Related:

https://groups.google.com/forum/#!topic/vertx/fLQPPAxkftM

https://github.com/eclipse-vertx/vert.x/issues/2606

lukehutch avatar Mar 08 '19 11:03 lukehutch

An alternative to watch for changes to the certificates would be to use the --renew-hook to send a e.g. REST request using e.g. curl to the server to refresh the certificates. You could run a separate HTTP-only REST api on a different port for this purpose alone for example.

xkr47 avatar Mar 11 '19 08:03 xkr47

@xkr47 Yes, or you could use the Hazelcast CLI to send a message on the event bus, or (ideally) vertx-shell could be extended with a reload-certificates command.

Vert.x currently has no dynamic certificate reload support though, so that needs to be fixed first, e.g. by using your DynamicCertOptions class (which I discovered after filing this bug report). I really think this should be part of vertx-core.

lukehutch avatar Mar 11 '19 08:03 lukehutch

(DynamicCertOptions is lower-level than DynamicCertManager but yeah sure that can be used as well.)

xkr47 avatar Mar 11 '19 13:03 xkr47

DynamicCertOptions would be the way to go I think, CertOptions have been designed to be extended this way.

On 11 Mar 2019, at 14:17, Jonas Berlin [email protected] wrote:

(DynamicCertOptions is lower-level but yeah sure that can be used as well.)

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/eclipse-vertx/vert.x/issues/2870#issuecomment-471534217, or mute the thread https://github.com/notifications/unsubscribe-auth/AANxigsSHv_XTd9DrNbT5qn75HwcCt-bks5vVld_gaJpZM4blLPR.

vietj avatar Mar 11 '19 13:03 vietj

@vietj Can something like that be built into Vert.x? It's not much extra code to support reload.

lukehutch avatar Mar 11 '19 17:03 lukehutch

I don't know yet, Ithink there is room for a vertx util based project to host things like this too

vietj avatar Mar 12 '19 16:03 vietj

that being said the dynamic cert options don't depend on anything

vietj avatar Mar 12 '19 16:03 vietj

Any update or workarounds for this?

carbotaniuman avatar May 23 '20 19:05 carbotaniuman

I have published a working reference implementation/demo here: Instant SSL Reloading For Vert.x I hope this is a bit useful for others who seek for a solution for this kind of use case.

There is no updating service provided by Vert.x itself, but it is possible to update and reload ssl configuration without restarting it by having a slightly different server configuration. I have provided one example of fetching the updated keystores from the file system, however it is also possible to use pem and der files. It is also possible to fetch the newly created certificates from a database or some other place.

This example is using my own library, which can be found here: SSLContext Kickstart which might be useful for others who still want to have this kind of feature of reloading ssl without restarting the server.

@vietj Do you think some of it can be used or integrated by Vert.x library to provide something like this out of the box?

Hakky54 avatar Apr 15 '22 23:04 Hakky54

thanks @Hakky54

I think we could provide in Vert.x an SPI to integrate Vertx to more easily integrate with SSLContext library

vietj avatar May 03 '22 14:05 vietj

Hi everyone, I have added my input regarding reloading the ssl configuration here: https://github.com/eclipse-vertx/vert.x/issues/4452 I am curious what everyones opinion would be for the solution. Not quite sure if this is what is ok for you @vietj ?

Hakky54 avatar Aug 09 '22 22:08 Hakky54

Hi everyone, I have created a PR with changes needed for doing automatic certificate reload in Vertx server. Let me know what your thoughts are, regarding this approach https://github.com/eclipse-vertx/vert.x/pull/4519. We run a background timer to check for certificate file changes and refresh SsLContext. We allow enabling refresh per certificate basis and also setting refresh rate per cert.

sarankk avatar Oct 25 '22 18:10 sarankk

@sarankk I think instead we should have an option on HttpServer to reload certificate so it can be used externally and we don't need to mess with SSL options which are already pretty crowded, e.g a method like refreshCertificate(KeyCertOptions), so any user could do that using its own periodic

vietj avatar Oct 26 '22 08:10 vietj

Hi @vietj I also did an attempt to support this out of the box within Vertx, you can find here my latest changes on the PR https://github.com/eclipse-vertx/vert.x/pull/4453. It is inspired from the PR https://github.com/eclipse-vertx/vert.x/pull/4519 but slightly different. The ssl reloading can be enabled by setting the refresh option on the HttpServerOptions. I have added an example usage/server configuration to the PR as a comment at the bottom. Can you maybe have a look at it? I am curious whether it is something in the right direction or needs to be adjusted.

Hakky54 avatar Oct 31 '22 09:10 Hakky54

See https://github.com/eclipse-vertx/vert.x/pull/4568

vietj avatar Dec 17 '22 10:12 vietj