mirror of
https://github.com/jupyterhub/jupyterhub.git
synced 2025-10-15 05:53:00 +00:00
move admin_users from JupyterHub to Authenticator
This commit is contained in:
@@ -191,7 +191,7 @@ Admin users of JupyterHub have the ability to take actions on users' behalf, suc
|
|||||||
restarting their servers, and adding and removing new users from the whitelist. Any users in the admin list are automatically added to the whitelist, if they are not already present. The set of initial Admin users can configured as follows:
|
restarting their servers, and adding and removing new users from the whitelist. Any users in the admin list are automatically added to the whitelist, if they are not already present. The set of initial Admin users can configured as follows:
|
||||||
|
|
||||||
```python
|
```python
|
||||||
c.JupyterHub.admin_users = {'mal', 'zoe'}
|
c.Authenticator.admin_users = {'mal', 'zoe'}
|
||||||
```
|
```
|
||||||
|
|
||||||
If `JupyterHub.admin_access` is True (not default), then admin users have permission to log in *as other
|
If `JupyterHub.admin_access` is True (not default), then admin users have permission to log in *as other
|
||||||
@@ -314,7 +314,7 @@ c.LocalAuthenticator.create_system_users = True
|
|||||||
|
|
||||||
# specify users and admin
|
# specify users and admin
|
||||||
c.Authenticator.whitelist = {'rgbkrk', 'minrk', 'jhamrick'}
|
c.Authenticator.whitelist = {'rgbkrk', 'minrk', 'jhamrick'}
|
||||||
c.JupyterHub.admin_users = {'jhamrick', 'rgbkrk'}
|
c.Authenticator.admin_users = {'jhamrick', 'rgbkrk'}
|
||||||
|
|
||||||
# start single-user notebook servers in ~/assignments,
|
# start single-user notebook servers in ~/assignments,
|
||||||
# with ~/assignments/Welcome.ipynb as the default landing page
|
# with ~/assignments/Welcome.ipynb as the default landing page
|
||||||
|
@@ -351,11 +351,9 @@ class JupyterHub(Application):
|
|||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
admin_users = Set(config=True,
|
admin_users = Set(config=True,
|
||||||
help="""set of usernames of admin users
|
help="""DEPRECATED, use Authenticator.admin_users instead."""
|
||||||
|
|
||||||
If unspecified, only the user that launches the server will be admin.
|
|
||||||
"""
|
|
||||||
)
|
)
|
||||||
|
|
||||||
tornado_settings = Dict(config=True)
|
tornado_settings = Dict(config=True)
|
||||||
|
|
||||||
cleanup_servers = Bool(True, config=True,
|
cleanup_servers = Bool(True, config=True,
|
||||||
@@ -580,16 +578,24 @@ class JupyterHub(Application):
|
|||||||
def init_users(self):
|
def init_users(self):
|
||||||
"""Load users into and from the database"""
|
"""Load users into and from the database"""
|
||||||
db = self.db
|
db = self.db
|
||||||
|
|
||||||
if not self.admin_users:
|
if self.admin_users and not self.authenticator.admin_users:
|
||||||
|
self.log.warn(
|
||||||
|
"\nJupyterHub.admin_users is deprecated."
|
||||||
|
"\nUse Authenticator.admin_users instead."
|
||||||
|
)
|
||||||
|
self.authenticator.admin_users = self.admin_users
|
||||||
|
admin_users = self.authenticator.admin_users
|
||||||
|
|
||||||
|
if not admin_users:
|
||||||
# add current user as admin if there aren't any others
|
# add current user as admin if there aren't any others
|
||||||
admins = db.query(orm.User).filter(orm.User.admin==True)
|
admins = db.query(orm.User).filter(orm.User.admin==True)
|
||||||
if admins.first() is None:
|
if admins.first() is None:
|
||||||
self.admin_users.add(getuser())
|
admin_users.add(getuser())
|
||||||
|
|
||||||
new_users = []
|
new_users = []
|
||||||
|
|
||||||
for name in self.admin_users:
|
for name in admin_users:
|
||||||
# ensure anyone specified as admin in config is admin in db
|
# ensure anyone specified as admin in config is admin in db
|
||||||
user = orm.User.find(db, name)
|
user = orm.User.find(db, name)
|
||||||
if user is None:
|
if user is None:
|
||||||
@@ -810,7 +816,7 @@ class JupyterHub(Application):
|
|||||||
db=self.db,
|
db=self.db,
|
||||||
proxy=self.proxy,
|
proxy=self.proxy,
|
||||||
hub=self.hub,
|
hub=self.hub,
|
||||||
admin_users=self.admin_users,
|
admin_users=self.authenticator.admin_users,
|
||||||
admin_access=self.admin_access,
|
admin_access=self.admin_access,
|
||||||
authenticator=self.authenticator,
|
authenticator=self.authenticator,
|
||||||
spawner_class=self.spawner_class,
|
spawner_class=self.spawner_class,
|
||||||
|
@@ -23,6 +23,12 @@ class Authenticator(LoggingConfigurable):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
db = Any()
|
db = Any()
|
||||||
|
admin_users = Set(config=True,
|
||||||
|
help="""set of usernames of admin users
|
||||||
|
|
||||||
|
If unspecified, only the user that launches the server will be admin.
|
||||||
|
"""
|
||||||
|
)
|
||||||
whitelist = Set(config=True,
|
whitelist = Set(config=True,
|
||||||
help="""Username whitelist.
|
help="""Username whitelist.
|
||||||
|
|
||||||
|
@@ -72,6 +72,9 @@ class NeverSpawner(MockSpawner):
|
|||||||
|
|
||||||
|
|
||||||
class MockPAMAuthenticator(PAMAuthenticator):
|
class MockPAMAuthenticator(PAMAuthenticator):
|
||||||
|
def _admin_users_default(self):
|
||||||
|
return {'admin'}
|
||||||
|
|
||||||
def system_user_exists(self, user):
|
def system_user_exists(self, user):
|
||||||
# skip the add-system-user bit
|
# skip the add-system-user bit
|
||||||
return not user.name.startswith('dne')
|
return not user.name.startswith('dne')
|
||||||
@@ -94,9 +97,6 @@ class MockHub(JupyterHub):
|
|||||||
def _spawner_class_default(self):
|
def _spawner_class_default(self):
|
||||||
return MockSpawner
|
return MockSpawner
|
||||||
|
|
||||||
def _admin_users_default(self):
|
|
||||||
return {'admin'}
|
|
||||||
|
|
||||||
def init_signal(self):
|
def init_signal(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user