News for hackers. Stuff that matters.
Re:On the fly SSL registration and renewal inside Nginx with... by kodablah on Wednesday July 20, 2016 @11:21AM (#12129708)
Nice. Good to see this has a shared storage option (Redis) for load balanced servers. The LE HTTP challenge gives no guarantee which A record it will use. Similarly, if your LB chooses another server even behind the same IP, it'd have to share the challenge state. I haven't read deeply, but I assume it handles the race conditions that can occur with auto renewal (i.e. different servers triggering auto renewal at the same time, overusing LE and hitting the quota faster). It was something I struggled with during the implementation of pluggable storage adapters for Caddy[0].

0 - https://github.com/mholt/caddy/pull/913

Re:On the fly SSL registration and renewal inside Nginx with... by okket on Wednesday July 20, 2016 @11:57AM (#12130025)
If you are going this scale, there is another way: Use your own DNS server and try the DNS-01 challenge. My setup works with [0]letsencrypt.sh, [1]pdns_api.sh, [2]PowerDNS4 (MySQL backend w/ replication) and a little script that distributes the certs and restarts services. The nice thing is, this works for anything you can put in DNS, you do not need not to respond to a HTTP request for a name (think mail server).

[0] https://github.com/lukas2511/letsencrypt.sh [1] https://github.com/silkeh/pdns_api.sh [2] https://github.com/PowerDNS/pdns

Re:On the fly SSL registration and renewal inside Nginx with... by nickblah on Wednesday July 20, 2016 @12:32PM (#12130335)
Yes, as long as you're using a shared storage adapter (like Redis), then for the most part, duplicate registration or renewal requests should be handled.

The approach to locking we're using is somewhat simplistic (and the specifics depend on the storage adapter you're using), so there might be some rare edge-cases in which 2 requests to Let's Encrypt slip through. However, that shouldn't actually affect the functionality (the last response simply wins). Here's a bit more detail in the code: https://github.com/GUI/lua-resty-auto-ssl/blob/v0.8.2/lib/re...

Re:On the fly SSL registration and renewal inside Nginx with... by bburky on Wednesday July 20, 2016 @09:41PM (#12133992)
> The LE HTTP challenge gives no guarantee which A record it will use.

That almost changed[0], but the current consensus[1] seems to be that you should be using dns-01 for validation behind a load balancer instead.

[0] https://github.com/ietf-wg-acme/acme/pull/138

[1] https://mailarchive.ietf.org/arch/msg/acme/6RSxtvpkcQNPmKs9f...

Re:On the fly SSL registration and renewal inside Nginx with... by andrewstuart2 on Wednesday July 20, 2016 @11:49AM (#12129961)
Re: hitting the quota faster, they have a staging environment that they explicitly mention as a target for client development. Probably not a helpful tip to you now, but others may find it useful.

https://letsencrypt.org/docs/staging-environment/

Re:On the fly SSL registration and renewal inside Nginx with... by artursapek on Wednesday July 20, 2016 @10:14AM (#12129146)
Wow, this is awesome. LetsEncrypt is great but I still find it somewhat clumsy to use it in production. This is the first no-downtime solution I've seen.

The certificate cartel is slowly dying :)

Re:On the fly SSL registration and renewal inside Nginx with... by snaky on Wednesday July 20, 2016 @10:22AM (#12129196)
You can even update Nginx binary with no downtime - https://nginx.org/en/docs/control.html#upgrade
Re:On the fly SSL registration and renewal inside Nginx with... by koolba on Wednesday July 20, 2016 @10:09AM (#12129106)
Hey this is pretty cool. Would be even cooler if it held off on the SSL handshake with the initial client until after the certificate was issued by LetsEncrypt. If it's only a couple of seconds it might be possible.
Re:On the fly SSL registration and renewal inside Nginx with... by nickblah on Wednesday July 20, 2016 @10:30AM (#12129260)
Author here.. If I'm understanding you correctly, I believe that's how things are already working. The very first time a client hits a new domain, the SSL handshake initiates the certificate registration with Let's Encrypt (assuming the domain is part of the whitelist of allowed domains). The certificate is registered in the background, while this first request is paused. The SSL handshake is then completed with the first client once the certificate is successfully issued. This does lead to the very first client's request being delayed a few seconds, but this is a one-time delay (per allowed domain).
Re:On the fly SSL registration and renewal inside Nginx with... by gonzo on Wednesday July 20, 2016 @10:46AM (#12129392)
Nice work!

We'll look into including this in pfsense 2.4.

Re:On the fly SSL registration and renewal inside Nginx with... by koolba on Wednesday July 20, 2016 @11:56AM (#12130022)
Ah I didn't realize that. I figured the first request kicks off the request process so it's available for subsequent requests. This is even cooler!
Re:On the fly SSL registration and renewal inside Nginx with... by aavotins on Wednesday July 20, 2016 @10:13AM (#12129134)
Or it would be even greater if it requested/generated all certificates upon configuration file parsing and delayed nginx from taking those values into account until valid certificates have been obtained.
Re:On the fly SSL registration and renewal inside Nginx with... by nickblah on Wednesday July 20, 2016 @10:39AM (#12129324)
Author here. Our current approach is perhaps a bit different, since we're not actually parsing the nginx config file, so we don't have knowledge of the domains at startup. Instead, we're relying on the "allow_domain" Lua function to be defined which provides a way to determine which domains should be allowed. By making this a Lua function, it allows for the logic behind this to be very flexible and dynamic (for example, nginx could handle wildcard requests to any domain, and then you could lookup what domains to allow SSL registration for from another dynamic source you might already have).

But I do like the idea of allowing this to be handled at startup too. Thanks for the idea!

Re:On the fly SSL registration and renewal inside Nginx with... by wyattjoh on Wednesday July 20, 2016 @10:49AM (#12129418)
Not having this featured built into NGINX is the reason why I transitioned my production servers over from it to Caddy. Having SSL just "dealt with" is the biggest time saver ever.
Re:On the fly SSL registration and renewal inside Nginx with... by msumpter on Wednesday July 20, 2016 @03:23PM (#12131731)
Awesome!

I had been playing around with https://github.com/jwilder/nginx-proxy and docker-gen to handle automatic Let's Encrypt generation for my docker containers.

It's amazing how quick to get some of these thing setup with very work: https://github.com/msumpter/docker-lua-resty-auto-ssl

Re:On the fly SSL registration and renewal inside Nginx with... by SixSigma on Thursday July 21, 2016 @04:10PM (#12139669)
You can use StartSSL free certs for TLS too

https://startssl.com/

I set up Courier today to use it for TLS imap

http://maht0x0r.blogspot.co.uk/2016/07/another-server-more-c...

Re:On the fly SSL registration and renewal inside Nginx with... by njharman on Wednesday July 20, 2016 @12:04PM (#12130095)
Let's Encrypt is awesome. I've used it to setup real https on several of my domains. It was easy, automatically renews, just works.
Re:On the fly SSL registration and renewal inside Nginx with... by tinganho on Wednesday July 20, 2016 @11:53AM (#12129993)
Just did something similar. Though with HAProxy inside a Docker container. https://github.com/tinganho/haproxy-with-letsencrypt-auto-re...
Re:On the fly SSL registration and renewal inside Nginx with... by noeleon on Thursday July 21, 2016 @08:08AM (#12136257)
The shared storage redis backed option is great. I hacked together something that served .well-known from an NFS mount to overcome my issues when behind a proxy / LB.

My $work has a very terribe DNS infrastructure that needs lots of work to implement dns-01.

Re:On the fly SSL registration and renewal inside Nginx with... by bsamuels on Wednesday July 20, 2016 @08:48PM (#12133751)
I wonder if there would be a way to integrate Let's Encrypt with router admin interfaces. It would be really cool if consumer routers used a valid https certificate on their web ui
Re:On the fly SSL registration and renewal inside Nginx with... by sandGorgon on Wednesday July 20, 2016 @11:55AM (#12130006)
This is awesome.. hopefully we can bake nginx inside docker. Without something like this, we could not spin up nginx because there was a circular dependency on the certificate files.
Re:On the fly SSL registration and renewal inside Nginx with... by hobs on Wednesday July 20, 2016 @11:58AM (#12130034)
I used a combo of https://github.com/dmp1ce/nginx-proxy-letsencrypt and https://github.com/jwilder/nginx-proxy with no problems besides normal nginx configuration.

Does assume you will have a shared volume so you can save/check certs, but it works great for my use case.

Re:On the fly SSL registration and renewal inside Nginx with... by sandGorgon on Wednesday July 20, 2016 @12:13PM (#12130164)
Well the shared volume to "seed" a certificate is a no go for us. I would rather spend 6 bucks for a cert.
Re:On the fly SSL registration and renewal inside Nginx with... by hobs on Wednesday July 20, 2016 @08:54PM (#12133775)
Totally get it, just thought I would share.
Re:On the fly SSL registration and renewal inside Nginx with... by d33 on Wednesday July 20, 2016 @04:18PM (#12132158)
Is there anything that would prevent an attack involving bogus SNI requests in order to trigger a DOS?
Re:On the fly SSL registration and renewal inside Nginx with... by nickblah on Wednesday July 20, 2016 @04:43PM (#12132354)
Yes, by default the module requires that you explicitly whitelist the domains you want to allow certificate registration for. So while you could allow any domain to be registered, that's not recommended for this precise reason. But the whitelist is defined as a Lua function, so you have quite a bit of flexibility in integrating the whitelist logic with other sources of information.

See https://github.com/GUI/lua-resty-auto-ssl#precautions and the "allowed_domain" configuration for a bit more detail.

Re:On the fly SSL registration and renewal inside Nginx with... by finnn on Wednesday July 20, 2016 @11:31AM (#12129795)
This is really cool. Have you considered implimenting the DVSNI challenge?
Re:On the fly SSL registration and renewal inside Nginx with... by nickblah on Wednesday July 20, 2016 @12:40PM (#12130407)
Author here. I hadn't really considered it, but it should be possible. Since we're handling this with nginx and Lua, it made it pretty trivial to handle the simple HTTP challenge (since we can easily intercept the /.well-known/acme-challenge request), so that's why we went with that approach, but other approaches should be possible.
Re:On the fly SSL registration and renewal inside Nginx with... by finnn on Wednesday July 20, 2016 @12:46PM (#12130471)
I guess I figured DVSNI should be even easier since you're already evaluating the domains of incoming TLS connections and picking which cert to respond with from there.
Re:On the fly SSL registration and renewal inside Nginx with... by nickblah on Wednesday July 20, 2016 @12:54PM (#12130525)
I haven't actually looked into DVSNI in too much detail before, so that could definitely be the case. I'll have to investigate a bit more (or any pull requests are always welcome). Thank you for the tip!
Re:On the fly SSL registration and renewal inside Nginx with... by finnn on Wednesday July 20, 2016 @01:02PM (#12130601)
No problem, thanks for building this!
Re:On the fly SSL registration and renewal inside Nginx with... by LoSboccacc on Wednesday July 20, 2016 @10:47AM (#12129400)
ah this would nicely handle the let's encrypt wildcard issue. too bad I just forked $$$ for a wildcard cert. but hey will turn off renew and have a go with this :)
Re:On the fly SSL registration and renewal inside Nginx with... by schoen on Wednesday July 20, 2016 @01:34PM (#12130853)
Bear in mind that you could potentially hit a rate limit depending on the number of subdomains you have (or a different rate limit depending on how the plugin requests particular certs). I'm sure a small number of users will become very aware of this issue very soon.

This is a reason that being at least somewhat aware of the overall list of names to be covered ahead of time could be helpful.

Re:On the fly SSL registration and renewal inside Nginx with... by bmurphy1976 on Wednesday July 20, 2016 @10:34AM (#12129280)
Apparently this requires OpenResty. OpenResty is an app server type platform built on Nginx. This does not appear to work on your standard run-of-the-mill Nginx system package.

OpenResty is a cool project, but it brings a lot of additional infrastructure along with it that you may not want.

It would be nice of this was clearly indicated in the title of this post.

Updated: see comment below, the README has been clarified, you can run this with the nginx_lua extension. You don't necessarily need all of OpenResty.

Re:On the fly SSL registration and renewal inside Nginx with... by snaky on Wednesday July 20, 2016 @10:40AM (#12129332)
Actually it does not require OpenResty, just ngx_lua module.
Re:On the fly SSL registration and renewal inside Nginx with... by dsp1234 on Wednesday July 20, 2016 @10:45AM (#12129372)
Someone should update the Installation section. It currently states:

  Requirements:

    OpenResty 1.9.7.2 or higher
Re:On the fly SSL registration and renewal inside Nginx with... by nickblah on Wednesday July 20, 2016 @11:05AM (#12129559)
I've updated the requirements in the README. Thanks for pointing that out!
Re:On the fly SSL registration and renewal inside Nginx with... by bmurphy1976 on Wednesday July 20, 2016 @12:15PM (#12130177)
OK, that's great! I recant my earlier comment. :)
Re:On the fly SSL registration and renewal inside Nginx with... by snaky on Wednesday July 20, 2016 @01:35PM (#12130858)
btw, what is a 'lot of additional infrastructure' that OpenResty brings?
Re:On the fly SSL registration and renewal inside Nginx with... by gtirloni on Wednesday July 20, 2016 @11:37AM (#12129845)
Compiling nginx from scratch to include ngx_lua is a bummer because of all the added questions that need to be answered (packaging, repositories, automation, etc).

It becomes 98% of the time spent enabling this awesome feature (at least on CentOS and Fedora, from what I can tell there aren't RPM packages for ngx_lua).

Re:On the fly SSL registration and renewal inside Nginx with... by msumpter on Wednesday July 20, 2016 @04:23PM (#12132196)
That has been one of my major driving forces behind creating Dockerfiles/docker-compose my personal/work projects to stand up quick environments. Docker support on CentOS 5 doesn't exist but I only have a few servers left from that era luckily.

If you want to give this a try within Docker I setup a repo here to try it out: https://github.com/msumpter/docker-lua-resty-auto-ssl

Re:On the fly SSL registration and renewal inside Nginx with... by snaky on Wednesday July 20, 2016 @11:40AM (#12129875)
Re:On the fly SSL registration and renewal inside Nginx with... by eloy on Wednesday July 20, 2016 @10:11AM (#12129111)
Please, please stop using the name "SSL" and use "TLS".

As others replied, x509 would be even more correct, but SSL is completely incorrect, because that protocol is insecure and shouldn't be used. Using SSL suggest that the software supports that protocol, although it doesn't (as it should)

Re:On the fly SSL registration and renewal inside Nginx with... by everfree on Wednesday July 20, 2016 @10:21AM (#12129195)
If we're getting nitpicky, let's use the term TLS to describe the protocol and X.509 to describe the certificates and renewals.
Re:On the fly SSL registration and renewal inside Nginx with... by blowski on Wednesday July 20, 2016 @10:23AM (#12129205)
As Shakespeare might once have said:

    What's in a name? That which we call TLS
    By any other name would still offer encryption.
Re:On the fly SSL registration and renewal inside Nginx with... by ssahoo on Wednesday July 20, 2016 @03:05PM (#12131586)
So taking extra lua dependency burden, and risk just to save 50 bucks to buy a real SSL certificate?

I'm going to call it certificateless SSL.