文件首頁
MySQL 8.4 參考手冊
相關文件 下載本手冊
PDF (US Ltr) - 39.9Mb
PDF (A4) - 40.0Mb
手冊頁 (TGZ) - 258.5Kb
手冊頁 (Zip) - 365.5Kb
Info (Gzip) - 4.0Mb
Info (Zip) - 4.0Mb


25.6.15.3 使用 TLS 連線

建立 CA 和憑證後,您可以執行具有 ndb_mgm 用戶端和 --test-tls 的方式,測試與管理伺服器的 TLS 連線可用性,如下所示

$> ndb_mgm --test-tls
No valid certificate.

如果用戶端可以使用 TLS 連線,則會產生適當的訊息。您可能需要包含其他 ndb_mgm 選項,例如 --ndb-tls-search-path,以方便 TLS 連線,如下所示

$> ndb_mgm --test-tls --ndb-tls-search-path="CA:keys"
Connected to management server at localhost port 1186 (using TLS)

如果用戶端在沒有使用 TLS 的情況下連線,也會顯示此資訊,類似於此處所示

$> ndb_mgm
Connected to management server at localhost port 1186 (using cleartext)
$>

您可以讓叢集使用使用 ndb_sign_keys 建立的 CA 和憑證,方法是對叢集執行輪流重新啟動,從管理節點開始,應該使用 --ndb-tls-search-path 選項重新啟動。在此之後,重新啟動資料節點,再次使用 --ndb-tls-search-path--ndb-tls-search-path 也支援 mysqld 作為叢集 API 節點執行。

為了使 TLS 運作,每個連線到叢集的節點都必須具有有效的憑證和金鑰。這包括資料節點、API 節點和公用程式。多個節點可以使用相同的憑證和金鑰檔案。

資料節點會記錄 TLS 連線,並包含所使用憑證檔案的完整路徑,如下所示

$> ndbmtd -c localhost:1186 --ndb-tls-search-path='CA:keys'
2023-12-19 12:02:15 [ndbd] INFO     -- NDB TLS 1.3 available using certificate file 'keys/ndb-data-node-cert'
2023-12-19 12:02:15 [ndbd] INFO     -- Angel connected to 'localhost:1186'
2023-12-19 12:02:15 [ndbd] INFO     -- Angel allocated nodeid: 5

您可以透過檢查 ndb_mgm 用戶端中 TLS INFO 命令的輸出,驗證叢集節點是否正在使用 TLS 連線,如下所示

$> ndb_mgm --ndb-tls-search-path="CA:keys"
-- NDB Cluster -- Management Client --
ndb_mgm> TLS INFO
Connected to management server at localhost port 1186 (using TLS)
 
Main interactive connection is using TLS
Event listener connection is using TLS
 
Server reports 6 TLS connections.

  Session ID:          32
  Peer address:        ::
  Certificate name:    NDB Node Dec 2023
  Certificate serial:  39:1E:4A:78:E5:93:45:09:FC:56
  Certificate expires: 21-Apr-2024
 
  Session ID:          31
  Peer address:        127.0.0.1
  Certificate name:    NDB Node Dec 2023
  Certificate serial:  39:1E:4A:78:E5:93:45:09:FC:56
  Certificate expires: 21-Apr-2024
 
  Session ID:          30
  Peer address:        127.0.0.1
  Certificate name:    NDB Node Dec 2023
  Certificate serial:  39:1E:4A:78:E5:93:45:09:FC:56
  Certificate expires: 21-Apr-2024
 
  Session ID:          18
  Peer address:        127.0.0.1
  Certificate name:    NDB Data Node Dec 2023
  Certificate serial:  57:5E:58:70:7C:49:B3:74:1A:99
  Certificate expires: 07-May-2024
 
  Session ID:          12
  Peer address:        127.0.0.1
  Certificate name:    NDB Data Node Dec 2023
  Certificate serial:  57:5E:58:70:7C:49:B3:74:1A:99
  Certificate expires: 07-May-2024
 
  Session ID:          1
  Peer address:        127.0.0.1
  Certificate name:    NDB Management Node Dec 2023
  Certificate serial:  32:10:44:3C:F4:7D:73:40:97:41
  Certificate expires: 17-May-2024
 
 
    Server statistics since restart
  Total accepted connections:        32
  Total connections upgraded to TLS: 8
  Current connections:               6
  Current connections using TLS:     6
  Authorization failures:            0
ndb_mgm>

如果 Current connectionsCurrent connections using TLS 相同,則表示所有叢集連線都在使用 TLS。

一旦您為所有節點建立 TLS 連線後,您應該將 TLS 作為嚴格要求。對於用戶端,您可以在每個叢集主機上的 my.cnf 檔案中設定 ndb-mgm-tls=strict 來執行此操作。透過在叢集 config.ini 檔案的 [mgm default] 區段中設定 RequireTls=true,然後對叢集執行輪流重新啟動,使此變更生效,來在管理伺服器上強制執行 TLS 要求。針對資料節點執行此操作,方法是在組態檔案的 [ndbd default] 區段中設定 RequireTls=true;在此之後,執行第二次叢集輪流重新啟動,以使變更在資料節點上生效。使用 --reload--config-file 選項兩次啟動 ndb_mgmd,以確保管理伺服器讀取兩個組態檔案變更的每一個。

若要更換私密金鑰,請使用 ndb_sign_keys --create-key 來建立新的金鑰和憑證,如果必要,可以使用 --node-id--node-type options 來限制替換為單一節點 ID、節點類型或兩者。如果此工具找到現有的金鑰和憑證檔案,則會重新命名它們以反映其停用狀態,並將新建立的金鑰和憑證儲存為作用中的檔案;下次重新啟動節點時會使用新的檔案。

若要更換憑證而不更換私密金鑰,請使用 ndb_sign_keys,而不要提供 --create-key 選項。這會為現有的金鑰建立新的憑證(而不更換金鑰),並停用舊的憑證。

ndb_sign_keys 也支援遠端金鑰簽署。使用 SSH,--remote-CA-host 選項會以 user@host 格式提供 CA 主機的 SSH 位址。預設情況下,本機 ndb_sign_keys 程序會使用系統 ssh 公用程式和位址,在遠端主機上使用正確的選項執行 ndb_sign_keys,以執行所需的簽署。或者,如果 --remote-openssl=true,則會在遠端主機上使用 openssl 而不是 ndb_sign_keys

使用遠端簽署時,透過網路傳送的資料是 PKCS#10 簽署要求,而不是永遠不會離開本機主機的私密金鑰。