Skip to content

Commit e9c43d3

Browse files
committed
[18.0-fr6] Fix shell injection in trust_flush CronJob
Replace the bash -c string concatenation of TrustFlushArgs with a direct argv array, preventing shell metacharacter injection. The CronJob now executes keystone-manage as Command: ["keystone-manage", "trust_flush", ...args] instead of Command: ["/bin/bash"] Args: ["-c", "keystone-manage trust_flush" + args]. Jira: OSPRH-32064 Signed-off-by: Martin Schuppert <mschuppert@redhat.com>
1 parent 4075e9e commit e9c43d3

1 file changed

Lines changed: 9 additions & 12 deletions

File tree

internal/keystone/cronjob.go

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ limitations under the License.
1616
package keystone
1717

1818
import (
19+
"strings"
20+
1921
memcachedv1 "github.com/openstack-k8s-operators/infra-operator/apis/memcached/v1beta1"
2022
keystonev1 "github.com/openstack-k8s-operators/keystone-operator/api/v1beta1"
2123
"github.com/openstack-k8s-operators/lib-common/modules/common/env"
@@ -26,11 +28,6 @@ import (
2628
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2729
)
2830

29-
const (
30-
// TrustFlushCommand -
31-
TrustFlushCommand = "keystone-manage trust_flush"
32-
)
33-
3431
// CronJob func
3532
func CronJob(
3633
instance *keystonev1.KeystoneAPI,
@@ -39,7 +36,10 @@ func CronJob(
3936
memcached *memcachedv1.Memcached,
4037
) *batchv1.CronJob {
4138

42-
args := []string{"-c", TrustFlushCommand + instance.Spec.TrustFlushArgs}
39+
cmd := []string{"keystone-manage", "trust_flush"}
40+
if instance.Spec.TrustFlushArgs != "" {
41+
cmd = append(cmd, strings.Fields(instance.Spec.TrustFlushArgs)...)
42+
}
4343

4444
envVars := map[string]env.Setter{}
4545
envVars["KOLLA_CONFIG_STRATEGY"] = env.SetValue("COPY_ALWAYS")
@@ -103,12 +103,9 @@ func CronJob(
103103
Spec: corev1.PodSpec{
104104
Containers: []corev1.Container{
105105
{
106-
Name: ServiceName + "-cron",
107-
Image: instance.Spec.ContainerImage,
108-
Command: []string{
109-
"/bin/bash",
110-
},
111-
Args: args,
106+
Name: ServiceName + "-cron",
107+
Image: instance.Spec.ContainerImage,
108+
Command: cmd,
112109
Env: env.MergeEnvs([]corev1.EnvVar{}, envVars),
113110
VolumeMounts: volumeMounts,
114111
SecurityContext: baseSecurityContext(),

0 commit comments

Comments
 (0)