Categorygithub.com/nirmata/kube-bench
repositorypackage
0.2.7-rc1
Repository: https://github.com/nirmata/kube-bench.git
Documentation: pkg.go.dev

# Packages

No description provided by the author

# README

kube-bench adapter

The kube-bench adapter runs a CIS benchmark check with a tool called kube-bench and produces a cluster-wide policy report based on the Policy Report Custom Resource Definition

Running

Prerequisites:

  • To run the Kubernetes cluster locally, tools like kind or minikube can be used. Here are the steps to run the kube-bench adapater with a kind cluster.

Steps

Common steps

# 1. Create a Kubernetes cluster
kind create cluster

# 2. Create a CustomResourceDefinition
kubectl create -f kubernetes/crd/v1alpha2/wgpolicyk8s.io_clusterpolicyreports.yaml

Steps to run kube-bench adapter in-cluster as a Cron-Job

# 3. Create Role, Role-Binding and Services
kubectl create -f kubernetes/role.yaml -f kubernetes/rb.yaml -f kubernetes/service.yaml

# 4. Create cron-job
kubectl create -f kubernetes/cron-job.yaml

# 5. Watch the jobs
kubectl get jobs --watch

# 6. Check policyreports created through the custom resource
kubectl get clusterpolicyreports

Steps to run kube-bench adapter from outside a cluster

Building
make build-local
Installing
# Create policy report using
./policyreport -name="kube-bench" -kube-bench-targets="master,node" -kube-bench-benchmark=cis-1.7 -category="CIS Kubernetes Benchmarks"

# Check policyreports created through the custom resource
kubectl get clusterpolicyreports
Command Line Arguments
ArgumentTypeDefault valueAllowed valueUsage
-categorystringCIS Kubernetes BenchmarksAny string name valid for categorycategory of the policy report
-namespacestringdefaultany string name for required namespacespecifies namespace where kube-bench job will run
-kube-bench-benchmarkstringcis-1.7See CIS Kubernetes Benchmark supportspecify the benchmark for kube-bench job
-kube-bench-targetsstring(accepts multiple values)master,node,etcd,policiesmaster, controlplane, node, etcd, policiestargets for benchmark of kube-bench job
-kube-bench-versionstring1.21Kubernetes Version like 1.20,1.21,etcspecify the Kubernetes version for kube-bench job
-kube-bench-imagestringaquasec/kube-bench:latestaquasec/kube-bench:(kube-bench-version)kube-bench image used as part of this test
-kubeconfigstring$HOME/.kube/configpath to your KUBECONFIGabsolute path to the kubeconfig file
-namestringkube-benchAny name of string typename of policy report

Project Maintenance

Updating the Policy Report CRD

Updating the kube-bench jobs

Notes:

  • Flags -name, -category are user configurable and can be changed by changing the variable on the right hand side.
  • In order to generate policy report in the form of YAML, we can do kubectl get clusterpolicyreports -o yaml > res.yaml which will generate it as res.yaml in this case.