mirror of
https://github.com/retspen/webvirtcloud
synced 2026-12-02 00:46:05 +00:00
feat(console): a working serial console
The xterm console never connected: socketiod expected a different token format, its worker had no compute credentials, one global console was shared by every client and its output broadcast to all of them, and the Docker image did not run socketiod at all. - console/tokens.py: one authorize() for noVNC and socketiod; the signed token is the only credential, checked at connect time. - socketiod: one pty worker per client (consolecallback with the instance id), one session per VM, a session cap, input and resize checked; the parent never opens libvirt. The engine.io same-origin check is on. - consolecallback: opens the console with the compute's credentials and exits with a message when it cannot. - Docker runs socketiod as a runit service; nginx proxies /socket.io/ with Host and the scheme for the origin check. Supervisor and systemd start it as well; WEBVIRTCLOUD_SERIAL_CONSOLE=1 enables it. - Tests: token and session unit tests, socketiod as a process, and a live test that reads SeaBIOS from a wvc-test VM on the TCP and SSH hosts.
This commit is contained in:
parent
9b0c6e2d8e
commit
d37aa42392
20 changed files with 592 additions and 569 deletions
|
|
@ -83,36 +83,11 @@ except ImportError:
|
|||
|
||||
|
||||
def get_connection_infos(token):
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.core.signing import BadSignature, SignatureExpired, TimestampSigner
|
||||
from instances.models import Instance
|
||||
from instances.utils import can_open_console
|
||||
from console.tokens import authorize
|
||||
from vrtManager.instance import wvmInstance
|
||||
|
||||
# The console view signs exactly "host:uuid:user_id". Anything else
|
||||
# (unsigned, expired, or without the user part) is rejected, because the
|
||||
# per-user access check below depends on user_id.
|
||||
signer = TimestampSigner(salt="console.novnc")
|
||||
try:
|
||||
unsigned = signer.unsign(token, max_age=120)
|
||||
host, uuid, user_id = unsigned.split(":")
|
||||
host = int(host)
|
||||
user_id = int(user_id)
|
||||
except (BadSignature, SignatureExpired, ValueError, TypeError):
|
||||
raise PermissionError("Invalid or expired console token")
|
||||
|
||||
try:
|
||||
instance = Instance.objects.get(compute_id=host, uuid=uuid)
|
||||
User = get_user_model()
|
||||
try:
|
||||
user = User.objects.get(id=user_id)
|
||||
except User.DoesNotExist:
|
||||
raise PermissionError("User not found")
|
||||
if not user.is_active:
|
||||
raise PermissionError("User account is inactive or disabled")
|
||||
if not can_open_console(user, instance):
|
||||
raise PermissionError("User no longer has access to this instance")
|
||||
|
||||
instance = authorize(token)
|
||||
conn = wvmInstance(
|
||||
instance.compute.hostname,
|
||||
instance.compute.login,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue