Jupyterhub在登录时创建用户和家庭

时间:2018-10-18 07:03:48

标签: jupyter-notebook jupyterhub

我已经设置了具有LDAP身份验证的jupyterhub服务器。 服务器和身份验证工作正常。 但是我的问题是,我需要在服务器上创建要手动登录的用户,否则他没有住所,并且出现此错误。

BBB()ggg { (test: [Test]) in

}

如果凭据正确,是否可以创建用户和家庭。 谢谢

编辑: 现在,我将jupyterhub-ldap-authenticator更新到版本0.3.0。那里直接支持自动主目录创建器。

我在jupyterhub_config.py文件中当前对LDAP部件的配置如下:

[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

但是我现在有问题,我得到以下错误。

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']

这是Log的输出。

500 : Internal Server Error

感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

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

首先,我安装了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

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