# AWS MSK 安全設定 ## Zookeeper 安全設定 ### 問題: 如何不讓任何一台VM,都可以存取Zookeeper** #### **解決方法:** 1. 把 zookeeper 的 ENI 安全群組使用獨立群組,並設置特定IP才能存取 2. 使用 TLS 進行資料傳輸加密-沒有控制存取(選用) **參考網址:** https://docs.aws.amazon.com/zh_tw/msk/latest/developerguide/zookeeper-security.html ## Kafka ACLs 存取設定(不要讓 Clinet Consumer 亂搞) ### 1. 先去 AWS MSK Console 把 server.properties 設定成以下格式: 新增 <font color="#f00">allow.everyone.if.no.acl.found=false</font> 以啟用 ACLs 控制清單 ``` auto.create.topics.enable=false default.replication.factor=3 min.insync.replicas=2 num.io.threads=8 num.network.threads=5 num.partitions=1 num.replica.fetchers=2 replica.lag.time.max.ms=30000 socket.receive.buffer.bytes=102400 socket.request.max.bytes=104857600 socket.send.buffer.bytes=102400 unclean.leader.election.enable=true zookeeper.session.timeout.ms=18000 allow.everyone.if.no.acl.found=false ``` ### 2. 請先在客戶端安裝 Kafka ##### (我們需要用到 Kafka 裡面內建的 sh檔案,因為我們無法直接進入 AWS MSK 主機內部) ``` sudo yum -y install java-11 wget https://archive.apache.org/dist/kafka/{YOUR MSK VERSION}/kafka_2.13-{YOUR MSK VERSION}.tgz tar -xzf kafka_2.13-{YOUR MSK VERSION}.tgz ``` ### 3. 設置範例 **CN=Distinguished-Name換成 SASL username** **EX: User:teddy610** #### 3.1 為某 SASL 使用者名稱啟用所有權限(可以操作任何 group 與 topic) ``` <path-to-your-kafka-installation>/bin/kafka-acls.sh --authorizer-properties zookeeper.connect=ZooKeeper-Connection-String --add --allow-principal "User:CN=Distinguished-Name" --operation All --group=* --topic=* ``` #### 3.2 對該使用者啟用所有 group 與 Topic 讀取權限 ``` <path-to-your-kafka-installation>/bin/kafka-acls.sh --authorizer-properties zookeeper.connect=ZooKeeper-Connection-String --add --allow-principal "User:CN=Distinguished-Name" --operation Read --group=* --topic=* ``` #### 3.3 對該使用者啟用所有Topic 寫入權限 ``` <path-to-your-kafka-installation>/bin/kafka-acls.sh --authorizer-properties zookeeper.connect=ZooKeeper-Connection-String --add --allow-principal "User:CN=Distinguished-Name" --operation Write --topic=* ``` #### 3.4 指定該使用者只能使用 groupid: test1 與 Topic: test1 的讀取權限 ``` <path-to-your-kafka-installation>/bin/kafka-acls.sh --authorizer-properties zookeeper.connect=ZooKeeper-Connection-String --add --allow-principal "User:CN=Distinguished-Name" --operation Read --group=test1 --topic=test1 ``` #### 3.5 查看該使用者 teddy 當前擁有權限 ``` <path-to-your-kafka-installation>/bin/kafka-acls.sh --authorizer-properties zookeeper.connect=ZooKeeper-Connection-String --list --principal User:teddy ``` #### 3.6 刪除使用者teddy 的寫入權限 ``` <path-to-your-kafka-installation>/bin/kafka-acls.sh --authorizer-properties zookeeper.connect=ZooKeeper-Connection-String --remove --allow-principal "User:teddy" --operation Write --topic=* ``` 參考網址: 1. https://docs.aws.amazon.com/zh_tw/msk/latest/developerguide/msk-authentication.html 2. https://cwiki.apache.org/confluence/display/KAFKA/Kafka+Authorization+Command+Line+Interface#KafkaAuthorizationCommandLineInterface-AddingAcls
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up