Repository navigation
squid: Fix nvmeof gateway startup with aes256k daemon #39
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
+261
−6
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
98 changes: 98 additions & 0 deletions
98
release-management/backports/01a15d41-e5b1-7d20-b6e3-e9ebcec19b81.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| --- | ||
| id: 01a15d41-e5b1-7d20-b6e3-e9ebcec19b81 | ||
| title: Fix nvmeof gateway startup with aes256k daemon keys | ||
| component: other | ||
| category: fix | ||
| provenance: | ||
| type: other | ||
| other: >- | ||
| Downstream-authored fix. No upstream PR exists yet. Written against | ||
| cobaltcore-dev/ceph#28 for the squid-19.2.7 effort. Upstream tracker | ||
| https://tracker.ceph.com/issues/81778 covers the same bug on squid and | ||
| tentacle. Related: tracker #79868 and ceph/ceph-nvmeof#2203. | ||
| upstream_trackers: | ||
| - https://tracker.ceph.com/issues/81778 | ||
| justification: | ||
| type: engineering | ||
| refs: | ||
| - cobaltcore-dev/cloud-storage#623 | ||
| - https://tracker.ceph.com/issues/81778 | ||
| risk: | ||
| blast: availability | ||
| conflict: substantive | ||
| coverage: partial | ||
| --- | ||
|
|
||
| ## Justification (public) | ||
|
|
||
| Since 19.2.6, cephadm creates daemon cephx keys with the `aes256k` key type. | ||
| The NVMe-oF gateway images for squid bundle their own librados, built before | ||
| `aes256k` existed, so a gateway cannot authenticate with such a key. It fails | ||
| to connect to the cluster and restarts. The nvmeof service never reaches its | ||
| target count. | ||
|
|
||
| ## Justification (internal) | ||
|
|
||
| - https://tracker.ceph.com/issues/81778 | ||
| - Teuthology runs #227, #259, #303, ... Surfaced in | ||
| `orch:cephadm:smoke-roleless/{0-distro/centos_9.stream_runc 0-nvme-loop 1-start 2-services/nvmeof 3-final}`, | ||
| job 3763 (2026-10-10): the mon grants `client.nvmeof.foo.vm06.qoywko` a key | ||
| with `"key_type": "aes256k"`. The gateway logs `rados.IOError: [errno 5] RADOS I/O error` | ||
| on each of 5 starts, then `Unable to create OMAP, exiting!`, and no mon ever | ||
| sees a connection attempt. Ends in `MaxWhileTries` after 300s. | ||
|
|
||
| ## Risk notes | ||
|
|
||
| - **blast: availability** — the patch changes which cephx key type cephadm | ||
| requests per daemon (`utils.key_type_for()`). nvmeof gets the previous `aes`, | ||
| every other daemon type keeps `aes256k`. A regression in that dispatch would | ||
| hand a daemon a key type its image cannot use. The same failure mode this | ||
| fixes, i.e. a daemon that will not start. No data path is touched and no | ||
| on-disk format changes, so nothing can be silently corrupted. | ||
| - **conflict: substantive** — fully custom downstream patch, not a cherry-pick | ||
| (rubric: "substantive conflicts requiring code change, OR fully custom"). It | ||
| applies cleanly to the effort branch, but it carries no upstream review | ||
| behind it; the code is new on this line. | ||
| - **coverage: partial** — new | ||
| `src/pybind/mgr/cephadm/tests/test_nvmeof_key_type.py` (5 tests) covers the | ||
| per-daemon dispatch, key creation and `key_rotate`. | ||
| - **Removal condition** — `LEGACY_CIPHER_DAEMON_TYPES` has to go back to empty | ||
| once a squid-line gateway image ships librados that understands `aes256k`. | ||
| The 1.7 and 2.0.0 images already do, but those are tentacle-related images. | ||
| Until that happens, every carry-forward of this patch re-applies the | ||
| downgrade. | ||
|
|
||
| ## Behavior change | ||
|
|
||
| NVMe-oF gateway daemon keys are created with key type `aes` instead of | ||
| `aes256k`. All other daemon types are unchanged, including the post-upgrade key | ||
| rotation, which only covers mon/mgr/osd/mds. `ceph orch daemon rotate-key` on a | ||
| gateway also produces an `aes` key. | ||
|
|
||
| This is a deliberate downgrade to a weaker cipher for one daemon type. `aes` | ||
| (`CEPH_CRYPTO_AES`) is AES-128-CBC with a fixed IV and a 16-byte key; `aes256k` | ||
| (`CEPH_CRYPTO_AES256KRB5`) is AES256-CTS-HMAC-SHA384-192 with a 32-byte key. So | ||
| the gateway's key loses both the longer key and the HMAC integrity. It is the | ||
| key type every daemon used before 19.2.6 and is still in `ALLOWED_CIPHERS`, not | ||
| a new weak mode. Exposure is limited to the `client.nvmeof.*` entity, whose | ||
| caps are `mon profile rbd` / `osd profile rbd`. | ||
|
|
||
| A gateway already deployed with an `aes256k` key has its key rotated to `aes` | ||
| on its next deploy, so a failed nvmeof service heals itself on redeploy rather | ||
| than needing manual cephx surgery. That rotation keys on daemon type, not on | ||
| what the running image supports, so redeploying a gateway whose image does | ||
| understand `aes256k` downgrades its key too. | ||
|
|
||
| ## Upgrade notes | ||
|
|
||
| Clusters without an NVMe-oF service: nothing to do. | ||
|
|
||
| If an nvmeof service is already stuck from a 19.2.6 or later deploy, redeploy | ||
| it once after the upgrade: | ||
|
|
||
| ``` | ||
| ceph orch redeploy nvmeof.<service> | ||
| ``` | ||
|
|
||
| The gateway's key is rotated to a type its image supports and the service comes | ||
| up. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| """ | ||
| nvmeof gateways get a key of the previous type (aes): the gateway images of | ||
| this release carry a librados from before aes256k and cannot connect with | ||
| an aes256k key. | ||
| """ | ||
| import base64 | ||
| import struct | ||
| from unittest.mock import MagicMock | ||
|
|
||
| from ceph.deployment.service_spec import NvmeofServiceSpec | ||
|
|
||
| from cephadm import utils | ||
| from cephadm.services.cephadmservice import CephadmDaemonDeploySpec | ||
| from cephadm.services.nvmeof import NvmeofService | ||
|
|
||
|
|
||
| def keyring(entity: str, key_type: int) -> str: | ||
| raw = struct.pack('<H', key_type) + b'\0' * 8 + \ | ||
| struct.pack('<H', 16 if key_type == 1 else 32) + \ | ||
| b'k' * (16 if key_type == 1 else 32) | ||
| return f'[{entity}]\n\tkey = {base64.b64encode(raw).decode()}\n' | ||
|
|
||
|
|
||
| def test_key_type_for(): | ||
| assert utils.key_type_for('nvmeof') == 'aes' | ||
| for t in ('osd', 'mds', 'mgr', 'mon', 'crash', 'rgw'): | ||
| assert utils.key_type_for(t) == utils.ROTATION_CIPHER == 'aes256k' | ||
|
|
||
|
|
||
| def test_keyring_key_type(): | ||
| assert utils.keyring_key_type(keyring('client.x', 1)) == 'aes' | ||
| assert utils.keyring_key_type(keyring('client.x', 2)) == 'aes256k' | ||
| assert utils.keyring_key_type('') is None | ||
| assert utils.keyring_key_type('[client.x]\n\tkey = !!!\n') is None | ||
|
|
||
|
|
||
| def test_key_rotate_keeps_nvmeof_on_the_legacy_type(): | ||
| from cephadm.module import CephadmOrchestrator | ||
| mgr = MagicMock() | ||
| mgr.mon_command.return_value = (0, '', '') | ||
| for daemon_type, want in (('nvmeof', 'aes'), ('osd', 'aes256k')): | ||
| spec = CephadmDaemonDeploySpec(host='h', daemon_id='a.b', | ||
| service_name=f'{daemon_type}.a', | ||
| daemon_type=daemon_type) | ||
| CephadmOrchestrator.key_rotate(mgr, spec) | ||
| assert mgr.mon_command.call_args[0][0]['key_type'] == want | ||
|
|
||
|
|
||
| def _service(keyrings): | ||
| mgr = MagicMock() | ||
| spec = NvmeofServiceSpec(service_id='a', pool='p') | ||
| mgr.spec_store.__getitem__.return_value.spec = spec | ||
| mgr.inventory.get_addr.return_value = '10.0.0.1' | ||
| mgr.mon_command.return_value = (0, '', '') | ||
| svc = NvmeofService(mgr) | ||
| svc.get_keyring_with_caps = MagicMock(side_effect=keyrings) | ||
| return mgr, svc | ||
|
|
||
|
|
||
| def _deploy(svc): | ||
| ds = CephadmDaemonDeploySpec(host='h', daemon_id='a.h.xyz', | ||
| service_name='nvmeof.a', daemon_type='nvmeof') | ||
| try: | ||
| svc.prepare_create(ds) | ||
| except Exception: | ||
| # past the keyring, prepare_create renders the gateway config from | ||
| # the mocked mgr; only the key handling is under test here | ||
| pass | ||
|
|
||
|
|
||
| def test_new_gateway_key_is_legacy(): | ||
| mgr, svc = _service([keyring('client.nvmeof.a.h.xyz', 1)]) | ||
| _deploy(svc) | ||
| assert svc.get_keyring_with_caps.call_args.kwargs['key_type'] == 'aes' | ||
| assert not any(c[0][0].get('prefix') == 'auth rotate' | ||
| for c in mgr.mon_command.call_args_list) | ||
|
|
||
|
|
||
| def test_gateway_with_an_aes256k_key_is_rotated_back(): | ||
| entity = 'client.nvmeof.a.h.xyz' | ||
| mgr, svc = _service([keyring(entity, 2), keyring(entity, 1)]) | ||
| _deploy(svc) | ||
| rot = [c[0][0] for c in mgr.mon_command.call_args_list | ||
| if c[0][0].get('prefix') == 'auth rotate'] | ||
| assert rot == [{'prefix': 'auth rotate', 'entity': entity, | ||
| 'format': 'json', 'key_type': 'aes'}] | ||
| assert svc.get_keyring_with_caps.call_count == 2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens when t != 1 and t != 2 KeyError exception happens?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The .get() will return None if the key is not found.