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 by its UUID in capitals

libvirt finds a secret by its UUID in capitals too, but its users were
looked up by the UUID as posted: a secret a VM's disk or a pool named
was deleted, and that VM or pool no longer started. They are now looked
up by the secret's own UUID.

A usage with a control character made the page fail (lxml refuses it in
XML text) and libvirt dropped a line break silently; the form refuses
both. An empty value set later showed libvirt's "value in
virSecretSetValue must not be NULL"; it is refused in words.
This commit is contained in:
catborise 2026-11-12 15:49:24 +03:00
parent 159049736d
commit b7724928fd
8 changed files with 104 additions and 49 deletions

View file

@ -6,12 +6,21 @@ class AddSecret(forms.Form):
usage_type = forms.ChoiceField(
choices=(("ceph", "Ceph"), ("iscsi", "iSCSI"), ("volume", _("Volume")), ("tls", "TLS"), ("vtpm", "vTPM")),
)
usage = forms.CharField()
usage = forms.CharField(strip=False) # stripped once checked: a line break at its end too
# a password keeps its spaces; none defines the secret without a value
value = forms.CharField(required=False, strip=False)
ephemeral = forms.BooleanField(required=False)
private = forms.BooleanField(required=False)
def clean_usage(self):
usage = self.cleaned_data["usage"]
# XML text cannot hold them, and libvirt drops a line break
if any(ord(char) < 32 for char in usage):
raise forms.ValidationError(_("The usage cannot have control characters or line breaks"))
if not usage.strip():
raise forms.ValidationError(self.fields["usage"].error_messages["required"], code="required")
return usage.strip()
# what a secret's usage and value are, per usage type, for the page's labels
USAGE_TEXTS = {

View file

@ -20,6 +20,19 @@ class CreateSecretFormTests(SimpleTestCase):
self.assertEqual((form.cleaned_data["value"], form.cleaned_data["ephemeral"], form.cleaned_data["private"]),
(" pw ", False, True))
def test_a_usage_with_a_control_character_is_refused(self):
# lxml refuses it in XML text (a 500); libvirt drops a line break
# at its ends too, which stripping would hide
for usage in ("iqn.test\x01", "a\nb", "iqn.test\n", "\tiqn.test"):
with self.subTest(usage=usage):
form = AddSecret({"usage_type": "iscsi", "usage": usage})
self.assertIn("control characters", str(form.errors["usage"]))
form = AddSecret({"usage_type": "iscsi", "usage": " "})
self.assertEqual(form.errors["usage"].as_data()[0].code, "required")
form = AddSecret({"usage_type": "iscsi", "usage": " iqn.test "})
self.assertTrue(form.is_valid(), form.errors)
self.assertEqual(form.cleaned_data["usage"], "iqn.test")
class CreateSecretDialogTests(TestCase):
def test_the_dialog_offers_the_usage_types_the_form_takes(self):