Skip to content

Commit 2d16ffe

Browse files
authored
Use PEM files directly as ZooKeeper keystore and truststore (#613)
1 parent fdcfe60 commit 2d16ffe

File tree

12 files changed

+116
-474
lines changed

12 files changed

+116
-474
lines changed

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ It includes support for:
160160
- [x] Broker
161161
- [x] Toolset
162162
- [x] Bookie
163-
- [x] ZooKeeper
163+
- [x] ZooKeeper (requires the `AdditionalCertificateOutputFormats=true` feature gate to be enabled in the cert-manager deployment when using cert-manager versions below 1.15.0)
164164
- [x] Authentication
165165
- [x] JWT
166166
- [x] OpenID
@@ -402,6 +402,15 @@ helm upgrade -n <namespace> -f values.yaml <pulsar-release-name> apachepulsar/pu
402402

403403
For more detailed information, see our [Upgrading](http://pulsar.apache.org/docs/helm-upgrade/) guide.
404404

405+
## Upgrading to Helm chart version 4.2.0 (not released yet)
406+
407+
### TLS configuration for ZooKeeper has changed
408+
409+
The TLS configuration for ZooKeeper has been changed to fix certificate and private key expiration issues.
410+
This change impacts configurations that have `tls.enabled` and `tls.zookeeper.enabled` set in `values.yaml`.
411+
The revised solution requires the `AdditionalCertificateOutputFormats=true` feature gate to be enabled in the `cert-manager` deployment when using cert-manager versions below 1.15.0.
412+
If you installed `cert-manager` using `./scripts/cert-manager/install-cert-manager.sh`, you can re-run the updated script to set the feature gate. The script currently installs or upgrades cert-manager LTS version 1.12.17, where the feature gate must be explicitly enabled.
413+
405414
## Upgrading from Helm Chart versions before 4.0.0 to 4.0.0 version and above
406415

407416
### Pulsar Proxy service's default type has been changed from `LoadBalancer` to `ClusterIP`

charts/pulsar/templates/_autorecovery.tpl

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Define autorecovery zookeeper client tls settings
3636
*/}}
3737
{{- define "pulsar.autorecovery.zookeeper.tls.settings" -}}
3838
{{- if and .Values.tls.enabled .Values.tls.zookeeper.enabled }}
39-
/pulsar/keytool/keytool.sh autorecovery {{ template "pulsar.autorecovery.hostname" . }} true;
39+
{{- include "pulsar.component.zookeeper.tls.settings" (dict "component" "autorecovery" "isClient" true) -}}
4040
{{- end }}
4141
{{- end }}
4242

@@ -51,11 +51,6 @@ Define autorecovery tls certs mounts
5151
- name: ca
5252
mountPath: "/pulsar/certs/ca"
5353
readOnly: true
54-
{{- if .Values.tls.zookeeper.enabled }}
55-
- name: keytool
56-
mountPath: "/pulsar/keytool/keytool.sh"
57-
subPath: keytool.sh
58-
{{- end }}
5954
{{- end }}
6055
{{- end }}
6156

@@ -72,18 +67,14 @@ Define autorecovery tls certs volumes
7267
path: tls.crt
7368
- key: tls.key
7469
path: tls.key
70+
- key: tls-combined.pem
71+
path: tls-combined.pem
7572
- name: ca
7673
secret:
7774
secretName: "{{ template "pulsar.certs.issuers.ca.secretName" . }}"
7875
items:
7976
- key: ca.crt
8077
path: ca.crt
81-
{{- if .Values.tls.zookeeper.enabled }}
82-
- name: keytool
83-
configMap:
84-
name: "{{ template "pulsar.fullname" . }}-keytool-configmap"
85-
defaultMode: 0755
86-
{{- end }}
8778
{{- end }}
8879
{{- end }}
8980

@@ -93,7 +84,7 @@ Define autorecovery init container : verify cluster id
9384
{{- define "pulsar.autorecovery.init.verify_cluster_id" -}}
9485
bin/apply-config-from-env.py conf/bookkeeper.conf;
9586
export BOOKIE_MEM="-Xmx128M";
96-
{{- include "pulsar.autorecovery.zookeeper.tls.settings" . -}}
87+
{{- include "pulsar.autorecovery.zookeeper.tls.settings" . }}
9788
until timeout 15 bin/bookkeeper shell whatisinstanceid; do
9889
sleep 3;
9990
done;

charts/pulsar/templates/_bookkeeper.tpl

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Define bookie zookeeper client tls settings
3737
*/}}
3838
{{- define "pulsar.bookkeeper.zookeeper.tls.settings" -}}
3939
{{- if and .Values.tls.enabled .Values.tls.zookeeper.enabled }}
40-
/pulsar/keytool/keytool.sh bookie {{ template "pulsar.bookkeeper.hostname" . }} true;
40+
{{- include "pulsar.component.zookeeper.tls.settings" (dict "component" "bookie" "isClient" true) -}}
4141
{{- end }}
4242
{{- end }}
4343

@@ -52,11 +52,6 @@ Define bookie tls certs mounts
5252
- name: ca
5353
mountPath: "/pulsar/certs/ca"
5454
readOnly: true
55-
{{- if .Values.tls.zookeeper.enabled }}
56-
- name: keytool
57-
mountPath: "/pulsar/keytool/keytool.sh"
58-
subPath: keytool.sh
59-
{{- end }}
6055
{{- end }}
6156
{{- end }}
6257

@@ -73,18 +68,16 @@ Define bookie tls certs volumes
7368
path: tls.crt
7469
- key: tls.key
7570
path: tls.key
71+
{{- if .Values.tls.zookeeper.enabled }}
72+
- key: tls-combined.pem
73+
path: tls-combined.pem
74+
{{- end }}
7675
- name: ca
7776
secret:
7877
secretName: "{{ template "pulsar.certs.issuers.ca.secretName" . }}"
7978
items:
8079
- key: ca.crt
8180
path: ca.crt
82-
{{- if .Values.tls.zookeeper.enabled }}
83-
- name: keytool
84-
configMap:
85-
name: "{{ template "pulsar.fullname" . }}-keytool-configmap"
86-
defaultMode: 0755
87-
{{- end }}
8881
{{- end }}
8982
{{- end }}
9083

@@ -147,7 +140,7 @@ Define bookie init container : verify cluster id
147140
{{- if not (and .Values.volumes.persistence .Values.bookkeeper.volumes.persistence) }}
148141
bin/apply-config-from-env.py conf/bookkeeper.conf;
149142
export BOOKIE_MEM="-Xmx128M";
150-
{{- include "pulsar.bookkeeper.zookeeper.tls.settings" . -}}
143+
{{- include "pulsar.bookkeeper.zookeeper.tls.settings" . }}
151144
until timeout 15 bin/bookkeeper shell whatisinstanceid; do
152145
sleep 3;
153146
done;
@@ -157,7 +150,7 @@ bin/bookkeeper shell bookieformat -nonInteractive -force -deleteCookie || true
157150
set -e;
158151
bin/apply-config-from-env.py conf/bookkeeper.conf;
159152
export BOOKIE_MEM="-Xmx128M";
160-
{{- include "pulsar.bookkeeper.zookeeper.tls.settings" . -}}
153+
{{- include "pulsar.bookkeeper.zookeeper.tls.settings" . }}
161154
until timeout 15 bin/bookkeeper shell whatisinstanceid; do
162155
sleep 3;
163156
done;

charts/pulsar/templates/_broker.tpl

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Define broker zookeeper client tls settings
4343
*/}}
4444
{{- define "pulsar.broker.zookeeper.tls.settings" -}}
4545
{{- if and .Values.tls.enabled .Values.tls.zookeeper.enabled }}
46-
/pulsar/keytool/keytool.sh broker {{ template "pulsar.broker.hostname" . }} true;
46+
{{- include "pulsar.component.zookeeper.tls.settings" (dict "component" "broker" "isClient" true) -}}
4747
{{- end }}
4848
{{- end }}
4949

@@ -58,11 +58,6 @@ Define broker tls certs mounts
5858
- name: ca
5959
mountPath: "/pulsar/certs/ca"
6060
readOnly: true
61-
{{- if .Values.tls.zookeeper.enabled }}
62-
- name: keytool
63-
mountPath: "/pulsar/keytool/keytool.sh"
64-
subPath: keytool.sh
65-
{{- end }}
6661
{{- end }}
6762
{{- end }}
6863

@@ -79,17 +74,15 @@ Define broker tls certs volumes
7974
path: tls.crt
8075
- key: tls.key
8176
path: tls.key
77+
{{- if .Values.tls.zookeeper.enabled }}
78+
- key: tls-combined.pem
79+
path: tls-combined.pem
80+
{{- end }}
8281
- name: ca
8382
secret:
8483
secretName: "{{ template "pulsar.certs.issuers.ca.secretName" . }}"
8584
items:
8685
- key: ca.crt
8786
path: ca.crt
88-
{{- if .Values.tls.zookeeper.enabled }}
89-
- name: keytool
90-
configMap:
91-
name: "{{ template "pulsar.fullname" . }}-keytool-configmap"
92-
defaultMode: 0755
93-
{{- end }}
9487
{{- end }}
9588
{{- end }}

charts/pulsar/templates/_certs.tpl

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,58 @@ Define the pulsar certs ca issuer secret name
5757
{{- fail "certs.issuers.ca.secretName is required when TLS is enabled and certs.internal_issuer.enabled is false" -}}
5858
{{- end -}}
5959
{{- end -}}
60+
{{- end -}}
61+
62+
{{/*
63+
Common certificate template
64+
Usage: {{- include "pulsar.cert.template" (dict "root" . "componentConfig" .Values.proxy "tlsConfig" .Values.tls.proxy) -}}
65+
*/}}
66+
{{- define "pulsar.cert.template" -}}
67+
{{- if eq .root.Values.certs.internal_issuer.apiVersion "cert-manager.io/v1beta1" -}}
68+
{{- fail "cert-manager.io/v1beta1 is no longer supported. Please set certs.internal_issuer.apiVersion to cert-manager.io/v1" -}}
69+
{{- end -}}
70+
apiVersion: "{{ .root.Values.certs.internal_issuer.apiVersion }}"
71+
kind: Certificate
72+
metadata:
73+
name: "{{ template "pulsar.fullname" .root }}-{{ .tlsConfig.cert_name }}"
74+
namespace: {{ template "pulsar.namespace" .root }}
75+
spec:
76+
# Secret names are always required.
77+
secretName: "{{ .root.Release.Name }}-{{ .tlsConfig.cert_name }}"
78+
{{- if .root.Values.tls.zookeeper.enabled }}
79+
additionalOutputFormats:
80+
- type: CombinedPEM
81+
{{- end }}
82+
duration: "{{ .root.Values.tls.common.duration }}"
83+
renewBefore: "{{ .root.Values.tls.common.renewBefore }}"
84+
subject:
85+
organizations:
86+
{{ toYaml .root.Values.tls.common.organization | indent 4 }}
87+
# The use of the common name field has been deprecated since 2000 and is
88+
# discouraged from being used.
89+
commonName: "{{ template "pulsar.fullname" .root }}-{{ .componentConfig.component }}"
90+
isCA: false
91+
privateKey:
92+
size: {{ .root.Values.tls.common.keySize }}
93+
algorithm: {{ .root.Values.tls.common.keyAlgorithm }}
94+
encoding: {{ .root.Values.tls.common.keyEncoding }}
95+
usages:
96+
- server auth
97+
- client auth
98+
# At least one of a DNS Name, USI SAN, or IP address is required.
99+
dnsNames:
100+
{{- if .tlsConfig.dnsNames }}
101+
{{ toYaml .tlsConfig.dnsNames | indent 4 }}
102+
{{- end }}
103+
- {{ printf "*.%s-%s.%s.svc.%s" (include "pulsar.fullname" .root) .componentConfig.component (include "pulsar.namespace" .root) .root.Values.clusterDomain | quote }}
104+
- {{ printf "%s-%s" (include "pulsar.fullname" .root) .componentConfig.component | quote }}
105+
# Issuer references are always required.
106+
issuerRef:
107+
name: "{{ template "pulsar.certs.issuers.ca.name" .root }}"
108+
# We can reference ClusterIssuers by changing the kind here.
109+
# The default value is Issuer (i.e. a locally namespaced Issuer)
110+
kind: Issuer
111+
# This is optional since cert-manager will default to this value however
112+
# if you are using an external issuer, change this to that issuer group.
113+
group: cert-manager.io
60114
{{- end -}}

charts/pulsar/templates/_toolset.tpl

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Define toolset zookeeper client tls settings
3636
*/}}
3737
{{- define "pulsar.toolset.zookeeper.tls.settings" -}}
3838
{{- if and .Values.tls.enabled .Values.tls.zookeeper.enabled -}}
39-
/pulsar/keytool/keytool.sh toolset {{ template "pulsar.toolset.hostname" . }} true;
39+
{{- include "pulsar.component.zookeeper.tls.settings" (dict "component" "toolset" "isClient" true) -}}
4040
{{- end -}}
4141
{{- end }}
4242

@@ -51,11 +51,6 @@ Define toolset tls certs mounts
5151
- name: ca
5252
mountPath: "/pulsar/certs/ca"
5353
readOnly: true
54-
{{- if .Values.tls.zookeeper.enabled }}
55-
- name: keytool
56-
mountPath: "/pulsar/keytool/keytool.sh"
57-
subPath: keytool.sh
58-
{{- end }}
5954
{{- end }}
6055
{{- end }}
6156

@@ -72,17 +67,13 @@ Define toolset tls certs volumes
7267
path: tls.crt
7368
- key: tls.key
7469
path: tls.key
70+
- key: tls-combined.pem
71+
path: tls-combined.pem
7572
- name: ca
7673
secret:
7774
secretName: "{{ template "pulsar.certs.issuers.ca.secretName" . }}"
7875
items:
7976
- key: ca.crt
8077
path: ca.crt
81-
{{- if .Values.tls.zookeeper.enabled }}
82-
- name: keytool
83-
configMap:
84-
name: "{{ template "pulsar.fullname" . }}-keytool-configmap"
85-
defaultMode: 0755
86-
{{- end }}
8778
{{- end }}
8879
{{- end }}

charts/pulsar/templates/_zookeeper.tpl

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,23 @@ Define zookeeper tls settings
5353
*/}}
5454
{{- define "pulsar.zookeeper.tls.settings" -}}
5555
{{- if and .Values.tls.enabled .Values.tls.zookeeper.enabled }}
56-
/pulsar/keytool/keytool.sh zookeeper {{ template "pulsar.zookeeper.hostname" . }} false;
56+
{{- include "pulsar.component.zookeeper.tls.settings" (dict "component" "zookeeper" "isClient" false) -}}
57+
{{- end }}
58+
{{- end }}
59+
60+
{{- define "pulsar.component.zookeeper.tls.settings" }}
61+
{{- $component := .component -}}
62+
{{- $isClient := .isClient -}}
63+
{{- $keyFile := printf "/pulsar/certs/%s/tls-combined.pem" $component -}}
64+
{{- $caFile := "/pulsar/certs/ca/ca.crt" -}}
65+
{{- if $isClient }}
66+
echo $'\n' >> conf/pulsar_env.sh
67+
echo "PULSAR_EXTRA_OPTS=\"\${PULSAR_EXTRA_OPTS} -Dzookeeper.clientCnxnSocket=org.apache.zookeeper.ClientCnxnSocketNetty -Dzookeeper.client.secure=true -Dzookeeper.client.certReload=true -Dzookeeper.ssl.keyStore.location={{- $keyFile }} -Dzookeeper.ssl.keyStore.type=PEM -Dzookeeper.ssl.trustStore.location={{- $caFile }} -Dzookeeper.ssl.trustStore.type=PEM\"" >> conf/pulsar_env.sh
68+
echo $'\n' >> conf/bkenv.sh
69+
echo "BOOKIE_EXTRA_OPTS=\"\${BOOKIE_EXTRA_OPTS} -Dzookeeper.clientCnxnSocket=org.apache.zookeeper.ClientCnxnSocketNetty -Dzookeeper.client.secure=true -Dzookeeper.client.certReload=true -Dzookeeper.ssl.keyStore.location={{- $keyFile }} -Dzookeeper.ssl.keyStore.type=PEM -Dzookeeper.ssl.trustStore.location={{- $caFile }} -Dzookeeper.ssl.trustStore.type=PEM\"" >> conf/bkenv.sh
70+
{{- else }}
71+
echo $'\n' >> conf/pulsar_env.sh
72+
echo "PULSAR_EXTRA_OPTS=\"\${PULSAR_EXTRA_OPTS} -Dzookeeper.ssl.keyStore.location={{- $keyFile }} -Dzookeeper.ssl.keyStore.type=PEM -Dzookeeper.ssl.trustStore.location={{- $caFile }} -Dzookeeper.ssl.trustStore.type=PEM\"" >> conf/pulsar_env.sh
5773
{{- end }}
5874
{{- end }}
5975

0 commit comments

Comments
 (0)