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 Audit Log Maxsize Not Properly Set for Kubernetes (C…
…heckmarx#5105) * + Audit Log Maxsize Not Properly Set * typo correction * correct positive_expected_result
- Loading branch information
1 parent
6e6b3f2
commit 2558da6
Showing
7 changed files
with
119 additions
and
0 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
assets/queries/k8s/audit_log_maxsize_not_properly_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": "35c0a471-f7c8-4993-aa2c-503a3c712a66", | ||
"queryName": "Audit Log Maxsize Not Properly Set", | ||
"severity": "LOW", | ||
"category": "Observability", | ||
"descriptionText": "When using kube-apiserver command, the '--audit-log-maxsize' flag should be defined and set to 100 or more MegaBytes", | ||
"descriptionUrl": "https://kubernetes.io/docs/reference/command-line-tools-reference/kube-apiserver/", | ||
"platform": "Kubernetes", | ||
"descriptionID": "9609fc23" | ||
} |
43 changes: 43 additions & 0 deletions
43
assets/queries/k8s/audit_log_maxsize_not_properly_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,43 @@ | ||
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") | ||
k8sLib.startWithFlag(container, "--audit-log-maxsize") | ||
not k8sLib.hasFlagEqualOrGreaterThanValue(container, "--audit-log-maxsize", 100) | ||
|
||
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": "IncorrectValue", | ||
"keyExpectedValue": "--audit-log-maxsize flag should be set to 100 or more MegaBytes", | ||
"keyActualValue": "--audit-log-maxsize flag is set to less than 100 MegaBytes", | ||
"searchLine": common_lib.build_search_line(split(specInfo.path, "."), [types[x], j, "command"]), | ||
} | ||
} | ||
|
||
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.startWithFlag(container, "--audit-log-maxsize") | ||
|
||
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": "--audit-log-maxsize flag should be defined and set to 100 or more MegaBytes", | ||
"keyActualValue": "--audit-log-maxsize flag is not defined", | ||
"searchLine": common_lib.build_search_line(split(specInfo.path, "."), [types[x], j, "command"]), | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
assets/queries/k8s/audit_log_maxsize_not_properly_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: ["--audit-log-maxsize=150"] | ||
restartPolicy: OnFailure |
13 changes: 13 additions & 0 deletions
13
assets/queries/k8s/audit_log_maxsize_not_properly_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","--audit-log-maxsize=100"] | ||
args: [] | ||
restartPolicy: OnFailure |
13 changes: 13 additions & 0 deletions
13
assets/queries/k8s/audit_log_maxsize_not_properly_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: ["--audit-log-maxsize=50"] | ||
restartPolicy: OnFailure |
13 changes: 13 additions & 0 deletions
13
assets/queries/k8s/audit_log_maxsize_not_properly_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: [] | ||
restartPolicy: OnFailure |
14 changes: 14 additions & 0 deletions
14
assets/queries/k8s/audit_log_maxsize_not_properly_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": "Audit Log Maxsize Not Properly Set", | ||
"severity": "LOW", | ||
"line": 11, | ||
"fileName": "positive1.yaml" | ||
}, | ||
{ | ||
"queryName": "Audit Log Maxsize Not Properly Set", | ||
"severity": "LOW", | ||
"line": 11, | ||
"fileName": "positive2.yaml" | ||
} | ||
] |