-
-
Notifications
You must be signed in to change notification settings - Fork 605
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
Enable Let's Encrypt to detect updated site_hosts #630
Conversation
c34ef9c
to
b6f361e
Compare
7a7cc1a
to
3a8e830
Compare
After generous and painstaking review from @swalkinshaw, I think this is ready. This PR originally intended to solve the problem that CSRs and certs would not detect changes in Upon further review, I see that other crucial changes would go undetected, but should trigger cert regeneration, i.e., changes in any of the following:
The revised 2nd commit hashes the combination of the above, per site, inserting a corresponding 7-digit ID into CSR and cert filenames. If any item above changes, the required filename will change, triggering creation of new CSRs and certs (if they don't already exist with this ID). Edit: I edited the 2nd commit, adjusting this line in -letsencrypt_cert_ids: "{ {% for item in generate_cert_ids.results %}'{{ item.item.key }}':'{{ item.stdout }}', {% endfor %} }"
+letsencrypt_cert_ids: "{ {% for item in generate_cert_ids.results if not item | skipped %}'{{ item.item.key }}':'{{ item.stdout }}', {% endfor %} }" How to updateNew serversNew servers provisioned with Trellis (after this PR is merged) will accommodate changes to Existing servers that do NOT need to add hosts to
|
3a8e830
to
68f40ef
Compare
Let's go forward with this 👍 Needs changelog + maybe docs? |
Each ID is a hash of the combination of the following: * var: site_hosts * var: letsencrypt_intermediate_cert_sha256sum * var: acme_tiny_commit * var: letsencrypt_ca * file: /etc/nginx/ssl/letsencrypt/{{ site }}.key * file: /var/lib/letsencrypt/account.key
Awesome work |
Update CSRs and certs
The primary problem to solve: If a user has already created Let's Encrypt CSRs and certs then modifies
site_hosts
, the LE role will fail to update the CSRs/certs.If an LE cert exists, it will not update if not older than 60 days. If a CSR exists, it will not be recreated because the
creates
parameter specifies the CSR file, and "when it already exists, this step will not be run."This PR updates the LE role to detect changes to
site_hosts
and update the CSR. The PR also updates therenew-certs.py
to detect changes to the CSR and update the cert, even if younger than 60 days.The CSR updates become idempotent via a new rsync like Trellis already uses for the .env file (details on rationale of using rsync for idempotence).Add acme challenge location to conf
Edit: The remainder of this comment is now obsolete after internal discussion and a decision to avoid the
replace
module.If a user has just updated to a version of Trellis that includes the LE role, the LE role's Test Acme Challenges would fail because the
wordpress-setup
role hasn't yet had a chance to insertinclude acme-challenge-location.conf;
into the conf. This challenge location could also be missing for users with current Trellis with ssl enabled with a non-LE provider. This missing challenge location has required users to run thewordpress
role first to update their conf before running theletsencrypt
role, an unexpected hassle.This PR updates the LE role to detect the missing challenge location and inserts it into the conf so that users no longer must run the
wordpress
role first. This feature is convenient but relies on the replace module, which introduces some risk. There are some reassurances, however.replace
task will not even run if the challenge location is already in the conf.wordpress
tag, which they would have had to do anyway without this attemptedreplace
. Then the challenge location will be in the conf and thereplace
won't ever run again for that user/project.replace
regex is designed to remove nothing. It should return everything matched, just adding the challenge location conf.Explaining some regex (suggestions welcome)
example:
(listen 80;(?:[^\{]*\n)*)(.*return 301 \$scheme:\/\/.*\$request_uri;)
(listen 80;(?:[^\{]*\n)*)
-- backref 1listen 80;
-- this portion of the match must begin withlisten 80;
(?:[^\{]*\n)*
?:
prevents the creation of a separate backref for this(?:pattern)
.[^\{]*\n
will match any character(s) -- except{
-- followed by a newline. Excluding the{
prevents matching across server/location blocks. For example, we wouldn't want a match to start at thelisten 80;
from the "ssl redirect server block" and finish on thereturn 301
in the following "general redirects server block."*
lets there be multiple instances of[^\{]*\n
(.*return 301 \$scheme:\/\/.*\$request_uri;)
-- backref 2The match patterns appear applicable to the conf for the past year (back to ff0fbff, June 30, 2015).
Handlers
Edit: The handler adjustment separated out to #722.