Skip to content

Commit

Permalink
Merge pull request kubescape#883 from kubescape/dev
Browse files Browse the repository at this point in the history
Minor changes
  • Loading branch information
David Wertenteil authored Oct 26, 2022
2 parents 3373b72 + 4277331 commit dd7a8fd
Show file tree
Hide file tree
Showing 12 changed files with 55 additions and 22 deletions.
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,15 @@ kubescape scan --submit --enable-host-scan --verbose
</br>

## Architecture in short
### CLI
<img src="docs/ks-cli-arch.png" width="300">
### [CLI](#kubescape-cli)
<div align="center">
<img src="docs/ks-cli-arch.png" width="300" alt="cli-diagram">
</div>

### Operator
<img src="docs/ks-operator-arch.png" width="300">
### [Operator](https://github.com/kubescape/helm-charts#readme)
<div align="center">
<img src="docs/ks-operator-arch.png" width="300" alt="operator-diagram">
</div>

### Please [star ⭐](https://github.com/kubescape/kubescape/stargazers) the repo if you want us to continue developing and improving Kubescape 😀

Expand Down Expand Up @@ -92,6 +96,7 @@ We hold community meetings in [Zoom](https://us02web.zoom.us/j/84020231442) on t
* [Overview](https://youtu.be/wdBkt_0Qhbg)
* [How To Secure Kubernetes Clusters With Kubescape And Armo](https://youtu.be/ZATGiDIDBQk)
* [Scan Kubernetes YAML files](https://youtu.be/Ox6DaR7_4ZI)
* [Scan container image registry](https://youtu.be/iQ_k8EnK-3s)
* [Scan Kubescape on an air-gapped environment (offline support)](https://youtu.be/IGXL9s37smM)
* [Managing exceptions in the Kubescape SaaS version](https://youtu.be/OzpvxGmCR80)
* [Configure and run customized frameworks](https://youtu.be/12Sanq_rEhs)
Expand Down
2 changes: 1 addition & 1 deletion core/cautils/fileutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"github.com/kubescape/opa-utils/objectsenvelopes"
"github.com/kubescape/opa-utils/objectsenvelopes/localworkload"

"gopkg.in/yaml.v2"
"gopkg.in/yaml.v3"
)

var (
Expand Down
5 changes: 3 additions & 2 deletions core/cautils/scaninfo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ func TestSetContextMetadata(t *testing.T) {
assert.Nil(t, ctx.HelmContextMetadata)
assert.Nil(t, ctx.RepoContextMetadata)
}
{
// TODO: tests were commented out due to actual http calls ; http calls should be mocked.
/*{
ctx := reporthandlingv2.ContextMetadata{}
setContextMetadata(&ctx, "https://github.com/kubescape/kubescape")
Expand All @@ -31,7 +32,7 @@ func TestSetContextMetadata(t *testing.T) {
assert.Equal(t, "kubescape", ctx.RepoContextMetadata.Repo)
assert.Equal(t, "kubescape", ctx.RepoContextMetadata.Owner)
assert.Equal(t, "master", ctx.RepoContextMetadata.Branch)
}
}*/
}

func TestGetHostname(t *testing.T) {
Expand Down
6 changes: 5 additions & 1 deletion core/cautils/workloadmappingutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cautils
import (
"strings"

"github.com/kubescape/k8s-interface/cloudsupport"
"github.com/kubescape/opa-utils/reporthandling/apis"
)

Expand All @@ -19,7 +20,10 @@ var (
"KubeProxyInfo",
"ControlPlaneInfo",
}
CloudResources = []string{"ClusterDescribe"}
CloudResources = []string{
"ClusterDescribe",
string(cloudsupport.TypeApiServerInfo),
}
)

func MapKSResource(ksResourceMap *KSResources, resources []string) []string {
Expand Down
4 changes: 2 additions & 2 deletions core/pkg/hostsensorutils/hostsensor.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ spec:
effect: NoSchedule
containers:
- name: host-sensor
image: quay.io/kubescape/host-scanner:v1.0.28
image: quay.io/kubescape/host-scanner:v1.0.32
securityContext:
privileged: true
readOnlyRootFilesystem: true
Expand Down Expand Up @@ -72,4 +72,4 @@ spec:
name: host-filesystem
hostNetwork: true
hostPID: true
hostIPC: true
hostIPC: true
19 changes: 19 additions & 0 deletions core/pkg/resourcehandler/k8sresources.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,32 @@ func (k8sHandler *K8sResourceHandler) GetResources(sessionObj *cautils.OPASessio
sessionObj.Metadata.ContextMetadata.ClusterContextMetadata.CloudProvider = provider
}
}

// api server info resource
err = k8sHandler.collectAPIServerInfoResource(allResources, ksResourceMap)
if err != nil {
logger.L().Warning("failed to collect api server info resource", helpers.Error(err))
}

cautils.StopSpinner()
logger.L().Info("Requested cloud provider data")
}

return k8sResourcesMap, allResources, ksResourceMap, nil
}

func (k8sHandler *K8sResourceHandler) collectAPIServerInfoResource(allResources map[string]workloadinterface.IMetadata, ksResourceMap *cautils.KSResources) error {
clusterAPIServerInfo, err := k8sHandler.k8s.DiscoveryClient.ServerVersion()
if err != nil {
return err
}
resource := cloudsupport.NewApiServerVersionInfo(clusterAPIServerInfo)
allResources[resource.GetID()] = resource
(*ksResourceMap)[fmt.Sprintf("%s/%s", resource.GetApiVersion(), resource.GetKind())] = []string{resource.GetID()}

return nil
}

func (k8sHandler *K8sResourceHandler) GetClusterAPIServerInfo() *version.Info {
clusterAPIServerInfo, err := k8sHandler.k8s.DiscoveryClient.ServerVersion()
if err != nil {
Expand Down
5 changes: 5 additions & 0 deletions core/pkg/resourcehandler/repositoryscanner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ var (
urlD = "https://raw.githubusercontent.com/kubescape/kubescape/master/examples/online-boutique/adservice.yaml"
)

/*
TODO: tests were commented out due to actual http calls ; http calls should be mocked.
func TestScanRepository(t *testing.T) {
{
files, err := ScanRepository(urlA, "")
Expand Down Expand Up @@ -112,6 +116,7 @@ func TestGithubGetYamlFromTree(t *testing.T) {
assert.Equal(t, 12, len(files))
}
}
*/

func TestGithubParse(t *testing.T) {
{
Expand Down
7 changes: 3 additions & 4 deletions core/pkg/resourcehandler/urlloader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ package resourcehandler

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestLoadResourcesFromUrl(t *testing.T) {
{
//TODO: tests were commented out due to actual http calls ; http calls should be mocked.
/*{
workloads, err := loadResourcesFromUrl([]string{"https://github.com/kubescape/kubescape/tree/master/examples/online-boutique"})
assert.NoError(t, err)
assert.Equal(t, 12, len(workloads))
Expand Down Expand Up @@ -62,5 +61,5 @@ func TestLoadResourcesFromUrl(t *testing.T) {
assert.Equal(t, "/v1//Service/adservice", w[1].GetID())
}
}
}
}*/
}
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ require (
github.com/google/uuid v1.3.0
github.com/johnfercher/maroto v0.37.0
github.com/kubescape/go-logger v0.0.6
github.com/kubescape/k8s-interface v0.0.83
github.com/kubescape/k8s-interface v0.0.84
github.com/kubescape/opa-utils v0.0.194
github.com/kubescape/rbac-utils v0.0.17
github.com/libgit2/git2go/v33 v33.0.9
Expand All @@ -26,7 +26,7 @@ require (
github.com/stretchr/testify v1.8.0
github.com/whilp/git-urls v1.0.0
golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3
gopkg.in/yaml.v2 v2.4.0
gopkg.in/yaml.v3 v3.0.1
helm.sh/helm/v3 v3.9.0
k8s.io/api v0.24.3
k8s.io/apimachinery v0.24.3
Expand Down Expand Up @@ -165,7 +165,7 @@ require (
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/square/go-jose.v2 v2.6.0 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
k8s.io/apiextensions-apiserver v0.24.2 // indirect
k8s.io/klog/v2 v2.60.1 // indirect
k8s.io/kube-openapi v0.0.0-20220328201542-3ee0da9b0b42 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -548,8 +548,8 @@ 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.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/k8s-interface v0.0.84 h1:k7YzpQ3SaN+bJCtpXzMj60WWIK9RkQQrU8dFQutr3LA=
github.com/kubescape/k8s-interface v0.0.84/go.mod h1:ihX96yqar+xogHl45mFE8zT9DLI06iy7XQPAP+j5KJE=
github.com/kubescape/opa-utils v0.0.194 h1:DroUvGV1R/PXsLPF6H4GB9LzcEylEMUKULs8vQBOU3w=
github.com/kubescape/opa-utils v0.0.194/go.mod h1:frMpD9wuK6rE3tMRIy6EM1X9zi+sSbXoDWjcSaq11og=
github.com/kubescape/rbac-utils v0.0.17 h1:B78kjlTKqjYK/PXwmi4GPysHsFxIwVz1KFb4+IGT29w=
Expand Down
2 changes: 1 addition & 1 deletion httphandler/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ require (
github.com/json-iterator/go v1.1.12 // indirect
github.com/jung-kurt/gofpdf v1.16.2 // indirect
github.com/kevinburke/ssh_config v0.0.0-20201106050909-4977a11b4351 // indirect
github.com/kubescape/k8s-interface v0.0.83 // indirect
github.com/kubescape/k8s-interface v0.0.84 // indirect
github.com/kubescape/rbac-utils v0.0.17 // indirect
github.com/libgit2/git2go/v33 v33.0.9 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
Expand Down
4 changes: 2 additions & 2 deletions httphandler/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -612,8 +612,8 @@ 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.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/k8s-interface v0.0.84 h1:k7YzpQ3SaN+bJCtpXzMj60WWIK9RkQQrU8dFQutr3LA=
github.com/kubescape/k8s-interface v0.0.84/go.mod h1:ihX96yqar+xogHl45mFE8zT9DLI06iy7XQPAP+j5KJE=
github.com/kubescape/opa-utils v0.0.194 h1:DroUvGV1R/PXsLPF6H4GB9LzcEylEMUKULs8vQBOU3w=
github.com/kubescape/opa-utils v0.0.194/go.mod h1:frMpD9wuK6rE3tMRIy6EM1X9zi+sSbXoDWjcSaq11og=
github.com/kubescape/rbac-utils v0.0.17 h1:B78kjlTKqjYK/PXwmi4GPysHsFxIwVz1KFb4+IGT29w=
Expand Down

0 comments on commit dd7a8fd

Please sign in to comment.