Skip to content

Commit 95b2363

Browse files
pooknullhors
andauthored
K8SPG-554: add .spec.tlsOnly field (#998)
https://perconadev.atlassian.net/browse/K8SPG-554 Co-authored-by: Viacheslav Sarzhan <slava.sarzhan@percona.com>
1 parent ccfeaf0 commit 95b2363

File tree

12 files changed

+44
-0
lines changed

12 files changed

+44
-0
lines changed

build/crd/crunchy/generated/postgres-operator.crunchydata.com_postgresclusters.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17756,6 +17756,8 @@ spec:
1775617756
format: int64
1775717757
type: integer
1775817758
type: array
17759+
tlsOnly:
17760+
type: boolean
1775917761
userInterface:
1776017762
description: The specification of a user interface that connects to
1776117763
PostgreSQL.

build/crd/percona/generated/pgv2.percona.com_perconapgclusters.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17427,6 +17427,8 @@ spec:
1742717427
pattern: ^repo[1-4]
1742817428
type: string
1742917429
type: object
17430+
tlsOnly:
17431+
type: boolean
1743017432
unmanaged:
1743117433
description: |-
1743217434
Suspends the rollout and reconciliation of changes made to the

config/crd/bases/pgv2.percona.com_perconapgclusters.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17833,6 +17833,8 @@ spec:
1783317833
pattern: ^repo[1-4]
1783417834
type: string
1783517835
type: object
17836+
tlsOnly:
17837+
type: boolean
1783617838
unmanaged:
1783717839
description: |-
1783817840
Suspends the rollout and reconciliation of changes made to the

config/crd/bases/postgres-operator.crunchydata.com_postgresclusters.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17667,6 +17667,8 @@ spec:
1766717667
minimum: 1
1766817668
type: integer
1766917669
type: array
17670+
tlsOnly:
17671+
type: boolean
1767017672
userInterface:
1767117673
description: The specification of a user interface that connects to
1767217674
PostgreSQL.

deploy/bundle.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18126,6 +18126,8 @@ spec:
1812618126
pattern: ^repo[1-4]
1812718127
type: string
1812818128
type: object
18129+
tlsOnly:
18130+
type: boolean
1812918131
unmanaged:
1813018132
description: |-
1813118133
Suspends the rollout and reconciliation of changes made to the
@@ -43350,6 +43352,8 @@ spec:
4335043352
minimum: 1
4335143353
type: integer
4335243354
type: array
43355+
tlsOnly:
43356+
type: boolean
4335343357
userInterface:
4335443358
description: The specification of a user interface that connects to
4335543359
PostgreSQL.

deploy/cr.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ spec:
2424
# name: cluster1-cert
2525
# customReplicationTLSSecret:
2626
# name: replication1-cert
27+
# tlsOnly: false
2728

2829
# standby:
2930
# enabled: true

deploy/crd.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18126,6 +18126,8 @@ spec:
1812618126
pattern: ^repo[1-4]
1812718127
type: string
1812818128
type: object
18129+
tlsOnly:
18130+
type: boolean
1812918131
unmanaged:
1813018132
description: |-
1813118133
Suspends the rollout and reconciliation of changes made to the
@@ -43350,6 +43352,8 @@ spec:
4335043352
minimum: 1
4335143353
type: integer
4335243354
type: array
43355+
tlsOnly:
43356+
type: boolean
4335343357
userInterface:
4335443358
description: The specification of a user interface that connects to
4335543359
PostgreSQL.

deploy/cw-bundle.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18126,6 +18126,8 @@ spec:
1812618126
pattern: ^repo[1-4]
1812718127
type: string
1812818128
type: object
18129+
tlsOnly:
18130+
type: boolean
1812918131
unmanaged:
1813018132
description: |-
1813118133
Suspends the rollout and reconciliation of changes made to the
@@ -43350,6 +43352,8 @@ spec:
4335043352
minimum: 1
4335143353
type: integer
4335243354
type: array
43355+
tlsOnly:
43356+
type: boolean
4335343357
userInterface:
4335443358
description: The specification of a user interface that connects to
4335543359
PostgreSQL.

internal/controller/postgrescluster/controller.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,16 @@ func (r *Reconciler) Reconcile(
235235
pgmonitor.PostgreSQLHBAs(cluster, &pgHBAs)
236236
pgbouncer.PostgreSQL(cluster, &pgHBAs)
237237

238+
// K8SPG-554
239+
if cluster.Spec.TLSOnly {
240+
for i := range pgHBAs.Mandatory {
241+
pgHBAs.Mandatory[i].TLSOnly()
242+
}
243+
for i := range pgHBAs.Default {
244+
pgHBAs.Default[i].TLSOnly()
245+
}
246+
}
247+
238248
pgParameters := postgres.NewParameters()
239249
// K8SPG-375
240250
if cluster.Spec.Extensions.PGStatMonitor {

internal/postgres/hba.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,13 @@ func (hba *HostBasedAuthentication) TLS() *HostBasedAuthentication {
135135
return hba
136136
}
137137

138+
func (hba *HostBasedAuthentication) TLSOnly() *HostBasedAuthentication {
139+
if hba.origin == "host" || hba.origin == "hostnossl" {
140+
hba.origin = "hostssl"
141+
}
142+
return hba
143+
}
144+
138145
// TCP makes hba match connection attempts made using TCP/IP, with or without SSL.
139146
func (hba *HostBasedAuthentication) TCP() *HostBasedAuthentication {
140147
hba.origin = "host"

0 commit comments

Comments
 (0)