在Docker 1.13及更高版本中,默認狀況下,羣管理器使用的Raft日誌在磁盤上加密。這種靜止加密保護你的服務的配置和數據不受得到加密Raft日誌訪問權的攻擊者的攻擊。引入該特性的緣由之一是支持新的Docker secrets特性。
當Docker從新啓動時,用於加密集羣節點間通訊的TLS密鑰和用於加密和解密磁盤Raft日誌的密鑰都被加載到每一個管理器節點的內存中。Docker 1.13引入了保護相互TLS加密密鑰和用於加密和解密Raft日誌的密鑰的能力,容許你得到這些密鑰的全部權,並要求手動解鎖管理器。這個功能叫作自動鎖。
當Docker從新啓動時,必須首先使用Docker在集羣被鎖定時生成的密鑰加密密鑰對集羣進行解鎖。你能夠在任什麼時候候輪轉此密鑰加密密鑰。
注意:當一個新節點加入羣集時,你不須要解鎖羣集,由於密鑰是經過相互的TLS傳播到它的。node
在初始化一個新集羣時,能夠使用--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.
在已有集羣中啓用自動鎖功能,設置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
使用docker swarm unlock 命令解鎖一個上鎖集羣加密
$ docker swarm unlock
Please enter unlock key:
輸入在鎖定集羣或輪轉密鑰時生成並顯示在命令輸出中的加密密鑰,集羣就會解鎖。spa
考慮這樣一種狀況:你的集羣按預期運行,而後管理器節點變得不可用。你能夠對問題進行故障排除並使物理節點從新聯機,可是你須要經過提供解鎖密鑰來讀取加密的憑據和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.
若是在羣集節點不可用以後輪轉了密鑰,而且你沒有上一個密鑰的記錄,則可能須要強制管理器離開羣集,並將其做爲新管理器加入到羣集中。日誌
你應該按期輪轉被鎖集羣的解鎖密鑰。
$ 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.
警告:當你輪轉解鎖密鑰時,請將舊鍵的記錄保留幾分鐘,這樣,若是管理器在獲取新鍵以前宕機,那麼它仍然能夠使用舊鍵解鎖。