Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem: Crash when trying to auth via websocket #630

Merged
merged 2 commits into from
Jun 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions src/aleph/vm/orchestrator/views/operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

from aleph.vm.models import VmExecution
from aleph.vm.orchestrator.run import create_vm_execution
from aleph.vm.orchestrator.views import authenticate_api_request
from aleph.vm.orchestrator.views.authentication import (
authenticate_websocket_message,
require_jwk_authentication,
Expand Down Expand Up @@ -68,7 +67,7 @@
ws = web.WebSocketResponse()
await ws.prepare(request)
try:
await authenticate_for_vm_or_403(execution, request, vm_hash, ws)
await authenticate_websocket_for_vm_or_403(execution, vm_hash, ws)

Check warning on line 70 in src/aleph/vm/orchestrator/views/operator.py

View check run for this annotation

Codecov / codecov/patch

src/aleph/vm/orchestrator/views/operator.py#L70

Added line #L70 was not covered by tests
await ws.send_json({"status": "connected"})

queue = execution.vm.get_log_queue()
Expand All @@ -88,12 +87,12 @@
execution.vm.unregister_queue(queue)


async def authenticate_for_vm_or_403(execution, request, vm_hash, ws):
"""Allow authentication via HEADER or via websocket"""
if authenticate_api_request(request):
logger.debug(f"Accepted request to access logs via the allocatioan api key on {vm_hash}")
return True
async def authenticate_websocket_for_vm_or_403(execution: VmExecution, vm_hash: ItemHash, ws: web.WebSocketResponse):
"""Authenticate a websocket connection.

Web browsers do not allow setting headers in WebSocket requests, so the authentication
relies on the first message sent by the client.
"""
first_message = await ws.receive_json()
credentials = first_message["auth"]
authenticated_sender = await authenticate_websocket_message(credentials)
Expand Down