Skip to content

feat: add one libvirt secret per ceph-access backend, prune stale secrets - #235

Open
Guno327 wants to merge 2 commits into
canonical:mainfrom
Guno327:os121/6-hypervisor-multi-secrets
Open

Guno327 wants to merge 2 commits into
canonical:mainfrom
Guno327:os121/6-hypervisor-multi-secrets

Conversation

@Guno327

@Guno327 Guno327 commented Oct 9, 2026 •

Copy link
Copy Markdown

To support the OS121 remote ceph feature, this snap needs to support
multiple ceph-access backends, which means storing one libvirt secret per
backend. During the development work I also found that stale libvirt secrets
were never pruned, so pruning was a necessary addition to this change.

Assisted-By: Claude Opus 5.5

QA steps

  1. tox -e py3, tox -e pep8.
  2. Install the snap over an existing one that has never had a
    ceph-access key: the configure hook succeeds.
  3. Add a second backend (ceph-access.<backend>.uuid and .key):
    sudo openstack-hypervisor.virsh secret-list shows one secret per
    backend, usage ceph-access.<backend>.
  4. Remove that backend's ceph-access key: its libvirt secret is removed,
    the other remains.
  5. Change only a backend's key: the secret value changes, the uuid does not.

Tested

Live on Sunbeam 2026.1, driven by the openstack-hypervisor charm:

  • first install with no ceph-access key: configure succeeded;
  • two, then three backends at once (Sunbeam's own microceph, an external
    cluster over an offer, an external cluster through ceph-proxy), one
    secret each;
  • removing a backend pruned only its secret;
  • uuids unchanged across a snap upgrade and across key rotation for both
    external backends, with volumes attached.

Links

Jira card: OPEN-4850
Depends on #230, an existing bug found during development (this branch is based on it).

@Guno327
Guno327 force-pushed the os121/6-hypervisor-multi-secrets branch 2 times, most recently from ba38ead to ac70d41 Compare October 9, 2026 16:57
@Guno327
Guno327 marked this pull request as ready for review October 21, 2026 18:33
@Guno327
Guno327 force-pushed the os121/6-hypervisor-multi-secrets branch 2 times, most recently from ff3e96d to 5b9224f Compare November 12, 2026 19:39
Signed-off-by: guno327 <gunnar.hovik@canonical.com>
@Guno327
Guno327 force-pushed the os121/6-hypervisor-multi-secrets branch from 5b9224f to 3390e7b Compare November 13, 2026 22:04
for secret_uuid, (key, usage) in desired.items():
try:
_ensure_secret(secret_uuid, key, usage)
except libvirt.libvirtError:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

If libvirt rejects the replacement, the old secret has already been undefined and this catch lets the configure hook succeed. I reproduced that with an injected libvirt error. Can we set the value in place when the UUID is unchanged and surface failed updates to the caller? A successful snap configuration change can otherwise leave the compute without the secret it needs. Secret replacement

def _prune_ceph_secrets(keep: set[str]) -> None:
"""Undefine per-backend secrets whose backend is gone."""
libvirt = _get_libvirt()
conn = libvirt.open("qemu:///system")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This opens libvirt even when the host has no Ceph settings. I injected an unavailable libvirt socket with an empty Ceph config. The previous implementation returned without opening the socket, while this path raised before the configure hook could reach Masakari or SR-IOV. Can we handle cleanup failure here so unrelated configuration can still proceed?

Configure hook order

libvirt = _get_libvirt()
desired = _desired_ceph_secrets(snap)
# Prune first, then add to handle same app getting new UUID
_prune_ceph_secrets(keep=set(desired))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

When a backend changes UUID, this removes the old secret before trying to define the replacement. I injected a failure in that second step: the old secret was already gone and configure returned normally. Could we preserve the old secret if the UUID change fails and add a regression test for that path?

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