-
Notifications
You must be signed in to change notification settings - Fork 100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Script to generate Kafka keystores for SSL #955
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e | ||
|
||
echo "Enter CA cert path:" | ||
read CA_CERT_PATH | ||
|
||
echo "Enter CA key path:" | ||
read CA_KEY_PATH | ||
|
||
echo "Set Keystore password:" | ||
read KEYSTORE_PASS | ||
|
||
if [ ! -e "$CA_CERT_PATH" ] || [ ! -e "$CA_KEY_PATH" ]; then | ||
echo "CA does not exist, please provide the corrrect paths in CA_CERT_PATH and CA_KEY_PATH" | ||
exit 1 | ||
fi | ||
|
||
if [ -z "$KEYSTORE_PASS" ]; then | ||
echo "Please provide a keystore password in KEYSTORE_PASS" | ||
exit 1 | ||
fi | ||
|
||
# Generate truststore containing CA | ||
keytool -keystore ./kafka.truststore.jks \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where does There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
-alias CARoot -import -file $CA_CERT_PATH \ | ||
-noprompt -dname "CN=kafka" -keypass $KEYSTORE_PASS -storepass $KEYSTORE_PASS | ||
|
||
# Generate keystore | ||
keytool -keystore ./kafka.keystore.jks \ | ||
-alias kafka -validity 365 -genkey -keyalg RSA \ | ||
-noprompt -dname "CN=kafka" -keypass $KEYSTORE_PASS -storepass $KEYSTORE_PASS | ||
|
||
# Create certificate signing request to keystore | ||
keytool -keystore ./kafka.keystore.jks -alias kafka \ | ||
-certreq -file cert-sign-req -keypass $KEYSTORE_PASS -storepass $KEYSTORE_PASS | ||
|
||
# Sign keystore's certificate using CA key | ||
openssl x509 -req -CA $CA_CERT_PATH -CAkey $CA_KEY_PATH \ | ||
-in ./cert-sign-req -out cert-sign \ | ||
-days 365 -CAcreateserial | ||
|
||
# Import CA into keystore | ||
keytool -keystore ./kafka.keystore.jks -alias CARoot \ | ||
-import -file $CA_CERT_PATH -keypass $KEYSTORE_PASS -storepass $KEYSTORE_PASS -noprompt | ||
|
||
# Import signed certificate back into keystore | ||
keytool -keystore ./kafka.keystore.jks -alias kafka -import \ | ||
-file ./cert-sign -keypass $KEYSTORE_PASS -storepass $KEYSTORE_PASS | ||
|
||
echo "Truststore and keystore have been successfully created" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For security reasons we may want to read the password from STDIN.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated the script to now use
read