I have set up a jupyterhub Server with an LDAP Authentification. The Server and the authentication work fine. But my problem is, that I need to create the user I want to login with manually on the Server else he doesn't have a home and I get this error.
[I 2018-10-18 09:01:56.869 JupyterHub base:499] User logged in: t1
[I 2018-10-18 09:01:56.871 JupyterHub log:158] 302 POST /hub/login?next= -> /user/t1/ (t1@::ffff:192.168.3.47) 296.81ms
[I 2018-10-18 09:01:56.882 JupyterHub log:158] 302 GET /user/t1/ -> /hub/user/t1/ (@::ffff:192.168.3.47) 1.30ms
[E 2018-10-18 09:01:56.938 JupyterHub user:477] Unhandled error starting t1's server: 'getpwnam(): name not found: t1'
[E 2018-10-18 09:01:56.957 JupyterHub web:1670] Uncaught exception GET /hub/user/t1/ (::ffff:192.168.3.47)
HTTPServerRequest(protocol='http', host='192.168.3.41:8000', method='GET', uri='/hub/user/t1/', version='HTTP/1.1', remote_ip='::ffff:192.168.3.47')
Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/tornado/web.py", line 1592, in _execute
result = yield result
File "/usr/local/lib/python3.6/dist-packages/jupyterhub/handlers/base.py", line 1052, in get
await self.spawn_single_user(user)
File "/usr/local/lib/python3.6/dist-packages/jupyterhub/handlers/base.py", line 705, in spawn_single_user
timedelta(seconds=self.slow_spawn_timeout), finish_spawn_future
File "/usr/local/lib/python3.6/dist-packages/jupyterhub/handlers/base.py", line 626, in finish_user_spawn
await spawn_future
File "/usr/local/lib/python3.6/dist-packages/jupyterhub/user.py", line 489, in spawn
raise e
File "/usr/local/lib/python3.6/dist-packages/jupyterhub/user.py", line 409, in spawn
url = await gen.with_timeout(timedelta(seconds=spawner.start_timeout), f)
File "/usr/local/lib/python3.6/dist-packages/jupyterhub/spawner.py", line 1090, in start
env = self.get_env()
File "/usr/local/lib/python3.6/dist-packages/jupyterhub/spawner.py", line 1083, in get_env
env = self.user_env(env)
File "/usr/local/lib/python3.6/dist-packages/jupyterhub/spawner.py", line 1070, in user_env
home = pwd.getpwnam(self.user.name).pw_dir
KeyError: 'getpwnam(): name not found: t1'
[E 2018-10-18 09:01:56.973 JupyterHub log:150] {
"X-Forwarded-Host": "192.168.3.41:8000",
"X-Forwarded-Proto": "http",
"X-Forwarded-Port": "8000",
"X-Forwarded-For": "::ffff:192.168.3.47",
"Cookie": "jupyterhub-hub-login=\"2|1:0|10:1539846116|20:jupyterhub-hub-login|44:NTc5OTcxZmQyNGU4NDA5NTk2MDQ1ZDU2MTNjYmI0YWQ=|a8fc650edf529f207cbf9516a0d710abcce7f123599701e4733f463773828e59\"; _xsrf=2|483ee87a|5bb8426d0014f212a146a53135b9aba9|1538554955; jupyterhub-session-id=90e264b21f9b4993ba65735c9e390adb",
"Accept-Language": "de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7",
"Accept-Encoding": "gzip, deflate",
"Referer": "http://192.168.3.41:8000/hub/login",
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36",
"Upgrade-Insecure-Requests": "1",
"Cache-Control": "max-age=0",
"Connection": "close",
"Host": "192.168.3.41:8000"
}
[E 2018-10-18 09:01:56.975 JupyterHub log:158] 500 GET /hub/user/t1/ (t1@::ffff:192.168.3.47) 82.51ms
Is there a way to create the user and the home if the credentials are correct. Thanks
Edit: Now I updated the jupyterhub-ldap-authenticator to version 0.3.0. There the automated home directory creator is directly supported.
My current configuration of the LDAP Part in the jupyterhub_config.py file looks like this:
c.JupyterHub.authenticator_class = 'ldapauthenticator.LDAPAuthenticator'
c.LDAPAuthenticator.server_hosts = ['ldap://ldap.example.com:389']
c.LDAPAuthenticator.bind_user_dn = 'uid=binduser,cn=users,dc=ldap,dc=example,dc=com'
c.LDAPAuthenticator.bind_user_password = 'Password'
c.LDAPAuthenticator.user_search_base = 'cn=users,dc=ldap,dc=example,dc=com'
c.LDAPAuthenticator.user_search_filter = '(&(objectClass=posixAccount)(uid={username}))'
c.LDAPAuthenticator.username_pattern = '[a-zA-Z0-9_.][a-zA-Z0-9_.-]{0,252}[a-zA-Z0-9_.$-]?'
c.LDAPAuthenticator.create_user_home_dir = True
c.LDAPAuthenticator.create_user_home_dir_cmd = ['mkhomedir_helper']
But I have now the problem, that i get the following error.
500 : Internal Server Error
This is the output of the Log.
[I 2018-11-13 10:40:03.183 JupyterHub log:158] 302 GET /hub/ -> /hub/login (@::ffff:192.168.3.47) 1.19ms
[I 2018-11-13 10:40:03.245 JupyterHub log:158] 200 GET /hub/login (@::ffff:192.168.3.47) 47.94ms
[I 2018-11-13 10:40:11.116 JupyterHub ldapauthenticator:586] User 't1' sucessfully authenticated against ldap server ['ldap://ldap.example.com:389'].
[I 2018-11-13 10:40:11.128 JupyterHub ldapauthenticator:290] Creating 't1' user home directory using command 'mkhomedir_helper t1'
[E 2018-11-13 10:40:11.133 JupyterHub web:1670] Uncaught exception POST /hub/login?next= (::ffff:192.168.3.47)
HTTPServerRequest(protocol='http', host='192.168.3.49:8000', method='POST', uri='/hub/login?next=', version='HTTP/1.1', remote_ip='::ffff:192.168.3.47')
Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/tornado/web.py", line 1592, in _execute
result = yield result
File "/usr/local/lib/python3.6/dist-packages/jupyterhub/handlers/login.py", line 81, in post
user = await self.login_user(data)
File "/usr/local/lib/python3.6/dist-packages/jupyterhub/handlers/base.py", line 483, in login_user
await maybe_future(self.authenticator.add_user(user))
File "/usr/local/lib/python3.6/dist-packages/ldapauthenticator/ldapauthenticator.py", line 269, in add_user
yield gen.maybe_future(self.add_user_home_dir(username))
File "/usr/local/lib/python3.6/dist-packages/ldapauthenticator/ldapauthenticator.py", line 295, in add_user_home_dir
raise RuntimeError("Failed to create system user %s: %s" % (username, err))
RuntimeError: Failed to create system user t1:
[E 2018-11-13 10:40:11.146 JupyterHub log:150] {
"X-Forwarded-Host": "192.168.3.49:8000",
"X-Forwarded-Proto": "http",
"X-Forwarded-Port": "8000",
"X-Forwarded-For": "::ffff:192.168.3.47",
"Accept-Language": "de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7",
"Accept-Encoding": "gzip, deflate",
"Referer": "http://192.168.3.49:8000/hub/login",
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36",
"Content-Type": "application/x-www-form-urlencoded",
"Upgrade-Insecure-Requests": "1",
"Origin": "http://192.168.3.49:8000",
"Cache-Control": "max-age=0",
"Content-Length": "29",
"Connection": "close",
"Host": "192.168.3.49:8000"
}
[E 2018-11-13 10:40:11.147 JupyterHub log:158] 500 POST /hub/login?next= (@::ffff:192.168.3.47) 603.82ms
Thanks for any help.
Found a way to solve my problem.
First, I installed the jupyterhub LDAP authenticator.
pip3 install jupyterhub-ldapauthenticator
After the installation, I edited the config file.
nano /etc/jupyterhub/jupyterhub_config.py
The config looks like this:
c.JupyterHub.authenticator_class = 'ldapauthenticator.LDAPAuthenticator'
c.LDAPAuthenticator.server_hosts = ['ldap://ldap.example.com:389']
c.LDAPAuthenticator.bind_user_dn = 'uid=ldapbind,cn=users,dc=ldap,dc=example,dc=com‘
c.LDAPAuthenticator.bind_user_password = ‘Password’
c.LDAPAuthenticator.user_search_base = 'cn=users,dc=ldap,dc=example,dc=com‘
c.LDAPAuthenticator.user_search_filter = '(&(objectClass=posixAccount)(uid={username}))'
c.LDAPAuthenticator.username_pattern = '[a-zA-Z0-9_.][a-zA-Z0-9_.-]{0,252}[a-zA-Z0-9_.$-]?'
c.LDAPAuthenticator.create_user_home_dir = True
c.LDAPAuthenticator.create_user_home_dir_cmd = ['mkhomedir_helper']
In the next step, I installed the following LDAP packages.
sudo apt-get install libnss-ldap libpam-ldap nscd
While the installation you can make the required changes for the configuration. After the installation, I needed to reconfigure the package because I need to change the password encryption.
sudo dpkg-reconfigure ldap-auth-config
Next, I changed the config file ldap.conf.
nano /etc/ldap/ldap.conf
From:
#BASE dc=unixmen,dc=local
#URI ldap://192.168.1.100
To:
BASE dc=ldap,dc=example,dc=com
URI ldap://ldap.example.com
The second config file I edited is nsswitch.conf. The ldap need to be added four times.
passwd: compat ldap
group: compat ldap
shadow: compat ldap
netgroup: ldap
After the changes, the service needs to be restarted.
systemctl restart nscd
Like this, I could solve my problem and it's still working for me.