-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add `security_protocol`, `sasl_mechanism`, `sasl_plain_username` and `sasl_plain_password` arguments like aiokafka.AIOKafkaConsumer client. Support SASL_PLAINTEXT and SASL_SSL security protocol. Support and test SASL PLAIN mechanism with both PLAINTEXT and SSL connections. A self-signed certificate is used for SSL connections. Signed-off-by: Julien Riou <[email protected]>
- Loading branch information
Showing
10 changed files
with
203 additions
and
11 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ansible |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
KafkaServer { | ||
org.apache.kafka.common.security.plain.PlainLoginModule required | ||
username="test" | ||
password="test"; | ||
}; | ||
Client{}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/usr/bin/env bash | ||
set -e | ||
DIR=$(dirname "${BASH_SOURCE[0]}") | ||
rm -f "${DIR}/snakeoil-ca.key" \ | ||
"${DIR}/snakeoil-ca.crt" \ | ||
"${DIR}/broker.csr" \ | ||
"${DIR}/broker-ca-signed.crt" \ | ||
"${DIR}/kafka.broker.keystore.jks" \ | ||
"${DIR}/kafka.broker.truststore.jks" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#!/usr/bin/env bash | ||
# Generate self-signed certificate for Kafka broker | ||
# Greatly inspired by https://github.com/ansibleinc/cp-demo/blob/master/scripts/security/certs-create-per-user.sh | ||
set -e | ||
|
||
CA_PATH=$(dirname "${BASH_SOURCE[0]}") | ||
|
||
# Generate CA | ||
openssl req -new -x509 -keyout snakeoil-ca.key -out snakeoil-ca.crt -days 365 -subj '/CN=snakeoil.ansible.com/OU=TEST/O=ANSIBLE/L=Boston/ST=MA/C=US' -passin pass:ansible -passout pass:ansible | ||
|
||
# Create broker keystore | ||
keytool -genkey -noprompt \ | ||
-alias broker \ | ||
-dname "CN=broker,OU=TEST,O=ANSIBLE,L=Boston,S=MA,C=US" \ | ||
-ext "SAN=dns:broker,dns:localhost" \ | ||
-keystore kafka.broker.keystore.jks \ | ||
-keyalg RSA \ | ||
-storepass ansible \ | ||
-keypass ansible \ | ||
-storetype pkcs12 | ||
|
||
# Create broker CSR | ||
keytool -keystore kafka.broker.keystore.jks -alias broker -certreq -file broker.csr -storepass ansible -keypass ansible -ext "SAN=dns:broker,dns:localhost" | ||
|
||
# Sign the host certificate with the certificate authority (CA) | ||
# Set a random serial number (avoid problems from using '-CAcreateserial' when parallelizing certificate generation) | ||
CERT_SERIAL=$(awk -v seed="$RANDOM" 'BEGIN { srand(seed); printf("0x%.4x%.4x%.4x%.4x\n", rand()*65535 + 1, rand()*65535 + 1, rand()*65535 + 1, rand()*65535 + 1) }') | ||
openssl x509 -req -CA "${CA_PATH}/snakeoil-ca.crt" -CAkey "${CA_PATH}/snakeoil-ca.key" -in broker.csr -out broker-ca-signed.crt -sha256 -days 365 -set_serial "${CERT_SERIAL}" -passin pass:ansible -extensions v3_req -extfile <(cat <<EOF | ||
[req] | ||
distinguished_name = req_distinguished_name | ||
x509_extensions = v3_req | ||
prompt = no | ||
[req_distinguished_name] | ||
CN = broker | ||
[v3_req] | ||
extendedKeyUsage = serverAuth, clientAuth | ||
EOF | ||
) | ||
|
||
# Sign and import the CA cert into the keystore | ||
keytool -noprompt -keystore kafka.broker.keystore.jks -alias snakeoil-caroot -import -file "${CA_PATH}/snakeoil-ca.crt" -storepass ansible -keypass ansible | ||
|
||
# Sign and import the host certificate into the keystore | ||
keytool -noprompt -keystore kafka.broker.keystore.jks -alias broker -import -file broker-ca-signed.crt -storepass ansible -keypass ansible -ext "SAN=dns:broker,dns:localhost" | ||
|
||
# Create truststore and import the CA cert | ||
keytool -noprompt -keystore kafka.broker.truststore.jks -alias snakeoil-caroot -import -file "${CA_PATH}/snakeoil-ca.crt" -storepass ansible -keypass ansible |
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
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
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
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