Skip to content

Commit 697585c

Browse files
committed
add support for TLS in CNPG
Signed-off-by: Utkarsh Srivastava <srivastavautkarsh8097@gmail.com>
1 parent 3548b6f commit 697585c

2 files changed

Lines changed: 23 additions & 3 deletions

File tree

pkg/system/db_reconciler.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,15 @@ func (r *Reconciler) reconcileClusterSpec(dbSpec *nbv1.NooBaaDBSpec) error {
303303
Enabled: true,
304304
}
305305

306+
if r.CNPGCluster.Spec.Certificates == nil {
307+
r.CNPGCluster.Spec.Certificates = &cnpgv1.CertificatesConfiguration{}
308+
}
309+
r.CNPGCluster.Spec.Certificates.ServerAltDNSNames = []string{
310+
r.ServiceDbPg.Name,
311+
r.ServiceDbPg.Name + "." + r.Request.Namespace,
312+
r.ServiceDbPg.Name + "." + r.Request.Namespace + ".svc",
313+
}
314+
306315
r.CNPGCluster.Spec.FailoverDelay = defaultFailoverDelaySec
307316

308317
r.setPostgresConfig()
@@ -610,6 +619,17 @@ func (r *Reconciler) setPostgresConfig() {
610619
}
611620
r.cnpgLog("PGTune config: memory=%dKB, cpu=%d, endpoints=%d", totalMemoryKB, cpuNum, endpointMaxCount)
612621

622+
// propagate TLS security settings to the PostgreSQL server
623+
tlsSec := r.NooBaa.Spec.Security.APIServerSecurity
624+
if tlsSec != nil && !util.IsTLSConfigDisabled() {
625+
if tlsSec.TLSMinVersion != nil {
626+
overrideParameters["ssl_min_protocol_version"] = string(*tlsSec.TLSMinVersion)
627+
}
628+
if len(tlsSec.TLSCiphers) > 0 {
629+
overrideParameters["ssl_ciphers"] = util.MapCiphersToOpenSSL(tlsSec.TLSCiphers)
630+
}
631+
}
632+
613633
// apply any user-specified DBConf overrides on top of the calculated values
614634
if r.NooBaa.Spec.DBSpec.DBConf != nil {
615635
for k, v := range r.NooBaa.Spec.DBSpec.DBConf {
@@ -891,6 +911,7 @@ func (r *Reconciler) wasClusterSpecChanged(existingClusterSpec *cnpgv1.ClusterSp
891911
!reflect.DeepEqual(existingClusterSpec.Monitoring, r.CNPGCluster.Spec.Monitoring) ||
892912
!reflect.DeepEqual(existingClusterSpec.PostgresConfiguration.Parameters, r.CNPGCluster.Spec.PostgresConfiguration.Parameters) ||
893913
!reflect.DeepEqual(existingClusterSpec.Backup, r.CNPGCluster.Spec.Backup) ||
914+
!reflect.DeepEqual(existingClusterSpec.Certificates, r.CNPGCluster.Spec.Certificates) ||
894915
existingClusterSpec.PriorityClassName != r.CNPGCluster.Spec.PriorityClassName ||
895916
existingClusterSpec.FailoverDelay != r.CNPGCluster.Spec.FailoverDelay
896917
}

pkg/system/phase2_creating.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -577,14 +577,13 @@ func (r *Reconciler) setDesiredCoreEnv(c *corev1.Container) {
577577
c.Env[j].Value = ""
578578
c.Env[j].ValueFrom = nil
579579
case "POSTGRES_SSL_REQUIRED":
580-
if r.NooBaa.Spec.ExternalPgSSLRequired {
580+
if r.NooBaa.Spec.ExternalPgSSLRequired || r.shouldReconcileCNPGCluster() {
581581
c.Env[j].Value = "true"
582582
}
583583
case "POSTGRES_SSL_UNAUTHORIZED":
584-
if r.NooBaa.Spec.ExternalPgSSLUnauthorized {
584+
if r.NooBaa.Spec.ExternalPgSSLUnauthorized || r.shouldReconcileCNPGCluster() {
585585
c.Env[j].Value = "true"
586586
}
587-
588587
case "POSTGRES_DBNAME_PATH":
589588
c.Env[j].Value = postgresSecretMountPath + "/dbname"
590589
case "POSTGRES_PASSWORD_PATH":

0 commit comments

Comments
 (0)