mirror of
https://github.com/retspen/webvirtcloud
synced 2026-11-09 11:46:49 +00:00
fix(instances): a new VM and each clone get a VNC password of their own
Since the VM create became a job (6f0c7300) every new VM was defined with
no VNC password, and a clone copied its source's password (or its lack
of one) exactly: every clone of a template shared it. Computes listen
for VNC on all their addresses (dev/libvirt-bootstrap.sh), so anyone who
could reach a compute's VNC ports opened any of these consoles directly,
without the panel; the README's firewall rule was the only guard.
The create job asks for create.py's random 8-character password again,
and a clone's VNC graphics get a new random one. The console page sends
the password to a user with passwordless_console, which the user create
form now ticks by default next to change_password; a user without it is
asked for the password, as the permission intends. Existing VMs keep
their settings.
Live create, clone and VM page tests pass on a TCP compute.
This commit is contained in:
parent
c5d0672c68
commit
1f9347e148
7 changed files with 47 additions and 3 deletions
|
|
@ -2398,6 +2398,10 @@ class wvmInstance(wvmConnect):
|
|||
raise ValueError(f"No MAC address for network interface {num}")
|
||||
net.find("mac").set("address", self.fix_mac(mac))
|
||||
|
||||
# the clone's console gets a password of its own: one copied from the source would open both
|
||||
for graphics in tree.findall("devices/graphics[@type='vnc']"):
|
||||
graphics.set("passwd", util.randomPasswd(8)) # the length VNC allows
|
||||
|
||||
nvram = tree.find("os/nvram")
|
||||
if nvram is not None and nvram.get("type", "file") != "file":
|
||||
raise util.OperationError(gettext_noop("Cannot clone a VM whose NVRAM is not a file"))
|
||||
|
|
|
|||
26
vrtManager/tests/test_clone_console.py
Normal file
26
vrtManager/tests/test_clone_console.py
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
"""A clone's VNC console gets a password of its own: one copied from its
|
||||
source (a template's, say) would open the source's and every other clone's."""
|
||||
|
||||
import unittest
|
||||
|
||||
from vrtManager.instance import wvmInstance
|
||||
|
||||
|
||||
def clone_graphics(passwd_attribute):
|
||||
p = wvmInstance.__new__(wvmInstance) # no connection: only these calls
|
||||
p.get_instances = lambda: []
|
||||
p._XMLDesc = lambda flags: f"""<domain><name>tpl</name><uuid>u</uuid><devices>
|
||||
<graphics type='vnc' port='-1' autoport='yes' {passwd_attribute} listen='0.0.0.0'/></devices></domain>"""
|
||||
tree, _ = p._clone_definition({"name": "copy"}, "abababab-0000-1111-2222-333333333333")
|
||||
return tree.find("devices/graphics")
|
||||
|
||||
|
||||
class CloneConsoleTestCase(unittest.TestCase):
|
||||
def test_each_clone_gets_its_own_vnc_password(self):
|
||||
passwords = {clone_graphics("passwd='shared12'").get("passwd") for _ in range(5)}
|
||||
self.assertNotIn("shared12", passwords)
|
||||
self.assertEqual(len(passwords), 5)
|
||||
self.assertTrue(all(len(p) == 8 for p in passwords)) # the length VNC allows
|
||||
|
||||
def test_a_source_without_a_password_gives_a_clone_with_one(self):
|
||||
self.assertEqual(len(clone_graphics("").get("passwd")), 8)
|
||||
Loading…
Add table
Add a link
Reference in a new issue