Skip to content

Commit edc6da2

Browse files
authored
enh: Operator auth. Better http error (#788)
make it more clear what the error is so it is easier for client and sdk developper to debug auth problem
1 parent 237e3fd commit edc6da2

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/aleph/vm/orchestrator/views/authentication.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,13 +234,19 @@ async def authenticate_jwk(request: web.Request) -> str:
234234
signed_operation = get_signed_operation(request)
235235
if signed_operation.content.domain != settings.DOMAIN_NAME:
236236
logger.debug(f"Invalid domain '{signed_operation.content.domain}' != '{settings.DOMAIN_NAME}'")
237-
raise web.HTTPUnauthorized(reason="Invalid domain")
237+
raise web.HTTPUnauthorized(
238+
reason=f"Invalid domain: Signed: '{signed_operation.content.domain}' != Request: '{settings.DOMAIN_NAME}'"
239+
)
238240
if signed_operation.content.path != request.path:
239241
logger.debug(f"Invalid path '{signed_operation.content.path}' != '{request.path}'")
240-
raise web.HTTPUnauthorized(reason="Invalid path")
242+
raise web.HTTPUnauthorized(
243+
reason=f"Invalid path. Signed: '{signed_operation.content.path}' != requested path: '{request.path}'"
244+
)
241245
if signed_operation.content.method != request.method:
242246
logger.debug(f"Invalid method '{signed_operation.content.method}' != '{request.method}'")
243-
raise web.HTTPUnauthorized(reason="Invalid method")
247+
raise web.HTTPUnauthorized(
248+
reason=f"Invalid method. Signed: '{signed_operation.content.method}' != request:'{request.method}"
249+
)
244250
return verify_signed_operation(signed_operation, signed_pubkey)
245251

246252

tests/supervisor/test_authentication.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ async def view(request, authenticated_sender):
194194
assert resp.status == 401, await resp.text()
195195

196196
r = await resp.json()
197-
assert {"error": "Invalid domain"} == r
197+
assert {"error": "Invalid domain: Signed: 'baddomain' != Request: 'localhost'"} == r
198198

199199

200200
@pytest.mark.asyncio

0 commit comments

Comments
 (0)