Skip to content

Commit 3113e8b

Browse files
committed
Add filter sensitive switch feature and corresponding configuration
1 parent f4a22b3 commit 3113e8b

File tree

7 files changed

+15
-3
lines changed

7 files changed

+15
-3
lines changed

deploy/all-cr.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -841,6 +841,8 @@ spec:
841841
value: x-live, x-service
842842
- name: JOYLIVE_CONTROL_PLANE_URL
843843
value:
844+
- name: JOYLIVE_FILTER_SENSITIVE
845+
value:
844846
- name: JOYLIVE_CLUSTER_ID
845847
value:
846848
- name: JOYLIVE_MATCH_KEY

deploy/joylive-injector/templates/deployment.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ spec:
4141
value: {{ .Values.matchEnvLabels }}
4242
- name: JOYLIVE_CONTROL_PLANE_URL
4343
value: {{ .Values.controlPlaneUrl }}
44+
- name: JOYLIVE_FILTER_SENSITIVE
45+
value: {{ .Values.filterSensitive }}
4446
- name: JOYLIVE_CLUSTER_ID
4547
value: {{ .Values.clusterId }}
4648
- name: JOYLIVE_MATCH_KEY

deploy/joylive-injector/values.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ containerArgs:
3232

3333
matchEnvLabels: x-live, x-service
3434
controlPlaneUrl: ""
35+
filterSensitive: ""
3536

3637
imagePullSecrets: [ ]
3738
nameOverride: ""
29 Bytes
Binary file not shown.

main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ func init() {
113113
rootCmd.PersistentFlags().StringVar(&config.Key, "key", "", "Admission Controller TLS cert key")
114114
rootCmd.PersistentFlags().StringVar(&config.MatchLabels, "match-label", config.MatchLabels, "Match label")
115115
rootCmd.PersistentFlags().StringVar(&config.ControlPlaneUrl, "control-plane-url", config.ControlPlaneUrl, "Control Plane URL")
116+
rootCmd.PersistentFlags().StringVar(&config.FilterSensitive, "filter-sensitive", config.FilterSensitive, "Filter Sensitive Switch")
116117
rootCmd.PersistentFlags().StringVar(&config.ClusterId, "cluster-id", config.ClusterId, "Cluster ID")
117118
//rootCmd.PersistentFlags().StringVar(&config.KubeConfig, "kubeconfig", config.KubeConfig, "Path to the kubeconfig file")
118119

pkg/config/config.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const (
2222
NamespaceEnvName = "JOYLIVE_NAMESPACE"
2323
MatchLabelsEnvName = "JOYLIVE_MATCH_ENV_LABELS"
2424
ControlPlaneUrlEnvName = "JOYLIVE_CONTROL_PLANE_URL"
25+
FilterSensitiveEnvName = "JOYLIVE_FILTER_SENSITIVE"
2526
ClusterIdEnvName = "JOYLIVE_CLUSTER_ID"
2627
DefaultNamespace = "joylive"
2728
AgentVersionLabel = "x-live-version"
@@ -49,6 +50,7 @@ var (
4950
Addr string
5051
MatchLabels string
5152
ControlPlaneUrl string
53+
FilterSensitive string
5254
ClusterId string
5355
WebHookMatchKey string
5456
WebHookMatchValue string
@@ -75,6 +77,8 @@ func init() {
7577
MatchLabels = os.Getenv(MatchLabelsEnvName)
7678
// Initialize the default control plane url from environment variables
7779
ControlPlaneUrl = os.Getenv(ControlPlaneUrlEnvName)
80+
// Initialize the switch for filter sensitive from environment variables
81+
FilterSensitive = os.Getenv(FilterSensitiveEnvName)
7882
// Initialize the default cluster id from environment variables
7983
ClusterId = os.Getenv(ClusterIdEnvName)
8084
WebHookMatchKey = os.Getenv(WebHookMatchKeyEnv)

pkg/resource/control.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,11 @@ func GetApplicationEnvironments(labels map[string]string) (map[string]string, er
5858
return nil, response.Error
5959
}
6060
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
61+
if len(config.FilterSensitive) != 0 && config.FilterSensitive == "true" {
62+
// Filter out keys ending with "USERNAME" and "PASSWORD" to enhance security.
63+
if strings.HasSuffix(key, "USERNAME") || strings.HasSuffix(key, "PASSWORD") {
64+
continue
65+
}
6466
}
6567
envMaps[key] = value
6668
}

0 commit comments

Comments
 (0)