Skip to content

Commit 9a3a7f4

Browse files
authored
[67117] Changes to connect to EDB using password (#1060)
* Retrieve Posgres password from secret * Correct volume name used now Signed-off-by: Abhishek Pandey <[email protected]> * Enabling password authentication for Postgres during migration Signed-off-by: Abhishek Pandey <[email protected]> --------- Signed-off-by: Abhishek Pandey <[email protected]>
1 parent bd7e0ef commit 9a3a7f4

File tree

4 files changed

+28
-46
lines changed

4 files changed

+28
-46
lines changed

internal/controller/operator/containers.go

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -371,12 +371,8 @@ func buildAuthServiceContainer(instance *operatorv1alpha1.Authentication, authSe
371371
MountPath: "/certs/saml-certs",
372372
},
373373
{
374-
Name: "pgsql-ca-cert",
375-
MountPath: "/certs/pgsql-ca",
376-
},
377-
{
378-
Name: "pgsql-client-cert",
379-
MountPath: "/certs/pgsql-client",
374+
Name: "pgsql-certs",
375+
MountPath: "/certs/pgsql",
380376
},
381377
{
382378
Name: "pgsql-client-cred",
@@ -719,12 +715,8 @@ func buildIdentityProviderContainer(instance *operatorv1alpha1.Authentication, i
719715
MountPath: "/certs/saml-certs",
720716
},
721717
{
722-
Name: "pgsql-ca-cert",
723-
MountPath: "/certs/pgsql-ca",
724-
},
725-
{
726-
Name: "pgsql-client-cert",
727-
MountPath: "/certs/pgsql-client",
718+
Name: "pgsql-certs",
719+
MountPath: "/certs/pgsql",
728720
},
729721
{
730722
Name: "pgsql-client-cred",
@@ -1080,12 +1072,8 @@ func buildIdentityManagerContainer(instance *operatorv1alpha1.Authentication, id
10801072
MountPath: "/opt/ibm/identity-mgmt/config/scim-config",
10811073
},
10821074
{
1083-
Name: "pgsql-ca-cert",
1084-
MountPath: "/certs/pgsql-ca",
1085-
},
1086-
{
1087-
Name: "pgsql-client-cert",
1088-
MountPath: "/certs/pgsql-client",
1075+
Name: "pgsql-certs",
1076+
MountPath: "/certs/pgsql",
10891077
},
10901078
{
10911079
Name: "pgsql-client-cred",

internal/controller/operator/deployment.go

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -989,35 +989,10 @@ func buildIdpVolumes(ldapCACert string, routerCertSecret string) []corev1.Volume
989989
},
990990
},
991991
{
992-
Name: "pgsql-ca-cert",
992+
Name: "pgsql-certs",
993993
VolumeSource: corev1.VolumeSource{
994994
Secret: &corev1.SecretVolumeSource{
995-
SecretName: common.DatastoreEDBSecretName,
996-
Items: []corev1.KeyToPath{
997-
{
998-
Key: "ca.crt",
999-
Path: "ca.crt",
1000-
},
1001-
},
1002-
DefaultMode: &partialAccess,
1003-
},
1004-
},
1005-
},
1006-
{
1007-
Name: "pgsql-client-cert",
1008-
VolumeSource: corev1.VolumeSource{
1009-
Secret: &corev1.SecretVolumeSource{
1010-
SecretName: common.DatastoreEDBSecretName,
1011-
Items: []corev1.KeyToPath{
1012-
{
1013-
Key: "tls.crt",
1014-
Path: "tls.crt",
1015-
},
1016-
{
1017-
Key: "tls.key",
1018-
Path: "tls.key",
1019-
},
1020-
},
995+
SecretName: common.DatastoreEDBSecretName,
1021996
DefaultMode: &partialAccess,
1022997
},
1023998
},

internal/controller/operator/migration.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,20 @@ func (r *AuthenticationReconciler) getPostgresDB(ctx context.Context, req ctrl.R
252252
return nil, err
253253
}
254254

255+
if datastoreCertSecret.Data["DATABASE_PASSWORD"] != nil {
256+
return dbconn.NewPostgresDB(
257+
dbconn.Name(datastoreCertCM.Data["DATABASE_NAME"]),
258+
dbconn.ID(req.Namespace),
259+
dbconn.Port(datastoreCertCM.Data["DATABASE_PORT"]),
260+
dbconn.User(datastoreCertCM.Data["DATABASE_USER"]),
261+
dbconn.Password(string(datastoreCertSecret.Data["DATABASE_PASSWORD"])),
262+
dbconn.Host(datastoreCertCM.Data["DATABASE_RW_ENDPOINT"]),
263+
dbconn.Schemas("platformdb", "oauthdbschema", "metadata"),
264+
dbconn.TLSConfig(
265+
datastoreCertSecret.Data["ca.crt"],
266+
datastoreCertSecret.Data["tls.crt"],
267+
datastoreCertSecret.Data["tls.key"]))
268+
}
255269
return dbconn.NewPostgresDB(
256270
dbconn.Name(datastoreCertCM.Data["DATABASE_NAME"]),
257271
dbconn.ID(req.Namespace),

internal/database/connectors/dbconn.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,12 @@ func NewPostgresDB(opts ...DBOption) (*PostgresDB, error) {
6666
}
6767

6868
func (p *PostgresDB) Connect(ctx context.Context) (err error) {
69-
dsn := fmt.Sprintf("host=%s user=%s dbname=%s port=%s sslmode=require", p.Host, p.User, p.Name, p.Port)
69+
var dsn string
70+
if len(p.Password) > 0 {
71+
dsn = fmt.Sprintf("host=%s user=%s password=%s dbname=%s port=%s sslmode=require", p.Host, p.User, p.Password, p.Name, p.Port)
72+
} else {
73+
dsn = fmt.Sprintf("host=%s user=%s dbname=%s port=%s sslmode=require", p.Host, p.User, p.Name, p.Port)
74+
}
7075
var connConfig *pgx.ConnConfig
7176
if connConfig, err = pgx.ParseConfig(dsn); err != nil {
7277
return err

0 commit comments

Comments
 (0)