nativeauthenticator
nativeauthenticator copied to clipboard
How to initialize UNIX system users - is there a LocalNativeAuthenticator?
Hi,
Maybe there are some elements I don't understand...
-
I had to signup with my already existing admin user to be able to login.
-
When I create a user with the admin panel, I have an error 500 because the nativeauthenticator.NativeAuthenticator does not allow to pass an option like : c.LocalAuthenticator.create_system_users = True /home/{new_user} is not created.
Am I missing someting ? Thanks in advance :)
Hi @odovad sorry for the delay. I don't think we have create_system_users
as an option on NativeAuth. Users must necessarily signup otherwise the system will not know them
Initializing users is not behind any authentication, to create them I used a small script, maybe it is useful to someone else.
import requests
creds = [('user', 'good_password123')]
for cred in creds:
requests.post('https://jupyterhub.mydomain.com/hub/signup', data={'username':cred[0], 'pw': cred[1]})
I have same issue.Since nativeauthenticator doesn't inherit LocalAuthenticator
,we can't set c.LocalAuthenticator.create_system_users = True
I solve it by setting config c.Spawner.pre_spawn_hook
,so that everytime before jupyterhub spawns server,it will execute some python code.
for example
from subprocess import check_call
def create_system_user(spawner):
username = spawner.user.name
check_call(['bash', '/srv/jupyterhub/adduser.sh', username])
c.Spawner.pre_spawn_hook = create_system_user
adduser.sh code
adduser -q --gecos '""' --home /home/$1 --disabled-password $1 || "True"
It will create system user if user not exists, otherwise return do nothing
Running jupyterhub inside docker with c.JupyterHub.spawner_class = 'jupyterhub.spawner.LocalProcessSpawner'
, what worked for me was (based on the answer above by @user919lx ):
def create_system_user(spawner):
"""Hook to create system user before spawning notebook. Required since NativeAuthenticator does not create users."""
username = spawner.user.name
check_call(['useradd', username, "-m"])
c.Spawner.pre_spawn_hook = create_system_user