diff --git a/jupyterhub/tests/test_spawner.py b/jupyterhub/tests/test_spawner.py index 8245a0a8..c4da2f06 100644 --- a/jupyterhub/tests/test_spawner.py +++ b/jupyterhub/tests/test_spawner.py @@ -374,13 +374,13 @@ async def test_spawner_bad_api_token(app): (["self"], [], ["access:servers!server=USER/", "users:activity!user"]), ( ["self"], - ["admin:groups", "users:activity!server"], - ["users:activity!server=USER/"], + ["admin:groups", "read:servers!server"], + ["users:activity!user", "read:servers!server=USER/"], ), ( - ["self", "read:groups!group=x"], - ["admin:groups", "users:activity!user"], - ["read:groups!group=x", "read:groups:name!group=x", "users:activity!user"], + ["self", "read:groups!group=x", "users:activity"], + ["admin:groups", "users:activity"], + ["read:groups!group=x", "read:groups:name!group=x", "users:activity"], ), ], ) diff --git a/jupyterhub/user.py b/jupyterhub/user.py index 1ff81ddb..11eb9110 100644 --- a/jupyterhub/user.py +++ b/jupyterhub/user.py @@ -693,6 +693,16 @@ class User: scope + server_filter if scope.endswith("!server") else scope for scope in requested_scopes } + # ensure activity scope is requested, since activity doesn't work without + activity_scope = "users:activity!user" + if not {activity_scope, "users:activity", "inherit"}.intersection( + requested_scopes + ): + self.log.warning( + f"Adding required scope {activity_scope} to server token, missing from Spawner.server_token_scopes. Please make sure to add it!" + ) + requested_scopes |= {activity_scope} + have_scopes = roles.roles_to_scopes(roles.get_roles_for(self.orm_user)) have_scopes |= {"inherit"} jupyterhub_client = (