diff --git a/llama_stack/distribution/server/auth.py b/llama_stack/distribution/server/auth.py index 12e342c92..52e6a013c 100644 --- a/llama_stack/distribution/server/auth.py +++ b/llama_stack/distribution/server/auth.py @@ -172,8 +172,10 @@ class AuthenticationMiddleware: if auth_response.access_attributes: user_attributes = auth_response.access_attributes.model_dump(exclude_none=True) else: - logger.warning("Authentication response did not contain any attributes") - user_attributes = {} + logger.warning("No access attributes, setting namespace to api_key by default") + user_attributes = { + "namespaces": [api_key], + } scope["user_attributes"] = user_attributes logger.debug(f"Authentication successful: {len(user_attributes)} attributes") diff --git a/tests/unit/server/test_auth.py b/tests/unit/server/test_auth.py index b078448a2..5e93719d2 100644 --- a/tests/unit/server/test_auth.py +++ b/tests/unit/server/test_auth.py @@ -201,4 +201,6 @@ async def test_auth_middleware_no_attributes(mock_middleware, mock_scope): await middleware(mock_scope, mock_receive, mock_send) assert "user_attributes" in mock_scope - assert mock_scope["user_attributes"] == {} + attributes = mock_scope["user_attributes"] + assert "namespaces" in attributes + assert attributes["namespaces"] == ["test-api-key"]