Skip to content

python-common/cryptotools: reimplement on top of cryptography - #69510

Merged
tchaikov merged 1 commit into
ceph:mainfrom
tchaikov:wip-cryptotools-sans-pyopenssl
Jun 26, 2026
Merged

tchaikov merged 1 commit into
ceph:mainfrom
tchaikov:wip-cryptotools-sans-pyopenssl

Conversation

@tchaikov

@tchaikov tchaikov commented Jun 16, 2026 •

Copy link
Copy Markdown
Contributor

the last change dropped X509Req, but InternalCryptoCaller still uses pyOpenSSL, which keeps deprecating and removing its OpenSSL.crypto and OpenSSL.SSL APIs. pyOpenSSL's own README [1] says:

If you are using pyOpenSSL for anything other than making a TLS
connection you should move to cryptography and drop your pyOpenSSL
dependency.

none of this module makes a TLS connection, and we already depend on cryptography and use it in cephadm/ssl_cert_utils.py.

so reimplement the caller with cryptography:

  • create_private_key(): rsa.generate_private_key() dumped as PKCS8 PEM, the same format pyOpenSSL produced.
  • create_self_signed_cert(): x509.CertificateBuilder, with the dname fields mapped to their NameOIDs.
  • _load_cert() and get_cert_issuer_info(): load_pem_x509_certificate() and cert.issuer.
  • certificate_days_to_expire(): cert.not_valid_after.
  • verify_tls(): compare the cert's and the key's public keys instead of loading them into an SSL.Context.

password_hash() and verify_password() already used bcrypt, so they are left as is. the output formats and error behavior are unchanged, hence the existing tls tests pass without changes.

[1] https://github.com/pyca/pyopenssl/blob/main/README.rst

POST-EDIT:

Fixes: https://tracker.ceph.com/issues/80414

Contribution Guidelines

  • To sign and title your commits, please refer to Submitting Patches to Ceph.

  • If you are submitting a fix for a stable branch (e.g. "quincy"), please refer to Submitting Patches to Ceph - Backports for the proper workflow.

  • When filling out the below checklist, you may click boxes directly in the GitHub web UI. When entering or editing the entire PR message in the GitHub web UI editor, you may also select a checklist item by adding an x between the brackets: [x]. Spaces and capitalization matter when checking off items this way.

Checklist

  • Tracker (select at least one)
    • References tracker ticket
    • Very recent bug; references commit where it was introduced
    • New feature (ticket optional)
    • Doc update (no ticket needed)
    • Code cleanup (no ticket needed)
  • Component impact
    • Affects Dashboard, opened tracker ticket
    • Affects Orchestrator, opened tracker ticket
    • No impact that needs to be tracked
  • Documentation (select at least one)
    • Updates relevant documentation
    • No doc update is appropriate
  • Tests (select at least one)
Show available Jenkins commands

You must only issue one Jenkins command per-comment. Jenkins does not understand
comments with more than one command.

@tchaikov

tchaikov commented Jun 16, 2026 •

Copy link
Copy Markdown
Contributor Author

@phlogistonjohn hi John, this is a follow up of #69446. it's much less urgent that it, but it should help us to address similar issues which might happen in future, due to the usage of deprecation-then-removed APIs in pyOpenSSL.

@tchaikov
tchaikov force-pushed the wip-cryptotools-sans-pyopenssl branch 2 times, most recently from 7ca180d to 0d44f4e Compare June 17, 2026 07:38
the last change dropped X509Req, but InternalCryptoCaller still uses
pyOpenSSL, which keeps deprecating and removing its OpenSSL.crypto and
OpenSSL.SSL APIs. pyOpenSSL's own README [1] says:

  If you are using pyOpenSSL for anything other than making a TLS
  connection you should move to cryptography and drop your pyOpenSSL
  dependency.

none of this module makes a TLS connection, and we already depend on
cryptography and use it in cephadm/ssl_cert_utils.py.

so reimplement the caller with cryptography:

- create_private_key(): rsa.generate_private_key() dumped as PKCS8 PEM,
  the same format pyOpenSSL produced.
- create_self_signed_cert(): x509.CertificateBuilder, with the dname
  fields mapped to their NameOIDs.
- _load_cert() and get_cert_issuer_info(): load_pem_x509_certificate()
  and cert.issuer.
- certificate_days_to_expire(): cert.not_valid_after.
- verify_tls(): compare the cert's and the key's public keys instead of
  loading them into an SSL.Context.

password_hash() and verify_password() already used bcrypt, so they are
left as is. the output formats and error behavior are unchanged, hence
the existing tls tests pass without changes.

[1] https://github.com/pyca/pyopenssl/blob/main/README.rst

Signed-off-by: Kefu Chai <[email protected]>
@tchaikov
tchaikov force-pushed the wip-cryptotools-sans-pyopenssl branch from 0d44f4e to d814088 Compare June 17, 2026 16:07

@phlogistonjohn phlogistonjohn left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Generally LGTM. We'll definitely want a robust teuthology run for this though!

@shraddhaag

shraddhaag commented Jun 26, 2026 •

Copy link
Copy Markdown
Contributor

@tchaikov
tchaikov merged commit 9b7d761 into ceph:main Jun 26, 2026
6 checks passed
@tchaikov
tchaikov deleted the wip-cryptotools-sans-pyopenssl branch June 26, 2026 06:29
dronenb added a commit to dronenb/rook that referenced this pull request Jul 15, 2026
This commit adds a new field to CephCluster (`.spec.dashboard.sslCertificateRef`) that can refer to a Kubernetes `Secret` of type `kubernetes.io/tls` (like those provisioned via cert-manager) that will be used by the Ceph Dashboard. It validates the cert public/private keys match, that they are RSA (presently a requirement for the Ceph dashboard, see https://docs.ceph.com/en/latest/mgr/dashboard/#ssl-tls-support, although this may change in the future with ceph/ceph#69510, there is an issue tracking this: https://tracker.ceph.com/issues/73324), and will watch the secret as part of the controller to ensure it gets reconciled when the secret changes. Also adds appropriate release notes.

Signed-off-by: Ben Dronen <[email protected]>
dronenb added a commit to dronenb/rook that referenced this pull request Jul 15, 2026
This commit adds a new field to CephCluster (`.spec.dashboard.sslCertificateRef`) that can refer to a Kubernetes `Secret` of type `kubernetes.io/tls` (like those provisioned via cert-manager) that will be used by the Ceph Dashboard. It validates the cert public/private keys match, that they are RSA (presently a requirement for the Ceph dashboard, see https://docs.ceph.com/en/latest/mgr/dashboard/#ssl-tls-support, although this may change in the future with ceph/ceph#69510, there is an issue tracking this: https://tracker.ceph.com/issues/73324), and will watch the secret as part of the controller to ensure it gets reconciled when the secret changes. Also adds appropriate release notes.

Signed-off-by: Ben Dronen <[email protected]>
dronenb added a commit to dronenb/rook that referenced this pull request Jul 15, 2026
This commit adds a new field to CephCluster (`.spec.dashboard.sslCertificateRef`) that can refer to a Kubernetes `Secret` of type `kubernetes.io/tls` (like those provisioned via cert-manager) that will be used by the Ceph Dashboard. It validates the cert public/private keys match, that they are RSA (presently a requirement for the Ceph dashboard, see https://docs.ceph.com/en/latest/mgr/dashboard/#ssl-tls-support, although this may change in the future with ceph/ceph#69510, there is an issue tracking this: https://tracker.ceph.com/issues/73324), and will watch the secret as part of the controller to ensure it gets reconciled when the secret changes. Also adds appropriate release notes.

Signed-off-by: Ben Dronen <[email protected]>
dronenb added a commit to dronenb/rook that referenced this pull request Jul 15, 2026
This commit adds a new field to CephCluster (`.spec.dashboard.sslCertificateRef`) that can refer to a Kubernetes `Secret` of type `kubernetes.io/tls` (like those provisioned via cert-manager) that will be used by the Ceph Dashboard. It validates the cert public/private keys match, that they are RSA (presently a requirement for the Ceph dashboard, see https://docs.ceph.com/en/latest/mgr/dashboard/#ssl-tls-support, although this may change in the future with ceph/ceph#69510, there is an issue tracking this: https://tracker.ceph.com/issues/73324), and will watch the secret as part of the controller to ensure it gets reconciled when the secret changes. Also adds appropriate release notes.

Signed-off-by: Ben Dronen <[email protected]>
dronenb added a commit to dronenb/rook that referenced this pull request Jul 15, 2026
This commit adds a new field to CephCluster (`.spec.dashboard.sslCertificateRef`) that can refer to a Kubernetes `Secret` of type `kubernetes.io/tls` (like those provisioned via cert-manager) that will be used by the Ceph Dashboard. It validates the cert public/private keys match, that they are RSA (presently a requirement for the Ceph dashboard, see https://docs.ceph.com/en/latest/mgr/dashboard/#ssl-tls-support, although this may change in the future with ceph/ceph#69510, there is an issue tracking this: https://tracker.ceph.com/issues/73324), and will watch the secret as part of the controller to ensure it gets reconciled when the secret changes. Also adds appropriate release notes.

Signed-off-by: Ben Dronen <[email protected]>
dronenb added a commit to dronenb/rook that referenced this pull request Jul 15, 2026
This commit adds a new field to CephCluster (`.spec.dashboard.sslCertificateRef`) that can refer to a Kubernetes `Secret` of type `kubernetes.io/tls` (like those provisioned via cert-manager) that will be used by the Ceph Dashboard. It validates the cert public/private keys match, that they are RSA (presently a requirement for the Ceph dashboard, see https://docs.ceph.com/en/latest/mgr/dashboard/#ssl-tls-support, although this may change in the future with ceph/ceph#69510, there is an issue tracking this: https://tracker.ceph.com/issues/73324), and will watch the secret as part of the controller to ensure it gets reconciled when the secret changes. Also adds appropriate release notes.

Signed-off-by: Ben Dronen <[email protected]>
dronenb added a commit to dronenb/rook that referenced this pull request Jul 17, 2026
This commit adds a new field to CephCluster (`.spec.dashboard.sslCertificateRef`) that can refer to a Kubernetes `Secret` of type `kubernetes.io/tls` (like those provisioned via cert-manager) that will be used by the Ceph Dashboard. It validates the cert public/private keys match, that they are RSA (presently a requirement for the Ceph dashboard, see https://docs.ceph.com/en/latest/mgr/dashboard/#ssl-tls-support, although this may change in the future with ceph/ceph#69510, there is an issue tracking this: https://tracker.ceph.com/issues/73324), and will watch the secret as part of the controller to ensure it gets reconciled when the secret changes. Also adds appropriate release notes.

Signed-off-by: Ben Dronen <[email protected]>
dronenb added a commit to dronenb/rook that referenced this pull request Jul 21, 2026
This commit adds a new field to CephCluster (`.spec.dashboard.sslCertificateRef`) that can refer to a Kubernetes `Secret` of type `kubernetes.io/tls` (like those provisioned via cert-manager) that will be used by the Ceph Dashboard. It validates the cert public/private keys match, that they are RSA (presently a requirement for the Ceph dashboard, see https://docs.ceph.com/en/latest/mgr/dashboard/#ssl-tls-support, although this may change in the future with ceph/ceph#69510, there is an issue tracking this: https://tracker.ceph.com/issues/73324), and will watch the secret as part of the controller to ensure it gets reconciled when the secret changes. Also adds appropriate release notes.

Signed-off-by: Ben Dronen <[email protected]>
@rkachach

rkachach commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

@tchaikov can you plz backport this PR to umbrella? The work on #71513 depends on it and we need it in umbrella to fix some PEM handling issues in the new certmgr.

@rkachach

rkachach commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

@tchaikov I created the issue https://tracker.ceph.com/issues/80414 to track the change and I'll be backporting it to umbrella.

@tchaikov

tchaikov commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor Author

@rkachach Redouane, actually i was reading your ping the day before yesterday but was in the middle of something else, and thought i could do it later.. thanks for creating the issue and the backport!

@rkachach

Copy link
Copy Markdown
Contributor

@rkachach Redouane, actually i was reading your ping the day before yesterday but was in the middle of something else, and thought i could do it later.. thanks for creating the issue and the backport!

No worries @tchaikov, thanks for the fix. Since I needed the commit to pass the make check of my backport PR I just cherry-picked it 👍

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