mirror of
https://github.com/aquasecurity/kube-bench.git
synced 2026-04-15 06:56:51 +00:00
Support CIS ACK 1.0.0 benchmark (#841)
* Support CIS ACK 1.0.0 benchmark * fix yaml lint * Fix TestMakeSubsitutions may failed when order of map changed * Support auto-detect platform when running on ACK * Apply suggestions from code review Co-authored-by: Yoav Rotem <yoavrotems97@gmail.com> Co-authored-by: Yoav Rotem <yoavrotems97@gmail.com>
This commit is contained in:
co-authored by
Yoav Rotem
parent
887965d31f
commit
47c2494728
+10
-8
@@ -306,7 +306,7 @@ func getKubeVersion() (*KubeVersion, error) {
|
||||
glog.Warning(missingKubectlKubeletMessage)
|
||||
glog.V(1).Info("unable to find the programs kubectl or kubelet in the PATH")
|
||||
glog.V(1).Infof("Cant detect version, assuming default %s", defaultKubeVersion)
|
||||
return &KubeVersion{baseVersion: defaultKubeVersion}, nil
|
||||
return &KubeVersion{baseVersion: defaultKubeVersion}, nil
|
||||
}
|
||||
return getKubeVersionFromKubelet(), nil
|
||||
}
|
||||
@@ -430,7 +430,7 @@ These program names are provided in the config.yaml, section '%s.%s.bins'
|
||||
func getPlatformName() string {
|
||||
|
||||
openShiftVersion := getOpenShiftVersion()
|
||||
if openShiftVersion != ""{
|
||||
if openShiftVersion != "" {
|
||||
return openShiftVersion
|
||||
}
|
||||
|
||||
@@ -458,6 +458,8 @@ func getPlatformBenchmarkVersion(platform string) string {
|
||||
return "eks-1.0"
|
||||
case "gke":
|
||||
return "gke-1.0"
|
||||
case "aliyun":
|
||||
return "ack-1.0"
|
||||
case "ocp-3.10":
|
||||
return "rh-0.7"
|
||||
case "ocp-4.1":
|
||||
@@ -466,7 +468,7 @@ func getPlatformBenchmarkVersion(platform string) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func getOpenShiftVersion() string{
|
||||
func getOpenShiftVersion() string {
|
||||
glog.V(1).Info("Checking for oc")
|
||||
_, err := exec.LookPath("oc")
|
||||
|
||||
@@ -482,9 +484,9 @@ func getOpenShiftVersion() string{
|
||||
subs = versionRe.FindStringSubmatch(string(out))
|
||||
}
|
||||
if len(subs) > 1 {
|
||||
glog.V(2).Infof("OCP output '%s' \nplatform is %s \nocp %v",string(out),getPlatformNameFromVersion(string(out)),subs[1])
|
||||
glog.V(2).Infof("OCP output '%s' \nplatform is %s \nocp %v", string(out), getPlatformNameFromVersion(string(out)), subs[1])
|
||||
ocpBenchmarkVersion, err := getOcpValidVersion(subs[1])
|
||||
if err == nil{
|
||||
if err == nil {
|
||||
return fmt.Sprintf("ocp-%s", ocpBenchmarkVersion)
|
||||
} else {
|
||||
glog.V(1).Infof("Can't get getOcpValidVersion: %v", err)
|
||||
@@ -504,13 +506,13 @@ func getOpenShiftVersion() string{
|
||||
func getOcpValidVersion(ocpVer string) (string, error) {
|
||||
ocpOriginal := ocpVer
|
||||
|
||||
for (!isEmpty(ocpVer)) {
|
||||
for !isEmpty(ocpVer) {
|
||||
glog.V(3).Info(fmt.Sprintf("getOcpBenchmarkVersion check for ocp: %q \n", ocpVer))
|
||||
if ocpVer == "3.10" || ocpVer == "4.1"{
|
||||
if ocpVer == "3.10" || ocpVer == "4.1" {
|
||||
glog.V(1).Info(fmt.Sprintf("getOcpBenchmarkVersion found valid version for ocp: %q \n", ocpVer))
|
||||
return ocpVer, nil
|
||||
}
|
||||
ocpVer = decrementVersion(ocpVer)
|
||||
ocpVer = decrementVersion(ocpVer)
|
||||
}
|
||||
|
||||
glog.V(1).Info(fmt.Sprintf("getOcpBenchmarkVersion unable to find a match for: %q", ocpOriginal))
|
||||
|
||||
+19
-4
@@ -15,14 +15,16 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"github.com/magiconair/properties/assert"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"sort"
|
||||
"strconv"
|
||||
"testing"
|
||||
|
||||
"github.com/magiconair/properties/assert"
|
||||
|
||||
"github.com/aquasecurity/kube-bench/check"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
@@ -389,9 +391,9 @@ func TestGetServiceFiles(t *testing.T) {
|
||||
|
||||
func TestMakeSubsitutions(t *testing.T) {
|
||||
cases := []struct {
|
||||
input string
|
||||
subst map[string]string
|
||||
exp string
|
||||
input string
|
||||
subst map[string]string
|
||||
exp string
|
||||
expectedSubs []string
|
||||
}{
|
||||
{input: "Replace $thisbin", subst: map[string]string{"this": "that"}, exp: "Replace that", expectedSubs: []string{"that"}},
|
||||
@@ -404,6 +406,7 @@ func TestMakeSubsitutions(t *testing.T) {
|
||||
if s != c.exp {
|
||||
t.Fatalf("Got %s expected %s", s, c.exp)
|
||||
}
|
||||
sort.Strings(subs)
|
||||
assert.Equal(t, c.expectedSubs, subs)
|
||||
})
|
||||
}
|
||||
@@ -536,6 +539,11 @@ func Test_getPlatformNameFromKubectlOutput(t *testing.T) {
|
||||
args: args{s: "v1.17.6-gke.1"},
|
||||
want: "gke",
|
||||
},
|
||||
{
|
||||
name: "ack",
|
||||
args: args{s: "v1.18.8-aliyun.1"},
|
||||
want: "aliyun",
|
||||
},
|
||||
{
|
||||
name: "unknown",
|
||||
args: args{s: "v1.17.6"},
|
||||
@@ -579,6 +587,13 @@ func Test_getPlatformBenchmarkVersion(t *testing.T) {
|
||||
},
|
||||
want: "gke-1.0",
|
||||
},
|
||||
{
|
||||
name: "aliyun",
|
||||
args: args{
|
||||
platform: "aliyun",
|
||||
},
|
||||
want: "ack-1.0",
|
||||
},
|
||||
{
|
||||
name: "unknown",
|
||||
args: args{
|
||||
|
||||
Reference in New Issue
Block a user