mirror of
https://github.com/retspen/webvirtcloud
synced 2026-11-11 12:46:49 +00:00
fix(instances): a template's console settings cannot be changed by a POST
A template's page has no console settings form (it is cloned, not run), but update_console still took a direct POST from a staff owner with is_change and is_vnc, or from a superuser. can_manage_console now refuses every template, so the page and the view use one rule. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Kk4h2TcUiaWmU5MUszYSea
This commit is contained in:
parent
d34b1eb2bf
commit
0cee65805d
4 changed files with 18 additions and 7 deletions
|
|
@ -45,6 +45,13 @@ class UpdateConsoleTestCase(TestCase):
|
|||
proxy.set_console_listener_addr.assert_called_once_with("0.0.0.0")
|
||||
proxy.set_console_passwd.assert_not_called()
|
||||
|
||||
def test_a_template_s_console_settings_are_not_changed(self):
|
||||
# its page has no console form: a template is cloned, not run
|
||||
self.instance.is_template = True
|
||||
self.instance.save()
|
||||
proxy, _ = self.post({**VNC, "keymap": "de"})
|
||||
proxy.set_console_keymap.assert_not_called()
|
||||
|
||||
def test_the_password_changes_by_the_action_chosen(self):
|
||||
for action, password in (("set", " a b c "), ("set", "éééé"), ("none", "")):
|
||||
with self.subTest(action, password=password):
|
||||
|
|
|
|||
|
|
@ -463,15 +463,13 @@ def can_manage_console(user, instance):
|
|||
"""
|
||||
Who may see and change a VM's console settings, including its VNC
|
||||
password: an active superuser, or an active owner with both is_change and
|
||||
is_vnc; on a template only a staff owner (as get_instance(perm_type="change")).
|
||||
is_vnc. No one on a template: it is cloned, not run.
|
||||
is_staff and the global view_instances permission alone do not count.
|
||||
"""
|
||||
if not user.is_active:
|
||||
if not user.is_active or instance.is_template:
|
||||
return False
|
||||
if user.is_superuser:
|
||||
return True
|
||||
if instance.is_template and not user.is_staff:
|
||||
return False
|
||||
return UserInstance.objects.filter(
|
||||
instance=instance, user=user, is_change=True, is_vnc=True
|
||||
).exists()
|
||||
|
|
|
|||
|
|
@ -288,8 +288,7 @@ def _instance_page(request, pk, instance, compute):
|
|||
publickeys = UserSSHKey.objects.filter(user_id=request.user.id)
|
||||
# The console form renders the VNC password, so only users who may manage
|
||||
# console settings get the form (and the password) at all.
|
||||
# a template is cloned, not run: no console settings or host devices on its page
|
||||
can_manage_console = utils.can_manage_console(request.user, instance) and not instance.is_template
|
||||
can_manage_console = utils.can_manage_console(request.user, instance)
|
||||
console_form = None
|
||||
if can_manage_console:
|
||||
console_form = ConsoleForm(instance=instance, is_superuser=request.user.is_superuser)
|
||||
|
|
|
|||
|
|
@ -136,9 +136,16 @@ ROLE_EXPECTATIONS = {
|
|||
|
||||
# A template VM: only superusers and staff owners change or delete it; other
|
||||
# owners keep view, power (poweron and powercycle are no-ops on a template)
|
||||
# and console. Cloning has its own rule, see the clone test.
|
||||
# and console. No one changes its console settings: a template is cloned, not
|
||||
# run. Cloning has its own rule, see the clone test.
|
||||
TEMPLATE_ROLE_EXPECTATIONS = {
|
||||
**ROLE_EXPECTATIONS,
|
||||
"staff_owner_is_change_is_vnc": (
|
||||
True,
|
||||
False,
|
||||
{"is_change": True, "is_vnc": True},
|
||||
VIEW_VM | POWER_AND_CONSOLE | CHANGE_VM | TEMPLATE_FLAG,
|
||||
),
|
||||
"owner_is_change": (False, False, {"is_change": True}, VIEW_VM | POWER_AND_CONSOLE),
|
||||
"owner_is_delete": (False, False, {"is_delete": True}, VIEW_VM | POWER_AND_CONSOLE),
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue