

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 控制對 Amazon MSK 叢集中 Apache ZooKeeper 節點的存取
<a name="zookeeper-security"></a>

基於安全考量，您可以對屬於 Amazon MSK 叢集的 Apache ZooKeeper 節點存取權進行限制。若要限制對這些節點的存取權，您可以將個別的安全群組指派給這些節點。然後，您可以決定誰可以存取該安全群組。

**重要**  
本節不適用於在 KRaft 模式下執行的叢集。請參閱 [KRaft 模式](metadata-management.md#kraft-intro)。

**Topics**
+ [

# 將 Apache ZooKeeper 節點放在個別的安全群組
](zookeeper-security-group.md)
+ [

# 搭配 Apache ZooKeeper 使用 TLS 安全功能
](zookeeper-security-tls.md)

# 將 Apache ZooKeeper 節點放在個別的安全群組
<a name="zookeeper-security-group"></a>

若要限制對 Apache ZooKeeper 節點的存取，您可以為其指派個別的安全群組。您可以透過設定安全群組規則來選擇有權存取此新安全群組的人員。

1. 取得叢集的 Apache ZooKeeper 連線字串。若要了解作法，請參閱[ZooKeeper 模式](metadata-management.md#msk-get-connection-string)。連線字串包含 Apache ZooKeeper 節點的 DNS 名稱。

1. 使用 `host` 或 `ping` 之類的工具，來將您在上一個步驟中獲得的 DNS 名稱轉換為 IP 地址。儲存這些 IP 地址，因為稍後在此程序中需要這些資訊。

1. 登入 AWS 管理主控台 ，並在 [https://console.aws.amazon.com/ec2/](https://console.aws.amazon.com/ec2/)：// 開啟 Amazon EC2 主控台。

1. 在左側窗格中的 **NETWORK & SECURITY (網路與安全)** 下，選擇 **Network Interfaces (網路界面)**。

1. 在網路界面表格上方的搜尋欄位中，輸入叢集的名稱，然後輸入 return。這會將表格中顯示的網路界面數量限制為與叢集相關聯的那些界面。

1. 在清單中與第一個網路界面相對應的資料列開頭選取核取方塊。

1. 在頁面底部的詳細資訊窗格中，尋找 **Primary private IPv4 IP (主要私有 IPv4 IP)**。如果此 IP 地址與您在此程序的第一步中獲得的其中一個 IP 地址相符，這意味著系統會將此網路界面指派給屬於您叢集的 Apache ZooKeeper 節點。否則，請取消選取此網路界面旁的核取方塊，然後選取清單中的下一個網路界面。網路界面的選取順序無關緊要。在接下來的步驟中，您將對指派給 Apache ZooKeeper 節點的所有網路界面一個接一個執行相同的操作。

1. 當您選取與 Apache ZooKeeper 節點對應的網路界面時，請選擇頁面頂端的 **Actions (動作)** 功能表，然後選擇 **Change Security Groups (變更安全群組)**。將新的安全群組指派至此網路界面。如需有關建立安全群組的詳細資訊，請參閱 Amazon VPC 文件中的[建立安全群組](https://docs.aws.amazon.com/vpc/latest/userguide/VPC_SecurityGroups.html?shortFooter=true#CreatingSecurityGroups)。

1. 重複上述步驟，將相同的新安全群組指派給與叢集 Apache ZooKeeper 節點相關聯的所有網路界面。

1. 您現在可以選擇可存取此全新安全群組的人員。如需有關設定安全群組規則的資訊，請參閱 Amazon VPC 文件中的[新增、移除和更新規則](https://docs.aws.amazon.com/vpc/latest/userguide/VPC_SecurityGroups.html?shortFooter=true#AddRemoveRules)。

# 搭配 Apache ZooKeeper 使用 TLS 安全功能
<a name="zookeeper-security-tls"></a>

您可以使用 TLS 安全功能加密用戶端與 Apache ZooKeeper 節點之間的傳輸。要搭配 Apache ZooKeeper 節點使用 TLS 安全功能，請執行以下操作：
+ 叢集必須使用 Apache Kafka 2.5.1 版或更高版本以搭配 Apache ZooKeeper 使用 TLS 安全功能。
+ 建立或設定叢集時啟用 TLS 安全功能。使用 Apache Kafka version 2.5.1 版或更高版本建立，且啟用 TLS 的叢集，會自動搭配 Apache ZooKeeper 端點使用 TLS 安全功能。如需有關 TLS 安全功能設定的資訊，請參閱 [開始使用 Amazon MSK 加密](msk-working-with-encryption.md)。
+ 使用 [DescribeCluste ](https://docs.aws.amazon.com/msk/1.0/apireference/clusters-clusterarn.html#DescribeCluster) 操作擷取 TLS Apache ZooKeeper 端點。
+ 建立 Apache ZooKeeper 組態檔案，以搭配 `kafka-configs.sh` 和 [https://kafka.apache.org/documentation/#security_authz_cli](https://kafka.apache.org/documentation/#security_authz_cli) 工具使用，或搭配 ZooKeeper Shell 使用。搭配各個工具，您可以使用 `--zk-tls-config-file` 參數來指定您的 Apache ZooKeeper 組態。

  以下範例顯示了一個典型的 Apache ZooKeeper 組態檔案：

  ```
  zookeeper.ssl.client.enable=true
  zookeeper.clientCnxnSocket=org.apache.zookeeper.ClientCnxnSocketNetty
  zookeeper.ssl.keystore.location=kafka.jks
  zookeeper.ssl.keystore.password=test1234
  zookeeper.ssl.truststore.location=truststore.jks
  zookeeper.ssl.truststore.password=test1234
  ```
+ 對於其他命令 (如 `kafka-topics`)，您必須使用 `KAFKA_OPTS` 環境變量來設定 Apache ZooKeeper 參數。以下範例演示了如何設定 `KAFKA_OPTS` 環境變量來將 Apache ZooKeeper 參數傳遞到其他命令：

  ```
  export KAFKA_OPTS="
  -Dzookeeper.clientCnxnSocket=org.apache.zookeeper.ClientCnxnSocketNetty 
  -Dzookeeper.client.secure=true 
  -Dzookeeper.ssl.trustStore.location=/home/ec2-user/kafka.client.truststore.jks
  -Dzookeeper.ssl.trustStore.password=changeit"
  ```

  設定 `KAFKA_OPTS` 環境變數之後，就可以正常使用 CLI 命令。以下範例使用來自 `KAFKA_OPTS` 環境變量的 Apache ZooKeeper 組態建立 Apache Kafka 主題：

  ```
  <path-to-your-kafka-installation>/bin/kafka-topics.sh --create --zookeeper ZooKeeperTLSConnectString --replication-factor 3 --partitions 1 --topic AWSKafkaTutorialTopic
  ```

**注意**  
您在 Apache ZooKeeper 組態檔案中使用的參數名稱，與您在 `KAFKA_OPTS` 環境變量中使用的參數不一致。請注意您在組態檔案和 `KAFKA_OPTS` 環境變量中使用了哪些參數名稱。

如需有關透過 TLS 存取 Apache ZooKeeper 節點的詳細資訊，請參閱 [ KIP-515: Enable ZK client to use the new TLS supported authentication](https://cwiki.apache.org/confluence/display/KAFKA/KIP-515%3A+Enable+ZK+client+to+use+the+new+TLS+supported+authentication)。