الأمان: المصادقة والتفويض
نفّذ تدابير الأمان الأساسية في Kafka، بما في ذلك مصادقة العملاء وتفويض الوصول إلى البيانات
الأمان: المصادقة والتفويض درس مجاني في Apache Kafka & Stream Processing Fundamentals على CoddyKit. هذا هو الدرس 3 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Apache Kafka & Stream Processing Fundamentals، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Apache Kafka & Stream Processing Fundamentals 4 دروس في المجموع.
بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.
Why Secure Kafka?
In today's data-driven world, securing your data is paramount. Kafka, often the backbone for critical data streams, needs robust security measures.
Without security, sensitive information could be exposed, data integrity compromised, and compliance regulations violated. This lesson covers the fundamental ways to protect your Kafka cluster.
Authentication: Who Are You?
Authentication is the process of verifying the identity of a client (like a producer or consumer) trying to connect to a Kafka broker.
Think of it like showing your ID at an airport. Kafka needs to confirm that you are who you claim to be before allowing any interaction. This prevents unauthorized users from even connecting.
Authorization: What Can You Do?
Once a client is authenticated (their identity is confirmed), authorization determines what actions they are permitted to perform.
This is like having a boarding pass after showing your ID. The pass dictates which gate you can access and which flight you can board. Kafka uses authorization to control access to specific topics, consumer groups, and other resources.
Kafka's Security Toolkit
Kafka offers several mechanisms to implement both authentication and authorization:
- Authentication: Primarily handled by SASL (Simple Authentication and Security Layer) or SSL/TLS.
- Authorization: Managed through Access Control Lists (ACLs), which define permissions for authenticated users on specific resources.
These layers work together to create a secure data streaming environment.
SASL/PLAIN Broker Setup
SASL (Simple Authentication and Security Layer) provides a framework for authentication. One common mechanism is SASL/PLAIN, which uses a simple username and password.
To enable SASL/PLAIN on a Kafka broker, you need to add security configurations to its server.properties file. Here's a basic example:
# server.properties
listeners=PLAINTEXT://:9092,SASL_PLAINTEXT://:9093
sasl.enabled.mechanisms=PLAIN
sasl.mechanism.inter.broker.protocol=PLAIN
authorizer.class.name=kafka.security.auth.SimpleAclAuthorizer
supers.users=User:admin
listener.name.sasl_plaintext.plain.sasl.jaas.config=
org.apache.kafka.common.security.plain.PlainLoginModule required
username="admin" password="admin-secret";
Client Authentication with SASL/PLAIN
Once the broker is configured for SASL/PLAIN, clients (producers or consumers) must provide valid credentials to connect. You specify these details in the client's configuration.
Try running this simple Java producer example, configured to use SASL/PLAIN:
import org.apache.kafka.clients.producer.*;
import java.util.Properties;
public class SecureProducer {
public static void main(String[] args) {
Properties props = new Properties();
props.put("bootstrap.servers", "localhost:9093");
props.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");
props.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer");
// SASL_PLAINTEXT configuration
props.put("security.protocol", "SASL_PLAINTEXT");
props.put("sasl.mechanism", "PLAIN");
props.put("sasl.jaas.config",
"org.apache.kafka.common.security.plain.PlainLoginModule required " +
"username=\"admin\" password=\"admin-secret\";");
Producer<String, String> producer = new KafkaProducer<>(props);
try {
for (int i = 0; i < 5; i++) {
String message = "Hello Secure Kafka " + i;
producer.send(new ProducerRecord<>("my-secure-topic", "key" + i, message));
System.out.println("Sent: " + message);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
producer.close();
}
}
}Authorization with Access Control Lists
After a client authenticates, Kafka uses Access Control Lists (ACLs) to decide if they are authorized to perform a specific action on a resource.
An ACL is a rule that specifies who (a user principal), from where (host), can do what (operation like READ, WRITE), on which resource (topic, group, broker).
Managing ACLs with the CLI
Kafka provides a command-line tool, kafka-acls.sh, to manage ACLs. You can grant or revoke permissions for users on various Kafka resources.
Here are some common commands:
- Grant write access to a topic:
kafka-acls.sh --authorizer-properties authorizer.properties --add --allow-principal User:admin --producer --topic my-secure-topic - Grant read access to a consumer group:
kafka-acls.sh --authorizer-properties authorizer.properties --add --allow-principal User:consumerUser --consumer --group my-group - List all ACLs:
kafka-acls.sh --authorizer-properties authorizer.properties --list --topic my-secure-topic
Security Checkpoint
You've learned about the fundamental security concepts in Kafka. Let's test your understanding!
Which of the following best describes the purpose of Authorization in Kafka?
Secure Streams: A Summary
Great job! You've covered the essentials of Kafka security.
- Authentication verifies who a client is (e.g., via SASL/PLAIN).
- Authorization determines what an authenticated client can do (e.g., via ACLs).
- Implementing these measures protects your data streams from unauthorized access and ensures data integrity.
Securing your Kafka cluster is a critical step for any production deployment!
الأسئلة الشائعة
هل درس «الأمان: المصادقة والتفويض» مجاني؟
نعم — نص درس «الأمان: المصادقة والتفويض» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Apache Kafka & Stream Processing Fundamentals، انتقل إلى CoddyKit PRO. تتضمن دورة Apache Kafka & Stream Processing Fundamentals 4 دروس في المجموع.
ماذا ستتعلم في «الأمان: المصادقة والتفويض»؟
نفّذ تدابير الأمان الأساسية في Kafka، بما في ذلك مصادقة العملاء وتفويض الوصول إلى البيانات تتمرن على Apache Kafka & Stream Processing Fundamentals مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ Apache Kafka & Stream Processing Fundamentals؟
لا تُشترط خبرة سابقة. Apache Kafka & Stream Processing Fundamentals على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 3 من أصل 4.
كم من الوقت يستغرق درس «الأمان: المصادقة والتفويض»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس Apache Kafka & Stream Processing Fundamentals هذا؟
نعم. كل درس في Apache Kafka & Stream Processing Fundamentals يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- أدوات سطر الأوامر لـ Kafka
- مراقبة Kafka باستخدام JMX والأدوات
- الأمان: المصادقة والتفويض
- تتبّع تأخر المستهلكين والتنبيه