-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathentry.sh
More file actions
executable file
·93 lines (88 loc) · 2.26 KB
/
Copy pathentry.sh
File metadata and controls
executable file
·93 lines (88 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/usr/bin/env sh
set -e
## Parse args
PORT=9092
LISTENER=kafka
for i in $@; do case $i in
-port=*) PORT="${i#-port=}"; ;;
-listener=*) LISTENER="${i#-listener=}"; ;;
-principal=*) PRINCIPAL="${i#-principal=}"; ;;
-keytab=*) KEYTAB="${i#-keytab=}"; ;;
-kdc=*) KDC="${i#-kdc=}"; ;;
-silent) SILENT=1; ;;
esac; done
## Generate configs
cp /kafka/config/server.properties.original /tmp/server.properties
KAFKA_PROPS=/tmp/server.properties
echo >> $KAFKA_PROPS
## SASL_PLAINTEXT security
if [ "$PRINCIPAL" ] && [ "$KEYTAB" ] && [ "$KDC" ]; then
## Extract realm and name form PRINCIPAL
PRINCIPAL_REALM=${PRINCIPAL#*@}
PRINCIPAL_NAME=${PRINCIPAL%/*}
## Inject path to JAAS into KAFKA_OPTS
KAFKA_JAAS=/kafka/config/kafka.jaas
sed -i '16iKAFKA_OPTS="-Djava.security.auth.login.config=/kafka/config/kafka.jaas"' /kafka/bin/kafka-run-class.sh
## Generate JAAS
cat >$KAFKA_JAAS <<EOF
KafkaServer {
com.sun.security.auth.module.Krb5LoginModule required
useKeyTab=true
storeKey=true
useTicketCache=true
keyTab="$KEYTAB"
principal="$PRINCIPAL";
};
KafkaClient {
com.sun.security.auth.module.Krb5LoginModule required
useKeyTab=true
keyTab="$KEYTAB"
principal="$PRINCIPAL";
};
EOF
## Generate krb5.conf
cat >/etc/krb5.conf <<EOF
[libdefaults]
default_realm = $PRINCIPAL_REALM
rdns = false
[realms]
$PRINCIPAL_REALM = {
kdc = $KDC
rdns = false
}
[domain_realm]
realm = $PRINCIPAL_REALM
[logging]
kdc = CONSOLE
EOF
## Kafka server
cat >>$KAFKA_PROPS <<EOF
listeners=SASL_PLAINTEXT://:$PORT
advertised.listeners=SASL_PLAINTEXT://$LISTENER:$PORT
inter.broker.listener.name=SASL_PLAINTEXT
sasl.kerberos.service.name=$PRINCIPAL_NAME
allow.everyone.if.no.acl.found=true
controlled.shutdown.enable=false
EOF
## PLAINTEXT security
else
cat >>$KAFKA_PROPS <<EOF
listeners=PLAINTEXT://:$PORT
advertised.listeners=PLAINTEXT://$LISTENER:$PORT
controlled.shutdown.enable=false
EOF
fi
## Decrease verbosity
if [ "$SILENT" ]; then
cat >>/kafka/config/log4j.properties <<EOF
log4j.rootLogger=WARN, stdout
log4j.logger.kafka=WARN
log4j.logger.org.apache.kafka=WARN
log4j.logger.org.apache.zookeeper=WARN
log4j.logger.org.I0Itec.zkclient.ZkClient=WARN
EOF
fi
## Start Zookepeer
zookeeper-server-start.sh -daemon /kafka/config/zookeeper.properties
## Start Kafka
exec kafka-server-start.sh $KAFKA_PROPS