Skip to content

Commit

Permalink
[#234] Use TLS for connecting to Kafka.
Browse files Browse the repository at this point in the history
New certificates are created for the example Kafka broker. The broker
is configured to expect TLS encrypted connections from clients. The
truststore is added to all services and adapters that need to connect
to Kafka. This is currently a "jks" file because in Kafka the support for
the "pem" format was added in version 2.7 and Hono currently uses the
Kafka clients in version 2.6.

Signed-off-by: Abel Buechner-Mihaljevic <[email protected]>
  • Loading branch information
b-abel committed May 25, 2021
1 parent bbc3e66 commit ac4fa72
Show file tree
Hide file tree
Showing 18 changed files with 93 additions and 9 deletions.
7 changes: 7 additions & 0 deletions charts/hono/example/ca_opts
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,10 @@ subjectKeyIdentifier = hash
keyUsage = keyAgreement,keyEncipherment,digitalSignature
extendedKeyUsage = serverAuth, clientAuth
subjectAltName = DNS.1:localhost

[ req_ext_kafka ]

subjectKeyIdentifier = hash
keyUsage = keyAgreement,keyEncipherment,digitalSignature
extendedKeyUsage = serverAuth, clientAuth
subjectAltName = DNS.1:*.eclipse-hono-kafka-headless,DNS.2:*.eclipse-hono-kafka-headless.hono,DNS.3:*.eclipse-hono-kafka-headless.hono.svc.cluster.local,DNS.4:localhost
29 changes: 29 additions & 0 deletions charts/hono/example/certs/kafka-cert.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
-----BEGIN CERTIFICATE-----
MIIChjCCAiygAwIBAgIUOrdAF96Bl8S68x9iLGpXTUkHZX4wCgYIKoZIzj0EAwIw
UDELMAkGA1UEBhMCQ0ExDzANBgNVBAcMBk90dGF3YTEUMBIGA1UECgwLRWNsaXBz
ZSBJb1QxDTALBgNVBAsMBEhvbm8xCzAJBgNVBAMMAmNhMB4XDTIxMDUyNTEzMDEx
OFoXDTIyMDUyNTEzMDExOFowUzELMAkGA1UEBhMCQ0ExDzANBgNVBAcMBk90dGF3
YTEUMBIGA1UECgwLRWNsaXBzZSBJb1QxDTALBgNVBAsMBEhvbm8xDjAMBgNVBAMM
BWthZmthM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4EFgQUBxIgSnCFs43mB6a9umhpKCA2I30wDwYDVR0TAQH/BAUw
AwEB/zALBgNVHQ8EBAMCAQYwCgYIKoZIzj0EAwIDSAAwRQIgRau0yW4JCG+2e3w5
KFWzCYV20/DNJ2Lj5ospGvNhl9sCIQCYde5228wNvKT3Qw6vk70HiS5r/mhFNJaZ
aPyf7W2E4g==
-----END CERTIFICATE-----
5 changes: 5 additions & 0 deletions charts/hono/example/certs/kafka-key.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-----BEGIN PRIVATE KEY-----
MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgDl9XTUixhhdRyYXM
T+3yickHXeaQwTkCDn3KeaSJI2qhRANCAASYeE00TykWRX+8cry7d6k1gLGy0bKz
VXiorXfX5OrypBByLIHgGVJ3mWEcJO9kqU8CB8Pck7VqOgkUoRzeRDva
-----END PRIVATE KEY-----
Binary file added charts/hono/example/certs/kafkaKeyStore.jks
Binary file not shown.
4 changes: 4 additions & 0 deletions charts/hono/example/create_certs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ AMQP_ADAPTER_KEY_STORE=amqpKeyStore.p12
AMQP_ADAPTER_KEY_STORE_PWD=amqpkeys
EXAMPLE_GATEWAY_KEY_STORE=exampleGatewayKeyStore.p12
EXAMPLE_GATEWAY_KEY_STORE_PWD=examplegatewaykeys
KAFKA_KEY_STORE=kafkaKeyStore.jks
# the bitnami Kafka chart expects truststore and keystore to have the same name
KAFKA_KEY_STORE_PWD=honotrust
# set to either EC or RSA
KEY_ALG=EC

Expand Down Expand Up @@ -141,5 +144,6 @@ create_cert artemis $ARTEMIS_KEY_STORE $ARTEMIS_KEY_STORE_PWD
create_cert coap-adapter $COAP_ADAPTER_KEY_STORE $COAP_ADAPTER_KEY_STORE_PWD
create_cert amqp-adapter $AMQP_ADAPTER_KEY_STORE $AMQP_ADAPTER_KEY_STORE_PWD
create_cert example-gateway $EXAMPLE_GATEWAY_KEY_STORE $EXAMPLE_GATEWAY_KEY_STORE_PWD
create_cert kafka $KAFKA_KEY_STORE $KAFKA_KEY_STORE_PWD

create_client_cert 4711
4 changes: 3 additions & 1 deletion charts/hono/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,11 @@ kafka:
{{- if .dot.Values.kafkaMessagingClusterExample.enabled }}
commonClientConfig:
bootstrap.servers: {{ .dot.Release.Name }}-{{ .dot.Values.kafka.nameOverride }}-0.{{ .dot.Release.Name }}-{{ .dot.Values.kafka.nameOverride }}-headless.{{ .dot.Release.Namespace }}:{{ .dot.Values.kafka.service.port }}
security.protocol: SASL_PLAINTEXT
security.protocol: SASL_SSL
sasl.mechanism: SCRAM-SHA-512
sasl.jaas.config: "org.apache.kafka.common.security.scram.ScramLoginModule required username=\"{{ first .dot.Values.kafka.auth.sasl.jaas.clientUsers }}\" password=\"{{ first .dot.Values.kafka.auth.sasl.jaas.clientPasswords }}\";"
ssl.truststore.location: /etc/hono/truststore.jks
ssl.truststore.password: honotrust
{{- else if not .dot.Values.adapters.kafkaMessagingSpec.commonClientConfig.bootstrap.servers }}
{{- required ".Values.adapters.kafkaMessagingSpec.commonClientConfig.bootstrap.servers MUST be set if example Kafka cluster is disabled" nil }}
{{- end }}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{{- if .Values.adapters.amqp.enabled }}
#
# Copyright (c) 2019, 2020 Contributors to the Eclipse Foundation
# Copyright (c) 2019, 2021 Contributors to the Eclipse Foundation
#
# See the NOTICE file(s) distributed with this work for additional
# information regarding copyright ownership.
Expand Down Expand Up @@ -41,4 +41,5 @@ data:
cert.pem: {{ .Files.Get "example/certs/amqp-adapter-cert.pem" | b64enc }}
trusted-certs.pem: {{ .Files.Get "example/certs/trusted-certs.pem" | b64enc }}
adapter.credentials: {{ .Files.Get "example/amqp-adapter.credentials" | b64enc }}
{{- end }}
truststore.jks: {{ .Files.Get "example/certs/trustStore.jks" | b64enc }}
{{- end }}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{{- if .Values.adapters.coap.enabled }}
#
# Copyright (c) 2019, 2020 Contributors to the Eclipse Foundation
# Copyright (c) 2019, 2021 Contributors to the Eclipse Foundation
#
# See the NOTICE file(s) distributed with this work for additional
# information regarding copyright ownership.
Expand Down Expand Up @@ -38,4 +38,5 @@ data:
cert.pem: {{ .Files.Get "example/certs/coap-adapter-cert.pem" | b64enc }}
trusted-certs.pem: {{ .Files.Get "example/certs/trusted-certs.pem" | b64enc }}
adapter.credentials: {{ .Files.Get "example/coap-adapter.credentials" | b64enc }}
truststore.jks: {{ .Files.Get "example/certs/trustStore.jks" | b64enc }}
{{- end }}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{{- if .Values.adapters.http.enabled }}
#
# Copyright (c) 2019, 2020 Contributors to the Eclipse Foundation
# Copyright (c) 2019, 2021 Contributors to the Eclipse Foundation
#
# See the NOTICE file(s) distributed with this work for additional
# information regarding copyright ownership.
Expand Down Expand Up @@ -41,4 +41,5 @@ data:
cert.pem: {{ .Files.Get "example/certs/http-adapter-cert.pem" | b64enc }}
trusted-certs.pem: {{ .Files.Get "example/certs/trusted-certs.pem" | b64enc }}
adapter.credentials: {{ .Files.Get "example/http-adapter.credentials" | b64enc }}
truststore.jks: {{ .Files.Get "example/certs/trustStore.jks" | b64enc }}
{{- end }}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{{- if .Values.adapters.kura.enabled }}
#
# Copyright (c) 2019, 2020 Contributors to the Eclipse Foundation
# Copyright (c) 2019, 2021 Contributors to the Eclipse Foundation
#
# See the NOTICE file(s) distributed with this work for additional
# information regarding copyright ownership.
Expand Down Expand Up @@ -40,4 +40,5 @@ data:
cert.pem: {{ .Files.Get "example/certs/kura-adapter-cert.pem" | b64enc }}
trusted-certs.pem: {{ .Files.Get "example/certs/trusted-certs.pem" | b64enc }}
adapter.credentials: {{ .Files.Get "example/kura-adapter.credentials" | b64enc }}
truststore.jks: {{ .Files.Get "example/certs/trustStore.jks" | b64enc }}
{{- end }}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{{- if .Values.adapters.lora.enabled }}
#
# Copyright (c) 2019, 2020 Contributors to the Eclipse Foundation
# Copyright (c) 2019, 2021 Contributors to the Eclipse Foundation
#
# See the NOTICE file(s) distributed with this work for additional
# information regarding copyright ownership.
Expand Down Expand Up @@ -40,4 +40,5 @@ data:
cert.pem: {{ .Files.Get "example/certs/lora-adapter-cert.pem" | b64enc }}
trusted-certs.pem: {{ .Files.Get "example/certs/trusted-certs.pem" | b64enc }}
adapter.credentials: {{ .Files.Get "example/lora-adapter.credentials" | b64enc }}
truststore.jks: {{ .Files.Get "example/certs/trustStore.jks" | b64enc }}
{{- end }}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{{- if .Values.adapters.mqtt.enabled }}
#
# Copyright (c) 2019, 2020 Contributors to the Eclipse Foundation
# Copyright (c) 2019, 2021 Contributors to the Eclipse Foundation
#
# See the NOTICE file(s) distributed with this work for additional
# information regarding copyright ownership.
Expand Down Expand Up @@ -45,4 +45,5 @@ data:
cert.pem: {{ .Files.Get "example/certs/mqtt-adapter-cert.pem" | b64enc }}
trusted-certs.pem: {{ .Files.Get "example/certs/trusted-certs.pem" | b64enc }}
adapter.credentials: {{ .Files.Get "example/mqtt-adapter.credentials" | b64enc }}
truststore.jks: {{ .Files.Get "example/certs/trustStore.jks" | b64enc }}
{{- end }}
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,5 @@ data:
trusted-certs.pem: {{ .Files.Get "example/certs/trusted-certs.pem" | b64enc }}
auth-server-cert.pem: {{ .Files.Get "example/certs/auth-server-cert.pem" | b64enc }}
adapter.credentials: {{ .Files.Get "example/command-router.credentials" | b64enc }}
truststore.jks: {{ .Files.Get "example/certs/trustStore.jks" | b64enc }}
{{- end }}
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,5 @@ data:
cert.pem: {{ .Files.Get "example/certs/device-registry-cert.pem" | b64enc }}
trusted-certs.pem: {{ .Files.Get "example/certs/trusted-certs.pem" | b64enc }}
auth-server-cert.pem: {{ .Files.Get "example/certs/auth-server-cert.pem" | b64enc }}
truststore.jks: {{ .Files.Get "example/certs/trustStore.jks" | b64enc }}
{{- end }}
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,5 @@ data:
cert.pem: {{ .Files.Get "example/certs/device-registry-cert.pem" | b64enc }}
trusted-certs.pem: {{ .Files.Get "example/certs/trusted-certs.pem" | b64enc }}
auth-server-cert.pem: {{ .Files.Get "example/certs/auth-server-cert.pem" | b64enc }}
truststore.jks: {{ .Files.Get "example/certs/trustStore.jks" | b64enc }}
{{- end }}
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,5 @@ data:
cert.pem: {{ .Files.Get "example/certs/device-registry-cert.pem" | b64enc }}
trusted-certs.pem: {{ .Files.Get "example/certs/trusted-certs.pem" | b64enc }}
auth-server-cert.pem: {{ .Files.Get "example/certs/auth-server-cert.pem" | b64enc }}
truststore.jks: {{ .Files.Get "example/certs/trustStore.jks" | b64enc }}
{{- end }}
23 changes: 23 additions & 0 deletions charts/hono/templates/kafka/kafka-secret.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{{- if .Values.kafkaMessagingClusterExample.enabled }}
#
# Copyright (c) 2021 Contributors to the Eclipse Foundation
#
# See the NOTICE file(s) distributed with this work for additional
# information regarding copyright ownership.
#
# This program and the accompanying materials are made available under the
# terms of the Eclipse Public License 2.0 which is available at
# http://www.eclipse.org/legal/epl-2.0
#
# SPDX-License-Identifier: EPL-2.0
#
apiVersion: v1
kind: Secret
metadata:
{{- $args := dict "dot" . "component" "kafka" "name" "kafka-jks" }}
{{- include "hono.metadata" $args | nindent 2 }}
type: Opaque
data:
"kafka.truststore.jks": {{ .Files.Get "example/certs/trustStore.jks" | b64enc }}
"kafka-0.keystore.jks": {{ .Files.Get "example/certs/kafkaKeyStore.jks" | b64enc }}
{{- end }}
6 changes: 5 additions & 1 deletion charts/hono/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1778,7 +1778,7 @@ kafka:
service:
port: 9092
auth:
clientProtocol: sasl
clientProtocol: sasl_tls
sasl:
jaas:
clientUsers:
Expand All @@ -1787,3 +1787,7 @@ kafka:
- "hono-secret"
zookeeperUser: zookeeperUser
zookeeperPassword: zookeeperPassword
tls:
type: jks
existingSecret: "{{ .Release.Name }}-kafka-jks"
password: honotrust

0 comments on commit ac4fa72

Please sign in to comment.