Security & Production
ไอเดียในหนึ่งประโยค
หัวข้อที่มีชื่อว่า “ไอเดียในหนึ่งประโยค”การทำ Kafka ให้ปลอดภัยคือสามชั้นซ้อนกัน encryption in transit ด้วย TLS, authentication ด้วย SASL หรือ mTLS เพื่อพิสูจน์ว่า client เป็นใคร และ authorization ด้วย ACL เพื่อคุมว่า client นั้นทำอะไรได้ ทั้งหมดวางอยู่บน cluster ที่ตั้งค่าให้ durable
encryption และ authentication
หัวข้อที่มีชื่อว่า “encryption และ authentication”โดย default listener ของ Kafka พูด plaintext สำหรับ production คุณเปิด TLS/SSL เพื่อให้ traffic ระหว่าง client กับ broker และระหว่าง broker ด้วยกันเอง ถูก encrypt ระหว่างส่ง เหนือขึ้นไปคุณเพิ่ม authentication เพื่อให้ broker รู้ว่าใครกำลังเชื่อมต่อ Kafka รองรับ SASL mechanism หลายแบบบวกกับ mutual TLS
- SASL/SCRAM salted challenge-response โดยเก็บ credential ไว้ใน cluster เป็นตัวเลือกที่นิยมและ self-contained
- SASL/PLAIN username กับ password ปลอดภัยเฉพาะ บน TLS
- SASL/OAUTHBEARER OAuth 2.0 bearer token สำหรับ integrate กับ identity provider
- mTLS TLS certificate ของ client เองคือ identity จึงไม่ต้องมี password แยก
# Broker listener using TLS for encryption + SASL/SCRAM for authenticationlisteners=SASL_SSL://:9093security.inter.broker.protocol=SASL_SSLsasl.enabled.mechanisms=SCRAM-SHA-256ssl.keystore.location=/etc/kafka/broker.keystore.jksssl.truststore.location=/etc/kafka/broker.truststore.jksauthorization ด้วย ACL
หัวข้อที่มีชื่อว่า “authorization ด้วย ACL”authentication พิสูจน์ identity ส่วน authorization ตัดสินว่า identity นั้นทำอะไรได้ authorizer ของ Kafka เช็ค ACL กฎอย่าง “user analytics Read topic orders ได้” คุณจัดการ ACL ด้วย kafka-acls.sh โดยใช้ --bootstrap-server เสมอ
# Allow user "analytics" to consume from topic "orders"kafka-acls.sh --bootstrap-server localhost:9092 \ --add --allow-principal User:analytics \ --operation Read --topic orders --group analytics-group
# Allow user "order-service" to produce to topic "orders"kafka-acls.sh --bootstrap-server localhost:9092 \ --add --allow-principal User:order-service \ --operation Write --topic ordersflowchart LR client["Client"] -->|"TLS: encrypt in transit"| enc["Encryption"] enc -->|"SASL / mTLS: who are you"| authn["Authentication"] authn -->|"ACLs: what may you do"| authz["Authorization"] authz --> broker["Broker serves the request"]
checklist ความพร้อม production
หัวข้อที่มีชื่อว่า “checklist ความพร้อม production”security เป็นเพียงคอลัมน์หนึ่งของความพร้อม production durability กับ observability คือคอลัมน์ที่เหลือ ก่อน cluster รับ traffic จริง ยืนยันว่า
- replication factor >= 3 บน topic สำคัญ เพื่อให้เสีย broker ได้สองตัวโดยไม่สูญข้อมูล
min.insync.replicas=2คู่กับacks=allการเขียนต้องการ in-sync replica อย่างน้อยสองตัว คือคอมโบ production ที่ durable- TLS ทุกที่, SASL หรือ mTLS authentication และ ACL ล็อกแต่ละ principal ให้ least privilege
- monitoring และ alerting บน consumer lag, under-replicated partition และ request latency
- quota เพื่อกัน client ตัวเดียวที่ทำตัวไม่ดีไม่ให้แย่ง bandwidth หรือ request ของทั้ง cluster
# Durable topic-level defaults for productiondefault.replication.factor=3min.insync.replicas=2# and producers set acks=all