Skip to content

Fix /api/me permissions in fps-auth-jupyterhub - #670

Merged
davidbrochart merged 2 commits into
jupyter-server:mainfrom
Thanatos9404:auth-jupyterhub-api-me-permissions
Oct 16, 2026
Merged

davidbrochart merged 2 commits into
jupyter-server:mainfrom
Thanatos9404:auth-jupyterhub-api-me-permissions

Conversation

@Thanatos9404

Copy link
Copy Markdown
Contributor

Fixes #657

GET /api/me?permissions=... in fps-auth-jupyterhub intersected the requested actions with a dict created empty on the line before, so every requested resource came back with an empty list, whatever the user could actually do.

The issue suggests reading them from user.permissions, but nothing fills that column for JupyterHub users, and by default the Hub has nothing to fill it with: it grants access to a single-user server as a whole, through the access scope. So this follows what the rest of the plugin, and jupyterhub-singleuser for jupyter_server, already do:

  • current_user(permissions) only checks the access scope and ignores permissions, and websocket_auth(permissions) returns the requested permissions unchanged.
  • In jupyterhub-singleuser, JupyterHubAuthorizer.is_authorized ignores the action and the resource and only checks the access scopes. So with the default JupyterHubAuthorizer, jupyter_server's /api/me returns every requested action to a user who got in.

/api/me now reports every requested action as allowed, which matches what the server lets the user do. Without permissions (or with permissions=null) it still returns {}, and a user without the access scope still gets a 403.

If you'd rather have real per-user permissions, the alternative is to read them in the OAuth callback from JupyterHub custom scopes (for example custom:jupyter_server:<action>:<resource>, as in JupyterHub's examples/read-only), store them in user.permissions, and check them in current_user() and websocket_auth() the way fps_auth's user mode does. Happy to switch this PR to that, or do it as a follow-up.

Tests

There were no tests for this plugin, so this adds plugins/auth_jupyterhub/tests/test_auth_jupyterhub.py. It mocks HubOAuth.token_for_code and HubOAuth.user_for_token, starts from the 307 redirect to the Hub (keeping the state cookie), calls /oauth_callback with a code as the Hub would, and then calls /api/me:

  • test_api_me_permissions: a user with the access scope asks for {"contents": ["read", "write"], "kernels": ["execute"]} and gets it back. On main this fails with {'contents': [], 'kernels': []}.
  • test_api_me_no_permissions: without permissions, and with permissions=null, the response has "permissions": {}.
  • test_api_me_requires_access_scope: a user without the access scope gets a 403. It passes before and after, and shows the change doesn't widen access.

Run locally on Windows 11 with every package installed in editable mode, as in the README:

  • pytest -v --timeout=60 (Python 3.13): 177 passed.
  • pytest plugins/auth_jupyterhub/tests on Python 3.10 and 3.14: 4 passed each.
  • mypy ./api ./plugins, ruff check and ruff format --check on src api notebooks plugins tests, and pre-commit run --files on the changed files: clean.

Thanatos9404 and others added 2 commits October 16, 2026 11:30
GET /api/me?permissions=... intersected the requested actions with a
dict created empty on the line before, so every requested resource came
back with no allowed actions, whatever the user could actually do.

By default JupyterHub grants access to a single-user server as a whole,
through the access scope. current_user(permissions) only checks the
access scope and ignores permissions, and websocket_auth(permissions)
returns the requested permissions unchanged. jupyterhub-singleuser does
the same for jupyter_server: JupyterHubAuthorizer allows every action
once the access scope check passes. So /api/me now reports every
requested action as allowed, which matches what the plugin enforces.

Add tests for the plugin, with the Hub's OAuth calls mocked.

Fixes jupyter-server#657
@davidbrochart

Copy link
Copy Markdown
Collaborator

Thanks @Thanatos9404, I've added a test in Thanatos9404#1. What do you think?

@Thanatos9404

Copy link
Copy Markdown
Contributor Author

Thanks @davidbrochart, that's a good case to cover: a token whose access scope is for another user's server still gets a 403. I ran the auth_jupyterhub tests with it (5 passed, ruff clean) and moved this branch to your commit, so it's part of this PR now.

@davidbrochart davidbrochart left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Thanatos9404.

@davidbrochart
davidbrochart merged commit 86bf2e0 into jupyter-server:main Oct 16, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

auth_jupyterhub: get_api_me never sees the user's permissions

2 participants