I have a perfectly working Filebeat 5.0.0-alpha5 and Kafka 0.10 setup. They reside in different physical servers, each as a Docker container.
I am trying to set them up to use SSL(TLS) instead of PLAINTEXT.
I am just testing it for now so I don't have any previous certificates/CAs and am creating everything now for my development environment.
I started by following Apache's documentation about how to set up TLS for Kafka.
Basically it amounted to this bash script:
#!/bin/bash
PASSWORD=test1234
VALIDITY=365
keytool -keystore kafka.server.keystore.jks -alias localhost -validity $VALIDITY -genkey
openssl req -new -x509 -keyout ca-key -out ca-cert -days $VALIDITY
keytool -keystore kafka.server.truststore.jks -alias CARoot -import -file ca-cert
keytool -keystore kafka.client.truststore.jks -alias CARoot -import -file ca-cert
keytool -keystore kafka.server.keystore.jks -alias localhost -certreq -file cert-file
openssl x509 -req -CA ca-cert -CAkey ca-key -in cert-file -out cert-signed -days $VALIDITY -CAcreateserial -passin pass:$PASSWORD
keytool -keystore kafka.server.keystore.jks -alias CARoot -import -file ca-cert
keytool -keystore kafka.server.keystore.jks -alias localhost -import -file cert-signed
keytool -keystore kafka.client.keystore.jks -alias localhost -validity $VALIDITY -genkey
keytool -keystore kafka.client.keystore.jks -alias localhost -certreq -file cert-file
openssl x509 -req -CA ca-cert -CAkey ca-key -in cert-file -out cert-signed -days $VALIDITY -CAcreateserial -passin pass:$PASSWORD
keytool -keystore kafka.client.keystore.jks -alias CARoot -import -file ca-cert
keytool -keystore kafka.client.keystore.jks -alias localhost -import -file cert-signed
Which produced the following files:
ca-cert
ca-cert.srl
ca-key
cert-file
cert-signed
kafka.client.keystore.jks
kafka.client.truststore.jks
kafka.server.keystore.jks
kafka.server.truststore.jks
After setting up Kafka's config files and restarting it, everything seems to be working fine.
Now begins the part where I am unsure of what I'm doing.
I know that Filebeats' TLS settings requires these 3 entries:
tls.certificate_authorities: ["file"]
tls.certificate: "file"
tls.certificate_key: "file"
I tried to identify my files and match them, and guessed that ca-cert is for tls.certificate_authorities and cert_signed is for tls.certificate. Is this correct?
This is how they look:
ca_cert:
-----BEGIN CERTIFICATE-----
...
-----END CERTIFICATE-----
cert_signed:
-----BEGIN CERTIFICATE-----
...
-----END CERTIFICATE-----
Now I tried to extract the private key from kafka.client.keystore.jks by saving it as a p12 file:
keytool -importkeystore -srckeystore kafka.client.keystore.jks -destkeystore kafka.client.keystore.p12 -deststoretype PKCS12 -srcalias localhost -deststorepass test1234 -destkeypass test1234
openssl pkcs12 -in kafka.client.keystore.p12 -nodes -nocerts -out key.pem
key.pem:
Bag Attributes
friendlyName: localhost
localKeyID: SOME HEX
Key Attributes: <No Attributes>
-----BEGIN PRIVATE KEY-----
...
-----END PRIVATE KEY-----
Now that I have all the files, I copied them to the Filebeat server and tried to start it with these settings under the Kafka output section:
tls.certificate_authorities: ["/ssl/ca-cert"]
tls.certificate: "/ssl/cert-signed"
tls.certificate_key: "/ssl/key.pem"
But then Filebeat exits instantly with this error:
filebeat_1 | 2016/08/31 16:02:41.276236 beat.go:263: INFO Home path: [/] Config path: [/] Data path: [//data] Logs path: [//logs]
filebeat_1 | 2016/08/31 16:02:41.284449 beat.go:174: INFO Setup Beat: filebeat; Version: 5.0.0-alpha5
filebeat_1 | 2016/08/31 16:02:41.284464 processor.go:42: DBG Processors:
filebeat_1 | 2016/08/31 16:02:41.284470 beat.go:180: DBG Initializing output plugins
filebeat_1 | 2016/08/31 16:02:41.284494 kafka.go:67: DBG initialize kafka output
filebeat_1 | 2016/08/31 16:02:41.287109 tls.go:98: CRIT Failed loading client certificate%!(EXTRA *errors.errorString=crypto/tls: failed to parse private key)
filebeat_1 | 2016/08/31 16:02:41.287123 outputs.go:81: ERR failed to initialize kafka plugin as output: crypto/tls: failed to parse private key
filebeat_1 | 2016/08/31 16:02:41.287129 beat.go:284: CRIT Exiting: error initializing publisher: crypto/tls: failed to parse private key
filebeat_1 | Exiting: error initializing publisher: crypto/tls: failed to parse private key
I also tried to crop the 'header' of the pem file to make it look like this:
-----BEGIN PRIVATE KEY-----
...
-----END PRIVATE KEY-----
Still no cigar.
What am I missing here?
I would appreciate any help at this point, thanks!