forked from Checkmarx/kics
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(query): Added Authorization Mode Node Not Set for Kubernetes (Ch…
…eckmarx#5070) * + Authorization Mode Node Not Set * + added func to k8s library and description change
- Loading branch information
1 parent
1cf3067
commit 397c9a0
Showing
8 changed files
with
101 additions
and
17 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
assets/queries/k8s/authorization_mode_node_not_set/metadata.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"id": "4d7ee40f-fc5d-427d-8cac-dffbe22d42d1", | ||
"queryName": "Authorization Mode Node Not Set", | ||
"severity": "MEDIUM", | ||
"category": "Insecure Configurations", | ||
"descriptionText": "When using kube-apiserver command, the 'authorization-mode' flag should have 'Node' mode", | ||
"descriptionUrl": "https://kubernetes.io/docs/reference/command-line-tools-reference/kube-apiserver/", | ||
"platform": "Kubernetes", | ||
"descriptionID": "1d944481" | ||
} |
24 changes: 24 additions & 0 deletions
24
assets/queries/k8s/authorization_mode_node_not_set/query.rego
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package Cx | ||
|
||
import data.generic.common as common_lib | ||
import data.generic.k8s as k8sLib | ||
|
||
CxPolicy[result] { | ||
resource := input.document[i] | ||
metadata := resource.metadata | ||
specInfo := k8sLib.getSpecInfo(resource) | ||
types := {"initContainers", "containers"} | ||
container := specInfo.spec[types[x]][j] | ||
common_lib.inArray(container.command, "kube-apiserver") | ||
not k8sLib.hasFlagWithValue(container, "--authorization-mode", "Node") | ||
|
||
result := { | ||
"documentId": input.document[i].id, | ||
"searchKey": sprintf("metadata.name={{%s}}.%s.%s.name={{%s}}.command", [metadata.name, specInfo.path, types[x], container.name]), | ||
"issueType": "MissingAttribute", | ||
"keyExpectedValue": "--authorization-mode flag contains 'Node' mode", | ||
"keyActualValue": "--authorization-mode flag does not contain 'Node' mode", | ||
"searchLine": common_lib.build_search_line(split(specInfo.path, "."), [types[x], j, "command"]), | ||
} | ||
} | ||
|
13 changes: 13 additions & 0 deletions
13
assets/queries/k8s/authorization_mode_node_not_set/test/negative1.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
apiVersion: v1 | ||
kind: Pod | ||
metadata: | ||
name: command-demo | ||
labels: | ||
purpose: demonstrate-command | ||
spec: | ||
containers: | ||
- name: command-demo-container | ||
image: gcr.io/google_containers/kube-apiserver-amd64:v1.6.0 | ||
command: ["kube-apiserver"] | ||
args: ["--authorization-mode=RBAC,Node"] | ||
restartPolicy: OnFailure |
13 changes: 13 additions & 0 deletions
13
assets/queries/k8s/authorization_mode_node_not_set/test/negative2.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
apiVersion: v1 | ||
kind: Pod | ||
metadata: | ||
name: command-demo | ||
labels: | ||
purpose: demonstrate-command | ||
spec: | ||
containers: | ||
- name: command-demo-container | ||
image: gcr.io/google_containers/kube-apiserver-amd64:v1.6.0 | ||
command: ["kube-apiserver","--authorization-mode=RBAC,Node"] | ||
args: [] | ||
restartPolicy: OnFailure |
13 changes: 13 additions & 0 deletions
13
assets/queries/k8s/authorization_mode_node_not_set/test/positive1.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
apiVersion: v1 | ||
kind: Pod | ||
metadata: | ||
name: command-demo | ||
labels: | ||
purpose: demonstrate-command | ||
spec: | ||
containers: | ||
- name: command-demo-container | ||
image: gcr.io/google_containers/kube-apiserver-amd64:v1.6.0 | ||
command: ["kube-apiserver"] | ||
args: ["--authorization-mode=AlwaysAllow"] | ||
restartPolicy: OnFailure |
13 changes: 13 additions & 0 deletions
13
assets/queries/k8s/authorization_mode_node_not_set/test/positive2.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
apiVersion: v1 | ||
kind: Pod | ||
metadata: | ||
name: command-demo | ||
labels: | ||
purpose: demonstrate-command | ||
spec: | ||
containers: | ||
- name: command-demo-container | ||
image: gcr.io/google_containers/kube-apiserver-amd64:v1.6.0 | ||
command: ["kube-apiserver"] | ||
args: ["--authorization-mode=RBAC"] | ||
restartPolicy: OnFailure |
14 changes: 14 additions & 0 deletions
14
assets/queries/k8s/authorization_mode_node_not_set/test/positive_expected_result.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[ | ||
{ | ||
"queryName": "Authorization Mode Node Not Set", | ||
"severity": "MEDIUM", | ||
"line": 11, | ||
"filename": "positive1.yaml" | ||
}, | ||
{ | ||
"queryName": "Authorization Mode Node Not Set", | ||
"severity": "MEDIUM", | ||
"line": 11, | ||
"filename": "positive2.yaml" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters