@@ -56,8 +56,8 @@ const (
56
56
Ipv4Regex = `((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)`
57
57
Ipv4NetworkRegex = Ipv4Regex + "/([0-9]{1,2})"
58
58
Ipv4AddressOrNetworkRegex = Ipv4Regex + "(/([0-9]{1,2}))?"
59
- ClusterAPIServerPlaceholder = "<CLUSTER_API_SERVER>"
60
59
ClusterBaseDomainPlaceholder = "<CLUSTER_BASE_DOMAIN>"
60
+ ClusterHostPlaceholder = "<CLUSTER_DOMAIN_HOST>"
61
61
UnableToCreateAnonymizerErrorMessage = "Unable to create anonymizer, " +
62
62
"some data won't be anonymized(ipv4 and cluster base domain). The error is %v"
63
63
clusterNetworksRecordName = "config/network.json"
@@ -109,6 +109,7 @@ func NewAnonymizerFromConfigClient(
109
109
networkClient networkv1client.NetworkV1Interface ,
110
110
configurator configobserver.Interface ,
111
111
dataPolicy v1alpha1.DataPolicy ,
112
+ sensitiveVals map [string ]string ,
112
113
) (* Anonymizer , error ) {
113
114
anonBuilder := & AnonBuilder {}
114
115
anonBuilder .
@@ -120,19 +121,15 @@ func NewAnonymizerFromConfigClient(
120
121
WithRunningInCluster (true ).
121
122
WithSecretsClient (kubeClient .CoreV1 ().Secrets (secretNamespace ))
122
123
123
- baseDomain , err := utils .GetClusterBaseDomain (ctx , configClient )
124
- if err != nil {
125
- return nil , err
124
+ for value , placeholder := range sensitiveVals {
125
+ anonBuilder .WithSensitiveValue (value , placeholder )
126
126
}
127
- anonBuilder .WithSensitiveValue (baseDomain , ClusterBaseDomainPlaceholder )
128
127
129
- APIServerURLs , err := utils .GetClusterAPIServerInfo (ctx , configClient )
128
+ baseDomain , err := utils .GetClusterBaseDomain (ctx , configClient )
130
129
if err != nil {
131
130
return nil , err
132
131
}
133
- for _ , v := range APIServerURLs {
134
- anonBuilder .WithSensitiveValue (v , ClusterAPIServerPlaceholder )
135
- }
132
+ anonBuilder .WithSensitiveValue (baseDomain , ClusterBaseDomainPlaceholder )
136
133
137
134
return anonBuilder .Build ()
138
135
}
@@ -310,15 +307,18 @@ func NewAnonymizerFromConfig(
310
307
configurator configobserver.Interface ,
311
308
dataPolicy v1alpha1.DataPolicy ,
312
309
) (* Anonymizer , error ) {
310
+ sensitiveVals := make (map [string ]string )
313
311
kubeClient , err := kubernetes .NewForConfig (protoKubeConfig )
314
312
if err != nil {
315
313
return nil , err
316
314
}
315
+ sensitiveVals [extractDomain (protoKubeConfig .Host )] = ClusterHostPlaceholder
317
316
318
317
gatherKubeClient , err := kubernetes .NewForConfig (gatherProtoKubeConfig )
319
318
if err != nil {
320
319
return nil , err
321
320
}
321
+ sensitiveVals [extractDomain (gatherProtoKubeConfig .Host )] = ClusterHostPlaceholder
322
322
323
323
configClient , err := configv1client .NewForConfig (gatherKubeConfig )
324
324
if err != nil {
@@ -329,8 +329,12 @@ func NewAnonymizerFromConfig(
329
329
if err != nil {
330
330
return nil , err
331
331
}
332
+ sensitiveVals [extractDomain (gatherKubeConfig .Host )] = ClusterHostPlaceholder
332
333
333
- return NewAnonymizerFromConfigClient (ctx , kubeClient , gatherKubeClient , configClient , networkClient , configurator , dataPolicy )
334
+ return NewAnonymizerFromConfigClient (ctx ,
335
+ kubeClient , gatherKubeClient , configClient , networkClient ,
336
+ configurator , dataPolicy , sensitiveVals ,
337
+ )
334
338
}
335
339
336
340
// AnonymizeMemoryRecord takes record.MemoryRecord, removes the sensitive data from it and returns the same object
@@ -542,3 +546,16 @@ func getNextIP(originalIP net.IP, mask net.IPMask) (net.IP, bool) {
542
546
543
547
return resultIP , false
544
548
}
549
+
550
+ // extractDomain truncates protocol, host and port of the URL argument
551
+ // and returns the base domain
552
+ func extractDomain (url string ) string {
553
+ baseDomain := strings .Join (strings .Split (url , "." )[1 :], "." ) // removes protocol and host parts
554
+ domain := strings .Split (baseDomain , ":" )[0 ] // removes port (if any)
555
+
556
+ if domain == "" { // in case the URL is malformed
557
+ return url
558
+ }
559
+
560
+ return domain
561
+ }
0 commit comments