You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Dask Gateway's JupyterHub authentication is able to authenticate a JupyterHub user, but not a JupyterHub service
What you expected to happen:
Dask Gateway being able to authenticate a JupyterHub service
Minimal Complete Verifiable Example:
The easiest way to create a minimum verifiable example for this was to replicate one of the tests, if you paste the following code in this file, you'll see the test fails:
@pytest.mark.skipif(nothub_mocking, reason="JupyterHub not installed")@pytest.mark.asyncioasyncdeftest_jupyterhub_auth_service(monkeypatch):
fromjupyterhub.tests.utilsimportadd_userjhub_api_token=uuid.uuid4().hexjhub_service_token=uuid.uuid4().hexjhub_bind_url="http://127.0.0.1:%i/@/space%%20word/"%random_port()
hub_config=Config()
hub_config.JupyterHub.services= [
{"name": "dask-gateway", "api_token": jhub_api_token},
{"name": "any-service", "api_token": jhub_service_token}
]
hub_config.JupyterHub.bind_url=jhub_bind_urlclassMockHub(hub_mocking.MockHub):
definit_logging(self):
passhub=MockHub(config=hub_config)
# Configure gatewayconfig=Config()
config.DaskGateway.authenticator_class= (
"dask_gateway_server.auth.JupyterHubAuthenticator"
)
config.JupyterHubAuthenticator.jupyterhub_api_token=jhub_api_tokenconfig.JupyterHubAuthenticator.jupyterhub_api_url=jhub_bind_url+"api/"asyncwithtemp_gateway(config=config) asg:
asyncwithtemp_hub(hub):
# Create a new jupyterhub user alice, and get the api tokenu=add_user(hub.db, name="alice")
api_token=u.new_api_token()
hub.db.commit()
# Configure auth with incorrect api tokenauth=JupyterHubAuth(api_token=api_token)
asyncwithg.gateway_client(auth=auth) asgateway:
# Auth succeeds with user tokengateway.list_clusters()
# Auth doesn't works with service tokenauth.api_token=jhub_api_tokenawaitgateway.list_clusters()
Command to run the test
Command to run this test, after pasting it in the file mentioned above (after the development environment is set):
py.test -s -k 'test_jupyterhub_auth_service'
Error:
Error Log
version.BuildInfo{Version:"v3.2.1", GitCommit:"fe51cd1e31e6a202cba7dead9552a6d418ded79a", GitTreeState:"clean", GoVersion:"go1.13.10"}
=============================testsessionstarts==============================platformdarwin--Python3.8.10, pytest-6.2.4, py-1.10.0, pluggy-0.13.1rootdir: /Users/aktech/quansight/dask-gatewayplugins: asyncio-0.12.0collected116items/115deselected/5skippedtests/test_auth.py12:42:37.663 [ConfigProxy] �[32minfo�[39m: Proxyinghttp://127.0.0.1:50033to (nodefault)
12:42:37.666 [ConfigProxy] �[32minfo�[39m: ProxyAPIathttp://127.0.0.1:8001/api/routes12:42:37.838 [ConfigProxy] �[32minfo�[39m: 200GET/api/routes12:42:37.840 [ConfigProxy] �[32minfo�[39m: 200GET/api/routes12:42:37.842 [ConfigProxy] �[32minfo�[39m: Addingroute/@/spaceword->http://127.0.0.1:808112:42:37.843 [ConfigProxy] �[32minfo�[39m: Routeadded/@/spaceword->http://127.0.0.1:808112:42:37.843 [ConfigProxy] �[32minfo�[39m: 201POST/api/routes/@/space%20word12:42:37.905 [ConfigProxy] �[33mwarn�[39m: TerminatedF===================================FAILURES===================================_________________________test_jupyterhub_auth_service_________________________monkeypatch=<_pytest.monkeypatch.MonkeyPatchobjectat0x7fea34547730>
@pytest.mark.skipif(nothub_mocking, reason="JupyterHub not installed")
@pytest.mark.asyncioasyncdeftest_jupyterhub_auth_service(monkeypatch):
fromjupyterhub.tests.utilsimportadd_userjhub_api_token=uuid.uuid4().hexjhub_service_token=uuid.uuid4().hexjhub_bind_url="http://127.0.0.1:%i/@/space%%20word/"%random_port()
hub_config=Config()
hub_config.JupyterHub.services= [
{"name": "dask-gateway", "api_token": jhub_api_token},
{"name": "any-service", "api_token": jhub_service_token}
]
hub_config.JupyterHub.bind_url=jhub_bind_urlclassMockHub(hub_mocking.MockHub):
definit_logging(self):
passhub=MockHub(config=hub_config)
# Configure gatewayconfig=Config()
config.DaskGateway.authenticator_class= (
"dask_gateway_server.auth.JupyterHubAuthenticator"
)
config.JupyterHubAuthenticator.jupyterhub_api_token=jhub_api_tokenconfig.JupyterHubAuthenticator.jupyterhub_api_url=jhub_bind_url+"api/"asyncwithtemp_gateway(config=config) asg:
asyncwithtemp_hub(hub):
# Create a new jupyterhub user alice, and get the api tokenu=add_user(hub.db, name="alice")
api_token=u.new_api_token()
hub.db.commit()
# Configure auth with incorrect api tokenauth=JupyterHubAuth(api_token=api_token)
asyncwithg.gateway_client(auth=auth) asgateway:
# Auth succeeds with user tokengateway.list_clusters()
# Auth doesn't works with service tokenauth.api_token=jhub_api_token>awaitgateway.list_clusters()
tests/test_auth.py:211:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
dask-gateway/dask_gateway/client.py:434: in_clustersresp=awaitself._request("GET", url)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self=Gateway<http://127.0.0.1:50035>, method='GET'url='http://127.0.0.1:50035/api/v1/clusters/', json=Noneasyncdef_request(self, method, url, json=None):
ifself._sessionisNone:
# "unsafe" allows cookies to be set for ip addresses, which can# commonly serve dask-gateway deployments. Since this client is# only ever used with a single endpoint, there is no danger of# leaking cookies to a different server that happens to have the# same ip.self._session=aiohttp.ClientSession(
cookie_jar=aiohttp.CookieJar(unsafe=True)
)
session=self._sessionresp=awaitsession.request(method, url, json=json, **self._request_kwargs)
ifresp.status==401:
headers, context=self.auth.pre_request(resp)
resp=awaitsession.request(
method, url, json=json, headers=headers, **self._request_kwargs
)
self.auth.post_response(resp, context)
ifresp.status>=400:
try:
msg=awaitresp.json()
msg=msg["error"]
exceptException:
msg=awaitresp.text()
ifresp.statusin {404, 422}:
raiseValueError(msg)
elifresp.status==409:
raiseGatewayClusterError(msg)
elifresp.status==500:
>raiseGatewayServerError(msg)
Edask_gateway.client.GatewayServerError: 500InternalServerErrorEEServergotitselfintroubledask-gateway/dask_gateway/client.py:417: GatewayServerError===============================warningssummary===============================dask-gateway/dask_gateway/client.py:21/Users/aktech/quansight/dask-gateway/dask-gateway/dask_gateway/client.py:21: FutureWarning: format_bytesisdeprecatedandwillberemovedinafuturerelease. Pleaseusedask.utils.format_bytesinstead.
fromdistributed.utilsimportLoopRunner, format_bytestests/test_auth.py::test_jupyterhub_auth_service/Users/aktech/quansight/dask-gateway/tests/test_auth.py:207: RuntimeWarning: coroutine'Gateway._clusters'wasneverawaitedgateway.list_clusters()
--Docs: https://docs.pytest.org/en/stable/warnings.html===========================shorttestsummaryinfo============================FAILEDtests/test_auth.py::test_jupyterhub_auth_service-dask_gateway.client...
===========1failed, 5skipped, 115deselected, 2warningsin3.53s===========
Actual Error (missing groups key):
JupyterHub service doesn't have a groups attribute.
What happened:
Dask Gateway's JupyterHub authentication is able to authenticate a JupyterHub user, but not a JupyterHub service
What you expected to happen:
Dask Gateway being able to authenticate a JupyterHub service
Minimal Complete Verifiable Example:
The easiest way to create a minimum verifiable example for this was to replicate one of the tests, if you paste the following code in this file, you'll see the test fails:
Paste here:
dask-gateway/tests/test_auth.py
dask-gateway/tests/test_auth.py
Line 119 in 46cfcbf
Command to run the test
Command to run this test, after pasting it in the file mentioned above (after the development environment is set):
Error:
Error Log
Actual Error (missing groups key):
groups
attribute.Anything else we need to know?:
Environment:
The text was updated successfully, but these errors were encountered: