mirror of
https://github.com/retspen/webvirtcloud
synced 2026-11-08 11:16:47 +00:00
create_secret wrote the usage value into the secret XML with an f-string,
unchecked: a quote, "<" or "&" broke the XML or added to it. The page's
pattern ([a-z0-9. ]+) was the only check and refused real values: a
volume secret's path ("/") and an iSCSI IQN ("-", ":"). The XML is now
built with lxml, so the value is text whatever it holds, and the input
keeps only required and the form's 100 characters; libvirt reports a
value it does not take.
A live test creates a volume, an iSCSI and a Ceph secret with real
values through the page.
30 lines
1.1 KiB
Python
30 lines
1.1 KiB
Python
import base64
|
|
|
|
from lxml import etree
|
|
from vrtManager.connection import wvmConnect
|
|
|
|
# the element of <usage> that holds the value, per usage type
|
|
USAGE_ELEMENTS = {"ceph": "name", "volume": "volume", "iscsi": "target"}
|
|
|
|
|
|
class wvmSecrets(wvmConnect):
|
|
def create_secret(self, ephemeral, private, secret_type, data):
|
|
# built with lxml: data is text, whatever characters it holds
|
|
secret = etree.Element("secret", ephemeral=ephemeral, private=private)
|
|
usage = etree.SubElement(secret, "usage", type=secret_type)
|
|
etree.SubElement(usage, USAGE_ELEMENTS[secret_type]).text = data
|
|
self.wvm.secretDefineXML(etree.tostring(secret, encoding="unicode"))
|
|
|
|
def get_secret_value(self, uuid):
|
|
secrt = self.get_secret(uuid)
|
|
value = secrt.value()
|
|
return base64.b64encode(value)
|
|
|
|
def set_secret_value(self, uuid, value):
|
|
secrt = self.get_secret(uuid)
|
|
value = base64.b64decode(value)
|
|
secrt.setValue(value)
|
|
|
|
def delete_secret(self, uuid):
|
|
secrt = self.get_secret(uuid)
|
|
secrt.undefine()
|