1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-12-03 17:36:05 +00:00

fix(virtsecrets): a secret in use is not deleted, and a password is stored as typed

- A secret is in use when a VM names it in a disk, a host device or its
  vTPM, or a pool in its source, by UUID or by its usage within the usage
  type, as they run and as saved. The vTPM, host devices and pools' saved
  definitions were not checked before.
- A Ceph key is taken in base64, as `ceph auth get-key` prints it; any other
  value is a password or passphrase stored as typed, spaces included.
- A new secret takes its value at once; a value refused leaves no secret.
- TLS and vTPM secrets can be created; the usage has no length limit.
- Every POST redirects; the list is read once and only with its users; a
  secret, VM or pool gone meanwhile is left out.
- domain_trees() is shared by the in-use checks of secrets, network filters,
  networks and pools; the storage page's Ceph secret picker reads the same
  listing.
This commit is contained in:
catborise 2026-10-29 09:29:20 +03:00
parent 2c99dae701
commit 1850d2de8e
17 changed files with 429 additions and 249 deletions

View file

@ -127,7 +127,7 @@ class PoolAndVolumeRowTests(TransactionTestCase):
conn.get_size.return_value = (1, 1)
conn.get_storages_info.return_value = []
conn.get_storages.return_value = ["default"]
conn.get_secrets.return_value = []
conn.get_secrets_info.return_value = []
conn.update_volumes.return_value = []
conn.create_volume.return_value = "disk1.qcow2"
setattr(self, name, conn)

View file

@ -2,13 +2,13 @@
path another one has, an RBD pool only a Ceph secret of the host; a refused
pool opens the dialog again with what was entered and why."""
from unittest.mock import MagicMock, patch
from unittest.mock import patch
from computes.models import Compute
from django.contrib.auth import get_user_model
from django.test import SimpleTestCase, TestCase
from django.urls import reverse
from libvirt import VIR_SECRET_USAGE_TYPE_CEPH, VIR_SECRET_USAGE_TYPE_VOLUME, libvirtError
from libvirt import libvirtError
from lxml import html
from storages.forms import AddStgPool
@ -63,11 +63,10 @@ class DialogTests(TestCase):
self.addCleanup(patcher.stop)
pools = [{**pool, "status": 1, "autostart": 1, "volumes": 0, "size": 1, "free": 1, "used_percent": 0} for pool in POOLS]
self.conn.get_storages_info.return_value = pools
secrets = {SECRET: (VIR_SECRET_USAGE_TYPE_CEPH, "client.libvirt"),
"00000000-0000-0000-0000-000000000003": (VIR_SECRET_USAGE_TYPE_VOLUME, "/var/lib/libvirt/images/a.img")}
self.conn.get_secrets.return_value = list(secrets)
self.conn.get_secret.side_effect = lambda uuid: MagicMock(**{"usageType.return_value": secrets[uuid][0],
"usageID.return_value": secrets[uuid][1]})
self.conn.get_secrets_info.return_value = [
{"uuid": SECRET, "usage_type": "ceph", "usage": "client.libvirt"},
{"uuid": "00000000-0000-0000-0000-000000000003", "usage_type": "volume", "usage": "/var/lib/libvirt/images/a.img"},
]
self.url = reverse("storages", args=[self.compute.pk])
def page(self, response):

View file

@ -139,7 +139,7 @@ class PoolListTests(TestCase):
]
with patch("storages.views.wvmStorages") as storages:
storages.return_value.get_storages_info.return_value = pools
storages.return_value.get_secrets.return_value = []
storages.return_value.get_secrets_info.return_value = []
page = html.fromstring(self.client.get(reverse("storages", args=[compute.pk])).content)
cards = [" ".join(" ".join(card.itertext()).split()) for card in page.xpath("//div[@class='card h-100']")]
self.assertEqual(cards, [

View file

@ -10,7 +10,7 @@ from django.http import HttpResponseRedirect, JsonResponse
from django.shortcuts import get_object_or_404, redirect, render
from django.urls import reverse
from django.utils.translation import gettext_lazy as _
from libvirt import VIR_SECRET_USAGE_TYPE_CEPH, libvirtError
from libvirt import libvirtError
from operations import claims, jobs
from operations.utils import busy_message
from logs.audit import audit, failed
@ -79,11 +79,7 @@ def storages(request, compute_id):
storages = conn.get_storages_info()
iso_pool = next((pool for pool in storages if pool["name"] == "iso"), None)
# the secrets an RBD pool can use, by the name they were given
ceph_secrets = []
for uuid in conn.get_secrets():
secret = conn.get_secret(uuid)
if secret.usageType() == VIR_SECRET_USAGE_TYPE_CEPH:
ceph_secrets.append({"uuid": uuid, "usage": secret.usageID()})
ceph_secrets = [secret for secret in conn.get_secrets_info() if secret["usage_type"] == "ceph"]
if request.method == "POST" and "create" in request.POST:
form = AddStgPool(request.POST, pools=storages, ceph_secrets=[s["uuid"] for s in ceph_secrets])