auto-ssl / auto-ssl/lua-resty-auto-ssl

Pure Lua ACME protocol implementation

Open
#132 2 comments 7 reactions 0 assignees View on GitHub
enhancement
Dominant language
Lua
Stars
2k
Forks
184
PR merge metrics
No merged PRs in 30d

Description

I'm opening this issue to track the idea of a pure Lua ACME client implementation (instead of relying on dehydrated). I'm not sure if/when this will happen, but I thought it was worth having an issue to reference and be able to discuss.

This idea has been rolling around since the initial creation of lua-resty-auto-ssl, as the TODO section of the README has noted since the beginning:

> We currently rely on [dehydrated](https://github.com/lukas2511/dehydrated) as our Let's Encrypt client. It's called in a non-blocking fashion via [lua-resty-shell](https://github.com/juce/lua-resty-shell) and [sockproc](https://github.com/juce/sockproc), however it might be simpler to eventually replace this approach with a native OpenResty Let's Encrypt client someday.

For the most part, using dehydrated has served us well, and has allowed us to offload all the underlying ACME protocol work for registering certs with Let's Encrypt. That being said, the reliance on lua-resty-shell and sockproc also adds complexity to lua-resty-auto-ssl for a few reasons:

- It requires the extra local HTTP server running on port 8999 used for communication between dehydrated's shell scripts and lua-resty-auto-ssl.
- Running sockproc in the background, and getting permissions right can lead to some funky installation/runtime issues. While for the most part, things should be automatic and I think this is working for most users, various different installations can lead to edge-case issues (a decent number of GitHub issues can probably be traced back to this, but here's a few random examples that seem like they could be related: https://github.com/GUI/lua-resty-auto-ssl/issues/121, https://github.com/GUI/lua-resty-auto-ssl/issues/114, https://github.com/GUI/lua-resty-auto-ssl/issues/98
- Installing sockproc requires a build process involving make and gcc, which means lua-resty-auto-ssl can only be installed via LuaRocks, and not OpenResty's OPM: https://github.com/GUI/lua-resty-auto-ssl/issues/45 While there's nothing wrong with LuaRocks, and OPM may eventually support modules that require compiling, it would be nice to be able to support OPM installs.

With the ACME v2 protocol now finalized, this idea has been increasingly on my mind. On the one hand, creating a pure Lua ACME client implementation will require a decent amount of new work, but the prospect of being able to ditch the reliance on sockproc is appealing (not that there's anything wrong with sockproc, but it just complicates our setup/installation and architecture).

If we wanted to go down this path, my general idea has been the creation of 1 or 2 new Lua libraries:

- OpenSSL bindings: We need some way to create new certificates directly in Lua and do the lower-level OpenSSL things (that dehydrated currently does with the openssl command line tools). [luaossl](https://github.com/wahern/luaossl) could be used, although this is a C-based module, which means it can only currently be installed via LuaRocks (so no OPM). I've recently been toying around with a [lua-openssl-ffi](https://github.com/GUI/lua-openssl-ffi) module to perform everything in OpenSSL via FFI (which means nothing in C needs to be compiled, so this could be installed via OPM).
- ACME client: My idea had been to create a new `lua-resty-acme` library that would use the OpenSSL library and lua-resty-http to actually implement the ACME v2 protocol. lua-resty-auto-ssl would still exist as a higher-level library that used lua-resty-acme (lua-resty-acme would only implement the protocol, playing a similar role to dehydrated, while lua-resty-auto-ssl would still perform all the nginx integration, SNI-based registration, certificate storage, etc.).

So again, I'm not sure if/when this will happen, but I at least wanted to get some of these ideas finally out there in a more concrete format.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the README TODO and trace how dehydrated is invoked through lua-resty-shell and sockproc. Compare the proposed lua-resty-acme, OpenSSL bindings, and lua-resty-http responsibilities; done would mean a native ACME v2 path that removes the extra sockproc and local HTTP-server dependencies while preserving lua-resty-auto-ssl's integration.

Written by the indexing model from the issue text.

Assessment

Tech stack
lua, nginx
Domain
backend, security
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.