1
0
mirror of https://github.com/aquasecurity/kube-bench.git synced 2024-12-19 13:18:07 +00:00

Add ":" as a valid flag-value separator for tests

This is useful for checking values in YAML (possibly JSON) kubernetes config files.
This commit is contained in:
Abubakr-Sadik Nii Nai Davis 2019-04-10 22:47:26 +00:00
parent 54502c5f75
commit 4b8a7ffbe1
4 changed files with 22 additions and 1 deletions

View File

@ -166,6 +166,8 @@ func (c *Check) Run() {
i++
}
glog.V(3).Info(out.String())
finalOutput := c.Tests.execute(out.String())
if finalOutput != nil {
c.ActualValue = finalOutput.actualResult

View File

@ -158,3 +158,12 @@ groups:
set: true
- id: 14
text: "check that flag some-arg is set to some-val with ':' separator"
tests:
test_items:
- flag: "some-arg"
compare:
op: eq
value: some-val
set: true

View File

@ -68,7 +68,7 @@ func (t *testItem) execute(s string) *testOutput {
// --flag
// somevalue
//pttn := `(` + t.Flag + `)(=)*([^\s,]*) *`
pttn := `(` + t.Flag + `)(=)*([^\s]*) *`
pttn := `(` + t.Flag + `)(=|: *)*([^\s]*) *`
flagRe := regexp.MustCompile(pttn)
vals := flagRe.FindStringSubmatch(s)

View File

@ -110,6 +110,16 @@ func TestTestExecute(t *testing.T) {
controls.Groups[0].Checks[13],
"2:45 ../kubernetes/kube-apiserver --option --admission-control=Something ---audit-log-maxage=40",
},
{
// check for ':' as argument-value separator, with space between arg and val
controls.Groups[0].Checks[14],
"2:45 kube-apiserver some-arg: some-val --admission-control=Something ---audit-log-maxage=40",
},
{
// check for ':' as argument-value separator, with no space between arg and val
controls.Groups[0].Checks[14],
"2:45 kube-apiserver some-arg:some-val --admission-control=Something ---audit-log-maxage=40",
},
}
for _, c := range cases {