?
This document uses PHP Chinese website manual Release
在 Docker 1.13 及更高版本中,群集管理器使用的 Raft 日志默認(rèn)在磁盤上加密。這種靜態(tài)加密可以保護(hù)您的服務(wù)配置和數(shù)據(jù)免受攻擊者的攻擊,而攻擊者可以訪問加密的 Raft 日志。此功能推出的原因之一是支持新的 Docker 機(jī)密功能。
當(dāng) Docke r重新啟動時,用于加密群集節(jié)點(diǎn)間通信的 TLS 密鑰以及用于加密和解密磁盤上的 Raft 日志的密鑰都會加載到每個管理器節(jié)點(diǎn)的內(nèi)存中。Docker 1.13引入了保護(hù)相互TLS加密密鑰和用于加密和解密 Raft 日志的密鑰的功能,允許您擁有這些密鑰的所有權(quán)并要求手動解鎖管理人員。該功能稱為自動鎖定。
當(dāng) Docker 重新啟動時,您必須先使用 Docker 在群集鎖定時生成的密鑰加密密鑰解鎖群集。您可以隨時旋轉(zhuǎn)此密鑰加密密鑰。
注意:當(dāng)新節(jié)點(diǎn)加入群體時,不需要解鎖群體,因為密鑰通過相互 TLS 傳播給它。
當(dāng)您初始化新的群集時,可以使用該--autolock
標(biāo)志在Docker 重新啟動時啟用群集管理器節(jié)點(diǎn)的自動鎖定。
$ 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:2377To 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
將密鑰存放在安全的地方,例如密碼管理器。
當(dāng) Docker 重新啟動時,您需要解鎖群集。您會看到類似以下的錯誤,并且服務(wù)無法啟動。
$ sudo service docker restart $ docker service ls Error response from daemon: Swarm is encrypted and needs to be unlocked before it can be used. Please use "docker swarm unlock" to unlock it.
要在現(xiàn)有群集上啟用自動鎖定,請將該autolock
標(biāo)志設(shè)置為true
。
$ docker swarm update --autolock=trueSwarm 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.
要禁用自動鎖定,請設(shè)置--autolock
為false
。用于讀寫
Raft 日志的相互 TLS 密鑰和加密密鑰將以未加密方式存儲在磁盤上。在未加密的情況下存儲加密密鑰的風(fēng)險與無需解鎖每個管理器就能夠重新啟動群集的便利性之間存在折衷。
$ docker swarm update --autolock=false
在禁用自動鎖定功能后,如果管理器在配置為使用舊密鑰進(jìn)行鎖定時發(fā)生故障,請將解鎖密鑰保留一小段時間。
要解鎖已鎖定的群組,請使用docker swarm unlock
。
$ docker swarm unlock Please enter unlock key:
輸入在鎖定群組或旋轉(zhuǎn)鑰匙時生成并顯示在命令輸出中的加密密鑰,并且群體解鎖。
考慮一下你的團(tuán)隊按預(yù)期運(yùn)行的情況,然后經(jīng)理節(jié)點(diǎn)變得不可用。您排除故障并使物理節(jié)點(diǎn)重新聯(lián)機(jī),但您需要通過提供解鎖密鑰來解鎖管理器,以便讀取加密憑證和 Raft 日志。
如果自從節(jié)點(diǎn)離開群集后密鑰沒有旋轉(zhuǎn),并且群體中有法定的功能管理器節(jié)點(diǎn),則可以使用docker swarm unlock-key
沒有任何參數(shù)的方式查看當(dāng)前的解鎖密鑰。
$ 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.
如果在群組節(jié)點(diǎn)變得不可用并且沒有前一個密鑰的記錄后旋轉(zhuǎn)密鑰,則可能需要強(qiáng)制經(jīng)理離開群集并將其作為新經(jīng)理加入群組。
您應(yīng)定期輪換已鎖定的群組的解鎖密鑰。
$ 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.
警告:旋轉(zhuǎn)解鎖密鑰時,請將舊密鑰的記錄保留幾分鐘,以便經(jīng)理在獲取新密鑰之前關(guān)閉,但仍舊可能會鎖定舊密鑰。