mTLS 身份验证示例

通过设置具有证书颁发机构文件、SSL 私钥和 SSL 证书文件的特定验证模式,Driverless AI 可支持`TLS 双向身份验证 (mTLS) <https://en.wikipedia.org/wiki/Mutual_authentication>`__ 。下图以图示方式展示了 mTLS 身份验证过程。

mTLS Authentication

配置属性说明

使用以下配置选项来配置 mTLS。

  • ssl_client_verify_mode: 设置客户端验证模式。从以下验证模式中选择:

  • CERT_NONE: 客户端无需提供证书。如果提供证书,则将忽略由此产生的任何验证错误。

  • CERT_OPTIONAL: 客户端无需提供证书。如果提供证书,则将根据已配置的 CA 证书链进行验证。

  • CERT_REQUIRED: 客户端需要提供证书以供验证。请注意,为使 Driverless 能够验证其自身的回调请求,在选择此模式时需要配置 ssl_client_key_filessl_client_crt_file 选项。

  • ssl_ca_file: 指定由您所在组织提供的`证书颁发机构 (CA) <https://en.wikipedia.org/wiki/Certificate_authority>`__ 证书文件的路径。当启用客户端身份验证时,此证书将被用于验证客户端证书。如果未指定路径,则将使用系统默认证书对客户端进行验证。

  • ssl_key_file: 指定 web 服务器私钥文件。这通常由您所在组织的系统管理员创建。

  • ssl_crt_file: 指定 web 服务器公钥证书文件。这通常由您所在组织的系统管理员创建。

  • ssl_client_key_file: 如果 ssl_client_verify_mode = "CERT_REQUIRED" ,则需要此文件。指定 Driverless AI 用于对其自身进行身份验证的 私钥 文件。这通常由您所在组织的系统管理员创建。

  • ssl_client_crt_file: 如果 ssl_client_verify_mode = "CERT_REQUIRED",则需要此文件。指定 Driverless AI 用于对其自身进行身份验证的私有 客户端证书 文件。这通常由您所在组织的系统管理员创建。

  • auth_tls_crl_file: 指定将用于验证客户端证书的 证书吊销列表 文件的路径。此文件包含已吊销的用户 ID 列表。

配置方案

下表列出了采用上述配置选项组合时,mTLS 身份验证的用户证书行为。

config.toml 设置

用户未持有证书

用户持有正确有效的证书

用户持有已吊销的证书

ssl_client_verify_mode='CERT_NONE'

用户证书被忽略

用户证书被忽略

已吊销的用户证书被忽略

ssl_client_verify_mode='CERT_OPTIONAL'

用户证书被忽略

用户证书被设置用于启动 Driverless AI,但不用于验证证书

已吊销的用户证书未经验证

ssl_client_verify_mode='CERT_REQUIRED'

不允许

用户提供 Driverless AI 所使用的有效证书,但是无法对该用户进行身份验证

用户吊销列表未经过验证

sl_client_verify_mode='CERT_REQUIRED'

以及

authentication_method='tls_authentication'

不允许

用户提供有效证书。此证书用于连接 Driverless AI 服务器以及身份验证。

验证已吊销的用户证书并在 AUTH_TLS_CRL_FILE 中提供已吊销证书文件。

启用 mTLS 身份验证

在 Docker 映像中启用 mTLS 身份验证,指定您想要使用的身份验证环境变量。每个变量必须以 DRIVERLESS_AI_ 开头。

nvidia-docker run \
  --pid=host \
  --init \
  --rm \
  --shm-size=256m \
  -p 12345:12345 \
  -u `id -u`:`id -g` \
  -e DRIVERLESS_AI_ENABLE_HTTPS=true \
  -e DRIVERLESS_AI_SSL_KEY_FILE=/etc/dai/private_key.pem \
  -e DRIVERLESS_AI_SSL_CRT_FILE=/etc/dai/cert.pem \
  -e DRIVERLESS_AI_AUTHENTICATION_METHOD=tls_certificate \
  -e DRIVERLESS_AI_SSL_CLIENT_VERIFY_MODE=CERT_REQUIRED \
  -e DRIVERLESS_AI_SSL_CA_FILE=/etc/dai/rootCA.pem \
  -e DRIVERLESS_AI_SSL_CLIENT_KEY_FILE=/etc/dai/client_config_key.key \
  -e DRIVERLESS_AI_SSL_CLIENT_CRT_FILE=/etc/dai/client_config_cert.pem \
  -v /user/log:/log \
  -v /user/tmp:/tmp \
  -v /user/certificates/server_config_key.pem:/etc/dai/private_key.pem \
  -v /user/certificates/server_config_cert.pem:/etc/dai/cert.pem \
  -v /user/certificates/client_config_cert.pem:/etc/dai/client_config_cert.pem \
  -v /user/certificates/client_config_key.key:/etc/dai/client_config_key.key \
  -v /user/certificates/rootCA.pem:/etc/dai/rootCA.pem \
  h2oai/dai-centos7-x86_64:1.9.2.1-cuda10.0.xx

请注意:当请求证书验证时,使用 Docker 参数 --hostname 以确保证书主机名可从 Docker 容器内解析至此容器的 IP 地址。

本机安装包括 DEB、RPM 和 TAR SH 安装。以下示例展示了如何编辑 config.toml 文件以启用 mTLS 身份验证。

  1. 导出 Driverless AI config.toml 文件或将其添加至 ~/.bashrc。例如:

# DEB and RPM
export DRIVERLESS_AI_CONFIG_FILE="/etc/dai/config.toml"

# TAR SH
export DRIVERLESS_AI_CONFIG_FILE="/path/to/your/unpacked/dai/directory/config.toml"
  1. 打开 config.toml 文件并编辑以下身份验证变量。安装 Driverless AI 后,可在 etc/dai 文件夹中找到 config.toml 文件。

# Path to the Certification Authority certificate file. This certificate will be
# used when to verify client certificate when client authentication is turned on.
# If this is not set, clients are verified using default system certificates.
#
ssl_ca_file = "/etc/pki/ca.crt"

# Sets the client verification mode.
# CERT_NONE: Client does not need to provide the certificate and if it does any
# verification errors are ignored.
# CERT_OPTIONAL: Client does not need to provide the certificate and if it does
# certificate is verified agains set up CA chains.
# CERT_REQUIRED: Client needs to provide a certificate and certificate is
# verified.
# You'll need to set 'ssl_client_key_file' and 'ssl_client_crt_file'
# When this mode is selected for Driverless to be able to verify
# it's own callback requests.
#
ssl_client_verify_mode = "CERT_REQUIRED"

# Path to the private key that Driverless will use to authenticate itself when
# CERT_REQUIRED mode is set.
#
ssl_client_key_file = "/etc/pki/dai-self.key"

# Path to the client certificate that Driverless will use to authenticate itself
# when CERT_REQUIRED mode is set.
#
ssl_client_crt_file = "/etc/pki/dai-self.crt"

# Enable client certificate authentication
authentication_method = "tls_certificate"
  1. 启动(或重启)Driverless AI。