Last active
June 4, 2021 15:02
-
-
Save osowski/d536d42dd90b9a854737ef90f74d7792 to your computer and use it in GitHub Desktop.
Kafka Security Article #2 Snippets - TLS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bootstrap.servers=kafka.{kubernetes-cluster-fully-qualified-domain-name}:443 | |
security.protocol=SSL | |
ssl.truststore.location={/provided/to/you/by/kafka/administrator} | |
ssl.truststore.password={__provided_to_you_by_kafka_administrator__} | |
ssl.keystore.location={/generated/in/coordination/with/kafka/adminstrator} | |
ssl.keystore.password={__generated_in_coordination_with_kafka_administrator__} | |
ssl.key.password={__generated_in_coordination_with_kafka_administrator__} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bootstrap.servers=kafka.{namespace}.svc.cluster.local:9071 | |
security.protocol=SSL | |
ssl.truststore.location={/provided/to/you/by/kafka/administrator} | |
ssl.truststore.password={__provided_to_you_by_kafka_administrator__} | |
ssl.keystore.location={/generated/in/coordination/with/kafka/adminstrator} | |
ssl.keystore.password={__generated_in_coordination_with_kafka_administrator__} | |
ssl.key.password={__generated_in_coordination_with_kafka_administrator__} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
listeners: | |
- name: plain | |
port: 9092 | |
type: internal | |
tls: false | |
- name: tls | |
port: 9093 | |
type: internal | |
tls: true | |
- name: external | |
port: 9094 | |
type: route | |
tls: true | |
authentication: | |
type: tls |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
curl https://archive.apache.org/dist/kafka/2.6.1/kafka_2.13-2.6.1.tgz -o kafka.tgz | |
tar xvf kafka.tgz | |
cd kafka_2.13-2.6.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
oc project kafka-security |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export BOOTSTRAP="$(oc get route my-cluster-kafka-bootstrap -ojsonpath='{.spec.host}'):443" | |
export CONFIG_FILE=local-config-tls.properties | |
export CACERT_DIR=cacert-blog | |
export KAFKAUSER_DIR=my-user-blog |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rm -f ${CONFIG_FILE} | |
echo "security.protocol=SSL" >> ${CONFIG_FILE} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rm -rf ${CACERT_DIR} | |
mkdir ${CACERT_DIR} | |
oc extract secret/my-cluster-cluster-ca-cert --to=./${CACERT_DIR} | |
echo "ssl.truststore.location=$(pwd)/${CACERT_DIR}/ca.p12" >> ${CONFIG_FILE} | |
echo "ssl.truststore.password=$(cat ${CACERT_DIR}/ca.password)" >> ${CONFIG_FILE} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rm -rf ${KAFKAUSER_DIR} | |
mkdir ${KAFKAUSER_DIR} | |
oc extract secret/my-user --to=./${KAFKAUSER_DIR} | |
echo "ssl.keystore.location=$(pwd)/${KAFKAUSER_DIR}/user.p12" >> ${CONFIG_FILE} | |
echo "ssl.keystore.password=$(cat ${KAFKAUSER_DIR}/user.password)" >> ${CONFIG_FILE} | |
echo "ssl.key.password=$(cat ${KAFKAUSER_DIR}/user.password)" >> ${CONFIG_FILE} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bin/kafka-topics.sh --bootstrap-server ${BOOTSTRAP} \ | |
--command-config ${CONFIG_FILE} --list |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bin/kafka-console-producer.sh --bootstrap-server ${BOOTSTRAP} \ | |
--producer.config ${CONFIG_FILE} --topic my-topic |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bin/kafka-console-consumer.sh --bootstrap-server ${BOOTSTRAP} \ | |
--consumer.config ${CONFIG_FILE} --topic my-topic --from-beginning |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
curl https://archive.apache.org/dist/kafka/2.6.1/kafka_2.13-2.6.1.tgz -o kafka.tgz | |
tar xvf kafka.tgz | |
cd kafka_2.13-2.6.1 | |
oc project kafka-security | |
export BOOTSTRAP="$(oc get route my-cluster-kafka-bootstrap -ojsonpath='{.spec.host}'):443" | |
export CONFIG_FILE=local-config-tls.properties | |
export CACERT_DIR=cacert-blog | |
export KAFKAUSER_DIR=my-user-blog | |
rm -f ${CONFIG_FILE} | |
echo "security.protocol=SSL" >> ${CONFIG_FILE} | |
rm -rf ${CACERT_DIR} | |
mkdir ${CACERT_DIR} | |
oc extract secret/my-cluster-cluster-ca-cert --to=./${CACERT_DIR} | |
echo "ssl.truststore.location=$(pwd)/${CACERT_DIR}/ca.p12" >> ${CONFIG_FILE} | |
echo "ssl.truststore.password=$(cat ${CACERT_DIR}/ca.password)" >> ${CONFIG_FILE} | |
rm -rf ${KAFKAUSER_DIR} | |
mkdir ${KAFKAUSER_DIR} | |
oc extract secret/my-user --to=./${KAFKAUSER_DIR} | |
echo "ssl.keystore.location=$(pwd)/${KAFKAUSER_DIR}/user.p12" >> ${CONFIG_FILE} | |
echo "ssl.keystore.password=$(cat ${KAFKAUSER_DIR}/user.password)" >> ${CONFIG_FILE} | |
echo "ssl.key.password=$(cat ${KAFKAUSER_DIR}/user.password)" >> ${CONFIG_FILE} | |
bin/kafka-topics.sh --bootstrap-server ${BOOTSTRAP} \ | |
--command-config ${CONFIG_FILE} --list | |
bin/kafka-console-producer.sh --bootstrap-server ${BOOTSTRAP} \ | |
--producer.config ${CONFIG_FILE} --topic my-topic | |
bin/kafka-console-consumer.sh --bootstrap-server ${BOOTSTRAP} \ | |
--consumer.config ${CONFIG_FILE} --topic my-topic --from-beginning |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
keytool -exportcert -keypass {truststore-password} \ | |
-keystore {provided-kafka-truststore.jks} \ | |
-rfc -file {desired-kafka-cert-output.pem} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bootstrap.servers={kafka-cluster-name}-kafka-bootstrap-{namespace}.{kubernetes-cluster-fully-qualified-domain-name}:443 | |
security.protocol=SSL | |
ssl.truststore.location={/provided/to/you/by/kafka/administrator} | |
ssl.truststore.password={__provided_to_you_by_kafka_administrator__} | |
ssl.keystore.location={/extracted/from/generated/kafka/user/secret}/user.p12 | |
ssl.keystore.password={__extracted_from_generated_kafka_user_secret_with_key=user.password__} | |
ssl.key.password={__extracted_from_generated_kafka_user_secret_with_key=user.password__} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bootstrap.servers={kafka-cluster-name}-kafka-bootstrap.{namespace}.svc.cluster.local:9093 | |
security.protocol=SSL | |
ssl.truststore.location={/provided/to/you/by/kafka/administrator} | |
ssl.truststore.password={__provided_to_you_by_kafka_administrator__} | |
ssl.keystore.location={/extracted/from/generated/kafka/user/secret}/user.p12 | |
ssl.keystore.password={__extracted_from_generated_kafka_user_secret_with_key=user.password__} | |
ssl.key.password={__extracted_from_generated_kafka_user_secret_with_key=user.password__} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment