身份验证
目录
身份验证¶
作为一个多租户应用,dask-gateway-server
需要一种方法来认证用户。与后端类似,身份验证也可以通过设置 c.DaskGateway.authenticator_class
来配置。这里我们介绍几种常见的实现方式。
用于测试的简单身份验证¶
出于测试目的,可以使用一种“简单”的身份验证方法。此方法实现身份验证,但不验证密码字段。因此,它不适合生产环境,仅用于测试。如果需要,可以配置一个可选的密码,该密码在所有用户之间共享。请注意,这只会稍微提高安全性,因为用户仍然可以轻松地互相冒充。
此协议是默认协议,由 dask_gateway_server.auth.SimpleAuthenticator
实现。无需进一步配置即可启用它。如果您想添加共享密码,可以将以下行添加到您的 dask_gateway_config.py
文件中
# Set a shared password.
c.SimpleAuthenticator.password = "mypassword"
更多信息请参见 SimpleAuthenticator 文档。
Kerberos 身份验证¶
Kerberos 可用于通过启用 dask_gateway_server.auth.KerberosAuthenticator
来验证用户身份。为此,您需要为运行 dask-gateway-server
的主机创建 HTTP
服务主体和 keytab(如果尚不存在)。Keytab 可以在命令行中创建,如下所示:
# Create the HTTP principal (if not already created)
$ kadmin -q "addprinc -randkey HTTP/FQDN"
# Create a keytab
$ kadmin -q "xst -norandkey -k /etc/dask-gateway/http.keytab HTTP/FQDN"
其中 FQDN
是运行 dask-gateway-server
的主机的完全限定域名。
将 keytab 文件存储在您认为合适的位置。我们建议将其与其他配置一起存储(通常在 /etc/dask-gateway/
中)。您还需要确保 http.keytab
文件仅对管理员用户(通常是运行 dask-gateway-server
的 dask
用户)可读。
$ chown dask /etc/dask-gateway/http.keytab
$ chmod 400 /etc/dask-gateway/http.keytab
要配置 dask-gateway-server
使用此 keytab 文件,您需要在 dask_gateway_config.py
文件中添加以下行
# Enable Kerberos for user-facing authentication
c.DaskGateway.authenticator_class = "dask_gateway_server.auth.KerberosAuthenticator"
# The location of the HTTP keytab
c.KerberosAuthenticator.keytab = "/etc/dask-gateway/http.keytab"
更多信息请参见 KerberosAuthenticator 文档。
使用 JupyterHub 的身份验证¶
JupyterHub 提供了一个多用户交互式笔记本环境。在与 JupyterHub 一起部署 Dask-Gateway 时,您可以配置 Dask-Gateway 使用 JupyterHub 进行身份验证。为此,我们将 dask-gateway
注册为 JupyterHub 服务。
首先我们需要生成一个 API 令牌 - 这通常使用 openssl
完成
$ openssl rand -hex 32
然后将以下行添加到您的 dask_gateway_config.py
文件中
c.DaskGateway.authenticator_class = "dask_gateway_server.auth.JupyterHubAuthenticator"
c.JupyterHubAuthenticator.api_token = "<API TOKEN>"
c.JupyterHubAuthenticator.api_url = "<API URL>"
其中
<API TOKEN>
是上面生成的令牌<API URL>
是 JupyterHub 的 API URL。这通常采用以下形式https://<JUPYTERHUB-HOST>:<JUPYTERHUB-PORT>/hub/api
。
您还需要将 API 令牌注册到 JupyterHub。这可以通过将以下内容添加到相应的 jupyterhub_config.py
文件中来完成
c.JupyterHub.services = [
{"name": "dask-gateway", "api_token": "<API TOKEN>"}
]
再次,将 <API TOKEN>
替换为上述输出。
通过此配置,JupyterHub 将用于验证用户与 dask-gateway-server
之间的请求。
更多信息请参见 JupyterHubAuthenticator 文档。