Repository navigation
Fix /api/me permissions in fps-auth-jupyterhub - #670
Merged
davidbrochart merged 2 commits intoOct 16, 2026
Merged
davidbrochart merged 2 commits into
davidbrochart merged 2 commits into
Conversation
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
Collaborator
|
Thanks @Thanatos9404, I've added a test in Thanatos9404#1. What do you think? |
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
approved these changes
Oct 16, 2026
davidbrochart
left a comment
Collaborator
There was a problem hiding this comment.
Thanks @Thanatos9404.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 ignorespermissions, andwebsocket_auth(permissions)returns the requested permissions unchanged.JupyterHubAuthorizer.is_authorizedignores the action and the resource and only checks the access scopes. So with the defaultJupyterHubAuthorizer, jupyter_server's/api/mereturns every requested action to a user who got in./api/menow reports every requested action as allowed, which matches what the server lets the user do. Withoutpermissions(or withpermissions=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'sexamples/read-only), store them inuser.permissions, and check them incurrent_user()andwebsocket_auth()the way fps_auth'susermode 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 mocksHubOAuth.token_for_codeandHubOAuth.user_for_token, starts from the 307 redirect to the Hub (keeping the state cookie), calls/oauth_callbackwith 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. Onmainthis fails with{'contents': [], 'kernels': []}.test_api_me_no_permissions: withoutpermissions, and withpermissions=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/testson Python 3.10 and 3.14: 4 passed each.mypy ./api ./plugins,ruff checkandruff format --checkonsrc api notebooks plugins tests, andpre-commit run --fileson the changed files: clean.