Skip to content

Commit f4a22b3

Browse files
committed
Enhance security by filtering out sensitive keys and improve version handling in ConfigMap injection
1 parent 845326b commit f4a22b3

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

pkg/mutation/mutation_deploy.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,14 +242,24 @@ func AddApplicationEnvironments(source appsv1.Deployment, target *appsv1.Deploym
242242

243243
func createOrUpdateConfigMap(deploy *appsv1.Deployment) error {
244244
configMapData := config.DefaultInjectorConfigMap
245-
if version, ok := deploy.Spec.Template.Labels[config.AgentVersionLabel]; ok {
245+
// Prefer version from pod template labels, fallback to deployment labels.
246+
version, ok := deploy.Spec.Template.Labels[config.AgentVersionLabel]
247+
if !ok {
248+
version = deploy.Labels[config.AgentVersionLabel]
249+
}
250+
251+
if version != "" {
246252
if agentVersion, ok := config.InjectorAgentVersion[version]; ok {
247253
cmd, configExists := config.InjectorConfigMaps[agentVersion.ConfigMapName]
248254
if agentVersion.Enable && configExists {
249255
configMapData = cmd
250-
log.Info("[mutation] injection-deploy: Inject the specified version of configMap",
256+
log.Info("[mutation] injection-deploy: Injecting specified version of ConfigMap",
251257
zap.String("deployment", deploy.Name), zap.String("version", version),
252258
zap.String("cmName", agentVersion.ConfigMapName))
259+
// Ensure the pod template has the agent version label.
260+
deploy.Spec.Template.Labels[config.AgentVersionLabel] = version
261+
} else {
262+
log.Warnf("[mutation] injection-deploy: Specified agent version '%s' for deployment '%s' is not enabled or its config is missing. Using default.", version, deploy.Name)
253263
}
254264
}
255265
}

pkg/mutation/mutation_pod.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,13 @@ func addPodInitContainer(targetPod *corev1.Pod, _ []corev1.EnvVar, deploymentNam
238238
agentVersion = v.Version
239239
log.Info("[mutation] injection-pod: Inject the specified version to pod",
240240
zap.String("pod", targetPod.Name), zap.String("version", agentVersion))
241+
} else {
242+
log.Warnf("[mutation] injection-pod: The specified version %s is not enabled or the configuration information is missing, using the default version %s",
243+
av, config.DefaultInjectorConfig.AgentConfig.Version)
241244
}
245+
} else {
246+
log.Warnf("[mutation] injection-pod: The specified version %s does not exist, using the default version %s",
247+
av, config.DefaultInjectorConfig.AgentConfig.Version)
242248
}
243249
}
244250
agentInitContainer := &corev1.Container{

pkg/resource/control.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"io"
77
"net/http"
8+
"strings"
89

910
"github.com/jd-opensource/joylive-injector/pkg/config"
1011
)
@@ -57,6 +58,10 @@ func GetApplicationEnvironments(labels map[string]string) (map[string]string, er
5758
return nil, response.Error
5859
}
5960
for key, value := range response.Data {
61+
// Filter out keys ending with "USERNAME" and "PASSWORD" to enhance security.
62+
if strings.HasSuffix(key, "USERNAME") || strings.HasSuffix(key, "PASSWORD") {
63+
continue
64+
}
6065
envMaps[key] = value
6166
}
6267
envMaps["APPLICATION_NAME"] = application

0 commit comments

Comments
 (0)