mirror of
https://github.com/retspen/webvirtcloud
synced 2026-12-02 08:56:07 +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:
parent
159049736d
commit
b7724928fd
8 changed files with 104 additions and 49 deletions
Binary file not shown.
|
|
@ -11,7 +11,7 @@ msgid ""
|
|||
msgstr ""
|
||||
"Project-Id-Version: PACKAGE VERSION\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2026-11-12 12:21+0000\n"
|
||||
"POT-Creation-Date: 2026-11-12 12:49+0000\n"
|
||||
"PO-Revision-Date: 2020-11-04 12:00+0000\n"
|
||||
"Last-Translator: catborise <muhammetalisag@gmail.com>, 2020\n"
|
||||
"Language-Team: Turkish (https://www.transifex.com/catborise/teams/110663/tr/)\n"
|
||||
|
|
@ -71,8 +71,8 @@ msgstr "Geçersiz anahtar"
|
|||
#: instances/templates/create_instance_w2.html:42
|
||||
#: interfaces/templates/interface.html:119 networks/templates/network.html:145
|
||||
#: networks/templates/network.html:373 nwfilters/templates/nwfilters.html:29
|
||||
#: storages/templates/storage.html:123 virtsecrets/forms.py:25
|
||||
#: virtsecrets/forms.py:27
|
||||
#: storages/templates/storage.html:123 virtsecrets/forms.py:32
|
||||
#: virtsecrets/forms.py:34
|
||||
msgid "Name"
|
||||
msgstr "Ad"
|
||||
|
||||
|
|
@ -4348,7 +4348,7 @@ msgstr ""
|
|||
"Sanal makine çalışıyor: değişiklikler bir sonraki başlatmada uygulanır."
|
||||
|
||||
#: instances/templates/instances/edit_instance_volume.html:24
|
||||
#: virtsecrets/forms.py:23
|
||||
#: virtsecrets/forms.py:30
|
||||
msgid "Volume path"
|
||||
msgstr "Birim yolu"
|
||||
|
||||
|
|
@ -8913,11 +8913,15 @@ msgstr "Oturumu Kapat"
|
|||
msgid "Processing"
|
||||
msgstr "İşleniyor"
|
||||
|
||||
#: virtsecrets/forms.py:18
|
||||
#: virtsecrets/forms.py:19
|
||||
msgid "The usage cannot have control characters or line breaks"
|
||||
msgstr "Kullanım denetim karakteri ya da satır sonu içeremez"
|
||||
|
||||
#: virtsecrets/forms.py:25
|
||||
msgid "Ceph secret name"
|
||||
msgstr "Ceph parola adı"
|
||||
|
||||
#: virtsecrets/forms.py:19
|
||||
#: virtsecrets/forms.py:26
|
||||
msgid ""
|
||||
"The name a disk or pool names it by, e.g. client.libvirt secret, not the Ceph"
|
||||
" user; one secret per name."
|
||||
|
|
@ -8925,64 +8929,64 @@ msgstr ""
|
|||
"Bir disk veya havuzun ona başvurduğu ad, örn. client.libvirt secret; Ceph "
|
||||
"kullanıcısı değil. Her ad için bir parola."
|
||||
|
||||
#: virtsecrets/forms.py:20
|
||||
#: virtsecrets/forms.py:27
|
||||
msgid "Key"
|
||||
msgstr "Anahtar"
|
||||
|
||||
#: virtsecrets/forms.py:20
|
||||
#: virtsecrets/forms.py:27
|
||||
msgid "The key as ceph auth get-key prints it."
|
||||
msgstr "ceph auth get-key komutunun yazdırdığı haliyle anahtar."
|
||||
|
||||
#: virtsecrets/forms.py:21
|
||||
#: virtsecrets/forms.py:28
|
||||
msgid "iSCSI target"
|
||||
msgstr "iSCSI hedefi"
|
||||
|
||||
#: virtsecrets/forms.py:21
|
||||
#: virtsecrets/forms.py:28
|
||||
msgid "The name a disk or pool names it by, e.g. the target IQN."
|
||||
msgstr "Bir disk veya havuzun ona başvurduğu ad, örn. hedef IQN."
|
||||
|
||||
#: virtsecrets/forms.py:22
|
||||
#: virtsecrets/forms.py:29
|
||||
msgid "CHAP password"
|
||||
msgstr "CHAP parolası"
|
||||
|
||||
#: virtsecrets/forms.py:22
|
||||
#: virtsecrets/forms.py:29
|
||||
msgid "The password as it is typed."
|
||||
msgstr "Parola, yazıldığı gibi."
|
||||
|
||||
#: virtsecrets/forms.py:23
|
||||
#: virtsecrets/forms.py:30
|
||||
msgid "The path of the encrypted volume it unlocks."
|
||||
msgstr "Kilidini açtığı şifreli birimin yolu."
|
||||
|
||||
#: virtsecrets/forms.py:24 virtsecrets/forms.py:26 virtsecrets/forms.py:28
|
||||
#: virtsecrets/forms.py:31 virtsecrets/forms.py:33 virtsecrets/forms.py:35
|
||||
msgid "Passphrase"
|
||||
msgstr "Parola ifadesi"
|
||||
|
||||
#: virtsecrets/forms.py:24 virtsecrets/forms.py:28
|
||||
#: virtsecrets/forms.py:31 virtsecrets/forms.py:35
|
||||
msgid "The passphrase as it is typed."
|
||||
msgstr "Yazıldığı haliyle parola ifadesi."
|
||||
|
||||
#: virtsecrets/forms.py:25
|
||||
#: virtsecrets/forms.py:32
|
||||
msgid "A name for it; qemu.conf names it by its UUID."
|
||||
msgstr "Ona bir ad; qemu.conf ona UUID'si ile başvurur."
|
||||
|
||||
#: virtsecrets/forms.py:26
|
||||
#: virtsecrets/forms.py:33
|
||||
msgid "The passphrase of the TLS key, as it is typed."
|
||||
msgstr "TLS anahtarının parola ifadesi, yazıldığı haliyle."
|
||||
|
||||
#: virtsecrets/forms.py:27
|
||||
#: virtsecrets/forms.py:34
|
||||
msgid "A name for it; a VM's vTPM names it by its UUID."
|
||||
msgstr "Ona bir ad; bir sanal makinenin vTPM'i ona UUID'si ile başvurur."
|
||||
|
||||
#: virtsecrets/forms.py:29 virtsecrets/templates/create_secret_block.html:32
|
||||
#: virtsecrets/forms.py:36 virtsecrets/templates/create_secret_block.html:32
|
||||
#: virtsecrets/templates/secrets.html:100
|
||||
msgid "Value"
|
||||
msgstr "Değer"
|
||||
|
||||
#: virtsecrets/forms.py:29
|
||||
#: virtsecrets/forms.py:36
|
||||
msgid "The value as it is typed."
|
||||
msgstr "Yazıldığı haliyle değer."
|
||||
|
||||
#: virtsecrets/forms.py:30
|
||||
#: virtsecrets/forms.py:37
|
||||
msgid "Leave it blank to give it later."
|
||||
msgstr "Daha sonra vermek için boş bırakın."
|
||||
|
||||
|
|
@ -10238,17 +10242,21 @@ msgid "A Ceph key is base64 text, as `ceph auth get-key` prints it"
|
|||
msgstr ""
|
||||
"Ceph anahtarı, `ceph auth get-key` komutunun yazdırdığı gibi base64 metindir"
|
||||
|
||||
#: vrtManager/virtsecrets.py:115
|
||||
#: vrtManager/virtsecrets.py:105
|
||||
msgid "Type the secret's value"
|
||||
msgstr "Parolanın değerini yazın"
|
||||
|
||||
#: vrtManager/virtsecrets.py:118
|
||||
#, python-format
|
||||
msgid "VMs %(names)s"
|
||||
msgstr "%(names)s sanal makineleri"
|
||||
|
||||
#: vrtManager/virtsecrets.py:117
|
||||
#: vrtManager/virtsecrets.py:120
|
||||
#, python-format
|
||||
msgid "pools %(names)s"
|
||||
msgstr "%(names)s havuzları"
|
||||
|
||||
#: vrtManager/virtsecrets.py:118
|
||||
#: vrtManager/virtsecrets.py:121
|
||||
#, python-format
|
||||
msgid "Secret %(uuid)s is used by %(named)s; remove it from them first"
|
||||
msgstr ""
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -7,7 +7,7 @@ msgid ""
|
|||
msgstr ""
|
||||
"Project-Id-Version: \n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2026-11-12 12:21+0000\n"
|
||||
"POT-Creation-Date: 2026-11-12 12:49+0000\n"
|
||||
"PO-Revision-Date: \n"
|
||||
"Last-Translator: \n"
|
||||
"Language-Team: \n"
|
||||
|
|
@ -68,8 +68,8 @@ msgstr "无效的密钥"
|
|||
#: instances/templates/create_instance_w2.html:42
|
||||
#: interfaces/templates/interface.html:119 networks/templates/network.html:145
|
||||
#: networks/templates/network.html:373 nwfilters/templates/nwfilters.html:29
|
||||
#: storages/templates/storage.html:123 virtsecrets/forms.py:25
|
||||
#: virtsecrets/forms.py:27
|
||||
#: storages/templates/storage.html:123 virtsecrets/forms.py:32
|
||||
#: virtsecrets/forms.py:34
|
||||
msgid "Name"
|
||||
msgstr "名称"
|
||||
|
||||
|
|
@ -4159,7 +4159,7 @@ msgid "The VM is running: the changes apply at its next start."
|
|||
msgstr "虚拟机正在运行:更改将在下次启动时生效。"
|
||||
|
||||
#: instances/templates/instances/edit_instance_volume.html:24
|
||||
#: virtsecrets/forms.py:23
|
||||
#: virtsecrets/forms.py:30
|
||||
msgid "Volume path"
|
||||
msgstr "卷路径"
|
||||
|
||||
|
|
@ -8420,74 +8420,78 @@ msgstr "退出登录"
|
|||
msgid "Processing"
|
||||
msgstr "处理中"
|
||||
|
||||
#: virtsecrets/forms.py:18
|
||||
#: virtsecrets/forms.py:19
|
||||
msgid "The usage cannot have control characters or line breaks"
|
||||
msgstr "用途不能包含控制字符或换行符"
|
||||
|
||||
#: virtsecrets/forms.py:25
|
||||
msgid "Ceph secret name"
|
||||
msgstr "Ceph 机密名称"
|
||||
|
||||
#: virtsecrets/forms.py:19
|
||||
#: virtsecrets/forms.py:26
|
||||
msgid ""
|
||||
"The name a disk or pool names it by, e.g. client.libvirt secret, not the Ceph"
|
||||
" user; one secret per name."
|
||||
msgstr "磁盘或存储池引用它时使用的名称,例如 client.libvirt secret,而不是 Ceph 用户;每个名称一个机密。"
|
||||
|
||||
#: virtsecrets/forms.py:20
|
||||
#: virtsecrets/forms.py:27
|
||||
msgid "Key"
|
||||
msgstr "密钥"
|
||||
|
||||
#: virtsecrets/forms.py:20
|
||||
#: virtsecrets/forms.py:27
|
||||
msgid "The key as ceph auth get-key prints it."
|
||||
msgstr "ceph auth get-key 输出的密钥。"
|
||||
|
||||
#: virtsecrets/forms.py:21
|
||||
#: virtsecrets/forms.py:28
|
||||
msgid "iSCSI target"
|
||||
msgstr "iSCSI 目标"
|
||||
|
||||
#: virtsecrets/forms.py:21
|
||||
#: virtsecrets/forms.py:28
|
||||
msgid "The name a disk or pool names it by, e.g. the target IQN."
|
||||
msgstr "磁盘或存储池引用它时使用的名称,例如目标 IQN。"
|
||||
|
||||
#: virtsecrets/forms.py:22
|
||||
#: virtsecrets/forms.py:29
|
||||
msgid "CHAP password"
|
||||
msgstr "CHAP 密码"
|
||||
|
||||
#: virtsecrets/forms.py:22
|
||||
#: virtsecrets/forms.py:29
|
||||
msgid "The password as it is typed."
|
||||
msgstr "按原样输入的密码。"
|
||||
|
||||
#: virtsecrets/forms.py:23
|
||||
#: virtsecrets/forms.py:30
|
||||
msgid "The path of the encrypted volume it unlocks."
|
||||
msgstr "它所解锁的加密卷的路径。"
|
||||
|
||||
#: virtsecrets/forms.py:24 virtsecrets/forms.py:26 virtsecrets/forms.py:28
|
||||
#: virtsecrets/forms.py:31 virtsecrets/forms.py:33 virtsecrets/forms.py:35
|
||||
msgid "Passphrase"
|
||||
msgstr "口令"
|
||||
|
||||
#: virtsecrets/forms.py:24 virtsecrets/forms.py:28
|
||||
#: virtsecrets/forms.py:31 virtsecrets/forms.py:35
|
||||
msgid "The passphrase as it is typed."
|
||||
msgstr "按原样输入的口令。"
|
||||
|
||||
#: virtsecrets/forms.py:25
|
||||
#: virtsecrets/forms.py:32
|
||||
msgid "A name for it; qemu.conf names it by its UUID."
|
||||
msgstr "为它起个名称;qemu.conf 通过其 UUID 引用它。"
|
||||
|
||||
#: virtsecrets/forms.py:26
|
||||
#: virtsecrets/forms.py:33
|
||||
msgid "The passphrase of the TLS key, as it is typed."
|
||||
msgstr "TLS 密钥的口令,按原样输入。"
|
||||
|
||||
#: virtsecrets/forms.py:27
|
||||
#: virtsecrets/forms.py:34
|
||||
msgid "A name for it; a VM's vTPM names it by its UUID."
|
||||
msgstr "为它起个名称;虚拟机的 vTPM 通过其 UUID 引用它。"
|
||||
|
||||
#: virtsecrets/forms.py:29 virtsecrets/templates/create_secret_block.html:32
|
||||
#: virtsecrets/forms.py:36 virtsecrets/templates/create_secret_block.html:32
|
||||
#: virtsecrets/templates/secrets.html:100
|
||||
msgid "Value"
|
||||
msgstr "值"
|
||||
|
||||
#: virtsecrets/forms.py:29
|
||||
#: virtsecrets/forms.py:36
|
||||
msgid "The value as it is typed."
|
||||
msgstr "按原样输入的值。"
|
||||
|
||||
#: virtsecrets/forms.py:30
|
||||
#: virtsecrets/forms.py:37
|
||||
msgid "Leave it blank to give it later."
|
||||
msgstr "留空则稍后再设置。"
|
||||
|
||||
|
|
@ -9635,17 +9639,21 @@ msgstr "MAC 地址的格式必须为 AA:BB:CC:DD:EE:FF,实际为 %(mac)s"
|
|||
msgid "A Ceph key is base64 text, as `ceph auth get-key` prints it"
|
||||
msgstr "Ceph 密钥是 base64 文本,即 `ceph auth get-key` 输出的内容"
|
||||
|
||||
#: vrtManager/virtsecrets.py:115
|
||||
#: vrtManager/virtsecrets.py:105
|
||||
msgid "Type the secret's value"
|
||||
msgstr "请输入机密的值"
|
||||
|
||||
#: vrtManager/virtsecrets.py:118
|
||||
#, python-format
|
||||
msgid "VMs %(names)s"
|
||||
msgstr "虚拟机 %(names)s"
|
||||
|
||||
#: vrtManager/virtsecrets.py:117
|
||||
#: vrtManager/virtsecrets.py:120
|
||||
#, python-format
|
||||
msgid "pools %(names)s"
|
||||
msgstr "存储池 %(names)s"
|
||||
|
||||
#: vrtManager/virtsecrets.py:118
|
||||
#: vrtManager/virtsecrets.py:121
|
||||
#, python-format
|
||||
msgid "Secret %(uuid)s is used by %(named)s; remove it from them first"
|
||||
msgstr "机密 %(uuid)s 正被 %(named)s 使用;请先从中移除它"
|
||||
|
|
|
|||
|
|
@ -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 = {
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
|
|
|
|||
|
|
@ -76,6 +76,11 @@ class SecretValueTests(SimpleTestCase):
|
|||
self.set_value("ceph", value)
|
||||
self.assertNotIn(value, str(refused.exception))
|
||||
|
||||
def test_an_empty_value_is_refused_in_words(self):
|
||||
# libvirt says "value in virSecretSetValue must not be NULL"
|
||||
with self.assertRaisesRegex(OperationError, "Type the secret's value"):
|
||||
self.set_value("iscsi", "")
|
||||
|
||||
|
||||
ISCSI = "8f2c0000-0000-4000-8000-000000000002"
|
||||
|
||||
|
|
@ -177,10 +182,19 @@ class DeleteTests(SimpleTestCase):
|
|||
def test_a_secret_a_vm_or_a_pool_names_is_not_deleted(self):
|
||||
conn = connection(domains=[vm("db-2", f"<disk><auth><secret type='ceph' uuid='{CEPH}'/></auth></disk>")],
|
||||
pools=[pool("ceph-rbd", "<auth type='ceph'><secret usage='client.libvirt'/></auth>")])
|
||||
conn.wvm.secretLookupByUUIDString.return_value.UUIDString.return_value = CEPH
|
||||
with self.assertRaisesRegex(OperationError, f"Secret {CEPH} is used by VMs db-2; pools ceph-rbd"):
|
||||
conn.delete_secret(CEPH)
|
||||
conn.wvm.secretLookupByUUIDString.return_value.undefine.assert_not_called()
|
||||
|
||||
def test_a_secret_in_use_named_in_capitals_is_not_deleted(self):
|
||||
# libvirt finds it by the UUID in capitals, its users name it in small letters
|
||||
conn = connection(domains=[vm("db-2", f"<disk><auth><secret type='ceph' uuid='{CEPH}'/></auth></disk>")])
|
||||
conn.wvm.secretLookupByUUIDString.return_value.UUIDString.return_value = CEPH
|
||||
with self.assertRaisesRegex(OperationError, "is used by VMs db-2"):
|
||||
conn.delete_secret(CEPH.upper())
|
||||
conn.wvm.secretLookupByUUIDString.return_value.undefine.assert_not_called()
|
||||
|
||||
def test_an_unused_secret_is_deleted(self):
|
||||
conn = connection(domains=[vm("web-1", f"<disk><auth><secret type='ceph' uuid='{CEPH}'/></auth></disk>")])
|
||||
conn.delete_secret(ISCSI)
|
||||
|
|
|
|||
|
|
@ -101,6 +101,8 @@ class wvmSecrets(wvmConnect):
|
|||
def set_secret_value(self, uuid, value):
|
||||
"""value as typed on the page; its bytes follow the secret's usage
|
||||
type (value_bytes)."""
|
||||
if not value: # libvirt takes none
|
||||
raise util.OperationError(gettext_noop("Type the secret's value"))
|
||||
secret = self.wvm.secretLookupByUUIDString(uuid)
|
||||
usage_type = etree.fromstring(secret.XMLDesc(0)).xpath("string(usage/@type)")
|
||||
secret.setValue(value_bytes(usage_type, value))
|
||||
|
|
@ -109,6 +111,7 @@ class wvmSecrets(wvmConnect):
|
|||
"""Refused while a VM or a pool names it (get_users): without it that
|
||||
VM or pool would no longer start."""
|
||||
secret = self.wvm.secretLookupByUUIDString(uuid)
|
||||
uuid = secret.UUIDString() # as its users name it: libvirt takes it in capitals too
|
||||
if users := self.get_users(self.get_secrets_info()).get(uuid):
|
||||
named = []
|
||||
if users["vms"]:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue