Skip to content

certmgr adding support for fullchain PEM - #68632

Merged
rkachach merged 13 commits into
ceph:mainfrom
rkachach:fix_issue_75710
Sep 2, 2026
Merged

rkachach merged 13 commits into
ceph:mainfrom
rkachach:fix_issue_75710

Conversation

@rkachach

@rkachach rkachach commented Apr 27, 2026 •

Copy link
Copy Markdown
Contributor

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

  1. Rename ssl_cert_utils.py → ssl_certs.py — prep step so the next commit's move is a clean diff.
  2. Add fullchain PEM ingestion support — new canonical parser 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 old parse_combined_pem_file.
  3. Move TLS PEM utilities to python-common (ceph.deployment.tls_utils) so they're reusable outside cephadm. No behavior change.
  4. Add unit tests for the new parser/detectors and all cephadm ingest paths (CLI, service spec, error/edge cases).

Key design points

  • Split on ingest, store separately: fullchain blobs are parsed at the boundary (CLI/spec); internal storage always keeps key and cert chain apart.
  • Soft chain ordering, hard key/cert match: chain order isn't enforced, but the key must match the leaf cert's public key; encrypted keys are rejected early.
  • Minimal, targeted changes — no broad refactors.

Testing

Unit testing

  • New unit tests in ceph/tests/test_tls_utils.py and cephadm/tests/test_certmgr_fullchain_pem.py.
  • Existing cephadm/orchestrator test suites updated and passing.

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:

  • certmgr CLI fullchain ingestion
  • cert/key split behavior
  • chain-only certificate handling
  • RGW spec inline certificate handling
  • invalid PEM rejection
  • encrypted private key rejection
  • duplicate private key rejection
  • certmgr listing output
  • new contains_chain: true indicator
  • certmgr health/check behavior

Manual test cases executed

Upgrade testing from squid (no certmgr)

started from an rgw spec using a rgw_frontend_ssl_certificate with a PEM bundle which contains an RSA private key as following:

service_type: rgw
service_id: rgw
service_name: rgw.rgw
spec:
  rgw_frontend_port: 9999
  ssl: true
  rgw_frontend_ssl_certificate: |
    -----BEGIN RSA PRIVATE KEY-----
    MIIEpAIBAAKCAQEAqI7BYkj6Dwxo1TtVLcNfm+vtnVoKZMiWQ5n1OfwpZAQIL7i/
    gt6ex4Hv4ODkeUo7si8/M71Tf1njcKm0MnPkw3nyMRgefsftfmSacSz2F8H7x9SW

After the upgrade the rgw_frontend_ssl_certificate is parsed correctly:

[ceph: root@ceph-node-0 /]# ceph orch ps
NAME                        HOST         PORTS             STATUS         REFRESHED  AGE  MEM USE  MEM LIM  VERSION               IMAGE ID      CONTAINER ID  
alertmanager.ceph-node-0    ceph-node-0  *:9093,9094       running (2m)     98s ago  21m    17.6M        -  0.28.1                91c01b3cec9b  2ddf35e6e611  
alertmanager.ceph-node-2    ceph-node-2  *:9093,9094       running (2m)     99s ago  16m    17.4M        -  0.28.1                91c01b3cec9b  d73bfb851156  
ceph-exporter.ceph-node-0   ceph-node-0  *:9926            running (3m)     98s ago  22m    7688k        -  21.3.0-413-g41c9db34  117d7d877c65  728f1c7096d7  
ceph-exporter.ceph-node-1   ceph-node-1  *:9926            running (3m)    100s ago  18m    7807k        -  21.3.0-413-g41c9db34  117d7d877c65  7aade6610815  
ceph-exporter.ceph-node-2   ceph-node-2  *:9926            running (3m)     99s ago  18m    7875k        -  21.3.0-413-g41c9db34  117d7d877c65  0debe23e43ea  
crash.ceph-node-0           ceph-node-0                    running (6m)     98s ago  22m    7444k        -  21.3.0-413-g41c9db34  117d7d877c65  ba62f96285b7  
crash.ceph-node-1           ceph-node-1                    running (6m)    100s ago  17m    7448k        -  21.3.0-413-g41c9db34  117d7d877c65  25b1a383c19e  
crash.ceph-node-2           ceph-node-2                    running (6m)     99s ago  17m    7448k        -  21.3.0-413-g41c9db34  117d7d877c65  5bb4f8e42db1  
grafana.ceph-node-0         ceph-node-0  *:3000            running (2m)     98s ago  21m     102M        -  12.3.1                5cdab57891ea  2dd41fc8ade0  
mgr.ceph-node-0.dpuleq      ceph-node-0  *:8443,9283,8765  running (9m)     98s ago  23m     274M        -  21.3.0-413-g41c9db34  117d7d877c65  b3e245860ac7  
mgr.ceph-node-2.puylvp      ceph-node-2  *:8443,9283,8765  running (8m)     99s ago  17m     173M        -  21.3.0-413-g41c9db34  117d7d877c65  6d7f605498fd  
mon.ceph-node-0             ceph-node-0                    running (8m)     98s ago  23m    57.5M    2048M  21.3.0-413-g41c9db34  117d7d877c65  d20b43f02bae  
mon.ceph-node-1             ceph-node-1                    running (7m)    100s ago  17m    44.4M    2048M  21.3.0-413-g41c9db34  117d7d877c65  78a88a80d072  
mon.ceph-node-2             ceph-node-2                    running (7m)     99s ago  17m    41.1M    2048M  21.3.0-413-g41c9db34  117d7d877c65  f905ee54a5df  
node-exporter.ceph-node-0   ceph-node-0  *:9100            running (3m)     98s ago  22m    6788k        -  1.9.1                 255ec253085f  9f70f9cdf418  
node-exporter.ceph-node-1   ceph-node-1  *:9100            running (3m)    100s ago  17m    6656k        -  1.9.1                 255ec253085f  5aa8b5f48196  
node-exporter.ceph-node-2   ceph-node-2  *:9100            running (2m)     99s ago  17m    6391k        -  1.9.1                 255ec253085f  10bfcf7c3329  
osd.0                       ceph-node-0                    running (5m)     98s ago  19m    76.7M    4096M  21.3.0-413-g41c9db34  117d7d877c65  e8139f38e7d3  
osd.1                       ceph-node-2                    running (4m)     99s ago  17m    67.6M    4096M  21.3.0-413-g41c9db34  117d7d877c65  c2d2e93eafa6  
osd.2                       ceph-node-1                    running (5m)    100s ago  17m    76.1M    4096M  21.3.0-413-g41c9db34  117d7d877c65  9d665d2e63da  
prometheus.ceph-node-0      ceph-node-0  *:9095            running (10m)    98s ago  21m    44.2M        -  3.6.0                 4fcecf061b74  fc76b1d5a12f  
rgw.rgw.ceph-node-1.ymyzmx  ceph-node-1  *:9999            running (4m)    100s ago  16m    77.3M        -  21.3.0-413-g41c9db34  117d7d877c65  dea19656bcfe  
rgw.rgw.ceph-node-2.lyprij  ceph-node-2  *:9999            running (4m)     99s ago  16m    77.1M        -  21.3.0-413-g41c9db34  117d7d877c65  a10ccc8d46ad  
[ceph: root@ceph-node-0 /]# 
[ceph: root@ceph-node-0 /]# 
[ceph: root@ceph-node-0 /]# ceph orch certmgr cert ls
rgw_ssl_cert
  scope: service
  certificates
    rgw.rgw
      subject
        commonName: rgw.example.com
      contains_chain: True
      validity
        remaining_days: 824
cephadm_root_ca_cert
  scope: global
  certificates
    subject
      commonName: cephadm-root-3ef8b7ca-70a6-11f1-ab99-525400c961c3
    contains_chain: False
    validity
      remaining_days: 3652
[ceph: root@ceph-node-0 /]# 
[ceph: root@ceph-node-0 /]# 
[ceph: root@ceph-node-0 /]# ceph orch ls --export --service-name rgw.rgw
service_type: rgw
service_id: rgw
service_name: rgw.rgw
placement:
  count: 2
spec:
  certificate_source: inline
  rgw_exit_timeout_secs: 120
  rgw_frontend_port: 9999
  ssl: true
  ssl_cert: |
    -----BEGIN CERTIFICATE-----
    MIIDlDCCAnygAwIBAgIUa7YgQrohVVDFKxMxBd9g7rowP3UwDQYJKoZIhvcNAQEL
    BQAwLjEsMCoGA1UEAwwjY2VydG1nciBtYW51YWwgdGVzdCBpbnRlcm1lZGlhdGUg
    Q0EwHhcNMjYwNjI0MTQwNzAyWhcNMjgwOTI3MTQwNzAyWjAaMRgwFgYDVQQDDA9y
    Z3cuZXhhbXBsZS5jb20wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCo
    jsFiSPoPDGjVO1Utw1+b6+2dWgpkyJZDmfU5/ClkBAgvuL+C3p7Hge/g4OR5Sjuy
    Lz8zvVN/WeNwqbQyc+TDefIxGB5+x+1+ZJpxLPYXwfvH1JaONZq+tmrc78VxaOWT
    cHYT6YQ6mdZZxsgfDYHZq94Apq9eotlhGjeejZfeYXnyAhWD7TKTmtW2MBouu/Bc
    XZbHnV5Iwk8yqzIUprv917gLHnzFlVdac/ylXGbBlKKxn0oNCLs2a0ZLiEC7TiRc
    aexbtJd7eq8Dj0K5GF0a3XvdPhr7TThP8M25cALWFOYYp/a02ixLp/Pz1+Ms5MqY
    VxOILnqmhfBQ9GUKeDstAgMBAAGjgb0wgbowRQYDVR0RBD4wPIIPcmd3LmV4YW1w
    bGUuY29tgglsb2NhbGhvc3SCGHJndy5yZWFsLXZhbGlkYXRpb24udGVzdIcEfwAA
    ATAMBgNVHRMBAf8EAjAAMA4GA1UdDwEB/wQEAwIFoDATBgNVHSUEDDAKBggrBgEF
    BQcDATAdBgNVHQ4EFgQUbw9rH1PfjGok+r27iyN9yukiIWYwHwYDVR0jBBgwFoAU
    /fdBP5tgaGbKzEo8zZe2T1wjl4gwDQYJKoZIhvcNAQELBQADggEBAHLZlJ8cTV1h
    /iF0ijOKEAkrV0l9c2fwGD/7WdlR1W3bQxpHo5ijSL4hteT0jhsO6tLm+NGiMPtD
    euykjjN7g+xYdB6OUSrutdvqGMVxNDk5nfT58vtODkzTGH29kCw13BD16AbGG1zE
    Qt7mz/ydUk56EX4hODgH6aEMTqXESAEPZun/Y9n9t4vgcxCSellOys0Y5FDFhS7Z
    biUWxgBijIYUY2riQ+QuC/Z4SfUMzBBmI11D9mY5ez3tNP5QgHT6uTlgIG391ULj
    IYdZcDtElYKWHyABsO8w6LenlxEk5Y3/GHjNon226NbiqYCMKSSX9NNV0KZ8VWi1
    47Jro6oJIsg=
    -----END CERTIFICATE-----
    -----BEGIN CERTIFICATE-----
    MIIDSDCCAjCgAwIBAgIUeq2P7BEW6eUAt5QOxRcZA52uilYwDQYJKoZIhvcNAQEL
    BQAwJjEkMCIGA1UEAwwbY2VydG1nciBtYW51YWwgdGVzdCByb290IENBMB4XDTI2
    MDYyNDE0MDcwMloXDTMxMDYyNDE0MDcwMlowLjEsMCoGA1UEAwwjY2VydG1nciBt
    YW51YWwgdGVzdCBpbnRlcm1lZGlhdGUgQ0EwggEiMA0GCSqGSIb3DQEBAQUAA4IB
    DwAwggEKAoIBAQC62rYhHxelFgY+m02m3Zmq+vn9D6TmpCqb1+/h+dXs6cqtCxKz
    TB4j/8BhyyenC958ori3lm7Wq47u55Z9EJdSD8bCx5ijUU5uXHDhCSvrRC7fFdqy
    ORPF7uVRoVEOE3hxvKS0o9wj+J4Y3V7ekG5ZZd8GNhLmVlWiPN832Bd2ChXDnf8U
    obvnZJyEJE8ZgcT4/3zwUIQXSUTGWKV+Pty0nW2jTMVGTaDGrIuQa5ScN6cFV6Vc
    F2XPqhGQyUIC5NwGzFFEH+EhHPtPycTK8LP6nNmNmj/Md3GrJovD9e+qreEC8UCD
    q7AtJqSe1emmUofY2VKuY8Z2CzUaAbCxLY6TAgMBAAGjZjBkMBIGA1UdEwEB/wQI
    MAYBAf8CAQAwDgYDVR0PAQH/BAQDAgGGMB0GA1UdDgQWBBT990E/m2BoZsrMSjzN
    l7ZPXCOXiDAfBgNVHSMEGDAWgBSr/DbBd5LAVg7z24a1KlYL2pnAvzANBgkqhkiG
    9w0BAQsFAAOCAQEAMHGhy9ZYN6lpzGXRQdRQHqiTWA9qjFiKhCIkerZkAJrcdI/4
    BVQbGxhEcPApGN6+myWLEny8vhyB1Ceui0VqxgYvMCbC35PukWBEW6bjYQV28U3Q
    rjwFPR+vEVWGDK8yZ6xyEDv/yvzbHdlz286FHTwkiyEoaPwcyomlNMWQX6OBH3LC
    0tUgw+RQhxqtfr5BEu3r/vYHjdKiwPy9uGe2nz64Gr24Uj++FEBTnT2J/uuYdIfp
    C6pUH71SmtEB2O1LIMWeA+Aq3Fu1smHoLX5Hqu3nn05yPlOXVmxnCP9Bk8qFYnt+
    DDQIqD7CLnnGAHZ64/pRvuWzfQQPEXDX6XqbMA==
    -----END CERTIFICATE-----
  ssl_key: |
    -----BEGIN RSA PRIVATE KEY-----
    MIIEpAIBAAKCAQEAqI7BYkj6Dwxo1TtVLcNfm+vtnVoKZMiWQ5n1OfwpZAQIL7i/
    gt6ex4Hv4ODkeUo7si8/M71Tf1njcKm0MnPkw3nyMRgefsftfmSacSz2F8H7x9SW
    jjWavrZq3O/FcWjlk3B2E+mEOpnWWcbIHw2B2aveAKavXqLZYRo3no2X3mF58gIV
    g+0yk5rVtjAaLrvwXF2Wx51eSMJPMqsyFKa7/de4Cx58xZVXWnP8pVxmwZSisZ9K
    DQi7NmtGS4hAu04kXGnsW7SXe3qvA49CuRhdGt173T4a+004T/DNuXAC1hTmGKf2
    tNosS6fz89fjLOTKmFcTiC56poXwUPRlCng7LQIDAQABAoIBAANblHhNL6F+KETp
    4DArWW0o7mOU8ZNJzKUMJcAjYyaxVK/2fzgnBF7v1IsukG3bHPYAHOYhbzdyE54M
    lqmFcxeP3ofZbQmLjYadvqhRXiFbzL1dRFbLHPt4o8HUXKimw9AvVSylgg7jPlFn
    MmRQ4H+pQ5rnlDrMf+juzko+wpw/Lpm9LLMdTA5tRd2GT6KDtjwNmcuRYNsUbuqm
    BfhkOConRL81NEebjLVZdUwXbNze/xMSy7mGmyNO+oQOVwaSFTpLI/1/28tlgOjq
    oG9SzWRMabtMwS/TcEXf4oT7Ar8h9CUwgoBV8Pc6JpB3Eaitc1dyXsRelGVZMFfB
    YZ9vCYECgYEA32bbG1D0JMqJUcDN2JYcXpxld6FEgOy09xlfQIA6t00Lh5VhvV0y
    fSi5Am8O3FsQYSFyK8Y0Gr8eph/GR3enGlpST1g2zG7KAyBcYhT0WFVLSPA2HFE3
    dXzFnA313jwhd483fxi1eGe8Td2sXGBz4jl6Oialc7tj+VvwDjnAmIECgYEAwSc0
    LAZqn5MWh58WYfeotJ2FVziDicQ+eWwrexiAG0ZbKbZ6l47jjyJDuK+fBUJ1j121
    X6LqJ9xUZrWzHgIx7+dFhL4IqlHCA6z9kfX+M84ASeXj11CRThuUZjeYaYRIplPe
    D90xsmr1iw6Uv8W4qNb2Q2V8s5glzxKXbRObLK0CgYAlGC0VkhGX8lFu07baWcKI
    Kyvl+08moSdDSGE6kpAtU4uwjatXCByUD6j4sHwlNrG3jxgoEJciQc3TA7+mqkWC
    6LB2IE2pEFRWxI7ScmxIJpGDoO87MHkm9vrQ+Lh0mENuWMd8QRwQzBjGTSKLjDBx
    xd13vmcGmnz1MMDhe9FxAQKBgQCtpTcMFUCp8SwiBO20aVfr+Gk1voLSyfB4bLyy
    T5Zr7tZqK7kOo9EEjwNe99P4gIT7vH0gW3AzIatnIxbCdaq7SKmA6u8TX6kScOUN
    4Z8Ep8Aur1Qj8DSRic3iDz0gL2K41VEf5fWVtv7EYvlrZq/aala+xHBVbQUgolAs
    KaIpiQKBgQCytmcZ0zdK4QEDhkqfABUsGYpeJd3IOgUii6yMbwuDpbNRP9vFC8Zd
    tKxRvvISUpu4dnGzPwHyl/skfADimWybu0uUDmgErGbfy0mBsRyPI2C49pj9kiJ7
    yLU2CHv+rqasMdrIxVtmLdDJI9a6jgilk1N8d8oKbb7yU8VbY/G4iw==
    -----END RSA PRIVATE KEY-----

1. CLI fullchain happy path: cert-key set -i

Tested storing a combined PEM bundle containing private key + leaf certificate + intermediate certificate.

Verified:

  • command succeeded
  • certificate was stored under rgw_ssl_cert
  • private key was stored separately under rgw_ssl_key
  • certificate output did not contain private key material
  • key output did not contain certificate material
  • cert ls showed the leaf certificate information
  • cert ls showed contains_chain: true

Result: PASS

2. CLI chain-only certificate plus separate key

Tested storing a chain-only PEM and matching key through separate cert/key operations.

Verified:

  • chain-only certificate was stored successfully
  • key was stored separately
  • cert ls showed contains_chain: true
  • retrieved cert contained only certificate material
  • retrieved key contained only private key material

Result: PASS

3. Single-certificate PEM

Tested storing a single leaf certificate without intermediate certificates.

Verified:

  • certificate was stored successfully
  • contains_chain: true was not present
  • no contains_chain: false noise was added to the output

Result: PASS

4. Cert-only command rejects embedded private key

Tested passing a combined PEM bundle to the cert-only command.

Verified:

  • command failed as expected
  • error indicated that private key material was present
  • no certificate/key was stored for the rejected input

Result: PASS

5. RGW spec path with rgw_frontend_ssl_certificate

Tested applying an RGW spec containing a combined PEM bundle in rgw_frontend_ssl_certificate.

Verified:

  • spec apply succeeded
  • combined PEM was parsed and split into certificate and key
  • certificate was stored through certmgr
  • private key was stored separately
  • cert ls showed contains_chain: true
  • RGW service deployed/reconfigured successfully
  • no PEM/private key material was leaked in logs

Result: PASS

6. Chain-only RGW spec rejection

Tested applying an RGW spec where rgw_frontend_ssl_certificate contained only leaf certificate + intermediate certificate.

Verified:

  • spec apply failed as expected
  • error reported failure to parse/validate rgw_frontend_ssl_certificate
  • no RGW service was created/updated from the invalid spec
  • no certificate/key was stored for the invalid service
  • no PEM/private key material was leaked in logs

Result: PASS

7. Encrypted private key rejection

Tested passing a PEM bundle containing an encrypted private key.

Verified:

  • command failed as expected
  • error indicated encrypted private keys are unsupported
  • no certificate/key was stored

Result: PASS

8. Duplicate private key rejection

Tested passing a PEM bundle containing more than one private key block.

Verified:

  • command failed as expected
  • error indicated multiple/private key blocks
  • no certificate/key was stored

Result: PASS

9. Garbage input rejection

Tested passing non-PEM/random text input.

Verified:

  • command failed as expected
  • error indicated invalid or missing PEM certificate/key content
  • no certificate/key was stored

Result: PASS

10. Certificate health/check behavior

Tested certmgr health/check behavior after storing valid fullchain PEM input.

Verified:

  • no CEPHADM_CERT_ERROR was reported for valid fullchain input
  • certificate validity/status was based on the leaf certificate
  • intermediate certificates did not confuse expiry/status reporting
  • contains_chain: true remained visible in certificate listing output

Result: PASS

Final Result

All manual test cases passed successfully.

The change behaves as expected:

  • combined PEM bundles are accepted and split correctly
  • certificate chains are preserved in the cert store
  • private keys are stored separately from certificates
  • invalid PEM inputs are rejected cleanly
  • cert ls remains focused on the leaf certificate
  • fullchain presence is exposed via contains_chain: true
  • no private key material was exposed in certificate output or logs

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.

@github-actions

Copy link
Copy Markdown

This pull request can no longer be automatically merged: a rebase is needed and changes have to be manually resolved

@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown

This pull request can no longer be automatically merged: a rebase is needed and changes have to be manually resolved

Copilot AI 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.

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 ordered intermediate + leaf with 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 cryptography only to this test/tox requirements file does not declare it as a runtime dependency of the moved ceph.deployment.tls_utils module. src/python-common/setup.py:20-22 still publishes only pyyaml, and the python3-ceph-common RPM stanza at ceph.spec.in:1563-1566 likewise requires only PyYAML, so pip/RPM users can install python-common successfully and then get ModuleNotFoundError when importing this new shared utility. Add cryptography to the package/runtime metadata as well.
cryptography

@github-actions

Copy link
Copy Markdown

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]>
@rkachach
rkachach merged commit 1018afc into ceph:main Sep 2, 2026
7 checks passed
@github-actions

github-actions Bot commented Sep 2, 2026

Copy link
Copy Markdown

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
ticket and reset to Pending Backport state.

Update Log: https://github.com/ceph/ceph/actions/runs/33629122566

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