Skip to content

Commit 878f10f

Browse files
committed
added acls from yaml
1 parent aaba090 commit 878f10f

File tree

6 files changed

+83
-10
lines changed

6 files changed

+83
-10
lines changed

README.adoc

+10-1
Original file line numberDiff line numberDiff line change
@@ -3910,7 +3910,16 @@ docker exec -it broker /opt/kafka/bin/kafka-console-producer.sh --broker-list br
39103910
org.apache.kafka.common.errors.TopicAuthorizationException: Not authorized to access topics: [test]
39113911
----
39123912

3913-
Set topic read and topic write ACLs on topic _test_ for user _alice_:
3913+
Set topic read and topic write ACLs on topic _test_ for user _alice_; you have 2 options:
3914+
3915+
1. Run script run-acl.sh:
3916+
3917+
[source,bash]
3918+
----
3919+
docker exec broker sh -c "chmod +x /tmp/run-acl.sh && /tmp/run-acl.sh"
3920+
----
3921+
3922+
2. Run kafka acls cli:
39143923

39153924
[source,bash]
39163925
----

acls/config/acl-config.yaml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name: "Alice Topic Access"
2+
action: --add
3+
allow_principal: User:alice
4+
operations:
5+
- WRITE
6+
- READ
7+
8+
resource_pattern_type: literal
9+
10+
topics:
11+
- test
12+

acls/config/run-acl.sh

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/bin/bash
2+
3+
ACL_FILE=/tmp/acl-config.yaml
4+
5+
# Parse simple key-value pairs from YAML
6+
NAME=$(grep 'name:' $ACL_FILE | sed 's/.*: //')
7+
ACTION=$(grep 'action:' $ACL_FILE | sed 's/.*: //')
8+
ALLOW_PRINCIPAL=$(grep 'allow_principal:' $ACL_FILE | sed 's/.*: //')
9+
TRANSACTIONAL_ID=$(grep 'transactional_id:' $ACL_FILE| sed 's/.*: //')
10+
RESOURCE_PATTERN_TYPE=$(grep 'resource_pattern_type:' $ACL_FILE | sed 's/.*: //')
11+
12+
# Extract and clean operations (remove '-' and trim spaces)
13+
OPERATIONS=()
14+
while IFS= read -r line; do
15+
op=$(echo "$line" | sed -E 's/^\s*-\s*//' | xargs) # Remove '- ' and trim whitespace
16+
[[ -n "$op" ]] && OPERATIONS+=("$op") # Add only if non-empty
17+
done < <(awk '/operations:/ {flag=1; next} /^[^ ]/ {flag=0} flag' $ACL_FILE)
18+
19+
# Extract and clean topics (remove '-' and trim spaces)
20+
TOPICS=()
21+
while IFS= read -r line; do
22+
topic=$(echo "$line" | sed -E 's/^\s*-\s*//' | xargs) # Remove '- ' and trim whitespace
23+
[[ -n "$topic" ]] && TOPICS+=("$topic") # Add only if non-empty
24+
done < <(awk '/topics:/ {flag=1; next} /^[^ ]/ {flag=0} flag' $ACL_FILE)
25+
26+
# Display the ACL name for better logging
27+
echo "Running ACL Setup: $NAME"
28+
29+
# Loop through each topic and apply ACLs
30+
for topic in "${TOPICS[@]}"; do
31+
# Construct the base command
32+
CMD="/opt/kafka/bin/kafka-acls.sh --bootstrap-server broker:9092 --command-config /tmp/admin.properties $ACTION --allow-principal \"$ALLOW_PRINCIPAL\""
33+
34+
# Add each operation correctly
35+
for op in "${OPERATIONS[@]}"; do
36+
CMD+=" --operation $op"
37+
done
38+
39+
# Add the topic and resource pattern type
40+
CMD+=" --topic $topic"
41+
CMD+=" --resource-pattern-type $RESOURCE_PATTERN_TYPE"
42+
43+
# Include transactional ID if provided
44+
if [[ -n "$TRANSACTIONAL_ID" ]]; then
45+
CMD+=" --transactional-id $TRANSACTIONAL_ID"
46+
fi
47+
48+
# Print and execute the command
49+
echo "Executing: $CMD"
50+
eval "$CMD"
51+
done

acls/docker-compose.yml

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
---
2-
version: '2'
3-
42
services:
53

64
broker:
@@ -12,6 +10,9 @@ services:
1210
volumes:
1311
- ./config/alice.properties:/tmp/alice.properties
1412
- ./config/admin.properties:/tmp/admin.properties
13+
- ./config/admin.properties:/tmp/admin.properties
14+
- ./config/acl-config.yaml:/tmp/acl-config.yaml
15+
- ./config/run-acl.sh:/tmp/run-acl.sh
1516
environment:
1617
KAFKA_NODE_ID: 1
1718
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: CONTROLLER:PLAINTEXT,AUTH:SASL_PLAINTEXT,INTERNAL:PLAINTEXT

confluent-for-kubernetes/k8s/confluent-platform-reducted.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ metadata:
77
spec:
88
dataVolumeCapacity: 1G
99
image:
10-
application: docker.io/confluentinc/cp-kafka:7.8.0
10+
application: docker.io/confluentinc/cp-kafka:7.8.1
1111
init: confluentinc/confluent-init-container:2.10.0
1212
replicas: 1
1313
---
@@ -19,7 +19,7 @@ metadata:
1919
spec:
2020
replicas: 3
2121
image:
22-
application: confluentinc/cp-kafka:7.8.0
22+
application: confluentinc/cp-kafka:7.8.1
2323
init: confluentinc/confluent-init-container:2.10.0
2424
dataVolumeCapacity: 1Gi
2525
dependencies:

confluent-for-kubernetes/k8s/confluent-platform.yaml

+5-5
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ metadata:
77
spec:
88
dataVolumeCapacity: 1G
99
image:
10-
application: docker.io/confluentinc/cp-kafka:7.8.0
10+
application: docker.io/confluentinc/cp-kafka:7.8.1
1111
init: confluentinc/confluent-init-container:2.10.0
1212
replicas: 1
1313
---
@@ -19,7 +19,7 @@ metadata:
1919
spec:
2020
replicas: 3
2121
image:
22-
application: confluentinc/cp-kafka:7.8.0
22+
application: confluentinc/cp-kafka:7.8.1
2323
init: confluentinc/confluent-init-container:2.10.0
2424
dataVolumeCapacity: 1Gi
2525
dependencies:
@@ -37,7 +37,7 @@ metadata:
3737
spec:
3838
replicas: 1
3939
image:
40-
application: confluentinc/cp-kafka-connect-base:7.8.0
40+
application: confluentinc/cp-kafka-connect-base:7.8.1
4141
init: confluentinc/confluent-init-container:2.10.0
4242
dependencies:
4343
kafka:
@@ -63,7 +63,7 @@ metadata:
6363
spec:
6464
replicas: 1
6565
image:
66-
application: confluentinc/cp-schema-registry:7.8.0
66+
application: confluentinc/cp-schema-registry:7.8.1
6767
init: confluentinc/confluent-init-container:2.10.0
6868
---
6969
apiVersion: platform.confluent.io/v1beta1
@@ -76,6 +76,6 @@ spec:
7676
schemaRegistry:
7777
url: http://schemaregistry.confluent.svc.cluster.local:8081
7878
image:
79-
application: confluentinc/cp-kafka-rest:7.8.0
79+
application: confluentinc/cp-kafka-rest:7.8.1
8080
init: confluentinc/confluent-init-container:2.10.0
8181
replicas: 1

0 commit comments

Comments
 (0)