Jupyterhub 在登录时创建用户和主页

Rad*_*onx 4 jupyter-notebook jupyterhub

我已经设置了带有 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
Run Code Online (Sandbox Code Playgroud)

如果凭据正确,有没有办法创建用户和家庭。谢谢

编辑:现在我将 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']
Run Code Online (Sandbox Code Playgroud)

但我现在遇到了问题,我收到以下错误。

500 : Internal Server Error
Run Code Online (Sandbox Code Playgroud)

这是日志的输出。

[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
Run Code Online (Sandbox Code Playgroud)

谢谢你的帮助。

Rad*_*onx 6

找到了解决我的问题的方法。

\n\n

首先,我安装了 jupyterhub LDAP 身份验证器。

\n\n
pip3 install jupyterhub-ldapauthenticator\n
Run Code Online (Sandbox Code Playgroud)\n\n

安装后,我编辑了配置文件。

\n\n
nano /etc/jupyterhub/jupyterhub_config.py\n
Run Code Online (Sandbox Code Playgroud)\n\n

配置如下所示:

\n\n
c.JupyterHub.authenticator_class = 'ldapauthenticator.LDAPAuthenticator'\nc.LDAPAuthenticator.server_hosts =  ['ldap://ldap.example.com:389']\nc.LDAPAuthenticator.bind_user_dn = 'uid=ldapbind,cn=users,dc=ldap,dc=example,dc=com\xe2\x80\x98\nc.LDAPAuthenticator.bind_user_password = \xe2\x80\x98Password\xe2\x80\x99\nc.LDAPAuthenticator.user_search_base = 'cn=users,dc=ldap,dc=example,dc=com\xe2\x80\x98\nc.LDAPAuthenticator.user_search_filter = '(&(objectClass=posixAccount)(uid={username}))'\nc.LDAPAuthenticator.username_pattern = '[a-zA-Z0-9_.][a-zA-Z0-9_.-]{0,252}[a-zA-Z0-9_.$-]?'\nc.LDAPAuthenticator.create_user_home_dir = True\nc.LDAPAuthenticator.create_user_home_dir_cmd = ['mkhomedir_helper']\n
Run Code Online (Sandbox Code Playgroud)\n\n

在下一步中,我安装了以下 LDAP 软件包。

\n\n
sudo apt-get install libnss-ldap libpam-ldap nscd\n
Run Code Online (Sandbox Code Playgroud)\n\n

安装时您可以对配置进行所需的更改。\n安装后,我需要重新配置软件包,因为我需要更改密码加密。

\n\n
sudo dpkg-reconfigure ldap-auth-config\n
Run Code Online (Sandbox Code Playgroud)\n\n

接下来,我更改了配置文件 ldap.conf。

\n\n
nano /etc/ldap/ldap.conf\n
Run Code Online (Sandbox Code Playgroud)\n\n

从:

\n\n
#BASE\xc2\xa0\xc2\xa0\xc2\xa0 dc=unixmen,dc=local\n#URI\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0 ldap://192.168.1.100\n
Run Code Online (Sandbox Code Playgroud)\n\n

到:

\n\n
BASE\xc2\xa0\xc2\xa0\xc2\xa0 dc=ldap,dc=example,dc=com\nURI\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0 ldap://ldap.example.com\n
Run Code Online (Sandbox Code Playgroud)\n\n

我编辑的第二个配置文件是 nsswitch.conf。\nldap 需要添加四次。

\n\n
passwd:\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0 compat ldap\ngroup:\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0 compat ldap\nshadow:\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0 compat ldap\nnetgroup:       ldap\n
Run Code Online (Sandbox Code Playgroud)\n\n

更改后,需要重新启动服务。

\n\n
systemctl restart nscd\n
Run Code Online (Sandbox Code Playgroud)\n\n

像这样,我可以解决我的问题,而且它仍然对我有用。

\n