Skip to content

Commit 0ffc5bf

Browse files
mnenciaarmru
andauthored
fix(pooler): clear stale TLS status fields when configuration is removed (#9397)
The pooler status update logic only set status fields when resources were present, but never cleared them when absent. This caused stale TLS configuration (ServerCA, ClientCA, ClientTLS, ServerTLS) to persist in status even after being removed from the spec, breaking pooler connectivity. This particularly impacts users upgrading to v1.28 from any prior version. Before v1.28, the ServerTLS status field was always set to the cluster's server certificate. In v1.28, this field was repurposed for optional manual TLS authentication to PostgreSQL. On upgrade, the stale pre-v1.28 value persists, causing pgbouncer to use the wrong certificate and fail with "ssl/tls alert unsupported certificate" errors. This breaks all application connectivity through the pooler. The same issue affects any user who configures custom TLS settings and later removes them - pgbouncer continues using the stale certificates until manually intervened. This fix adds explicit clearing of optional TLS status fields when the corresponding resources are not configured, ensuring status accurately reflects the current specification. Closes #9392 Signed-off-by: Marco Nenciarini <[email protected]> Signed-off-by: Armando Ruocco <[email protected]> Co-authored-by: Armando Ruocco <[email protected]>
1 parent 95f97e7 commit 0ffc5bf

4 files changed

Lines changed: 69 additions & 2 deletions

File tree

‎internal/controller/pooler_status.go‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,27 +54,38 @@ func (r *PoolerReconciler) updatePoolerStatus(
5454
Name: resources.ServerCASecret.Name,
5555
Version: resources.ServerCASecret.ResourceVersion,
5656
}
57+
} else {
58+
updatedStatus.Secrets.ServerCA = apiv1.SecretVersion{}
5759
}
5860

5961
if resources.ClientCASecret != nil {
6062
updatedStatus.Secrets.ClientCA = apiv1.SecretVersion{
6163
Name: resources.ClientCASecret.Name,
6264
Version: resources.ClientCASecret.ResourceVersion,
6365
}
66+
} else {
67+
updatedStatus.Secrets.ClientCA = apiv1.SecretVersion{}
6468
}
6569

6670
if resources.ClientTLSSecret != nil {
6771
updatedStatus.Secrets.ClientTLS = apiv1.SecretVersion{
6872
Name: resources.ClientTLSSecret.Name,
6973
Version: resources.ClientTLSSecret.ResourceVersion,
7074
}
75+
} else {
76+
updatedStatus.Secrets.ClientTLS = apiv1.SecretVersion{}
7177
}
7278

7379
if resources.ServerTLSSecret != nil {
7480
updatedStatus.Secrets.ServerTLS = apiv1.SecretVersion{
7581
Name: resources.ServerTLSSecret.Name,
7682
Version: resources.ServerTLSSecret.ResourceVersion,
7783
}
84+
} else {
85+
// Clear ServerTLS when not using manual TLS authentication.
86+
// This is particularly important for migration from v1.27, where
87+
// ServerTLS was always set to the cluster's server certificate.
88+
updatedStatus.Secrets.ServerTLS = apiv1.SecretVersion{}
7889
}
7990

8091
if resources.Deployment != nil {

‎internal/controller/pooler_status_test.go‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,4 +186,47 @@ var _ = Describe("pooler_status unit tests", func() {
186186
Expect(poolerBefore.Status).To(BeEquivalentTo(poolerAfter.Status))
187187
})
188188
})
189+
190+
It("should clear ServerTLS status when not using manual TLS authentication (migration to v1.28)", func() {
191+
ctx := context.Background()
192+
namespace := newFakeNamespace(env.client)
193+
cluster := newFakeCNPGCluster(env.client, namespace)
194+
pooler := newFakePooler(env.client, cluster)
195+
196+
// Simulate a pre v1.28 Pooler with ServerTLS populated
197+
pooler.Status.Secrets = &apiv1.PoolerSecrets{
198+
ServerTLS: apiv1.SecretVersion{
199+
Name: cluster.GetServerTLSSecretName(),
200+
Version: "stale-version-from-v127",
201+
},
202+
}
203+
204+
res := &poolerManagedResources{
205+
Deployment: nil,
206+
Cluster: cluster,
207+
ClientCASecret: &corev1.Secret{
208+
ObjectMeta: metav1.ObjectMeta{
209+
Name: pooler.GetClientCASecretNameOrDefault(cluster),
210+
},
211+
},
212+
ClientTLSSecret: &corev1.Secret{
213+
ObjectMeta: metav1.ObjectMeta{
214+
Name: pooler.GetClientTLSSecretNameOrDefault(cluster),
215+
},
216+
},
217+
ServerCASecret: &corev1.Secret{
218+
ObjectMeta: metav1.ObjectMeta{
219+
Name: pooler.GetServerCASecretNameOrDefault(cluster),
220+
},
221+
},
222+
ServerTLSSecret: nil,
223+
}
224+
225+
err := env.poolerReconciler.updatePoolerStatus(ctx, pooler, res)
226+
Expect(err).ToNot(HaveOccurred())
227+
228+
Expect(pooler.Status.Secrets.ServerTLS.Name).To(BeEmpty())
229+
Expect(pooler.Status.Secrets.ServerTLS.Version).To(BeEmpty())
230+
assertClusterInheritedStatus(pooler, cluster)
231+
})
189232
})

‎tests/e2e/asserts_test.go‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2123,13 +2123,22 @@ func assertReadWriteConnectionUsingPgBouncerService(
21232123
clusterName, namespace, apiv1.ApplicationUserSecretSuffix)
21242124
Expect(err).ToNot(HaveOccurred())
21252125

2126+
// Get the database name from the cluster configuration
2127+
cluster, err := clusterutils.Get(env.Ctx, env.Client, namespace, clusterName)
2128+
Expect(err).ToNot(HaveOccurred())
2129+
2130+
dbName := cluster.GetApplicationDatabaseName()
2131+
if dbName == "" {
2132+
dbName = apiv1.DefaultApplicationDatabaseName
2133+
}
2134+
21262135
// verify that, if pooler type setup read write then it will allow both read and
21272136
// write operations or if pooler type setup read only then it will allow only read operations
21282137
if isPoolerRW {
2129-
AssertWritesToPrimarySucceeds(namespace, poolerService, "app", appUser,
2138+
AssertWritesToPrimarySucceeds(namespace, poolerService, dbName, appUser,
21302139
generatedAppUserPassword, connectionParams...)
21312140
} else {
2132-
AssertWritesToReplicaFails(namespace, poolerService, "app", appUser,
2141+
AssertWritesToReplicaFails(namespace, poolerService, dbName, appUser,
21332142
generatedAppUserPassword, connectionParams...)
21342143
}
21352144
}

‎tests/e2e/upgrade_test.go‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,10 @@ var _ = Describe("Upgrade", Label(tests.LabelUpgrade, tests.LabelNoOpenshift), O
674674

675675
AssertConfUpgrade(clusterName1, upgradeNamespace)
676676

677+
By("verifying connection through pooler after upgrade", func() {
678+
assertReadWriteConnectionUsingPgBouncerService(upgradeNamespace, clusterName1, pgBouncerSampleFile, true)
679+
})
680+
677681
By("installing a second Cluster on the upgraded operator", func() {
678682
// set the serverName to a random name
679683
err := os.Setenv("SERVER_NAME", serverName2)

0 commit comments

Comments
 (0)