PAMauthenticator with dummy Users and Passwords

I want to use a PAMauthenticator to define user names and dummy passwords for a Python lecture. I did this in jupyterhub_config.py as follows:

from jupyterhub.auth import PAMAuthenticator
from jupyterhub.spawner import SimpleLocalProcessSpawner

c.JupyterHub.authenticator_class  = PAMAuthenticator
c.PAMAuthenticator.open_sessions  = False

c.JupyterHub.spawner_class = SimpleLocalProcessSpawner

c.Authenticator.whitelist = {'user01','user02'}

c.PAMAuthenticator.dummy_passwords = {'user01': 'passwordUser01','user02': 'passwordUser02'}

Login is nevertheless not possible. What is wrong here.

I tried now this one but now I get spawn error:

c.JupyterHub.authenticator_class = 'firstuseauthenticator.FirstUseAuthenticator'

# from jupyterhub.auth import PAMAuthenticator
from jupyterhub.spawner import SimpleLocalProcessSpawner

# Use SimpleLocalProcessSpawner for simplicity (no containerization)
c.JupyterHub.spawner_class = SimpleLocalProcessSpawner

with error message:

[I 2023-08-23 12:08:18.981 JupyterHub spawner:1689] Spawning jupyterhub-singleuser
Traceback (most recent call last):
  File "/home/jupyteruser/.local/bin/jupyterhub-singleuser", line 5, in <module>
    from jupyterhub.singleuser import main
ModuleNotFoundError: No module named 'jupyterhub'

which is confusing since the message comes from jupyterhub.

Blockquote
Traceback (most recent call last):
File “/home/jupyteruser/.local/bin/jupyterhub-singleuser”, line 5, in
from jupyterhub.singleuser import main
ModuleNotFoundError: No module named ‘jupyterhub’

This is saying that jupyterhub is missing in your single user environments. You must have same version of jupyterhub in the single user environments and having just jupyterlab or notebook is not enough. Do a pip install --user jupyterhub as jupyteruser and it should work.

1 Like

It was installed.


jupyteruser@lin123:~/jupyter$ pip freeze | grep jupyter
jupyter-events==0.6.3
jupyter-lsp==2.2.0
jupyter-telemetry==0.1.0
jupyter_client==8.3.0
jupyter_core==5.3.1
jupyter_server==2.7.0
jupyter_server_terminals==0.4.4
jupyterhub==4.0.1
jupyterhub-firstuseauthenticator==1.0.0
jupyterlab==4.0.2
jupyterlab-pygments==0.1.2
jupyterlab_server==2.23.0

this is the full error message:

Traceback (most recent call last):
  File "/home/jupyteruser/.local/lib/python3.10/site-packages/jupyterhub/handlers/base.py", line 1076, in spawn_single_user
    await gen.with_timeout(
asyncio.exceptions.TimeoutError: Timeout

During handling of the above exception, another exception occurred:

[I 2023-08-23 14:25:14.473 JupyterHub log:191] 200 GET /hub/spawn-pending/XXX(di29394@172.31.89.46) 29.87ms
[I 2023-08-23 14:25:15.851 JupyterHub provider:659] Creating oauth client jupyterhub-user-XXX
[I 2023-08-23 14:25:15.877 JupyterHub spawner:1689] Spawning jupyterhub-singleuser
Traceback (most recent call last):
  File "/home/jupyteruser/.local/bin/jupyterhub-singleuser", line 5, in <module>
    from jupyterhub.singleuser import main
ModuleNotFoundError: No module named 'jupyterhub'
[I 2023-08-23 14:25:16.824 JupyterHub log:191] 302 GET /hub/spawn/XXX-> /hub/spawn-pending/di29394 (di29394@172.31.89.46) 1004.02ms
[I 2023-08-23 14:25:16.837 JupyterHub pages:398] XXX is pending spawn
[I 2023-08-23 14:25:16.841 JupyterHub log:191] 200 GET /hub/spawn-pending/di29394 (di29394@172.31.89.46) 6.98ms
Task exception was never retrieved
future: <Task finished name='Task-21' coro=<BaseHandler.spawn_single_user() done, defined at /home/jupyteruser/.local/lib/python3.10/site-packages/jupyterhub/handlers/base.py:869> exception=HTTPError()>
Traceback (most recent call last):
  File "/home/jupyteruser/.local/lib/python3.10/site-packages/jupyterhub/handlers/base.py", line 1076, in spawn_single_user
    await gen.with_timeout(
asyncio.exceptions.TimeoutError: Timeout

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/jupyteruser/.local/lib/python3.10/site-packages/jupyterhub/handlers/base.py", line 1110, in spawn_single_user
    raise web.HTTPError(
tornado.web.HTTPError: HTTP 500: Internal Server Error (Spawner failed to start [status=1]. The logs for XXX may contain details.)
[E 2023-08-23 14:25:36,888 configurable_http_proxy] 503 GET /hub/api/users/ XXX /server/progress Timeout during request
[I 2023-08-23 14:25:36.900 JupyterHub log:191] 200 GET /hub/error/503?url=/hub/api/users/di29394/server/progress (@127.0.0.1) 10.39ms
[E 2023-08-23 14:25:36,901 tornado.access] 503 GET /hub/api/users/di29394/server/progress?_xsrf=2%7C42ad9752%7C40209de1eb145a49e7e6a5af754b6eb3%7C1692785319 (172.31.89.46) 20018.38ms
[W 2023-08-23 14:25:44.923 JupyterHub user:933]  XXX 's server never showed up at http://127.0.0.1:60845/user/ XXX / after 30 seconds. Giving up.
    
    Common causes of this timeout, and debugging tips:
    
    1. The server didn't finish starting,
       or it crashed due to a configuration issue.
       Check the single-user server's logs for hints at what needs fixing.
    2. The server started, but is not accessible at the specified URL.
       This may be a configuration issue specific to your chosen Spawner.
       Check the single-user server logs and resource to make sure the URL
       is correct and accessible from the Hub.
    3. (unlikely) Everything is working, but the server took too long to respond.
       To fix: increase `Spawner.http_timeout` configuration
       to a number of seconds that is enough for servers to become responsive.
    
[E 2023-08-23 14:25:44.967 JupyterHub gen:630] Exception in Future <Task finished name='Task-22' coro=<BaseHandler.spawn_single_user.<locals>.finish_user_spawn() done, defined at /home/jupyteruser/.local/lib/python3.10/site-packages/jupyterhub/handlers/base.py:979> exception=TimeoutError("Server at http://127.0.0.1:60845/user/ XXX / didn't respond in 30 seconds")> after timeout
    Traceback (most recent call last):
      File "/home/jupyteruser/.local/lib/python3.10/site-packages/tornado/gen.py", line 625, in error_callback
        future.result()
      File "/home/jupyteruser/.local/lib/python3.10/site-packages/jupyterhub/handlers/base.py", line 986, in finish_user_spawn
        await spawn_future
      File "/home/jupyteruser/.local/lib/python3.10/site-packages/jupyterhub/user.py", line 914, in spawn
        await self._wait_up(spawner)
      File "/home/jupyteruser/.local/lib/python3.10/site-packages/jupyterhub/user.py", line 958, in _wait_up
        raise e
      File "/home/jupyteruser/.local/lib/python3.10/site-packages/jupyterhub/user.py", line 928, in _wait_up
        resp = await server.wait_up(
      File "/home/jupyteruser/.local/lib/python3.10/site-packages/jupyterhub/utils.py", line 289, in wait_for_http_server
        re = await exponential_backoff(
      File "/home/jupyteruser/.local/lib/python3.10/site-packages/jupyterhub/utils.py", line 237, in exponential_backoff
        raise asyncio.TimeoutError(fail_message)
    asyncio.exceptions.TimeoutError: Server at http://127.0.0.1:60845/user/ XXX / didn't respond in 30 seconds
    
[W 2023-08-23 14:25:44.969 JupyterHub users:666] Stream closed while handling /hub/api/users/ XXX /server/progress?_xsrf=2%7C42ad9752%7C40209de1eb145a49e7e6a5af754b6eb3%7C1692785319

Ok. solved it by installing the necessary files inside the environment of the users that are connecting and spawning. I have a batch file that executes this:

# copy pip.ini template
cp ../pip.conf /home/jupyterusers/jupyter/users/$USER_DIR

# Activate the virtual environment
source "$USER_DIR/bin/activate"

# Install required packages
pip3 install jupyterhub jupyter_core jupyter_server
# pip3 install numpy pandas cx_oracle scipy scikit-learn mysql-connector-python psycopg2

# Deactivate the virtual environment
deactivate