配置安全¶
Driverless AI 提供将敏感或安全配置信息存储于加密密钥库中的选项,此选项可作为将安全性设置在 config.toml 文件中保留为明文的替代方式。
配置覆盖链更新¶
从 config.toml 文件的纯文本中读取设置后,配置覆盖链即已更新,从而能加密密钥库中加载设置。环境变量仍可覆盖密钥库中的值:
1. h2oai/config/config.toml
[Internal, not visible to users]
2. config.toml
[Place file in a folder/mount file in docker container and provide path
in "DRIVERLESS_AI_CONFIG_FILE" environment variable]
3. Keystore file
[Set keystore_file parameter in config.toml or environment variable
"DRIVERLESS_AI_KEYSTORE_FILE" to point to a valid DAI keystore file
generated using the h2oai.keystore tool. If env variable is set, the value
in the config.toml for keystore_file path is overridden]
4. Environment variable
[Configuration variables can also be provided as environment
variables. They must have the prefix "DRIVERLESS_AI_" followed
by the variable name in caps. For example, "authentication_method"
can be provided as "DRIVERLESS_AI_AUTHENTICATION_METHOD"]
密钥库设置工作流¶
创建密钥库
尽管密钥库文件可包含 config.toml 支持的任何配置参数,但建议在密钥库文件中仅存储包含安全/敏感信息的配置参数,并将常规 config.toml 文件用于其他配置参数。
步骤 1:创建明文配置子集
首先,创建一个 config.clear 文件,此文件符合常规 config.toml 文件的 TOML 语法,并包含您想要安全存储的配置参数。例如:
vagrant@ubuntu-bionic:~$ cat /home/vagrant/config.clear
# ldap connection details
ldap_bind_password = "somepassword"
# Snowflake Connector credentials
snowflake_url = "https://sampleurl"
snowflake_user = "sampleuser"
snowflake_password = "samplepass"
snowflake_account = "sampleaccount"
vagrant@ubuntu-bionic:~$
步骤 2:使用 h2oai.keystore 工具创建密钥库
密钥库应放置于根或者运行 Driverless AI 进程的用户 id 可访问的位置。我们建议将密钥库与所有其他 Diverless 的配置文件一起存储为 /etc/dai/config.keystore
.
若需从 config.clear
文件创建密钥库,请使用 h2oai.keystore
工具:
密钥库工具需在由
dai-env.sh
脚本提供的 Driverless AI Python 环境中作为root
运行。Add-keys
命令将密钥库的路径作为第一个参数,并将明文 config.toml 子集作为第二个参数。如果密钥库不存在,则可创建一个。
所有
config.clear
中的密钥均嵌入至密钥库中或在密钥库中进行更新。如果密钥库中已经存在一个密钥,则会对其进行更新。如果密钥库中包含任何不在config.clear
中的密钥,则不会对其进行更改。创建密钥库文件后,建议确保:
根用户拥有所有权,并有读取和写入权限。
将用户组所有权更改至具有只读权限的 Driverless 用户组(或与在系统中运行 Driverless 进程的用户组 ID 匹配的相应 ID)。其他用户或用户组应不能具有此文件的读取权限。
Config.keystore
文件可与所有权权限一起创建。
(user1) $ sudo /bin/bash # this will get a shell as root. If root access shell is available; this step can be skipped
(root) # /opt/h2oai/dai/dai-env.sh python -m h2oai.keystore add-keys /etc/dai/config.keystore /home/vagrant/config.clear
....some output here
======================================================================
Key: ldap_bind_password; Action: Inserted
Key: snowflake_url; Action: Inserted
Key: snowflake_user; Action: Inserted
Key: snowflake_password; Action: Inserted
Key: snowflake_account; Action: Inserted
(root) # ls -l /etc/dai
total 240
-rw-rw-r-- 1 root root 353 Jul 14 03:28 EnvironmentFile.conf
-rw-r--r-- 1 root root 210 Jul 20 06:57 Group.conf
-rw-r--r-- 1 root root 209 Jul 20 06:57 User.conf
-rw-r----- 1 root dai 236 Jul 20 07:09 config.keystore
-rw-r--r-- 1 root root 157135 Jul 20 07:17 config.toml
-rw-rw-r-- 1 root root 347 Jul 14 03:28 jaas.conf
-rw-r--r-- 1 root root 62206 Jul 20 06:57 redis.conf
(root) # chown root:dai /etc/dai/config.keystore
(root) # chmod 640 /etc/dai/config.keystore
步骤 3:使用 h2oai.keystore 工具管理密钥库
H2oai.keystore
工具提供三个用于密钥库管理的命令。
Add-keys
: 通过配置添加或更新 Driverless AI 秘密密钥库。list-keys
: 列出 Driverless AI 密钥库中储存的密钥,但不会显示这些密钥的值。delete-keys
: 从密钥库中移除指定密钥。
(root) # /opt/h2oai/dai/dai-env.sh python -m h2oai.keystore --help
======================================================================
Usage: python -m h2oai.keystore [OPTIONS] COMMAND [ARGS]...
Options:
--help Show this message and exit.
Commands:
add-keys Adds/Update DAI secrets keystore (KEYSTORE_PATH) with config...
delete-keys Deleted keys provided as -k key1 -k key2 from the keystore...
list-keys Lists keys stored in Driverless AI KEYSTORE.
root@ubuntu-bionic:/etc/dai#
(root) # /opt/h2oai/dai/dai-env.sh python -m h2oai.keystore list-keys /etc/dai/config.keystore
======================================================================
ldap_bind_password = ******
snowflake_url = ******
snowflake_user = ******
snowflake_password = ******
snowflake_account = ******
root@ubuntu-bionic:/etc/dai#
-------- Deleting keys ------------
(root) # /opt/h2oai/dai/dai-env.sh python -m h2oai.keystore delete-keys /etc/dai/config.keystore -k snowflake_url -k snowflake_account
======================================================================
snowflake_url = Deleted
snowflake_account = Deleted
(root) # /opt/h2oai/dai/dai-env.sh python -m h2oai.keystore list-keys /etc/dai/config.keystore
======================================================================
ldap_bind_password = ******
snowflake_user = ******
snowflake_password = ******
root@ubuntu-bionic:/etc/dai#