From 4725f8b3cae3e699b5aa06af02f926a6f5808cdf Mon Sep 17 00:00:00 2001 From: David Wertenteil Date: Sun, 4 Sep 2022 15:02:04 +0300 Subject: [PATCH 1/4] update logger version --- core/cautils/customerloader.go | 4 ++-- core/cautils/datastructures.go | 2 +- core/cautils/getter/datastructures.go | 2 +- core/cautils/getter/kscloudapi.go | 2 +- go.mod | 2 +- go.sum | 4 ++-- httphandler/go.mod | 2 +- httphandler/go.sum | 4 ++-- 8 files changed, 11 insertions(+), 11 deletions(-) diff --git a/core/cautils/customerloader.go b/core/cautils/customerloader.go index a7bbb0e9..4016cbeb 100644 --- a/core/cautils/customerloader.go +++ b/core/cautils/customerloader.go @@ -182,11 +182,11 @@ TODO - supprot: KS_CACHE // path to cached files */ type ClusterConfig struct { + backendAPI getter.IBackend k8s *k8sinterface.KubernetesApi + configObj *ConfigObj configMapName string configMapNamespace string - backendAPI getter.IBackend - configObj *ConfigObj } func NewClusterConfig(k8s *k8sinterface.KubernetesApi, backendAPI getter.IBackend, credentials *Credentials, clusterName string) *ClusterConfig { diff --git a/core/cautils/datastructures.go b/core/cautils/datastructures.go index a4962bd3..733ca8d7 100644 --- a/core/cautils/datastructures.go +++ b/core/cautils/datastructures.go @@ -98,6 +98,6 @@ type RegoInputData struct { } type Policies struct { - Frameworks []string Controls map[string]reporthandling.Control // map[] + Frameworks []string } diff --git a/core/cautils/getter/datastructures.go b/core/cautils/getter/datastructures.go index 47a06626..d30abb1c 100644 --- a/core/cautils/getter/datastructures.go +++ b/core/cautils/getter/datastructures.go @@ -8,8 +8,8 @@ type FeLoginData struct { type FeLoginResponse struct { Token string `json:"accessToken"` RefreshToken string `json:"refreshToken"` - ExpiresIn int32 `json:"expiresIn"` Expires string `json:"expires"` + ExpiresIn int32 `json:"expiresIn"` } type KSCloudSelectCustomer struct { diff --git a/core/cautils/getter/kscloudapi.go b/core/cautils/getter/kscloudapi.go index 676b5129..437ffa06 100644 --- a/core/cautils/getter/kscloudapi.go +++ b/core/cautils/getter/kscloudapi.go @@ -42,8 +42,8 @@ type KSCloudAPI struct { accountID string clientID string secretKey string - feToken FeLoginResponse authCookie string + feToken FeLoginResponse loggedIn bool } diff --git a/go.mod b/go.mod index c3db7a65..4bc7464a 100644 --- a/go.mod +++ b/go.mod @@ -14,7 +14,7 @@ require ( github.com/go-git/go-git/v5 v5.4.2 github.com/google/uuid v1.3.0 github.com/johnfercher/maroto v0.37.0 - github.com/kubescape/go-logger v0.0.5 + github.com/kubescape/go-logger v0.0.6 github.com/kubescape/k8s-interface v0.0.83 github.com/kubescape/opa-utils v0.0.180 github.com/kubescape/rbac-utils v0.0.17 diff --git a/go.sum b/go.sum index 4210ffbc..47a367df 100644 --- a/go.sum +++ b/go.sum @@ -835,8 +835,8 @@ github.com/kr/pty v1.1.5/go.mod h1:9r2w37qlBe7rQ6e1fg1S/9xpWHSnaqNdHD3WcMdbPDA= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= -github.com/kubescape/go-logger v0.0.5 h1:lA25XvI4LT4JqwnNkIDUtwdYS4KVmnbWrVB7SRte2Es= -github.com/kubescape/go-logger v0.0.5/go.mod h1:DnVWEvC90LFY1nNMaNo6nBVOcqkLMK3S0qzXP1fzRvI= +github.com/kubescape/go-logger v0.0.6 h1:ynhAmwrz0O7Jtqq1CdmCZUrKveji25hVP+B/FAb3QrA= +github.com/kubescape/go-logger v0.0.6/go.mod h1:DnVWEvC90LFY1nNMaNo6nBVOcqkLMK3S0qzXP1fzRvI= github.com/kubescape/k8s-interface v0.0.83 h1:yQ1kWNZmKfBim/+NmxpPI/j7L9ASDq2h3mCNdmYgzqY= github.com/kubescape/k8s-interface v0.0.83/go.mod h1:ihX96yqar+xogHl45mFE8zT9DLI06iy7XQPAP+j5KJE= github.com/kubescape/opa-utils v0.0.180 h1:QPYgjAE17Zcvz2wihmtXhS1YCMDhTIlwgvwY2Gb0djw= diff --git a/httphandler/go.mod b/httphandler/go.mod index f003d13e..c73a56fd 100644 --- a/httphandler/go.mod +++ b/httphandler/go.mod @@ -10,7 +10,7 @@ require ( github.com/google/uuid v1.3.0 github.com/gorilla/mux v1.8.0 github.com/gorilla/schema v1.2.0 - github.com/kubescape/go-logger v0.0.5 + github.com/kubescape/go-logger v0.0.6 github.com/kubescape/kubescape/v2 v2.0.0-00010101000000-000000000000 github.com/kubescape/opa-utils v0.0.180 github.com/stretchr/testify v1.8.0 diff --git a/httphandler/go.sum b/httphandler/go.sum index 58fad021..ad9e7b2c 100644 --- a/httphandler/go.sum +++ b/httphandler/go.sum @@ -891,8 +891,8 @@ github.com/kr/pty v1.1.5/go.mod h1:9r2w37qlBe7rQ6e1fg1S/9xpWHSnaqNdHD3WcMdbPDA= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= -github.com/kubescape/go-logger v0.0.5 h1:lA25XvI4LT4JqwnNkIDUtwdYS4KVmnbWrVB7SRte2Es= -github.com/kubescape/go-logger v0.0.5/go.mod h1:DnVWEvC90LFY1nNMaNo6nBVOcqkLMK3S0qzXP1fzRvI= +github.com/kubescape/go-logger v0.0.6 h1:ynhAmwrz0O7Jtqq1CdmCZUrKveji25hVP+B/FAb3QrA= +github.com/kubescape/go-logger v0.0.6/go.mod h1:DnVWEvC90LFY1nNMaNo6nBVOcqkLMK3S0qzXP1fzRvI= github.com/kubescape/k8s-interface v0.0.83 h1:yQ1kWNZmKfBim/+NmxpPI/j7L9ASDq2h3mCNdmYgzqY= github.com/kubescape/k8s-interface v0.0.83/go.mod h1:ihX96yqar+xogHl45mFE8zT9DLI06iy7XQPAP+j5KJE= github.com/kubescape/opa-utils v0.0.180 h1:QPYgjAE17Zcvz2wihmtXhS1YCMDhTIlwgvwY2Gb0djw= From 46073e0a6cea2742d4681c0e56ec961bcf4455e7 Mon Sep 17 00:00:00 2001 From: David Wertenteil Date: Mon, 5 Sep 2022 10:12:28 +0300 Subject: [PATCH 2/4] update scanner image --- core/pkg/hostsensorutils/hostsensor.yaml | 2 +- core/pkg/resourcehandler/k8sresources_test.go | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/core/pkg/hostsensorutils/hostsensor.yaml b/core/pkg/hostsensorutils/hostsensor.yaml index b2aea6e0..16f368c2 100644 --- a/core/pkg/hostsensorutils/hostsensor.yaml +++ b/core/pkg/hostsensorutils/hostsensor.yaml @@ -33,7 +33,7 @@ spec: effect: NoSchedule containers: - name: host-sensor - image: quay.io/armosec/kube-host-sensor:latest + image: quay.io/kubescape/host-scanner:latest securityContext: privileged: true readOnlyRootFilesystem: true diff --git a/core/pkg/resourcehandler/k8sresources_test.go b/core/pkg/resourcehandler/k8sresources_test.go index 00025f4d..b8dfd17e 100644 --- a/core/pkg/resourcehandler/k8sresources_test.go +++ b/core/pkg/resourcehandler/k8sresources_test.go @@ -238,8 +238,8 @@ func TestIsMasterNodeTaints(t *testing.T) { }, { "names": [ - "quay.io/armosec/kube-host-sensor@sha256:82139d2561039726be060df2878ef023c59df7c536fbd7f6d766af5a99569fee", - "quay.io/armosec/kube-host-sensor:latest" + "quay.io/kubescape/host-scanner@sha256:82139d2561039726be060df2878ef023c59df7c536fbd7f6d766af5a99569fee", + "quay.io/kubescape/host-scanner:latest" ], "sizeBytes": 11796788 }, @@ -503,8 +503,8 @@ func TestIsMasterNodeTaints(t *testing.T) { }, { "names": [ - "quay.io/armosec/kube-host-sensor@sha256:82139d2561039726be060df2878ef023c59df7c536fbd7f6d766af5a99569fee", - "quay.io/armosec/kube-host-sensor:latest" + "quay.io/kubescape/host-scanner@sha256:82139d2561039726be060df2878ef023c59df7c536fbd7f6d766af5a99569fee", + "quay.io/kubescape/host-scanner:latest" ], "sizeBytes": 11796788 }, From ccb335160756408ef97fa6923ba6d99991ce5d61 Mon Sep 17 00:00:00 2001 From: David Wertenteil Date: Mon, 5 Sep 2022 11:35:08 +0300 Subject: [PATCH 3/4] remove windows exe extension --- build.py | 1 - 1 file changed, 1 deletion(-) diff --git a/build.py b/build.py index f9ed0380..bf33d395 100644 --- a/build.py +++ b/build.py @@ -25,7 +25,6 @@ def get_build_dir(): def get_package_name(): package_name = "kubescape" - if platform.system() == "Windows": package_name += ".exe" return package_name From 5634903aa0720e2d6fceccac9055566ca163c96e Mon Sep 17 00:00:00 2001 From: David Wertenteil Date: Thu, 15 Sep 2022 14:53:55 +0300 Subject: [PATCH 4/4] update AdoptClusterName --- core/cautils/customerloader.go | 7 ++++++- core/cautils/customerloader_test.go | 31 +++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/core/cautils/customerloader.go b/core/cautils/customerloader.go index 4016cbeb..a2a0fe8b 100644 --- a/core/cautils/customerloader.go +++ b/core/cautils/customerloader.go @@ -5,6 +5,7 @@ import ( "encoding/json" "fmt" "os" + "regexp" "strings" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -468,7 +469,11 @@ func DeleteConfigFile() error { } func AdoptClusterName(clusterName string) string { - return strings.ReplaceAll(clusterName, "/", "-") + re, err := regexp.Compile(`[^\w]+`) + if err != nil { + return clusterName + } + return re.ReplaceAllString(clusterName, "-") } func getConfigMapName() string { diff --git a/core/cautils/customerloader_test.go b/core/cautils/customerloader_test.go index 3a17106f..8a7f1ce5 100644 --- a/core/cautils/customerloader_test.go +++ b/core/cautils/customerloader_test.go @@ -191,3 +191,34 @@ func TestLoadConfigFromData(t *testing.T) { } } + +func TestAdoptClusterName(t *testing.T) { + tests := []struct { + name string + clusterName string + want string + }{ + { + name: "replace 1", + clusterName: "my-name__is--ks", + want: "my-name__is-ks", + }, + { + name: "replace 2", + clusterName: "my-name1", + want: "my-name1", + }, + { + name: "replace 3", + clusterName: "my:name", + want: "my-name", + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := AdoptClusterName(tt.clusterName); got != tt.want { + t.Errorf("AdoptClusterName() = %v, want %v", got, tt.want) + } + }) + } +}