docker swarm英文文档学习-11-上锁你的集群来保护你的加密密钥

Lock your swarm to protect its encryption key上锁你的集群来保护你的加密密钥

在Docker 1.13及更高版本中,默认状况下,群管理器使用的Raft日志在磁盘上加密。这种静止加密保护你的服务的配置和数据不受得到加密Raft日志访问权的攻击者的攻击。引入该特性的缘由之一是支持新的Docker secrets特性。

当Docker从新启动时,用于加密集群节点间通讯的TLS密钥和用于加密和解密磁盘Raft日志的密钥都被加载到每一个管理器节点的内存中。Docker 1.13引入了保护相互TLS加密密钥和用于加密和解密Raft日志的密钥的能力,容许你得到这些密钥的全部权,并要求手动解锁管理器。这个功能叫作自动锁。

当Docker从新启动时,必须首先使用Docker在集群被锁定时生成的密钥加密密钥对集群进行解锁。你能够在任什么时候候轮转此密钥加密密钥。

注意:当一个新节点加入群集时,你不须要解锁群集,由于密钥是经过相互的TLS传播到它的。node

 

Initialize a swarm with autolocking enabled 初始化启动自动锁功能的集群

在初始化一个新集群时,能够使用--autolock标志在Docker从新启动时启用集群管理器节点的自动锁。docker

$ docker swarm init --autolock

Swarm initialized: current node (k1q27tfyx9rncpixhk69sa61v) is now a manager.

To add a worker to this swarm, run the following command:

    docker swarm join \
    --token SWMTKN-1-0j52ln6hxjpxk2wgk917abcnxywj3xed0y8vi1e5m9t3uttrtu-7bnxvvlz2mrcpfonjuztmtts9 \
    172.31.46.109:2377

To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.

To unlock a swarm manager after it restarts, run the `docker swarm unlock`
command and provide the following key:

    SWMKEY-1-WuYH/IX284+lRcXuoVf38viIDK3HJEKY13MIHX+tTt8

将密钥存储在安全的地方,如密码管理器中。

当Docker重启时,你须要解锁集群。当你试图启动或从新启动服务时,锁定的集群会致使以下错误:安全

$ sudo service docker restart

$ docker service ls

Error response from daemon: Swarm is encrypted and needs to be unlocked before it can be used. Use "docker swarm unlock" to unlock it.

 

Enable or disable autolock on an existing swarm在已有集群中启用或禁用自动锁功能

在已有集群中启用自动锁功能,设置autolock标志为trueide

$ docker swarm update --autolock=true

Swarm updated.
To unlock a swarm manager after it restarts, run the `docker swarm unlock`
command and provide the following key:

    SWMKEY-1-+MrE8NgAyKj5r3NcR4FiQMdgu+7W72urH0EZeSmP/0Y

Please remember to store this key in a password manager, since without it you
will not be able to restart the manager.

若要禁用自动锁,请将--autolock设置为false。用于读写Raft日志的相互TLS密钥和加密密钥未加密地存储在磁盘上。在存储未加密的加密密钥的风险和从新启动集群而不须要解锁每一个管理器之间存在权衡。函数

$ docker swarm update --autolock=false

在禁用自动锁以后,请将解锁密钥保留一段时间,以防在仍然配置为使用旧密钥锁定时,管理器出现故障。this

 

Unlock a swarm解锁集群

使用docker swarm unlock 命令解锁一个上锁集群加密

$ docker swarm unlock

Please enter unlock key:

输入在锁定集群或轮转密钥时生成并显示在命令输出中的加密密钥,集群就会解锁。spa

 

View the current unlock key for a running swarm 查看正在运行的集群的当前解锁密钥

考虑这样一种状况:你的集群按预期运行,而后管理器节点变得不可用。你能够对问题进行故障排除并使物理节点从新联机,可是你须要经过提供解锁密钥来读取加密的凭据和Raft日志来解锁管理器。

若是自节点离开群集后密钥没有被轮转,而且你在群集中有一个仲裁的函数管理器节点,那么你能够使用docker swarm unlock-key查看当前的解锁密钥,而不须要任何参数。rest

$ docker swarm unlock-key

To unlock a swarm manager after it restarts, run the `docker swarm unlock`
command and provide the following key:

    SWMKEY-1-8jDgbUNlJtUe5P/lcr9IXGVxqZpZUXPzd+qzcGp4ZYA

Please remember to store this key in a password manager, since without it you
will not be able to restart the manager.

若是在群集节点不可用以后轮转了密钥,而且你没有上一个密钥的记录,则可能须要强制管理器离开群集,并将其做为新管理器加入到群集中。日志

 

Rotate the unlock key轮转解锁密钥

你应该按期轮转被锁集群的解锁密钥。

$ docker swarm unlock-key --rotate

Successfully rotated manager unlock key.

To unlock a swarm manager after it restarts, run the `docker swarm unlock`
command and provide the following key:

    SWMKEY-1-8jDgbUNlJtUe5P/lcr9IXGVxqZpZUXPzd+qzcGp4ZYA

Please remember to store this key in a password manager, since without it you
will not be able to restart the manager.

警告:当你轮转解锁密钥时,请将旧键的记录保留几分钟,这样,若是管理器在获取新键以前宕机,那么它仍然能够使用旧键解锁。

相关文章
相关标签/搜索