mirror of
https://github.com/aquasecurity/kube-bench.git
synced 2024-11-29 19:38:12 +00:00
Merge branch 'master' into unnecessary-warning
This commit is contained in:
commit
53eb720952
@ -539,7 +539,7 @@ groups:
|
|||||||
scored: true
|
scored: true
|
||||||
|
|
||||||
- id: 1.1.33
|
- id: 1.1.33
|
||||||
text: "1.1.34 Ensure that the --experimental-encryption-provider-config argument is
|
text: "Ensure that the --experimental-encryption-provider-config argument is
|
||||||
set as appropriate (Scored)"
|
set as appropriate (Scored)"
|
||||||
audit: "ps -ef | grep $apiserverbin | grep -v grep"
|
audit: "ps -ef | grep $apiserverbin | grep -v grep"
|
||||||
tests:
|
tests:
|
||||||
|
@ -27,6 +27,7 @@ import (
|
|||||||
var (
|
var (
|
||||||
envVarsPrefix = "KUBE_BENCH"
|
envVarsPrefix = "KUBE_BENCH"
|
||||||
cfgDir = "./cfg"
|
cfgDir = "./cfg"
|
||||||
|
defaultKubeVersion = "1.6"
|
||||||
cfgFile string
|
cfgFile string
|
||||||
jsonFmt bool
|
jsonFmt bool
|
||||||
pgSql bool
|
pgSql bool
|
||||||
|
39
cmd/util.go
39
cmd/util.go
@ -213,39 +213,30 @@ func multiWordReplace(s string, subname string, sub string) string {
|
|||||||
return strings.Replace(s, subname, sub, -1)
|
return strings.Replace(s, subname, sub, -1)
|
||||||
}
|
}
|
||||||
|
|
||||||
type version struct {
|
func getKubeVersion() string {
|
||||||
Server string
|
|
||||||
Client string
|
|
||||||
}
|
|
||||||
|
|
||||||
func getKubeVersion() *version {
|
|
||||||
ver := new(version)
|
|
||||||
// These executables might not be on the user's path.
|
// These executables might not be on the user's path.
|
||||||
_, err := exec.LookPath("kubectl")
|
_, err := exec.LookPath("kubectl")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s := fmt.Sprintf("Kubernetes version check skipped with error %v", err)
|
exitWithError(fmt.Errorf("kubernetes version check failed: %v", err))
|
||||||
continueWithError(err, sprintlnWarn(s))
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd := exec.Command("kubectl", "version")
|
cmd := exec.Command("kubectl", "version", "--short")
|
||||||
out, err := cmd.Output()
|
out, err := cmd.CombinedOutput()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s := fmt.Sprintf("Kubernetes version check skipped, with error getting kubectl version")
|
continueWithError(fmt.Errorf("%s", out), "")
|
||||||
continueWithError(err, sprintlnWarn(s))
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
clientVerRe := regexp.MustCompile(`Client.*Major:"(\d+)".*Minor:"(\d+)"`)
|
return getVersionFromKubectlOutput(string(out))
|
||||||
svrVerRe := regexp.MustCompile(`Server.*Major:"(\d+)".*Minor:"(\d+)"`)
|
}
|
||||||
|
|
||||||
sub := clientVerRe.FindStringSubmatch(string(out))
|
func getVersionFromKubectlOutput(s string) string {
|
||||||
ver.Client = sub[1] + "." + sub[2]
|
serverVersionRe := regexp.MustCompile(`Server Version: v(\d+.\d+)`)
|
||||||
|
subs := serverVersionRe.FindStringSubmatch(s)
|
||||||
sub = svrVerRe.FindStringSubmatch(string(out))
|
if len(subs) < 2 {
|
||||||
ver.Server = sub[1] + "." + sub[2]
|
printlnWarn(fmt.Sprintf("Unable to get kubectl version, using default version: %s", defaultKubeVersion))
|
||||||
|
return defaultKubeVersion
|
||||||
return ver
|
}
|
||||||
|
return subs[1]
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeSubstitutions(s string, ext string, m map[string]string) string {
|
func makeSubstitutions(s string, ext string, m map[string]string) string {
|
||||||
|
@ -17,7 +17,6 @@ package cmd
|
|||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
"regexp"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@ -182,19 +181,17 @@ func TestMultiWordReplace(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetKubeVersion(t *testing.T) {
|
func TestKubeVersionRegex(t *testing.T) {
|
||||||
ver := getKubeVersion()
|
ver := getVersionFromKubectlOutput(`Client Version: v1.8.0
|
||||||
if ver == nil {
|
Server Version: v1.8.12
|
||||||
t.Log("Expected non nil version info.")
|
`)
|
||||||
} else {
|
if ver != "1.8" {
|
||||||
if ok, err := regexp.MatchString(`\d+.\d+`, ver.Client); !ok && err != nil {
|
t.Fatalf("Expected 1.8 got %s", ver)
|
||||||
t.Logf("Expected:%v got %v\n", "n.m", ver.Client)
|
|
||||||
}
|
|
||||||
|
|
||||||
if ok, err := regexp.MatchString(`\d+.\d+`, ver.Server); !ok && err != nil {
|
|
||||||
t.Logf("Expected:%v got %v\n", "n.m", ver.Server)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ver = getVersionFromKubectlOutput("Something completely different")
|
||||||
|
if ver != "1.6" {
|
||||||
|
t.Fatalf("Expected 1.6 got %s", ver)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user