nativeauthenticator icon indicating copy to clipboard operation
nativeauthenticator copied to clipboard

How to initialize UNIX system users - is there a LocalNativeAuthenticator?

Open odovad opened this issue 5 years ago • 4 comments

Hi,

Maybe there are some elements I don't understand...

  1. I had to signup with my already existing admin user to be able to login.

  2. 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 :)

odovad avatar May 06 '19 16:05 odovad

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

leportella avatar Aug 08 '19 21:08 leportella

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]})

chicocvenancio avatar Aug 08 '19 22:08 chicocvenancio

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

user919lx avatar Sep 09 '19 03:09 user919lx

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

Caiofcas avatar Mar 31 '23 19:03 Caiofcas