Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update(query): Updated "Kubelet Server Periodic Certificate Switch Disabled" to "Rotate Kubelet Server Certificate Not Active" #5030

Merged
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ 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]
Expand All @@ -15,7 +16,7 @@ CxPolicy[result] {

result := {
"documentId": input.document[i].id,
"searchKey": sprintf("spec.command", []),
"searchKey": sprintf("metadata.name={{%s}}.%s.%s.name={{%s}}.command", [metadata.name, specInfo.path, types[x], container.name]),
"issueType": "IncorrectValue",
"keyExpectedValue": "--rotate-certificates flag to be true",
"keyActualValue": "--rotate-certificates flag is false",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ CxPolicy[result] {

result := {
"documentId": input.document[i].id,
"searchKey": sprintf("spec.command", []),
"searchKey": sprintf("metadata.name={{%s}}.%s.%s.name={{%s}}.command", [metadata.name, specInfo.path, types[x], container.name]),
"issueType": "IncorrectValue",
"keyExpectedValue": "--make-iptables-util-chains flag to be true",
"keyActualValue": "--make-iptables-util-chains= flag is false",
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"id": "1c621b8e-2c6a-44f5-bd6a-fb0fb7ba33e2",
"queryName": "Kubelet Server Periodic Certificate Switch Disabled",
"queryName": "Rotate Kubelet Server Certificate Not Active",
"severity": "MEDIUM",
"category": "Secret Management",
"descriptionText": "Kubelet argument RotateKubeletServerCertificate should be true",
"descriptionText": "The RotateKubeletServerCertificate argument should be true",
"descriptionUrl": "https://kubernetes.io/docs/tasks/inject-data-application/define-command-argument-container/",
"platform": "Kubernetes",
"descriptionID": "a4f48785"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,23 @@ package Cx
import data.generic.common as common_lib
import data.generic.k8s as k8sLib

commandList = {"kubelet", "kube-controller-manager"}

CxPolicy[result] {
resource := input.document[i]
metadata := resource.metadata
specInfo := k8sLib.getSpecInfo(resource)
types := {"initContainers", "containers"}
container := specInfo.spec[types[x]][j]
command := "kubelet"
command := commandList[_]

common_lib.inArray(container.command, command)
k8sLib.hasFlag(container, "--feature-gates=RotateKubeletServerCertificate=false")
k8sLib.startWithFlag(container,"--feature-gates=")
contains_feature(container, "RotateKubeletServerCertificate=false")
joaorufi marked this conversation as resolved.
Show resolved Hide resolved

result := {
"documentId": input.document[i].id,
"searchKey": sprintf("spec.command", []),
"searchKey": sprintf("metadata.name={{%s}}.%s.%s.name={{%s}}.command", [metadata.name, specInfo.path, types[x], container.name]),
"issueType": "IncorrectValue",
"keyExpectedValue": "--feature-gates=RotateKubeletServerCertificate flag to be true",
"keyActualValue": "--feature-gates=RotateKubeletServerCertificate flag is false",
Expand All @@ -37,3 +41,14 @@ CxPolicy[result] {
"keyActualValue": "RotateKubeletServerCertificate is false",
}
}


contains_feature(container, feature){
contains_in_array(container.command, feature)
} else {
contains_in_array(container.args, feature)
}

contains_in_array(arr, item) {
contains(arr[_], item)
}
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-container7
image: gcr.io/google_containers/kube-apiserver-amd64:v1.6.0
command: ["kube-controller-manager"]
args: ["--feature-gates=RotateKubeletServerCertificate=false"]
restartPolicy: OnFailure
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[
{
"queryName": "Rotate Kubelet Server Certificate Not Active",
"severity": "MEDIUM",
"line": 8,
"filename": "positive1.yaml"
},
{
"queryName": "Rotate Kubelet Server Certificate Not Active",
"severity": "MEDIUM",
"line": 11,
"filename": "positive2.yaml"
},
{
"queryName": "Rotate Kubelet Server Certificate Not Active",
"severity": "MEDIUM",
"line": 8,
"filename": "positive3.json"
},{
"queryName": "Rotate Kubelet Server Certificate Not Active",
"severity": "MEDIUM",
"line": 11,
"filename": "positive4.yaml"
}
]