This is an automated email from the ASF dual-hosted git repository. potiuk pushed a commit to branch v1-10-test in repository https://gitbox.apache.org/repos/asf/airflow.git
commit 6598002cfb724685e4375c67a41e0fd77b5d9d83 Author: Jarek Potiuk <[email protected]> AuthorDate: Sun Oct 11 22:38:30 2020 +0200 Mutual SSL added in PGBouncer configuration in the Chart (#11384) Adds SSL configuration for PGBouncer in the Helm Chart. PGBouncer is crucial to handle the big number of connections that airflow opens for the database, but often the database is outside of the Kubernetes Cluster or generally the environment where Airflow is installed and PGBouncer needs to connect securely to such database. This PR adds capability of seting CA/Certificate and Private Key in the PGBouncer configuration that allows for mTLS authentication (both client and server are authenticated) and secure connection even over public network. (cherry picked from commit 9a01ce04076b20cba7c4f31f2665602512c78cdf) --- chart/templates/_helpers.yaml | 18 +++++++++ .../templates/pgbouncer/pgbouncer-deployment.yaml | 22 +++++++++++ .../secrets/pgbouncer-certificates-secret.yaml | 44 ++++++++++++++++++++++ chart/values.schema.json | 27 +++++++++++++ chart/values.yaml | 8 ++++ 5 files changed, 119 insertions(+) diff --git a/chart/templates/_helpers.yaml b/chart/templates/_helpers.yaml index 02b255a..4f3e0a0 100644 --- a/chart/templates/_helpers.yaml +++ b/chart/templates/_helpers.yaml @@ -223,6 +223,10 @@ {{ .Release.Name }}-pgbouncer-config {{- end }} +{{ define "pgbouncer_certificates_secret" -}} +{{ .Release.Name }}-pgbouncer-certificates +{{- end }} + {{ define "pgbouncer_stats_secret" -}} {{ .Release.Name }}-pgbouncer-stats {{- end }} @@ -262,6 +266,20 @@ max_client_conn = {{ .Values.pgbouncer.maxClientConn }} verbose = {{ .Values.pgbouncer.verbose }} log_disconnections = {{ .Values.pgbouncer.logDisconnections }} log_connections = {{ .Values.pgbouncer.logConnections }} + +server_tls_sslmode = {{ .Values.pgbouncer.sslmode }} +server_tls_ciphers = {{ .Values.pgbouncer.ciphers }} + +{{- if .Values.pgbouncer.ssl.ca }} +server_tls_ca_file = /etc/pgbouncer/root.crt +{{- end }} +{{- if .Values.pgbouncer.ssl.cert }} +server_tls_cert_file = /etc/pgbouncer/server.crt +{{- end }} +{{- if .Values.pgbouncer.ssl.key }} +server_tls_key_file = /etc/pgbouncer/server.key +{{- end }} + {{- end }} {{ define "pgbouncer_users" }} diff --git a/chart/templates/pgbouncer/pgbouncer-deployment.yaml b/chart/templates/pgbouncer/pgbouncer-deployment.yaml index 8a79e65..9237e6c 100644 --- a/chart/templates/pgbouncer/pgbouncer-deployment.yaml +++ b/chart/templates/pgbouncer/pgbouncer-deployment.yaml @@ -54,6 +54,7 @@ spec: {{- end }} annotations: checksum/pgbouncer-config-secret: {{ include (print $.Template.BasePath "/secrets/pgbouncer-config-secret.yaml") . | sha256sum }} + checksum/pgbouncer-certificates-secret: {{ include (print $.Template.BasePath "/secrets/pgbouncer-certificates-secret.yaml") . | sha256sum }} spec: nodeSelector: {{ toYaml .Values.nodeSelector | indent 8 }} @@ -91,6 +92,24 @@ spec: subPath: users.txt mountPath: /etc/pgbouncer/users.txt readOnly: true +{{- if .Values.pgbouncer.ssl.ca }} + - name: pgbouncer-certificates + subPath: root.crt + mountPath: /etc/pgbouncer/root.crt + readOnly: true +{{- end }} +{{- if .Values.pgbouncer.ssl.cert }} + - name: pgbouncer-certificates + subPath: server.crt + mountPath: /etc/pgbouncer/server.crt + readOnly: true +{{- end }} +{{- if .Values.pgbouncer.ssl.key }} + - name: pgbouncer-certificates + subPath: server.key + mountPath: /etc/pgbouncer/server.key + readOnly: true +{{- end }} lifecycle: preStop: exec: @@ -125,4 +144,7 @@ spec: - name: pgbouncer-config secret: secretName: {{ template "pgbouncer_config_secret" . }} + - name: pgbouncer-certificates + secret: + secretName: {{ template "pgbouncer_certificates_secret" . }} {{- end }} diff --git a/chart/templates/secrets/pgbouncer-certificates-secret.yaml b/chart/templates/secrets/pgbouncer-certificates-secret.yaml new file mode 100644 index 0000000..d9f1f2d --- /dev/null +++ b/chart/templates/secrets/pgbouncer-certificates-secret.yaml @@ -0,0 +1,44 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +################################ +## Pgbouncer Certificate Secret +################################# +{{- if or .Values.pgbouncer.ssl.ca .Values.pgbouncer.ssl.cert .Values.pgbouncer.ssl.key }} +kind: Secret +apiVersion: v1 +metadata: + name: {{ template "pgbouncer_certificates_secret" . }} + labels: + release: {{ .Release.Name }} + chart: {{ .Chart.Name }} + heritage: {{ .Release.Service }} +{{- with .Values.labels }} +{{ toYaml . | indent 4 }} +{{- end }} +type: Opaque +data: +{{- if .Values.pgbouncer.ssl.ca }} + root.crt: {{ .Values.pgbouncer.ssl.ca | b64enc }} +{{- end }} +{{- if .Values.pgbouncer.ssl.cert }} + server.crt: {{ .Values.pgbouncer.ssl.cert | b64enc }} +{{- end }} +{{- if .Values.pgbouncer.ssl.key }} + server.key: {{ .Values.pgbouncer.ssl.key | b64enc }} +{{- end }} +{{- end }} diff --git a/chart/values.schema.json b/chart/values.schema.json index a5eda19..6c2c41a 100644 --- a/chart/values.schema.json +++ b/chart/values.schema.json @@ -764,6 +764,33 @@ "logConnections": { "description": "Log successful logins.", "type": "integer" + }, + "sslmode": { + "description": "SSL mode for pgbouncer.", + "type": "string", + "enum": ["disable", "allow", "prefer", "require", "verify-ca", "verify-full"] + }, + "ciphers": { + "description": "The allowed ciphers, might be 'fast', 'normal' or list ciphers separated with ':'.", + "type": "string" + }, + "ssl": { + "description": "SSL certificates for pgbouncer connection.", + "type": "object", + "properties": { + "ca": { + "description": "Certificate Authority for server side", + "type": ["string", "null"] + }, + "cert": { + "description": "Server Certificate for server side", + "type": ["string", "null"] + }, + "key": { + "description": "Private key used to authenticate with the server", + "type": ["string", "null"] + } + } } } }, diff --git a/chart/values.yaml b/chart/values.yaml index 800f58a..707a34b 100644 --- a/chart/values.yaml +++ b/chart/values.yaml @@ -448,6 +448,14 @@ pgbouncer: logDisconnections: 0 logConnections: 0 + sslmode: "prefer" + ciphers: "normal" + + ssl: + ca: ~ + cert: ~ + key: ~ + redis: terminationGracePeriodSeconds: 600
