Skip to content

Commit 5cc2cc9

Browse files
author
Serhii Zakharov
authored
fixed obfuscation permissions (#424)
1 parent 7a75a38 commit 5cc2cc9

File tree

5 files changed

+25
-12
lines changed

5 files changed

+25
-12
lines changed

Dockerfile.debug

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM registry.ci.openshift.org/ocp/builder:rhel-8-golang-1.15-openshift-4.8 AS builder
1+
FROM registry.ci.openshift.org/ocp/builder:rhel-8-golang-1.16-openshift-4.8 AS builder
22
RUN go get github.com/go-delve/delve/cmd/dlv
33
WORKDIR /go/src/github.com/openshift/insights-operator
44
COPY . .

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ build-debug: ## Compiles the insights operator in debug mode
9696

9797
.PHONY build-debug-container:
9898
build-debug-container: ## Compiles the insights operator and its container image for debug
99-
$(CONTAINER_RUNTIME) build -t insights-operator -f ./Dockerfile.debug ../.
99+
$(CONTAINER_RUNTIME) build -t insights-operator -f ./Dockerfile.debug .
100100

101101
## --------------------------------------
102102
## Tools

pkg/anonymization/anonymizer.go

+20-2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
configv1client "github.com/openshift/client-go/config/clientset/versioned/typed/config/v1"
3333
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3434
"k8s.io/client-go/kubernetes"
35+
"k8s.io/client-go/rest"
3536
"k8s.io/klog/v2"
3637
k8snet "k8s.io/utils/net"
3738

@@ -68,7 +69,7 @@ type ConfigProvider interface {
6869
Config() *config.Controller
6970
}
7071

71-
// NewAnonymizer creates a new instance of anonymizer with a provided config observer and sensitive data
72+
// NewAnonymizer creates a new instance of anonymizer
7273
func NewAnonymizer(clusterBaseDomain string, networks []string) (*Anonymizer, error) {
7374
networks = append(networks, "127.0.0.1/8")
7475

@@ -94,7 +95,7 @@ func NewAnonymizer(clusterBaseDomain string, networks []string) (*Anonymizer, er
9495
}, nil
9596
}
9697

97-
// NewAnonymizer creates a new instance of anonymizer with a provided config observer and openshift config client
98+
// NewAnonymizerFromConfigClient creates a new instance of anonymizer with a provided openshift config client
9899
func NewAnonymizerFromConfigClient(
99100
ctx context.Context, kubeClient kubernetes.Interface, configClient configv1client.ConfigV1Interface,
100101
) (*Anonymizer, error) {
@@ -147,6 +148,23 @@ func NewAnonymizerFromConfigClient(
147148
return NewAnonymizer(baseDomain, networks)
148149
}
149150

151+
// NewAnonymizerFromConfig creates a new instance of anonymizer with a provided kubeconfig
152+
func NewAnonymizerFromConfig(
153+
ctx context.Context, kubeConfig *rest.Config, protoKubeConfig *rest.Config,
154+
) (*Anonymizer, error) {
155+
kubeClient, err := kubernetes.NewForConfig(protoKubeConfig)
156+
if err != nil {
157+
return nil, err
158+
}
159+
160+
configClient, err := configv1client.NewForConfig(kubeConfig)
161+
if err != nil {
162+
return nil, err
163+
}
164+
165+
return NewAnonymizerFromConfigClient(ctx, kubeClient, configClient)
166+
}
167+
150168
// AnonymizeMemoryRecord takes record.MemoryRecord, removes the sensitive data from it and returns the same object
151169
func (anonymizer *Anonymizer) AnonymizeMemoryRecord(memoryRecord *record.MemoryRecord) *record.MemoryRecord {
152170
if len(anonymizer.clusterBaseDomain) != 0 {

pkg/controller/gather_job.go

+1-6
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"fmt"
66
"os"
77

8-
configv1client "github.com/openshift/client-go/config/clientset/versioned/typed/config/v1"
98
"k8s.io/apimachinery/pkg/runtime/schema"
109
"k8s.io/client-go/kubernetes"
1110
"k8s.io/client-go/kubernetes/scheme"
@@ -69,12 +68,8 @@ func (d *GatherJob) Gather(ctx context.Context, kubeConfig, protoKubeConfig *res
6968

7069
var anonymizer *anonymization.Anonymizer
7170
if anonymization.IsObfuscationEnabled(configObserver) {
72-
configClient, err := configv1client.NewForConfig(kubeConfig)
73-
if err != nil {
74-
return err
75-
}
7671
// anonymizer is responsible for anonymizing sensitive data, it can be configured to disable specific anonymization
77-
anonymizer, err = anonymization.NewAnonymizerFromConfigClient(ctx, kubeClient, configClient)
72+
anonymizer, err = anonymization.NewAnonymizerFromConfig(ctx, gatherKubeConfig, gatherProtoKubeConfig)
7873
if err != nil {
7974
return err
8075
}

pkg/controller/operator.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,10 @@ 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.NewAnonymizerFromConfigClient(ctx, kubeClient, configClient)
109+
anonymizer, err = anonymization.NewAnonymizerFromConfig(ctx, gatherKubeConfig, gatherProtoKubeConfig)
110110
if err != nil {
111+
// in case of an error anonymizer will be nil and anonymization will be just skipped
111112
klog.Errorf(anonymization.UnableToCreateAnonymizerErrorMessage, err)
112-
// anonymizer will be nil and anonymization will be just skipped
113113
}
114114
}
115115

0 commit comments

Comments
 (0)