diff --git a/go.mod b/go.mod index 9e9cbdc..3b7dd63 100644 --- a/go.mod +++ b/go.mod @@ -24,11 +24,11 @@ require ( github.com/gorilla/mux v1.8.1 github.com/kubescape/backend v0.0.37 github.com/kubescape/go-logger v0.0.28 - github.com/kubescape/k8s-interface v0.0.202 + github.com/kubescape/k8s-interface v0.0.214 github.com/kubescape/kubescape-network-scanner v0.0.15 github.com/kubescape/node-agent v0.3.38 github.com/kubescape/opa-utils v0.0.285 - github.com/kubescape/storage v0.0.239 + github.com/kubescape/storage v0.0.301 github.com/panjf2000/ants/v2 v2.11.3 github.com/spf13/viper v1.21.0 github.com/stretchr/testify v1.11.1 diff --git a/go.sum b/go.sum index afad064..2d79e84 100644 --- a/go.sum +++ b/go.sum @@ -702,8 +702,8 @@ github.com/kubescape/backend v0.0.37 h1:aAMd5M0Ih4h+enD0LdKzVIDXYVFqEuFBkSyjiGto github.com/kubescape/backend v0.0.37/go.mod h1:4TjTNf9GSD2XxrnW6doB3ANSFzFEkXKYZHGFQX0BiKM= github.com/kubescape/go-logger v0.0.28 h1:xulKTp9kOg3rD98sopFELQ6yZCHQoQXMDzteoSHDFKI= github.com/kubescape/go-logger v0.0.28/go.mod h1:YZHFjwGCDar1hP9OyBLE46oR7a0Y/Z/0FperDo8+9D0= -github.com/kubescape/k8s-interface v0.0.202 h1:yu9x+07crFQAgrBatFFU2WuuxMJfHUMHVuCzuHE9Q4M= -github.com/kubescape/k8s-interface v0.0.202/go.mod h1:d4NVhL81bVXe8yEXlkT4ZHrt3iEppEIN39b8N1oXm5s= +github.com/kubescape/k8s-interface v0.0.214 h1:j7KP0/5VvYOoQdBGV2+gRM3qnR8PWLAGF8RM/k/DmJ0= +github.com/kubescape/k8s-interface v0.0.214/go.mod h1:WNYUG93aZ5kDmuaRKFLtVhp18Yc6EfaHdD1gLYtVTN4= github.com/kubescape/kubescape-network-scanner v0.0.15 h1:LsaVCQzj0PbA30BeFdzxchW2bkg6nn5quwllWmm/2/s= github.com/kubescape/kubescape-network-scanner v0.0.15/go.mod h1:fqTzRCWsuniGEEZHtOEdITxnqx+i5ICdOVuenSQJd3U= github.com/kubescape/kubescape/v3 v3.0.4 h1:gZ5d8QMxLYZQ6Yz9wRvGcDQlBUIV+v/Y/41g56/YDy8= @@ -716,8 +716,8 @@ github.com/kubescape/rbac-utils v0.0.21-0.20230806101615-07e36f555520 h1:SqlwF8G github.com/kubescape/rbac-utils v0.0.21-0.20230806101615-07e36f555520/go.mod h1:wuxMUSDzGUyWd25IJfBzEJ/Udmw2Vy7npj+MV3u3GrU= github.com/kubescape/regolibrary v1.0.317-0.20240320124840-1d84ac7186ea h1:hLUe+1bdhiBD7xM/jliQozVd1NLYn1afQLxl5trQdPk= github.com/kubescape/regolibrary v1.0.317-0.20240320124840-1d84ac7186ea/go.mod h1:RK9dHjllKFnISDmVExQlI1B1z93TlQsAu/Kq9c0mt2U= -github.com/kubescape/storage v0.0.239 h1:hfuq1+CuEAKE7zCg9bB8gfU9vZoGMrJBgNh5tAD1rak= -github.com/kubescape/storage v0.0.239/go.mod h1:f6u/Lt3SjUTBrmzOStb33IkKTtaqKM4pyfV5d1lUMiY= +github.com/kubescape/storage v0.0.301 h1:SsyS1Xdq8ClIOqCB5gNg7X82lGfrSpWLI+J+VenHr6k= +github.com/kubescape/storage v0.0.301/go.mod h1:d/1hqWPda2clsjx2wmQgysnB5dThIo3rDKP7RWx+v+M= github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw= @@ -1126,8 +1126,8 @@ go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.43.0 h1:w1K go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.43.0/go.mod h1:HBy4BjzgVE8139ieRI75oXm3EcDN+6GhD88JT1Kjvxg= go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.43.0 h1:88Y4s2C8oTui1LGM6bTWkw0ICGcOLCAI5l6zsD1j20k= go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.43.0/go.mod h1:Vl1/iaggsuRlrHf/hfPJPvVag77kKyvrLeD10kpMl+A= -go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.35.0 h1:m639+BofXTvcY1q8CGs4ItwQarYtJPOWmVobfM1HpVI= -go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.35.0/go.mod h1:LjReUci/F4BUyv+y4dwnq3h/26iNOeC3wAIqgvTIZVo= +go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.43.0 h1:RAE+JPfvEmvy+0LzyUA25/SGawPwIUbZ6u0Wug54sLc= +go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.43.0/go.mod h1:AGmbycVGEsRx9mXMZ75CsOyhSP6MFIcj/6dnG+vhVjk= go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.43.0 h1:3iZJKlCZufyRzPzlQhUIWVmfltrXuGyfjREgGP3UUjc= go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.43.0/go.mod h1:/G+nUPfhq2e+qiXMGxMwumDrP5jtzU+mWN7/sjT2rak= go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.43.0 h1:mS47AX77OtFfKG4vtp+84kuGSFZHTyxtXIN269vChY0= diff --git a/mainhandler/findings.go b/mainhandler/findings.go index 2be1a04..fffb4ef 100644 --- a/mainhandler/findings.go +++ b/mainhandler/findings.go @@ -169,9 +169,9 @@ func summaryHasFailingSeverityAtLeast(summary *spdxv1beta1.WorkloadConfiguration // produced for from its kubescape.io/workload-* labels. It reports false when // the identifying labels are missing so an unidentifiable summary is skipped. func targetFromSummaryLabels(labels map[string]string) (remediators.Target, bool) { - kind := labels[helpers.KindMetadataKey] - name := labels[helpers.NameMetadataKey] - namespace := labels[helpers.NamespaceMetadataKey] + kind := labels[helpers.RelatedKindMetadataKey] + name := labels[helpers.RelatedNameMetadataKey] + namespace := labels[helpers.RelatedNamespaceMetadataKey] if kind == "" || name == "" { return remediators.Target{}, false } diff --git a/mainhandler/findings_test.go b/mainhandler/findings_test.go index aafa94c..d4215f0 100644 --- a/mainhandler/findings_test.go +++ b/mainhandler/findings_test.go @@ -24,9 +24,9 @@ func scanSummary(ns, kind, name string, controls map[string]spdxv1beta1.ScannedC Namespace: ns, Name: kind + "-" + name, Labels: map[string]string{ - helpers.KindMetadataKey: kind, - helpers.NameMetadataKey: name, - helpers.NamespaceMetadataKey: ns, + helpers.RelatedKindMetadataKey: kind, + helpers.RelatedNameMetadataKey: name, + helpers.RelatedNamespaceMetadataKey: ns, }, }, Spec: spdxv1beta1.WorkloadConfigurationScanSummarySpec{ diff --git a/watcher/containerprofilewatcher.go b/watcher/containerprofilewatcher.go index edac1c1..e3a31fe 100644 --- a/watcher/containerprofilewatcher.go +++ b/watcher/containerprofilewatcher.go @@ -161,13 +161,13 @@ func (wh *WatchHandler) getContainerProfileWatcher() (watch.Interface, error) { } func getPod(client kubernetes.Interface, obj *spdxv1beta1.ContainerProfile) (*corev1.Pod, error) { - if kind, ok := obj.Labels[helpersv1.KindMetadataKey]; !ok || kind != "Pod" { + if kind, ok := obj.Labels[helpersv1.RelatedKindMetadataKey]; !ok || kind != "Pod" { return nil, nil } - podName, ok := obj.Labels[helpersv1.NameMetadataKey] + podName, ok := obj.Labels[helpersv1.RelatedNameMetadataKey] if !ok || podName == "" { - return nil, fmt.Errorf("label %s is missing", helpersv1.NameMetadataKey) + return nil, fmt.Errorf("label %s is missing", helpersv1.RelatedNameMetadataKey) } pod, err := client.CoreV1().Pods(obj.Namespace).Get(context.TODO(), podName, metav1.GetOptions{}) @@ -179,10 +179,10 @@ func (wh *WatchHandler) hasMatchingPod(labels map[string]string) bool { gvr := schema.GroupVersionResource{ Group: labels[helpersv1.ApiGroupMetadataKey], Version: labels[helpersv1.ApiVersionMetadataKey], - Resource: strings.ToLower(labels[helpersv1.KindMetadataKey]) + "s", + Resource: strings.ToLower(labels[helpersv1.RelatedKindMetadataKey]) + "s", } - name := labels[helpersv1.NameMetadataKey] - namespace := labels[helpersv1.NamespaceMetadataKey] + name := labels[helpersv1.RelatedNameMetadataKey] + namespace := labels[helpersv1.RelatedNamespaceMetadataKey] // get the unstructured workload object workloadObj, err := wh.k8sAPI.DynamicClient.Resource(gvr).Namespace(namespace).Get(context.TODO(), name, metav1.GetOptions{}) if err != nil { @@ -201,7 +201,7 @@ func (wh *WatchHandler) hasMatchingPod(labels map[string]string) bool { if labelsStr.Len() > 0 { labelsStr.WriteString(",") } - labelsStr.WriteString(fmt.Sprintf("%s=%s", key, val)) + fmt.Fprintf(&labelsStr, "%s=%s", key, val) } if labelsStr.Len() == 0 { logger.L().Debug("hasMatchingPod - empty pod selector from workload", helpers.String("gvr", gvr.String()), helpers.String("namespace", namespace), helpers.String("name", name)) diff --git a/watcher/containerprofilewatcher_test.go b/watcher/containerprofilewatcher_test.go index 53cf78d..b3642da 100644 --- a/watcher/containerprofilewatcher_test.go +++ b/watcher/containerprofilewatcher_test.go @@ -92,8 +92,8 @@ func TestHandleContainerProfileEvents(t *testing.T) { helpersv1.StatusMetadataKey: helpersv1.Learning, }, Labels: map[string]string{ - helpersv1.KindMetadataKey: "Pod", - helpersv1.NameMetadataKey: "foo-1747274700", + helpersv1.RelatedKindMetadataKey: "Pod", + helpersv1.RelatedNameMetadataKey: "foo-1747274700", }, }, Spec: spdxv1beta1.ContainerProfileSpec{ @@ -115,8 +115,8 @@ func TestHandleContainerProfileEvents(t *testing.T) { helpersv1.StatusMetadataKey: helpersv1.Learning, }, Labels: map[string]string{ - helpersv1.KindMetadataKey: "Pod", - helpersv1.NameMetadataKey: "foo2-2747274700", + helpersv1.RelatedKindMetadataKey: "Pod", + helpersv1.RelatedNameMetadataKey: "foo2-2747274700", }, }, Spec: spdxv1beta1.ContainerProfileSpec{ @@ -366,9 +366,9 @@ func TestWatchHandler_hasMatchingPod(t *testing.T) { labels: map[string]string{ helpersv1.ApiGroupMetadataKey: "apps", helpersv1.ApiVersionMetadataKey: "v1", - helpersv1.KindMetadataKey: "Deployment", - helpersv1.NameMetadataKey: "nginx-deployment", - helpersv1.NamespaceMetadataKey: "web", + helpersv1.RelatedKindMetadataKey: "Deployment", + helpersv1.RelatedNameMetadataKey: "nginx-deployment", + helpersv1.RelatedNamespaceMetadataKey: "web", }, want: true, }, @@ -377,9 +377,9 @@ func TestWatchHandler_hasMatchingPod(t *testing.T) { labels: map[string]string{ helpersv1.ApiGroupMetadataKey: "apps", helpersv1.ApiVersionMetadataKey: "v1", - helpersv1.KindMetadataKey: "Deployment", - helpersv1.NameMetadataKey: "nginx-deployment", - helpersv1.NamespaceMetadataKey: "other", + helpersv1.RelatedKindMetadataKey: "Deployment", + helpersv1.RelatedNameMetadataKey: "nginx-deployment", + helpersv1.RelatedNamespaceMetadataKey: "other", }, want: false, }, @@ -388,9 +388,9 @@ func TestWatchHandler_hasMatchingPod(t *testing.T) { labels: map[string]string{ helpersv1.ApiGroupMetadataKey: "apps", helpersv1.ApiVersionMetadataKey: "v1", - helpersv1.KindMetadataKey: "Deployment", - helpersv1.NameMetadataKey: "empty-deployment", - helpersv1.NamespaceMetadataKey: "web", + helpersv1.RelatedKindMetadataKey: "Deployment", + helpersv1.RelatedNameMetadataKey: "empty-deployment", + helpersv1.RelatedNamespaceMetadataKey: "web", }, want: false, },