From d5c81c10d00079f4aa099662d3a86247ea23b7f6 Mon Sep 17 00:00:00 2001 From: Dawa Ometto Date: Mon, 1 Dec 2025 16:53:22 +0100 Subject: [PATCH 1/5] role jupyterhub: use unix socket by default --- playbooks/roles/jupyterhub/defaults/main.yml | 1 + playbooks/roles/jupyterhub/templates/jupyterhub_config.py.j2 | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/playbooks/roles/jupyterhub/defaults/main.yml b/playbooks/roles/jupyterhub/defaults/main.yml index 5632bc23..26b211b8 100644 --- a/playbooks/roles/jupyterhub/defaults/main.yml +++ b/playbooks/roles/jupyterhub/defaults/main.yml @@ -14,6 +14,7 @@ jupyterhub_http_password: "" jupyterhub_create_default_group: true jupyterhub_remote_user_header: REMOTE_USER jupyterhub_activate_remote_user_auth: false +jupyterhub_enable_unix_socket: true jupyterhub_config_env_keep: - JUPYTERHUB_ACTIVITY_URL - JUPYTERHUB_SERVER_NAME diff --git a/playbooks/roles/jupyterhub/templates/jupyterhub_config.py.j2 b/playbooks/roles/jupyterhub/templates/jupyterhub_config.py.j2 index cc4b79c1..af2fbe31 100644 --- a/playbooks/roles/jupyterhub/templates/jupyterhub_config.py.j2 +++ b/playbooks/roles/jupyterhub/templates/jupyterhub_config.py.j2 @@ -51,9 +51,12 @@ c.Spawner.args = [ c.Spawner.env_keep = {{ jupyterhub_config_env_keep | string }} # Server config - +{% if jupyterhub_enable_unix_socket %} +c.JupyterHub.hub_bind_url = "unix+http://{{ jupyterhub_user_home | replace("") }}%2Fjupyterhub.sock" +{% else %} c.JupyterHub.ip = "{{ jupyterhub_bind_addr }}" c.JypyterHub.port = {{ jupyterhub_port | int }} +{% endif %} c.JupyterHub.base_url = "{{ jupyterhub_uri }}" # Configure paths for essential server files From 4d488a12b861fc75e3af450e9d5a595c3bd8c54a Mon Sep 17 00:00:00 2001 From: Dawa Ometto Date: Mon, 1 Dec 2025 17:07:59 +0100 Subject: [PATCH 2/5] Fix URL replacement in JupyterHub config template --- playbooks/roles/jupyterhub/templates/jupyterhub_config.py.j2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/playbooks/roles/jupyterhub/templates/jupyterhub_config.py.j2 b/playbooks/roles/jupyterhub/templates/jupyterhub_config.py.j2 index af2fbe31..3c74d23c 100644 --- a/playbooks/roles/jupyterhub/templates/jupyterhub_config.py.j2 +++ b/playbooks/roles/jupyterhub/templates/jupyterhub_config.py.j2 @@ -52,7 +52,7 @@ c.Spawner.env_keep = {{ jupyterhub_config_env_keep | string }} # Server config {% if jupyterhub_enable_unix_socket %} -c.JupyterHub.hub_bind_url = "unix+http://{{ jupyterhub_user_home | replace("") }}%2Fjupyterhub.sock" +c.JupyterHub.hub_bind_url = "unix+http://{{ jupyterhub_user_home | replace("/", "%2F) }}%2Fjupyterhub.sock" {% else %} c.JupyterHub.ip = "{{ jupyterhub_bind_addr }}" c.JypyterHub.port = {{ jupyterhub_port | int }} From 53e79ed825535e68a960a9fec6f415b91bf961fb Mon Sep 17 00:00:00 2001 From: Dawa Ometto Date: Tue, 2 Dec 2025 08:26:39 +0100 Subject: [PATCH 3/5] Fix typo in JupyterHub configuration template --- playbooks/roles/jupyterhub/templates/jupyterhub_config.py.j2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/playbooks/roles/jupyterhub/templates/jupyterhub_config.py.j2 b/playbooks/roles/jupyterhub/templates/jupyterhub_config.py.j2 index 3c74d23c..4ead3afd 100644 --- a/playbooks/roles/jupyterhub/templates/jupyterhub_config.py.j2 +++ b/playbooks/roles/jupyterhub/templates/jupyterhub_config.py.j2 @@ -52,7 +52,7 @@ c.Spawner.env_keep = {{ jupyterhub_config_env_keep | string }} # Server config {% if jupyterhub_enable_unix_socket %} -c.JupyterHub.hub_bind_url = "unix+http://{{ jupyterhub_user_home | replace("/", "%2F) }}%2Fjupyterhub.sock" +c.JupyterHub.hub_bind_url = "unix+http://{{ jupyterhub_user_home | replace("/", "%2F") }}%2Fjupyterhub.sock" {% else %} c.JupyterHub.ip = "{{ jupyterhub_bind_addr }}" c.JypyterHub.port = {{ jupyterhub_port | int }} From 547c32d869dc67d82916a11c06b001365f41e480 Mon Sep 17 00:00:00 2001 From: Dawa Ometto Date: Tue, 2 Dec 2025 15:01:34 +0100 Subject: [PATCH 4/5] Fix unix socket mode, add debug mode --- .../jupyterhub/templates/jupyterhub_config.py.j2 | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/playbooks/roles/jupyterhub/templates/jupyterhub_config.py.j2 b/playbooks/roles/jupyterhub/templates/jupyterhub_config.py.j2 index 4ead3afd..af2522c3 100644 --- a/playbooks/roles/jupyterhub/templates/jupyterhub_config.py.j2 +++ b/playbooks/roles/jupyterhub/templates/jupyterhub_config.py.j2 @@ -38,6 +38,12 @@ c.AccessTokenAuthenticator.header_name = "{{ jupyterhub_remote_user_header }}" c.AccessTokenAuthenticator.logout_endpoint = "/logout" {% endif %} +{% if jupyterhub_debug %} +# Debug settings +c.JupyterHub.log_level = logging.DEBUG +c.ConfigurableHTTPProxy.debug = True +{% endif %} + # Spawner config c.JupyterHub.spawner_class = 'sudospawner.SudoSpawner' @@ -53,11 +59,16 @@ c.Spawner.env_keep = {{ jupyterhub_config_env_keep | string }} # Server config {% if jupyterhub_enable_unix_socket %} c.JupyterHub.hub_bind_url = "unix+http://{{ jupyterhub_user_home | replace("/", "%2F") }}%2Fjupyterhub.sock" +c.JupyterHub.hub_connect_url = c.JupyterHub.hub_bind_url +c.Spawner.environment.update({ + 'JUPYTERHUB_API_URL': "http://localhost:8000/hub/api", + 'JUPYTERHUB_ACTIVITY_URL': lambda spawner : f"http://localhost:8000/hub/api/users/{spawner.user.name}/activity" +}) {% else %} c.JupyterHub.ip = "{{ jupyterhub_bind_addr }}" c.JypyterHub.port = {{ jupyterhub_port | int }} -{% endif %} c.JupyterHub.base_url = "{{ jupyterhub_uri }}" +{% endif %} # Configure paths for essential server files c.JupyterHub.cookie_secret_file = "{{ jupyterhub_user_home }}/jupyterhub_cookie_secret" From 297d3cd19d3c21ca61aeba2e3af19006781d60d8 Mon Sep 17 00:00:00 2001 From: Dawa Ometto Date: Tue, 2 Dec 2025 15:01:51 +0100 Subject: [PATCH 5/5] role jupyterhub: activate debug in tests --- molecule/playbook-jupyterhub/molecule.yml | 1 + playbooks/roles/jupyterhub/defaults/main.yml | 1 + playbooks/roles/jupyterhub/molecule/default/converge.yml | 1 + 3 files changed, 3 insertions(+) diff --git a/molecule/playbook-jupyterhub/molecule.yml b/molecule/playbook-jupyterhub/molecule.yml index 200ee946..deaff12e 100644 --- a/molecule/playbook-jupyterhub/molecule.yml +++ b/molecule/playbook-jupyterhub/molecule.yml @@ -21,3 +21,4 @@ provisioner: jupyter_auth: noauth jupyter_activate_remote_user_auth: true # mock SRAM auth by enabling remote user auth in JupyterHub config, despite setting auth to noauth. jupyter_proxy_config: "{ proxy_set_header: { REMOTE_USER: '$$http_user'} }" + jupyterhub_debug: true diff --git a/playbooks/roles/jupyterhub/defaults/main.yml b/playbooks/roles/jupyterhub/defaults/main.yml index 26b211b8..2a9e4e47 100644 --- a/playbooks/roles/jupyterhub/defaults/main.yml +++ b/playbooks/roles/jupyterhub/defaults/main.yml @@ -28,3 +28,4 @@ jupyterhub_config_env_keep: - PATH - CONDA_ROOT - CONDA_DEFAULT_ENV +jupyterhub_debug: false diff --git a/playbooks/roles/jupyterhub/molecule/default/converge.yml b/playbooks/roles/jupyterhub/molecule/default/converge.yml index 76859df2..4be6d0e0 100644 --- a/playbooks/roles/jupyterhub/molecule/default/converge.yml +++ b/playbooks/roles/jupyterhub/molecule/default/converge.yml @@ -8,5 +8,6 @@ jupyterhub_proxy_config: proxy_set_header: REMOTE_USER: '$http_user' # allows us to set the 'user' header in tests to mock login + jupyterhub_debug: true roles: - role: jupyterhub