Repository navigation
certmgr adding support for fullchain PEM - #68632
Conversation
|
This pull request can no longer be automatically merged: a rebase is needed and changes have to be manually resolved |
ec90033 to
1a3fe30
Compare
d5a10b5 to
80218a9
Compare
|
This pull request can no longer be automatically merged: a rebase is needed and changes have to be manually resolved |
8dd0c27 to
6424644
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 20 out of 20 changed files in this pull request and generated 2 comments.
Comments suppressed due to low confidence (2)
src/python-common/ceph/deployment/tls_utils.py:72
- The implementation contradicts the stated soft-ordering behavior. Although this says chain order is not a hard error, validation always treats
cert_blocks[0]as the leaf, so a bundle orderedintermediate + leafwith a key matching the actual leaf is rejected as a key mismatch. Either identify the certificate matching the private key (and emit it first) or document and enforce leaf-first ordering as a requirement.
The leaf certificate is defined as the *first* ``CERTIFICATE`` block in
the input (the convention followed by every CA tool we are aware of).
Chain ordering is *not* enforced as a hard error — real-world CA tooling
sometimes emits chains in non-standard order — but the key **must** match
the leaf certificate public key.
src/python-common/requirements.txt:9
- Adding
cryptographyonly to this test/tox requirements file does not declare it as a runtime dependency of the movedceph.deployment.tls_utilsmodule.src/python-common/setup.py:20-22still publishes onlypyyaml, and thepython3-ceph-commonRPM stanza atceph.spec.in:1563-1566likewise requires only PyYAML, so pip/RPM users can install python-common successfully and then getModuleNotFoundErrorwhen importing this new shared utility. Addcryptographyto the package/runtime metadata as well.
cryptography
|
This pull request can no longer be automatically merged: a rebase is needed and changes have to be manually resolved |
Prep step for moving the PEM-parsing functions (parse_tls_pem_bundle and friends) out to ceph.deployment.tls_utils in a following commit. Renaming first keeps that move commit a clean "delete from here, add over there" diff against the new filename, rather than mixing a rename and a content move in the same patch. ssl_certs.py will hold only the SSLCerts class once the move lands. No behavior change; import sites updated accordingly. Signed-off-by: Redouane Kachach <[email protected]>
Add parse_tls_pem_bundle() as the canonical TLS PEM parser, supporting plain certs, cert+key pairs, and fullchain PEMs (key + leaf + intermediates) as emitted by many CAs. Split fullchain blobs on ingest via the new save_cert_key_from_pem() so downstream consumers never see combined PEM input — key and cert chain are always stored separately. Also: - Fix RGW legacy cert ingestion (inventory.py) to preserve intermediate certs instead of silently dropping them, and avoid logging PEM content (may contain private key material) on parse failure. - Avoid importing PEM-parsing utilities into orchestrator/module.py (would create a cephadm <-> orchestrator circular import) by having _cert_store_cert_key_set forward raw inbuf to cert_store_set_pair(), which already owns PEM parsing per-backend. - Remove now-unused parse_combined_pem_file from mgr_util.py. Fixes: https://tracker.ceph.com/issues/75710 Assisted-by: Claude <claude.ai> Assisted-by: ChatGPT <chatgpt.com> Signed-off-by: Redouane Kachach <[email protected]>
Relocate parse_tls_pem_bundle() and friends from cephadm/ssl_cert_utils.py into ceph.deployment.tls_utils so they're reusable outside the cephadm module. No behavior change. cephadm/ssl_certs.py now only contains SSLCerts; cert_mgr.py, inventory.py, module.py, and cephadmservice.py are updated to import from the new location. Drops the now-duplicate parse_combined_pem_file from python-common/ceph/deployment/utils.py. Fixes: https://tracker.ceph.com/issues/75710 Signed-off-by: Redouane Kachach <[email protected]>
RGWSpec.validate() attempts to migrate the legacy rgw_frontend_ssl_certificate field into ssl_cert/ssl_key by parsing it with parse_tls_pem_bundle(). If parsing failed (e.g. a cert/key format no longer accepted by the newer parser), validate() raised SpecValidationError. validate() is not only invoked on user-initiated `orch apply`, it also runs whenever existing specs are reloaded/reconciled (e.g. on mgr restart or during an upgrade). A persisted spec that was valid and running fine under the old parser could therefore start failing validation after an upgrade with no change to the actual cert/key. Since the orchestrator treats a spec that fails validation as unusable, this caused existing RGW daemons to be torn down as unmanaged/stray during upgrades. Move the migration logic into a dedicated _migrate_legacy_rgw_frontend_ssl_certificate() helper and make it best-effort: if parse_tls_pem_bundle() fails or returns an incomplete cert/key pair, log a warning and leave rgw_frontend_ssl_certificate untouched instead of raising. This keeps validate() non-destructive for legacy specs being reloaded, while still migrating the field cleanly whenever the bundle can be parsed. This does not change behavior for specs that already use ssl_cert/ ssl_key directly (no rgw_frontend_ssl_certificate set), since those never enter this code path. Fixes: https://tracker.ceph.com/issues/75710 Assisted-by: Claude <claude.ai> Assisted-by: ChatGPT <chatgpt.com> Signed-off-by: Redouane Kachach <[email protected]>
This adds automatic migration of the legacy `rgw_frontend_ssl_certificate` field on RGW specs to the newer `ssl_cert`/`ssl_key` fields. When an RGW spec has `ssl` enabled, no `ssl_cert` set, and a legacy `rgw_frontend_ssl_certificate` present, the new `_check_and_migrate_legacy_rgw_frontend_ssl_field` method parses the legacy field as a combined PEM bundle (private key + leaf certificate + optional intermediate CAs) and splits it into `ssl_cert` and `ssl_key`. On success, it sets `certificate_source` to `INLINE` and clears the legacy field. If `ssl_cert` is already set, the legacy field is left untouched since the new fields take precedence. Invalid or unparseable PEM bundles raise an `OrchestratorError` with a clear message describing the expected format, including the case where a certificate chain is provided without its private key. The migration check is called from `_apply_service_spec` right before `_check_cert_source`, so it runs ahead of spec validation. Fixes: https://tracker.ceph.com/issues/75710 Assisted-by: Claude <claude.ai> Assisted-by: ChatGPT <chatgpt.com> Signed-off-by: Redouane Kachach <[email protected]>
Keep RGW's legacy `rgw_frontend_ssl_certificate` handling backward compatible when automatic migration to `ssl_cert` / `ssl_key` cannot be performed. `RGWSpec.validate()` now treats the legacy-field migration as best-effort and non-destructive. This allows stored RGW specs to keep loading during mgr restart, failover, or upgrade even if the legacy PEM bundle cannot be parsed by the newer parser. For newly applied specs, cephadm performs a stricter check in the apply path before persisting the spec. If a user submits a new RGW spec using `rgw_frontend_ssl_certificate`, the field must contain a valid combined PEM bundle with one unencrypted private key and at least one certificate. Valid input is migrated to `ssl_cert` / `ssl_key` and the legacy field is cleared. Invalid input is rejected before it reaches the spec store. Also keep the RGW daemon configuration path compatible with unmigrated legacy specs. If an existing stored spec still has `rgw_frontend_ssl_certificate` and no migrated `ssl_cert` / `ssl_key` values, cephadm continues to use the legacy PEM value when writing the RGW certificate config-key. This avoids silently switching the service to cephadm-signed certificates, or failing later during reconfig/redeploy, when migration was intentionally skipped for upgrade safety. Fixes: https://tracker.ceph.com/issues/75710 Assisted-by: Claude <claude.ai> Assisted-by: ChatGPT <chatgpt.com> Signed-off-by: Redouane Kachach <[email protected]>
Add a contains_chain flag to certificate info returned by certmgr cert ls when the stored PEM contains more than one CERTIFICATE block. This keeps the default output focused on the leaf certificate while still making it clear when a user-provided fullchain PEM was stored. Single-certificate PEMs remain unchanged and do not include the flag. Fixes: https://tracker.ceph.com/issues/75710 Signed-off-by: Redouane Kachach <[email protected]>
Add test coverage for the new TLS PEM bundle handling: * ceph.deployment.tls_utils: parse_tls_pem_bundle() happy paths (PKCS#1/PKCS#8/EC keys, multi-cert chains, cert-only input) and error paths (no cert block, duplicate keys, key/cert mismatch, encrypted/unsupported key types, empty/garbage input); is_fullchain_pem() and contains_private_key() detectors; get_certificate_info() on fullchain input. * cephadm: CertMgr.save_cert_key_from_pem(), cert_store_set_pair(), cert_store_set_cert(), and _get_certificates_from_spec() — covering fullchain splitting, chain preservation/ordering, key mismatch and encrypted-key rejection, malformed multi-block input rejection, and the conflicting-separate-key case. * RGW legacy SSL input: cover best-effort migration of rgw_frontend_ssl_certificate during spec deserialization, ensuring invalid legacy input does not make stored specs fail to load. Also cover the stricter cephadm apply path, where newly applied RGW specs using the legacy field are validated, migrated to ssl_cert/ssl_key on success, and rejected before being persisted on invalid combined PEM input. Adds cryptography to src/python-common/requirements.txt as a test dependency. Fixture data is intentionally duplicated between cephadm/tests/pem_fixtures.py and python-common/ceph/tests/test_tls_utils.py rather than shared, since cephadm's test suite should not import test modules from python-common's test tree. Fixes: https://tracker.ceph.com/issues/75710 Assisted-by: Claude <claude.ai> Assisted-by: ChatGPT <chatgpt.com> Signed-off-by: Redouane Kachach <[email protected]>
Document the supported PEM input forms for certmgr and RGW HTTPS configuration. This clarifies that certificate chains are supported, that combined PEM input must include an unencrypted private key, and that reference mode requires both certificate and key entries. Fixes: https://tracker.ceph.com/issues/75710 Assisted-by: Claude <claude.ai> Assisted-by: ChatGPT <chatgpt.com> Signed-off-by: Redouane Kachach <[email protected]>
Rename function is_fullchain_pem to contains_multiple_pem_blocks to reflect precisely what it actually does. Signed-off-by: Redouane Kachach <[email protected]>
this checks seems to faild with older Python vesions, let's remove it as we already have the explict check if spec.service_type != 'rgw' Signed-off-by: Redouane Kachach <[email protected]>
`_check_and_migrate_legacy_rgw_frontend_ssl_field()` already returns early unless the service type is `rgw`, but mypy cannot infer that a generic `ServiceSpec` is an `RGWSpec` from the `service_type` value alone. Add an explicit `typing.cast(RGWSpec, spec)` after the service-type guard so RGW-specific attributes such as `rgw_frontend_ssl_certificate` are accepted by mypy. This keeps the runtime logic unchanged and avoids reintroducing an `isinstance(spec, RGWSpec)` check, which can be problematic in cephadm/mgr subinterpreter scenarios. Signed-off-by: Redouane Kachach <[email protected]>
`pyOpenSSL.crypto.PKey.check()` is RSA-only and raises `TypeError` for EC private keys, even when the key is valid. This caused valid ECDSA certificate/key pairs to fail TLS validation with: `Invalid private key: Only RSA keys can currently be checked.` Fix the code to only call `PKey.check()` for RSA keys. Non-RSA keys are still parsed by OpenSSL and the certificate/private-key pair is still validated through `context.check_privatekey()`, so mismatched or invalid key pairs are still rejected. This fixes EC user-provided certificates in certmgr/cephadm paths while preserving the existing RSA consistency check. Signed-off-by: Redouane Kachach <[email protected]>
6424644 to
b462ee3
Compare
|
This is an automated message by src/script/redmine-upkeep.py. I have resolved the following tracker ticket due to the merge of this PR: No backports are pending for the ticket. If this is incorrect, please update the tracker |
Summary
Adds support for proper ingesting of fullchain PEM blobs (private key + leaf cert + intermediate certs, as emitted by many CAs) into cephadm's certificate manager.
Follow-up:
Centralize PEM validation for certmgr and service cert/key inputs. Currently this PR focuses on fullchain PEM support/preservation for inline/RGW legacy input. A later change should enforce field-specific validation for cert-only, key-only, and cert/key pair paths, including certmgr reference mode. Tracking ticket https://tracker.ceph.com/issues/77693.
Fixes: https://tracker.ceph.com/issues/75710
Changes
ssl_cert_utils.py→ssl_certs.py— prep step so the next commit's move is a clean diff.parse_tls_pem_bundle(),CertMgr.save_cert_key_from_pem()ingest helper, fixes to RGW legacy cert handling and the orchestrator/cephadm circular-import boundary, removal of the oldparse_combined_pem_file.ceph.deployment.tls_utils) so they're reusable outside cephadm. No behavior change.Key design points
Testing
Unit testing
ceph/tests/test_tls_utils.pyandcephadm/tests/test_certmgr_fullchain_pem.py.Manual testing report
Manual validation was performed on a Ceph test cluster for the certmgr fullchain PEM handling changes.
Summary
All planned manual test cases completed successfully.
Result: PASS
The testing covered:
contains_chain: trueindicatorManual test cases executed
Upgrade testing from squid (no certmgr)
started from an rgw spec using a
rgw_frontend_ssl_certificatewith a PEM bundle which contains an RSA private key as following:After the upgrade the
rgw_frontend_ssl_certificateis parsed correctly:1. CLI fullchain happy path:
cert-key set -iTested storing a combined PEM bundle containing
private key + leaf certificate + intermediate certificate.Verified:
rgw_ssl_certrgw_ssl_keycert lsshowed the leaf certificate informationcert lsshowedcontains_chain: trueResult: PASS
2. CLI chain-only certificate plus separate key
Tested storing a chain-only PEM and matching key through separate cert/key operations.
Verified:
cert lsshowedcontains_chain: trueResult: PASS
3. Single-certificate PEM
Tested storing a single leaf certificate without intermediate certificates.
Verified:
contains_chain: truewas not presentcontains_chain: falsenoise was added to the outputResult: PASS
4. Cert-only command rejects embedded private key
Tested passing a combined PEM bundle to the cert-only command.
Verified:
Result: PASS
5. RGW spec path with
rgw_frontend_ssl_certificateTested applying an RGW spec containing a combined PEM bundle in
rgw_frontend_ssl_certificate.Verified:
cert lsshowedcontains_chain: trueResult: PASS
6. Chain-only RGW spec rejection
Tested applying an RGW spec where
rgw_frontend_ssl_certificatecontained onlyleaf certificate + intermediate certificate.Verified:
rgw_frontend_ssl_certificateResult: PASS
7. Encrypted private key rejection
Tested passing a PEM bundle containing an encrypted private key.
Verified:
Result: PASS
8. Duplicate private key rejection
Tested passing a PEM bundle containing more than one private key block.
Verified:
Result: PASS
9. Garbage input rejection
Tested passing non-PEM/random text input.
Verified:
Result: PASS
10. Certificate health/check behavior
Tested certmgr health/check behavior after storing valid fullchain PEM input.
Verified:
CEPHADM_CERT_ERRORwas reported for valid fullchain inputcontains_chain: trueremained visible in certificate listing outputResult: PASS
Final Result
All manual test cases passed successfully.
The change behaves as expected:
cert lsremains focused on the leaf certificatecontains_chain: trueContribution 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
xbetween the brackets:[x]. Spaces and capitalization matter when checking off items this way.Checklist
Show available Jenkins commands
jenkins test classic perfJenkins Job | Jenkins Job Definitionjenkins test crimson perfJenkins Job | Jenkins Job Definitionjenkins test signedJenkins Job | Jenkins Job Definitionjenkins test make checkJenkins Job | Jenkins Job Definitionjenkins test make check arm64Jenkins Job | Jenkins Job Definitionjenkins test submodulesJenkins Job | Jenkins Job Definitionjenkins test dashboardJenkins Job | Jenkins Job Definitionjenkins test dashboard cephadmJenkins Job | Jenkins Job Definitionjenkins test apiJenkins Job | Jenkins Job Definitionjenkins test docsReadTheDocs | Github Workflow Definitionjenkins test ceph-volume allJenkins Jobs | Jenkins Jobs Definitionjenkins test windowsJenkins Job | Jenkins Job Definitionjenkins test rook e2eJenkins Job | Jenkins Job DefinitionYou must only issue one Jenkins command per-comment. Jenkins does not understand
comments with more than one command.