Skip to content

JUPYTERHUB_OAUTH_SCOPES and JUPYTERHUB_OAUTH_ACCESS_SCOPES not correctly set with openpbs #300

@danmons

Description

@danmons

Echoing out the JUPYTERHUB_OAUTH_SCOPES and JUPYTERHUB_OAUTH_SCOPES environment variables from JupyterHub jobs created by batchspawner, these values appear incorrect.

The current solution I'm using is noted in this issue:
jupyterhub/jupyterhub#3866

I have the following in my batch_script section just before running the jupyterhub-singleuser component:

echo JUPYTERHUB_OAUTH_SCOPES "$JUPYTERHUB_OAUTH_SCOPES"
echo JUPYTERHUB_OAUTH_ACCESS_SCOPES "$JUPYTERHUB_OAUTH_ACCESS_SCOPES"

export JUPYTERHUB_OAUTH_SCOPES='["access:servers!server={username}/", "access:servers!user={username}"]'
export JUPYTERHUB_OAUTH_ACCESS_SCOPES='["access:servers!server={username}/", "access:servers!user={username}"]'

echo JUPYTERHUB_OAUTH_SCOPES "$JUPYTERHUB_OAUTH_SCOPES"
echo JUPYTERHUB_OAUTH_ACCESS_SCOPES "$JUPYTERHUB_OAUTH_ACCESS_SCOPES"

And it produces:

JUPYTERHUB_OAUTH_SCOPES [\access:servers!server=monsd/\, \access:servers!user=monsd\]
JUPYTERHUB_OAUTH_ACCESS_SCOPES [\access:servers!server=monsd/\, \access:servers!user=monsd\]

JUPYTERHUB_OAUTH_SCOPES ["access:servers!server=monsd/", "access:servers!user=monsd"]
JUPYTERHUB_OAUTH_ACCESS_SCOPES ["access:servers!server=monsd/", "access:servers!user=monsd"]

The top two lines are the default set by batchspawner, which then cause the resulting jupyterhub-singleuser instances to fail authentication. The bottom two are after I override them, and allow the instances to pass authentication and work.

Local instances of jupyterhub-singleuser, jupyter-server or JupyterLab all work fine. The problem only exists with batchspawner creating the jobs.

I'm using ProfileSpawner to build various launch profiles, and within that PBSSpawner via batchspawner.

jupyterhub_config.py snippet:

import batchspawner
c.JupyterHub.spawner_class = 'wrapspawner.ProfilesSpawner'
c.ProfilesSpawner.profiles = [
( 'Singularity /export/home/{username}/singularity/jupyterhub.sif', 'singularity_home_jupyter_cpu', 'batchspawner.PBSSpawner', dict(req_queue = 'workq', req_nprocs = '8', req_memory = '8gb', req_runtime = '1:00:00', batch_script = '''#!/bin/bash
#PBS -l walltime={runtime}
#PBS -l nodes=1:ppn={nprocs}
#PBS -l mem={memory}
#PBS -N jupyterhub
#PBS -v {keepvars}

echo JUPYTERHUB_OAUTH_SCOPES "$JUPYTERHUB_OAUTH_SCOPES"
echo JUPYTERHUB_OAUTH_ACCESS_SCOPES "$JUPYTERHUB_OAUTH_ACCESS_SCOPES"

export JUPYTERHUB_OAUTH_SCOPES='["access:servers!server={username}/", "access:servers!user={username}"]'
export JUPYTERHUB_OAUTH_ACCESS_SCOPES='["access:servers!server={username}/", "access:servers!user={username}"]'

echo JUPYTERHUB_OAUTH_SCOPES "$JUPYTERHUB_OAUTH_SCOPES"
echo JUPYTERHUB_OAUTH_ACCESS_SCOPES "$JUPYTERHUB_OAUTH_ACCESS_SCOPES"

singularity exec --bind /scratch /export/home/{username}/singularity/jupyterhub.sif {cmd}

''')),

Tested under both Python 3.10 and 3.12 with the following (batchspawner installed from main today).

batchspawner              1.3.0.dev0
jupyter_client            8.6.0
jupyter_core              5.7.1
jupyter-events            0.9.0
jupyter-lsp               2.2.3
jupyter_server            2.13.0
jupyter_server_terminals  0.5.2
jupyter-telemetry         0.1.0
jupyterhub                4.0.2
jupyterlab                4.1.2
jupyterlab_pygments       0.3.0
jupyterlab_server         2.25.3
tornado                   6.4
traitlets                 5.14.1
wrapspawner               1.0.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions