k8s: Validate API server not excluded admission plugins 32/95832/2
authorPawel Wieczorek <p.wieczorek2@samsung.com>
Tue, 17 Sep 2019 14:31:47 +0000 (16:31 +0200)
committerDaniel Rose <dr695h@att.com>
Thu, 19 Sep 2019 13:01:03 +0000 (13:01 +0000)
This patch verifies if CIS Kubernetes Benchmark v1.3.0 section
regarding master node configuration is satisfied (1.1.14).

Issue-ID: SECCOM-235
Change-Id: I63c2f8a5b94bfd6c9963805aae85595e6b6ad6d7
Signed-off-by: Pawel Wieczorek <p.wieczorek2@samsung.com>
test/security/k8s/src/check/cmd/check/check.go
test/security/k8s/src/check/validators/master/api.go
test/security/k8s/src/check/validators/master/api_test.go

index 64c4748..a351199 100644 (file)
@@ -61,4 +61,6 @@ func main() {
        log.Printf("IsServiceAccountAdmissionControlPluginIncluded: %t\n", master.IsServiceAccountAdmissionControlPluginIncluded(k8sParams))
        log.Printf("IsNodeRestrictionAdmissionControlPluginIncluded: %t\n", master.IsNodeRestrictionAdmissionControlPluginIncluded(k8sParams))
        log.Printf("IsEventRateLimitAdmissionControlPluginIncluded: %t\n", master.IsEventRateLimitAdmissionControlPluginIncluded(k8sParams))
+
+       log.Printf("IsNamespaceLifecycleAdmissionControlPluginNotExcluded: %t\n", master.IsNamespaceLifecycleAdmissionControlPluginNotExcluded(k8sParams))
 }
index 0bed711..dc22e35 100644 (file)
@@ -215,6 +215,14 @@ func IsEventRateLimitAdmissionControlPluginIncluded(params []string) bool {
        return false
 }
 
+// IsNamespaceLifecycleAdmissionControlPluginNotExcluded validates NamespaceLifecycle is excluded from admission control plugins.
+func IsNamespaceLifecycleAdmissionControlPluginNotExcluded(params []string) bool {
+       if isSingleFlagPresent("--disable-admission-plugins=", params) {
+               return !hasFlagArgumentIncluded("--disable-admission-plugins=", "NamespaceLifecycle", params)
+       }
+       return true
+}
+
 // isSingleFlagPresent checks presence of selected flag and whether it was used once.
 func isSingleFlagPresent(flag string, params []string) bool {
        found := filterFlags(params, flag)
index 4e12566..233662a 100644 (file)
@@ -305,5 +305,15 @@ var _ = Describe("Api", func() {
                        Entry("Is not present on Dublin cluster", kubeApiServerDublin, false),
                        Entry("Should be present on CIS-compliant cluster", kubeApiServerCISCompliant, true),
                )
+
+               DescribeTable("NamespaceLifecycle admission control plugin",
+                       func(params []string, expected bool) {
+                               Expect(IsNamespaceLifecycleAdmissionControlPluginNotExcluded(params)).To(Equal(expected))
+                       },
+                       Entry("Is explicitly disabled on insecure cluster", []string{"--disable-admission-plugins=Foo,Bar,NamespaceLifecycle,Baz,Quuz"}, false),
+                       Entry("Should not be disabled on CIS-compliant cluster", kubeApiServerCISCompliant, true),
+                       Entry("Should not be disabled on Casablanca cluster", kubeApiServerCasablanca, true),
+                       Entry("Should not be disabled on Dublin cluster", kubeApiServerDublin, true),
+               )
        })
 })