Skip to content

Rework letsencrypt::certonly for #175 #177

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

Merged
merged 1 commit into from
Mar 22, 2019
Merged

Conversation

cFire
Copy link
Contributor

@cFire cFire commented Feb 26, 2019

WIP: Need to test it and update documentation etc.

  • Added $ensure attribute
  • Renamed $ensure_cron back to $manage_cron
  • Returned $manage_cron back to a Boolean value
  • Made execute of "letsencrypt certonly ${title}" conditional to $ensure == 'present'
  • Added cleanup of directory for domain certs when $ensure == 'absent'
  • Used global $ensure to signal desired state of cronjobs

@Dan33l
Copy link
Member

Dan33l commented Feb 27, 2019

Tests were failing due to timeout. I relaunched them and now its ok.

@Dan33l Dan33l removed the tests-fail label Feb 27, 2019
@cFire cFire changed the title WIP rework letsencrypt::certonly for #175 Rework letsencrypt::certonly for #175 Feb 28, 2019
@Dan33l
Copy link
Member

Dan33l commented Mar 1, 2019

@cFire can you add [WIP] (Work In Progress) in the title and remove it when you have finished the work ?

@cFire
Copy link
Contributor Author

cFire commented Mar 1, 2019

The reason I've removed the WIP from the title is because it's ready for review (as far as I'm concerned). Sorry I did not explicitly mention that.

],
}
} else {
file { "${config_dir}/live/${live_path_domain}/":
Copy link
Contributor

@Rathios Rathios Mar 2, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did some testing to see what this'd do out of curiosity/concern. I'd personally look at running an exec to have certbot itself delete the certificate as rm -rf'ing the directory isn't quite sufficient to clean it all up. There are still files left behind in /etc/letsencrypt/renewal and /etc/letsencrypt/archive.

/etc/letsencrypt/renewal/certone.test.rawr.no.conf
/etc/letsencrypt/archive/certone.test.rawr.no

Certbot is unhappy about them as well:

$ certbot certificates
...
Renewal configuration file /etc/letsencrypt/renewal/certone.test.rawr.no.conf produced an unexpected error: expected /etc/letsencrypt/live/certone.test.rawr.no/cert.pem to be a symlink. Skipping.

Creating a new certificate again with the same name without cleaning up these files makes it append a -0001 to it, still leaving the old files behind and generating a certificate name the module can't clean up by itself.

What about something like this?

exec { "letsencrypt cleanup ${title}":
  command => "${letsencrypt_command} delete --cert-name ${title}",
  path    => $facts['path'],
  onlyif  => "test -d '${config_dir}/live/${live_path_domain}'",
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a much better idea. I'll look into implementing that over the coming week.

@cFire
Copy link
Contributor Author

cFire commented Mar 7, 2019

While working on implementing the delete function I noticed this;

$live_path_domain = regsubst($domains[0], '^\*\.', '')
$live_path = "${config_dir}/live/${live_path_domain}/cert.pem"

I think this is wrong when using a custom name like letsencrypt::certonly { "special_snowflake_${domain}": [...] } and will cause puppet to try and renew all certs every run.

Can someone please confirm I'm not seeing things that aren't there?
I think it should be

$live_path = "${config_dir}/live/${title}/cert.pem"

@cFire
Copy link
Contributor Author

cFire commented Mar 7, 2019

Pull request is ready for another round of reviews. All tests are passing and it seems to work well in my environments.

@Rathios
Copy link
Contributor

Rathios commented Mar 7, 2019

@cFire The reason ${title} is not used directly in the file path is because certbot generates the file path based on the first domain in the certificate (from $domains[0]). You can set the resource title independently from this, so if you pass both domains and a title, the path will probably be wrong. Certbot will also drop the wildcard if the first domain has one when generating the file path, eg. *.example.com gets stored in /etc/letsencrypt/live/example.com, thus the regsubst() to match that behavior.

@Rathios
Copy link
Contributor

Rathios commented Mar 7, 2019

@cFire I'm sorry, you were right - the sneaky feeling got me testing and certbot does use --cert-name to generate the file path and not $domains[0] / the first -d. It's easy to assume either since in some scenarios $title and $domains[0] will have the same value. So something like this should sort it? (With a comment to save others the same mistake)

# certbot uses --cert-name to generate the file path
$live_path_certname = regsubst($title, '^\*\.', '')
$live_path = "${config_dir}/live/${live_path_certname}/cert.pem"

Copy link
Member

@Dan33l Dan33l left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. Looks pretty good IMO.
I added a question in inline comment.

@cFire
Copy link
Contributor Author

cFire commented Mar 13, 2019

I'm mildly confused about what just happened, but besides ci needing to be re-triggered it seems to be in a correct state again.

@Dan33l Dan33l removed the needs-work not ready to merge just yet label Mar 13, 2019
@Dan33l
Copy link
Member

Dan33l commented Mar 13, 2019

I'm mildly confused about what just happened, but besides ci needing to be re-triggered it seems to be in a correct state again.

I relaunched the travis ci.
Can you squash yours commits ?

@cFire
Copy link
Contributor Author

cFire commented Mar 13, 2019

Well, that somehow broke absolutely everything. Stand by...

+ Added $ensure attribute
+ Renamed $ensure_cron back to $manage_cron
+ Returned $manage_cron back to a Boolean value
+ Made execute of "letsencrypt certonly ${title}" conditional to $ensure == 'present'
+ Added cleanup of directory for domain certs when $ensure == 'absent'
+ Used global $ensure to signal desired state of cronjobs
@cFire
Copy link
Contributor Author

cFire commented Mar 13, 2019

Fixed again. Used the wrong rebase strategy before.

@Dan33l
Copy link
Member

Dan33l commented Mar 14, 2019

A backward incompatible change was introduced by PR #161 . This PR #177 introduce an other change that permits a come back of manage_cron but introduce a new parameter ensure.

And so this PR is also backward incompatible.

@Dan33l
Copy link
Member

Dan33l commented Mar 14, 2019

@cFire thank you for the job.

@Dan33l Dan33l merged commit d306773 into voxpupuli:master Mar 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants