Skip to content

Commit f2178b0

Browse files
committed
chore(redis): Please gosec checking
Signed-off-by: Oliver Gondža <ogondza@gmail.com>
1 parent b04abd1 commit f2178b0

3 files changed

Lines changed: 29 additions & 44 deletions

File tree

controllers/argocd/configmap.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -778,7 +778,7 @@ func (r *ReconcileArgoCD) reconcileRedisHAConfigMap(cr *argoproj.ArgoCD, useTLSF
778778
desired := newConfigMapWithName(common.ArgoCDRedisHAConfigMapName, cr)
779779
desired.Data = map[string]string{
780780
"haproxy.cfg": getRedisHAProxyConfig(cr, useTLSForRedis),
781-
"haproxy_init.sh": getRedisHAProxyScript(cr),
781+
"haproxy_init.sh": getRedisHAProxyScript(),
782782
"init.sh": getRedisInitScript(),
783783
"redis.conf": getRedisConf(useTLSForRedis),
784784
"sentinel.conf": getRedisSentinelConf(useTLSForRedis),
@@ -841,7 +841,7 @@ func (r *ReconcileArgoCD) recreateRedisHAConfigMap(cr *argoproj.ArgoCD, useTLSFo
841841
return r.reconcileRedisHAConfigMap(cr, useTLSForRedis)
842842
}
843843

844-
func (r *ReconcileArgoCD) recreateRedisHAHealthConfigMap(cr *argoproj.ArgoCD, useTLSForRedis bool) error {
844+
func (r *ReconcileArgoCD) recreateRedisHAHealthConfigMap(cr *argoproj.ArgoCD) error {
845845
cm := newConfigMapWithName(common.ArgoCDRedisHAHealthConfigMapName, cr)
846846

847847
exists, err := argoutil.IsObjectFound(r.Client, cr.Namespace, cm.Name, cm)

controllers/argocd/secret.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,7 @@ func (r *ReconcileArgoCD) reconcileRedisTLSSecret(cr *argoproj.ArgoCD, useTLSFor
650650
if err != nil {
651651
return err
652652
}
653-
err = r.recreateRedisHAHealthConfigMap(cr, useTLSForRedis)
653+
err = r.recreateRedisHAHealthConfigMap(cr)
654654
if err != nil {
655655
return err
656656
}

controllers/argocd/util.go

Lines changed: 26 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,21 @@ func getRedisConfigPath() string {
426426
return common.ArgoCDDefaultRedisConfigPath
427427
}
428428

429+
func getRedisConfigContent(segment string) string {
430+
base := getRedisConfigPath()
431+
fp := filepath.Clean(filepath.Join(base, segment))
432+
if !strings.HasPrefix(fp, base) {
433+
panic(fmt.Errorf("unsafe path for %s + %s", base, segment))
434+
}
435+
436+
data, err := os.ReadFile(fp)
437+
if err != nil {
438+
log.Error(err, "unable to load redis "+segment)
439+
return ""
440+
}
441+
return string(data)
442+
}
443+
429444
// getRedisInitScript will load the redis configuration from a template on disk for the given ArgoCD.
430445
// If an error occurs, an empty string value will be returned.
431446
func getRedisConf(useTLSForRedis bool) string {
@@ -506,16 +521,10 @@ func getRedisHAProxyContainerImage(cr *argoproj.ArgoCD) string {
506521
return argoutil.CombineImageTag(img, tag)
507522
}
508523

509-
// getRedisInitScript will load the redis init script from a template on disk for the given ArgoCD.
524+
// getRedisInitScript will load the redis init script
510525
// If an error occurs, an empty string value will be returned.
511526
func getRedisInitScript() string {
512-
path := filepath.Join(getRedisConfigPath(), "init.sh")
513-
data, err := os.ReadFile(path)
514-
if err != nil {
515-
log.Error(err, "unable to load redis init.sh")
516-
return ""
517-
}
518-
return string(data)
527+
return getRedisConfigContent("init.sh")
519528
}
520529

521530
// getRedisHAProxySConfig will load the Redis HA Proxy configuration from a template on disk for the given ArgoCD.
@@ -535,16 +544,10 @@ func getRedisHAProxyConfig(cr *argoproj.ArgoCD, useTLSForRedis bool) string {
535544
return script
536545
}
537546

538-
// getRedisHAProxyScript will load the Redis HA Proxy init script from a template on disk for the given ArgoCD.
547+
// getRedisHAProxyScript will load the Redis HA Proxy init script
539548
// If an error occurs, an empty string value will be returned.
540-
func getRedisHAProxyScript(cr *argoproj.ArgoCD) string {
541-
path := filepath.Join(getRedisConfigPath(), "haproxy_init.sh")
542-
data, err := os.ReadFile(path)
543-
if err != nil {
544-
log.Error(err, "unable to load redis haproxy_init.sh")
545-
return ""
546-
}
547-
return string(data)
549+
func getRedisHAProxyScript() string {
550+
return getRedisConfigContent("haproxy_init.sh")
548551
}
549552

550553
// getRedisResources will return the ResourceRequirements for the Redis container.
@@ -586,40 +589,22 @@ func getRedisSentinelConf(useTLSForRedis bool) string {
586589
return conf
587590
}
588591

589-
// getRedisLivenessScript will load the redis liveness script from a template on disk for the given ArgoCD.
592+
// getRedisLivenessScript will load the redis liveness script
590593
// If an error occurs, an empty string value will be returned.
591594
func getRedisLivenessScript() string {
592-
path := filepath.Join(getRedisConfigPath(), "redis_liveness.sh")
593-
data, err := os.ReadFile(path)
594-
if err != nil {
595-
log.Error(err, "unable to load redis redis_liveness.sh")
596-
return ""
597-
}
598-
return string(data)
595+
return getRedisConfigContent("redis_liveness.sh")
599596
}
600597

601-
// getRedisReadinessScript will load the redis readiness script from a template on disk for the given ArgoCD.
598+
// getRedisReadinessScript will load the redis readiness script
602599
// If an error occurs, an empty string value will be returned.
603600
func getRedisReadinessScript() string {
604-
path := filepath.Join(getRedisConfigPath(), "redis_readiness.sh")
605-
data, err := os.ReadFile(path)
606-
if err != nil {
607-
log.Error(err, "unable to load redis redis_readiness.sh")
608-
return ""
609-
}
610-
return string(data)
601+
return getRedisConfigContent("redis_readiness.sh")
611602
}
612603

613-
// getSentinelLivenessScript will load the redis liveness script from a template on disk for the given ArgoCD.
604+
// getSentinelLivenessScript will load the redis liveness script
614605
// If an error occurs, an empty string value will be returned.
615606
func getSentinelLivenessScript() string {
616-
path := filepath.Join(getRedisConfigPath(), "sentinel_liveness.sh")
617-
data, err := os.ReadFile(path)
618-
if err != nil {
619-
log.Error(err, "unable to load redis sentinel_liveness.sh")
620-
return ""
621-
}
622-
return string(data)
607+
return getRedisConfigContent("sentinel_liveness.sh")
623608
}
624609

625610
// getRedisServerAddress will return the Redis service address for the given ArgoCD.

0 commit comments

Comments
 (0)