Jupyterhub 在登录时创建用户和主页
Jupyterhub create user and home at login
我已经设置了一个带有 LDAP 身份验证的 jupyterhub 服务器。
服务器和身份验证工作正常。
但我的问题是,我需要在服务器上创建我想手动登录的用户,否则他没有家,我收到此错误。
[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
如果凭据正确,是否可以创建用户和主页。
谢谢
编辑:
现在我将 jupyterhub-ldap-authenticator 更新到版本 0.3.0。直接支持自动主目录创建器。
我在 jupyterhub_config.py 文件中的 LDAP 部分的当前配置如下所示:
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']
但我现在遇到了问题,我收到以下错误。
500 : Internal Server Error
这是日志的输出。
[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
感谢您的帮助。
找到解决我问题的方法。
首先,我安装了 jupyterhub LDAP 身份验证器。
pip3 install jupyterhub-ldapauthenticator
安装后,我编辑了配置文件。
nano /etc/jupyterhub/jupyterhub_config.py
配置如下所示:
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']
在下一步中,我安装了以下 LDAP 包。
sudo apt-get install libnss-ldap libpam-ldap nscd
安装时您可以对配置进行必要的更改。
安装完成后,我需要重新配置包,因为我需要更改密码加密。
sudo dpkg-reconfigure ldap-auth-config
接下来,我更改了配置文件ldap.conf。
nano /etc/ldap/ldap.conf
发件人:
#BASE dc=unixmen,dc=local
#URI ldap://192.168.1.100
收件人:
BASE dc=ldap,dc=example,dc=com
URI ldap://ldap.example.com
我编辑的第二个配置文件是nsswitch.conf。
ldap需要添加四次。
passwd: compat ldap
group: compat ldap
shadow: compat ldap
netgroup: ldap
修改后需要重启服务。
systemctl restart nscd
像这样,我可以解决我的问题,而且它仍然对我有用。
我已经设置了一个带有 LDAP 身份验证的 jupyterhub 服务器。 服务器和身份验证工作正常。 但我的问题是,我需要在服务器上创建我想手动登录的用户,否则他没有家,我收到此错误。
[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
如果凭据正确,是否可以创建用户和主页。 谢谢
编辑: 现在我将 jupyterhub-ldap-authenticator 更新到版本 0.3.0。直接支持自动主目录创建器。
我在 jupyterhub_config.py 文件中的 LDAP 部分的当前配置如下所示:
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']
但我现在遇到了问题,我收到以下错误。
500 : Internal Server Error
这是日志的输出。
[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
感谢您的帮助。
找到解决我问题的方法。
首先,我安装了 jupyterhub LDAP 身份验证器。
pip3 install jupyterhub-ldapauthenticator
安装后,我编辑了配置文件。
nano /etc/jupyterhub/jupyterhub_config.py
配置如下所示:
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']
在下一步中,我安装了以下 LDAP 包。
sudo apt-get install libnss-ldap libpam-ldap nscd
安装时您可以对配置进行必要的更改。 安装完成后,我需要重新配置包,因为我需要更改密码加密。
sudo dpkg-reconfigure ldap-auth-config
接下来,我更改了配置文件ldap.conf。
nano /etc/ldap/ldap.conf
发件人:
#BASE dc=unixmen,dc=local
#URI ldap://192.168.1.100
收件人:
BASE dc=ldap,dc=example,dc=com
URI ldap://ldap.example.com
我编辑的第二个配置文件是nsswitch.conf。 ldap需要添加四次。
passwd: compat ldap
group: compat ldap
shadow: compat ldap
netgroup: ldap
修改后需要重启服务。
systemctl restart nscd
像这样,我可以解决我的问题,而且它仍然对我有用。