很重要的注意事项是:JupyterHub最好不要运行在没有SSL加密的公共网络。

SSL加密

SSL certificate

首先,获取官方可信的SSL证书,或自签名的证书。当将key和证书安装完毕后,需要在jupyterhub_config.py 中配置

c.JupyterHub.ssl_key = '/path/to/my.key'
c.JupyterHub.ssl_cert = '/path/to/my.cert'

letsencrypt

使用letsencrypt获得免费可信的SSL证书,配置

c.JupyterHub.ssl_key = '/etc/letsencrypt/live/{mydomain.tld}/privkey.pem'
c.JupyterHub.ssl_cert = '/etc/letsencrypt/live/{mydomain.tld}/fullchain.pem'

如果FQDN是example.com ,则配置

c.JupyterHub.ssl_key = '/etc/letsencrypt/live/example.com/privkey.pem'
c.JupyterHub.ssl_cert = '/etc/letsencrypt/live/example.com/fullchain.pem'

cookie文件

生成并保存cookie secret文件,cookie secret必须是32位随机字节,以hex编码,保存在jupyterhub_cookie_secret 文件

openssl rand -hex 32 > /srv/jupyterhub/jupyterhub_cookie_secret

在JupyterHub部署中,最好将其放在安全的位置,比如/srv/jupyterhub/jupyterhub_cookie_secret

而密钥文件的位置可以在jupyterhub_config.py 中配置

c.JupyterHub.cookie_secret_file = '/srv/jupyterhub/jupyterhub_cookie_secret'

cookie secret文件的推荐权限是600

环境变量

如果需要避免使用文件,可以使用环境变量JPY_COOKIE_SECRET

export JPY_COOKIE_SECRET=`openssl rand -hex 32`

二进制字符串

可以直接在jupyterhub_config.py 配置二进制字符串

c.JupyterHub.cookie_secret = bytes.fromhex('64 CHAR HEX STRING')

Proxy认证token

Hub会认证到Proxy的请求,它是由Hub与Proxy协定的token

openssl rand -hex 32

jupyterhub_config.py 配置

c.JupyterHub.proxy_auth_token = '0bc02bede919e99a26de1e2a7a5aadfaf6228de836ec39a05a6c6942831d8fe5'

生成为环境变量

export CONFIGPROXY_AUTH_TOKEN='openssl rand -hex 32'

results matching ""

    No results matching ""