Skip to content

Commit c8e1838

Browse files
author
Serhii Zakharov
authored
fix obfuscation translation table secret (#461)
* fix obfuscation translation table secret * fix tests
1 parent 4396c00 commit c8e1838

File tree

6 files changed

+15
-40
lines changed

6 files changed

+15
-40
lines changed

manifests/03-clusterrole.yaml

-32
Original file line numberDiff line numberDiff line change
@@ -222,38 +222,6 @@ subjects:
222222
namespace: openshift-insights
223223
name: gather
224224

225-
---
226-
apiVersion: rbac.authorization.k8s.io/v1
227-
kind: Role
228-
metadata:
229-
name: insights-operator-obfuscation-secret
230-
namespace: openshift-insights
231-
rules:
232-
- apiGroups:
233-
- ""
234-
resources:
235-
- secrets
236-
verbs:
237-
- get
238-
- list
239-
- create
240-
- update
241-
- delete
242-
243-
---
244-
apiVersion: rbac.authorization.k8s.io/v1
245-
kind: RoleBinding
246-
metadata:
247-
name: insights-operator-obfuscation-secret
248-
namespace: openshift-insights
249-
roleRef:
250-
kind: Role
251-
name: insights-operator-obfuscation-secret
252-
subjects:
253-
- kind: ServiceAccount
254-
name: gather
255-
namespace: openshift-insights
256-
257225
---
258226
apiVersion: rbac.authorization.k8s.io/v1
259227
kind: ClusterRoleBinding

pkg/anonymization/anonymizer.go

+11-5
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ func NewAnonymizer(clusterBaseDomain string, networks []string, secretsClient co
113113
func NewAnonymizerFromConfigClient(
114114
ctx context.Context,
115115
kubeClient kubernetes.Interface,
116+
gatherKubeClient kubernetes.Interface,
116117
configClient configv1client.ConfigV1Interface,
117118
networkClient networkv1client.NetworkV1Interface,
118119
) (*Anonymizer, error) {
@@ -135,7 +136,7 @@ func NewAnonymizerFromConfigClient(
135136
networks = append(networks, networksConfig.Spec.ExternalIP.Policy.AllowedCIDRs...)
136137
networks = append(networks, networksConfig.Spec.ExternalIP.Policy.RejectedCIDRs...)
137138

138-
clusterConfigV1, err := kubeClient.CoreV1().ConfigMaps("kube-system").Get(ctx, "cluster-config-v1", metav1.GetOptions{})
139+
clusterConfigV1, err := gatherKubeClient.CoreV1().ConfigMaps("kube-system").Get(ctx, "cluster-config-v1", metav1.GetOptions{})
139140
if err != nil {
140141
return nil, err
141142
}
@@ -183,24 +184,29 @@ func NewAnonymizerFromConfigClient(
183184

184185
// NewAnonymizerFromConfig creates a new instance of anonymizer with a provided kubeconfig
185186
func NewAnonymizerFromConfig(
186-
ctx context.Context, kubeConfig *rest.Config, protoKubeConfig *rest.Config,
187+
ctx context.Context, gatherKubeConfig *rest.Config, gatherProtoKubeConfig *rest.Config, protoKubeConfig *rest.Config,
187188
) (*Anonymizer, error) {
188189
kubeClient, err := kubernetes.NewForConfig(protoKubeConfig)
189190
if err != nil {
190191
return nil, err
191192
}
192193

193-
configClient, err := configv1client.NewForConfig(kubeConfig)
194+
gatherKubeClient, err := kubernetes.NewForConfig(gatherProtoKubeConfig)
194195
if err != nil {
195196
return nil, err
196197
}
197198

198-
networkClient, err := networkv1client.NewForConfig(kubeConfig)
199+
configClient, err := configv1client.NewForConfig(gatherKubeConfig)
199200
if err != nil {
200201
return nil, err
201202
}
202203

203-
return NewAnonymizerFromConfigClient(ctx, kubeClient, configClient, networkClient)
204+
networkClient, err := networkv1client.NewForConfig(gatherKubeConfig)
205+
if err != nil {
206+
return nil, err
207+
}
208+
209+
return NewAnonymizerFromConfigClient(ctx, kubeClient, gatherKubeClient, configClient, networkClient)
204210
}
205211

206212
// AnonymizeMemoryRecord takes record.MemoryRecord, removes the sensitive data from it and returns the same object

pkg/anonymization/anonymizer_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@ func TestAnonymizer_NewAnonymizerFromConfigClient(t *testing.T) {
318318
anonymizer, err := NewAnonymizerFromConfigClient(
319319
context.TODO(),
320320
kubeClient,
321+
kubeClient,
321322
configClient,
322323
networkClient,
323324
)

pkg/controller/gather_job.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func (d *GatherJob) Gather(ctx context.Context, kubeConfig, protoKubeConfig *res
6969
var anonymizer *anonymization.Anonymizer
7070
if anonymization.IsObfuscationEnabled(configObserver) {
7171
// anonymizer is responsible for anonymizing sensitive data, it can be configured to disable specific anonymization
72-
anonymizer, err = anonymization.NewAnonymizerFromConfig(ctx, gatherKubeConfig, gatherProtoKubeConfig)
72+
anonymizer, err = anonymization.NewAnonymizerFromConfig(ctx, gatherKubeConfig, gatherProtoKubeConfig, protoKubeConfig)
7373
if err != nil {
7474
return err
7575
}

pkg/controller/operator.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ func (s *Operator) Run(ctx context.Context, controller *controllercmd.Controller
106106
var anonymizer *anonymization.Anonymizer
107107
if anonymization.IsObfuscationEnabled(configObserver) {
108108
// anonymizer is responsible for anonymizing sensitive data, it can be configured to disable specific anonymization
109-
anonymizer, err = anonymization.NewAnonymizerFromConfig(ctx, gatherKubeConfig, gatherProtoKubeConfig)
109+
anonymizer, err = anonymization.NewAnonymizerFromConfig(ctx, gatherKubeConfig, gatherProtoKubeConfig, controller.ProtoKubeConfig)
110110
if err != nil {
111111
// in case of an error anonymizer will be nil and anonymization will be just skipped
112112
klog.Errorf(anonymization.UnableToCreateAnonymizerErrorMessage, err)

pkg/gatherers/clusterconfig/clusterconfig_gatherer.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func failableFunc(function gathererFuncPtr) gatheringFunction {
4646
}
4747

4848
var gatheringFunctions = map[string]gatheringFunction{
49-
"pdbs": importantFunc((*Gatherer).GatherPodDisruptionBudgets),
49+
"pdbs": failableFunc((*Gatherer).GatherPodDisruptionBudgets),
5050
"metrics": failableFunc((*Gatherer).GatherMostRecentMetrics),
5151
"operators": importantFunc((*Gatherer).GatherClusterOperators),
5252
"operators_pods_and_events": importantFunc((*Gatherer).GatherClusterOperatorPodsAndEvents),

0 commit comments

Comments
 (0)