Skip to content

Commit 6fd72b5

Browse files
phiscosxd
andauthored
feat: support ipv6 and custom pg_hba for pgbouncer (cloudnative-pg#1395)
This patch makes default pg_hba to use md5 auth method for both ipv4 and ipv6 connections. Also added parameter to allow configuring custom pg_hba rules, similarly to what can already be done for postgresql. Signed-off-by: Philippe Scorsolini <p.scorsolini@gmail.com> Signed-off-by: Jonathan Gonzalez V <jonathan.gonzalez@enterprisedb.com> Co-authored-by: Jonathan Gonzalez V <jonathan.gonzalez@enterprisedb.com>
1 parent 242ab76 commit 6fd72b5

File tree

5 files changed

+25
-0
lines changed

5 files changed

+25
-0
lines changed

api/v1/pooler_types.go

+5
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,11 @@ type PgBouncerSpec struct {
115115
// the CNPG documentation for a list of options you can configure
116116
Parameters map[string]string `json:"parameters,omitempty"`
117117

118+
// PostgreSQL Host Based Authentication rules (lines to be appended
119+
// to the pg_hba.conf file)
120+
// +optional
121+
PgHBA []string `json:"pg_hba,omitempty"`
122+
118123
// When set to `true`, PgBouncer will disconnect from the PostgreSQL
119124
// server, first waiting for all queries to complete, and pause all new
120125
// client connections until this value is set to `false` (default). Internally,

api/v1/zz_generated.deepcopy.go

+5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/postgresql.cnpg.io_poolers.yaml

+6
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,12 @@ spec:
9999
to `false` (default). Internally, the operator calls PgBouncer's
100100
`PAUSE` and `RESUME` commands.
101101
type: boolean
102+
pg_hba:
103+
description: PostgreSQL Host Based Authentication rules (lines
104+
to be appended to the pg_hba.conf file)
105+
items:
106+
type: string
107+
type: array
102108
poolMode:
103109
default: session
104110
description: The pool mode

docs/src/api_reference.md

+1
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,7 @@ Name | Description
666666
`authQuerySecret` | The credentials of the user that need to be used for the authentication query. In case it is specified, also an AuthQuery (e.g. "SELECT usename, passwd FROM pg_shadow WHERE usename=$1") has to be specified and no automatic CNPG Cluster integration will be triggered. | [*LocalObjectReference](#LocalObjectReference)
667667
`authQuery ` | The query that will be used to download the hash of the password of a certain user. Default: "SELECT usename, passwd FROM user_search($1)". In case it is specified, also an AuthQuerySecret has to be specified and no automatic CNPG Cluster integration will be triggered. | string
668668
`parameters ` | Additional parameters to be passed to PgBouncer - please check the CNPG documentation for a list of options you can configure | map[string]string
669+
`pg_hba ` | PostgreSQL Host Based Authentication rules (lines to be appended to the pg_hba.conf file) | []string
669670
`paused ` | When set to `true`, PgBouncer will disconnect from the PostgreSQL server, first waiting for all queries to complete, and pause all new client connections until this value is set to `false` (default). Internally, the operator calls PgBouncer's `PAUSE` and `RESUME` commands. | *bool
670671

671672
<a id='PodTemplateSpec'></a>

pkg/management/pgbouncer/config/config.go

+8
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,13 @@ auth_query = {{ .AuthQuery }}
8080
`
8181
pgbouncerHBAFileTemplateString = `
8282
local pgbouncer pgbouncer peer
83+
84+
{{ range $rule := .PgHba }}
85+
{{ $rule -}}
86+
{{ end }}
87+
8388
host all all 0.0.0.0/0 md5
89+
host all all ::/0 md5
8490
`
8591

8692
pgBouncerUserListTemplateString = `
@@ -180,6 +186,7 @@ func BuildConfigurationFiles(pooler *apiv1.Pooler, secrets *Secrets) (Configurat
180186
AuthQueryUser string
181187
AuthQueryPassword string
182188
Parameters string
189+
PgHba []string
183190
}{
184191
Pooler: pooler,
185192
AuthQuery: pooler.GetAuthQuery(),
@@ -193,6 +200,7 @@ func BuildConfigurationFiles(pooler *apiv1.Pooler, secrets *Secrets) (Configurat
193200
// Also, we want the list of parameters inside the PgBouncer configuration
194201
// to be stable.
195202
Parameters: stringifyPgBouncerParameters(parameters),
203+
PgHba: pooler.Spec.PgBouncer.PgHBA,
196204
}
197205

198206
err = pgBouncerIniTemplate.Execute(&pgbouncerIni, templateData)

0 commit comments

Comments
 (0)