0Pricing
Advanced Spring Boot 4: Event-Driven Architecture (Kafka) · บทเรียน

การกำหนดสิทธิ์ด้วย ACL

นำรายการควบคุมการเข้าถึง (ACL) มาใช้กับโบรกเกอร์ Kafka เพื่อกำหนดสิทธิ์อย่างละเอียดสำหรับผู้ผลิตและผู้ใช้

การกำหนดสิทธิ์ด้วย ACL เป็นบทเรียน Advanced Spring Boot 4: Event-Driven Architecture (Kafka) ฟรีบน CoddyKit นี่คือบทเรียนที่ 2 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Advanced Spring Boot 4: Event-Driven Architecture (Kafka) และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Advanced Spring Boot 4: Event-Driven Architecture (Kafka) มีบทเรียนทั้งหมด 4 บทเรียน

บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ

What are Kafka ACLs?

In our last lesson, we learned about authenticating with Kafka using SASL. But authentication just verifies who you are.

Authorization determines what you are allowed to do. This is where Access Control Lists (ACLs) come in.

Kafka ACLs provide fine-grained permissions, letting you control which users (or principals) can perform specific actions on Kafka resources.

The Core of Kafka Authorization

Authorization in Kafka revolves around three key concepts:

  • Principal: The authenticated user or client attempting an action (e.g., User:Alice, User:ProducerApp).
  • Operation: The action being attempted (e.g., READ, WRITE, CREATE, DELETE).
  • Resource: The Kafka entity the operation is performed on (e.g., a specific topic, a consumer group).

ACLs define which principals can perform which operations on which resources.

Different Types of Kafka Resources

Kafka allows you to set permissions on several types of resources:

  • Topic: For producing messages to or consuming from specific topics.
  • Group: For managing consumer group memberships and offset commits.
  • Cluster: For cluster-wide operations like describing brokers or creating topics.
  • TransactionalId: For using Kafka transactions.
  • DelegationToken: For managing delegation tokens (advanced).

Most common are Topic, Group, and Cluster resources.

ACL Syntax with `kafka-acls.sh`

ACLs are typically managed using the kafka-acls.sh command-line tool. You'll specify the principal, operation, and resource.

Here's a basic structure:

kafka-acls.sh --authorizer-properties ... \ --add --allow-principal 'User:Alice' \ --operation Read --topic 'my-topic'

This grants User:Alice permission to Read from my-topic.

ACLs for a Kafka Producer

A Kafka producer needs permissions to:

  • Write messages: To a specific topic.
  • Describe the cluster: To discover broker metadata.

Example commands to grant these permissions for a producer named User:ProducerApp on topic orders:

kafka-acls.sh --add --allow-principal 'User:ProducerApp' --operation Write --topic 'orders' --authorizer-properties ... kafka-acls.sh --add --allow-principal 'User:ProducerApp' --operation Describe --cluster --authorizer-properties ...

Spring Producer & ACLs

This Spring Boot producer sends a message to my-secured-topic. For it to work, the principal associated with this application (e.g., User:my-producer via SASL) must have the necessary ACLs configured on the Kafka broker.

Specifically, it needs WRITE permission on the topic and DESCRIBE permission on the cluster resource.

import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.context.annotation.Bean;

@SpringBootApplication
public class KafkaProducerAclApp {

    public static void main(String[] args) {
        SpringApplication.run(KafkaProducerAclApp.class, args);
    }

    @Bean
    public CommandLineRunner runner(KafkaTemplate<String, String> kafkaTemplate) {
        return args -> {
            String topic = "my-secured-topic";
            String message = "Hello from secured producer!";
            kafkaTemplate.send(topic, message);
            System.out.println("Sent message: '" + message + "' to topic: '" + topic + "'");
            System.out.println("Check Kafka broker logs for successful message receipt.");
        };
    }
}

ACLs for a Kafka Consumer

A Kafka consumer needs permissions to:

  • Read messages: From a specific topic.
  • Read from its consumer group: To manage offsets and join the group.
  • Describe the cluster: Like producers, for metadata.

Example commands for User:ConsumerApp on topic payments and group payment-processors:

kafka-acls.sh --add --allow-principal 'User:ConsumerApp' --operation Read --topic 'payments' --authorizer-properties ... kafka-acls.sh --add --allow-principal 'User:ConsumerApp' --operation Read --group 'payment-processors' --authorizer-properties ... kafka-acls.sh --add --allow-principal 'User:ConsumerApp' --operation Describe --cluster --authorizer-properties ...

Spring Consumer & ACLs

This Spring Boot consumer listens to my-secured-topic as part of my-secured-group. Its associated principal (e.g., User:my-consumer) needs specific ACLs.

It requires READ permission on the topic, READ permission on the consumer group, and DESCRIBE permission on the cluster resource.

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.kafka.annotation.KafkaListener;

@SpringBootApplication
public class KafkaConsumerAclApp {

    public static void main(String[] args) {
        SpringApplication.run(KafkaConsumerAclApp.class, args);
    }

    @KafkaListener(topics = "my-secured-topic", groupId = "my-secured-group")
    public void listen(String message) {
        System.out.println("Received secured message: " + message);
    }
}

Listing & Revoking ACLs

It's important to manage ACLs effectively. You can list all ACLs or specific ones:

kafka-acls.sh --list --topic 'my-topic' --authorizer-properties ...

To remove an ACL, use the --remove flag instead of --add, specifying the exact ACL you wish to revoke:

kafka-acls.sh --remove --allow-principal 'User:Alice' --operation Read --topic 'my-topic' --authorizer-properties ...

Regularly review and remove unnecessary permissions for security best practices.

ACLs Quick Check

Which of the following permissions are typically required for a Kafka consumer to successfully read messages from a topic and join a consumer group?

Recap: Securing with ACLs

Great job! You've learned how Kafka's authorization works using Access Control Lists (ACLs).

  • ACLs define who (principal) can do what (operation) on where (resource).
  • Key resources include topics, consumer groups, and the cluster itself.
  • You use kafka-acls.sh to manage these permissions on the broker.
  • Spring Boot Kafka applications implicitly rely on these ACLs being in place for their authenticated principals.

Next, we'll explore how to encrypt data in transit using SSL/TLS.

คำถามที่พบบ่อย

บทเรียน “การกำหนดสิทธิ์ด้วย ACL” ฟรีหรือไม่

ใช่ — ข้อความเต็มของ “การกำหนดสิทธิ์ด้วย ACL” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Advanced Spring Boot 4: Event-Driven Architecture (Kafka) ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Advanced Spring Boot 4: Event-Driven Architecture (Kafka) มีบทเรียนทั้งหมด 4 บทเรียน

คุณจะเรียนรู้อะไรในบทเรียน “การกำหนดสิทธิ์ด้วย ACL”

นำรายการควบคุมการเข้าถึง (ACL) มาใช้กับโบรกเกอร์ Kafka เพื่อกำหนดสิทธิ์อย่างละเอียดสำหรับผู้ผลิตและผู้ใช้ คุณปฏิบัติ Advanced Spring Boot 4: Event-Driven Architecture (Kafka) ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน

คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Advanced Spring Boot 4: Event-Driven Architecture (Kafka) หรือไม่

ไม่จำเป็นต้องมีประสบการณ์มาก่อน Advanced Spring Boot 4: Event-Driven Architecture (Kafka) บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 2 จากทั้งหมด 4 บทเรียน

บทเรียน “การกำหนดสิทธิ์ด้วย ACL” ใช้เวลานานแค่ไหน

บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย

ฉันเขียนและรันโค้ดในบทเรียน Advanced Spring Boot 4: Event-Driven Architecture (Kafka) นี้ได้ไหม

ได้ บทเรียน Advanced Spring Boot 4: Event-Driven Architecture (Kafka) ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ

บทเรียนทั้งหมดในหลักสูตรนี้

  1. การตรวจสอบสิทธิ์ด้วย SASL
  2. การกำหนดสิทธิ์ด้วย ACL
  3. การเข้ารหัสด้วย SSL/TLS
  4. การตรวจสอบและรักษาความปลอดภัยการเข้าถึง Schema Registry
← กลับไปที่ Advanced Spring Boot 4: Event-Driven Architecture (Kafka)