Skip to content
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

acme_certificate: fix crash when using fullchain_dest #324

Merged

Conversation

felixfontein
Copy link
Contributor

SUMMARY

I noticed that acme_certificate crashes when using the cryptography backend when renewing certificates if the fullchain_dest option is used, since it passes the content of the fullchain file to cryptography's load_pem_x509_certificate function. Since that one no longer calls libssl but uses its own parser (since cryptography 35.0.0), this leads to an error raised.

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

acme_certificate

@felixfontein
Copy link
Contributor Author

I'm currently wondering why CI didn't fail before, The crash happened here for me:

self.cert_days = self.client.backend.get_cert_days(self.fullchain_dest)
. Interestingly, I cannot reproduce this crash without my local cryptography installation, which is from a more recent main brancht version of pyca/cryptography. So maybe this isn't 35.0.0 related, but 36.0.0?

@felixfontein
Copy link
Contributor Author

Indeed, in cryptography 35.0.0 the code is different: https://github.com/pyca/cryptography/blob/35.0.0/src/rust/src/x509.rs#L393 It's actually due to a change in the main branch which probably will show up in 36.0.0. I created pyca/cryptography#6550 to track this breaking change in cryptography.

@felixfontein
Copy link
Contributor Author

I think we should still change this, since it's better to just pass one certificate on to load_pem_x509_certificate if we know there will be multiple (as in fullchain files) and we know we are only interested in the first certificate.

This will probably also be a problem with other modules which read PEM files, like x509_certificate_info. While cryptography's new behavior is definitely better for modules such as x509_certificate, some users might depend on the old behavior with x509_certificate_info.

@felixfontein
Copy link
Contributor Author

(The Zuul error is unrelated.)

Copy link
Collaborator

@Ajpantuso Ajpantuso left a comment

Choose a reason for hiding this comment

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

Regarding the case where concatenated certs should be processed would it make sense to decouple from cryptography's behavior by splitting and iterating that list ourselves and just call load_pem_x509_certificate uniformly (i.e. only use it with the assumption that the target is not a chain)?

plugins/module_utils/acme/backend_cryptography.py Outdated Show resolved Hide resolved
@felixfontein
Copy link
Contributor Author

Regarding the case where concatenated certs should be processed would it make sense to decouple from cryptography's behavior by splitting and iterating that list ourselves and just call load_pem_x509_certificate uniformly (i.e. only use it with the assumption that the target is not a chain)?

Yes, but we already do that (in the cases where we actually want all the certs). The problem are the places where we are only interested in the first cert, but didn't make that explicit.

Co-authored-by: Ajpantuso <ajpantuso@gmail.com>
@felixfontein
Copy link
Contributor Author

(plugins/module_utils/crypto/pem.py's split_pem_list is used for doing that in openssl_pkcs12, certificate_complete_chain, and for processing chains returned by the ACME CA.)

Copy link
Collaborator

@Ajpantuso Ajpantuso left a comment

Choose a reason for hiding this comment

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

LGTM

@felixfontein
Copy link
Contributor Author

recheck

@felixfontein felixfontein merged commit 51b6bb2 into ansible-collections:main Nov 5, 2021
@felixfontein felixfontein deleted the acme_certificate-fix branch November 5, 2021 07:51
@felixfontein
Copy link
Contributor Author

@Ajpantuso thanks for reviewing this!

@patchback
Copy link

patchback bot commented Nov 5, 2021

Backport to stable-1: 💚 backport PR created

✅ Backport PR branch: patchback/backports/stable-1/51b6bb210de397cb5a3d37f9da976125a3f102f1/pr-324

Backported as #325

🤖 @patchback
I'm built with octomachinery and
my source is open — https://github.com/sanitizers/patchback-github-app.

patchback bot pushed a commit that referenced this pull request Nov 5, 2021
* Fix crash when using fullchain_dest.

* Adjust changelog.

* Update plugins/module_utils/acme/backend_cryptography.py

Co-authored-by: Ajpantuso <ajpantuso@gmail.com>

Co-authored-by: Ajpantuso <ajpantuso@gmail.com>
(cherry picked from commit 51b6bb2)
felixfontein added a commit that referenced this pull request Nov 5, 2021
* Fix crash when using fullchain_dest.

* Adjust changelog.

* Update plugins/module_utils/acme/backend_cryptography.py

Co-authored-by: Ajpantuso <ajpantuso@gmail.com>

Co-authored-by: Ajpantuso <ajpantuso@gmail.com>
(cherry picked from commit 51b6bb2)

Co-authored-by: Felix Fontein <felix@fontein.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants