@@ -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.
431446func 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.
511526func 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.
591594func 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.
603600func 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.
615606func 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