From e8eedc529ee40ae41390bb68c29d3f51ffa43084 Mon Sep 17 00:00:00 2001 From: MinerYang Date: Mon, 17 Jul 2023 14:07:59 +0800 Subject: [PATCH] Allow redis password contains special characters (#1055) allow redis password contains special characters Signed-off-by: yminer fix lint update trivy secret --- controllers/goharbor/core/secrets.go | 9 +++++---- controllers/goharbor/exporter/deployments.go | 4 ++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/controllers/goharbor/core/secrets.go b/controllers/goharbor/core/secrets.go index 58bf3e9c0..1d106b9d5 100644 --- a/controllers/goharbor/core/secrets.go +++ b/controllers/goharbor/core/secrets.go @@ -3,6 +3,7 @@ package core import ( "context" "fmt" + "net/url" goharborv1 "github.com/goharbor/harbor-operator/apis/goharbor.io/v1beta1" harbormetav1 "github.com/goharbor/harbor-operator/apis/meta/v1alpha1" @@ -41,8 +42,8 @@ func (r *Reconciler) GetSecret(ctx context.Context, core *goharborv1.Core) (*cor redisPassword = string(password) } - - coreCacheDSN := core.Spec.Redis.GetDSNStringWithRawPassword(redisPassword) + // support redis password contains special character by using url.QueryEscape + coreCacheDSN := core.Spec.Redis.GetDSNStringWithRawPassword(url.QueryEscape(redisPassword)) var registryPassword string @@ -64,8 +65,8 @@ func (r *Reconciler) GetSecret(ctx context.Context, core *goharborv1.Core) (*cor registryPassword = string(password) } - - registryCacheDSN := core.Spec.Components.Registry.Redis.GetDSNStringWithRawPassword(registryPassword) + // support redis password contains special character by using url.QueryEscape + registryCacheDSN := core.Spec.Components.Registry.Redis.GetDSNStringWithRawPassword(url.QueryEscape(registryPassword)) return &corev1.Secret{ ObjectMeta: metav1.ObjectMeta{ diff --git a/controllers/goharbor/exporter/deployments.go b/controllers/goharbor/exporter/deployments.go index a7248e72c..485f5c9de 100644 --- a/controllers/goharbor/exporter/deployments.go +++ b/controllers/goharbor/exporter/deployments.go @@ -275,8 +275,8 @@ func (r *Reconciler) getJobServiceRedisURL(ctx context.Context, exporter *goharb if redisPassword == "" { logger.Get(ctx).Info("redis password secret of jobservice not found", "secret", exporter.Spec.JobService.Redis.PasswordRef) } - - return exporter.Spec.JobService.Redis.GetDSNStringWithRawPassword(redisPassword), nil + // support redis password contains special character by using url.QueryEscape + return exporter.Spec.JobService.Redis.GetDSNStringWithRawPassword(url.QueryEscape(redisPassword)), nil } func (r *Reconciler) getValueFromSecret(ctx context.Context, namespace, name, key string) (string, error) {