From 2a5712bd3c8246324018cb76785197d8b3620ad7 Mon Sep 17 00:00:00 2001 From: dwertent Date: Tue, 5 Oct 2021 16:11:41 +0300 Subject: [PATCH 1/2] fixed in cluster crash --- build/Dockerfile | 3 +++ cautils/k8sinterface/k8sconfig.go | 13 +++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/build/Dockerfile b/build/Dockerfile index 008bc618..caf221cd 100644 --- a/build/Dockerfile +++ b/build/Dockerfile @@ -10,4 +10,7 @@ RUN GOOS=linux CGO_ENABLED=0 go build -ldflags="-s -w " -installsuffix cgo -o k FROM alpine COPY --from=builder /work/kubescape /usr/bin/kubescape +# # Download the frameworks. Use the "--use-default" flag when running kubescape +# RUN kubescape download framework nsa && kubescape download framework mitre + CMD ["kubescape"] diff --git a/cautils/k8sinterface/k8sconfig.go b/cautils/k8sinterface/k8sconfig.go index a0ca53eb..bc1804ac 100644 --- a/cautils/k8sinterface/k8sconfig.go +++ b/cautils/k8sinterface/k8sconfig.go @@ -104,13 +104,18 @@ func GetClusterName() string { } func GetDefaultNamespace() string { + defaultNamespace := "default" clientCfg, err := clientcmd.NewDefaultClientConfigLoadingRules().Load() if err != nil { - return "default" + return defaultNamespace } - namespace := clientCfg.Contexts[clientCfg.CurrentContext].Namespace - if namespace == "" { - namespace = "default" + apiContext, ok := clientCfg.Contexts[clientCfg.CurrentContext] + if !ok || apiContext == nil { + return defaultNamespace + } + namespace := apiContext.Namespace + if apiContext.Namespace == "" { + namespace = defaultNamespace } return namespace } From f11f054fea167aa76b0041da9d0580dc16c4e4b5 Mon Sep 17 00:00:00 2001 From: dwertent Date: Tue, 5 Oct 2021 16:51:03 +0300 Subject: [PATCH 2/2] offline not new feature --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 83f57a7c..4b0ee369 100644 --- a/README.md +++ b/README.md @@ -115,7 +115,7 @@ for example: ``` helm template bitnami/mysql --generate-name --dry-run | kubescape scan framework nsa - ``` -### Offline Support +### Offline Support It is possible to run Kubescape offline!