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

Fix fixpath for controls C-0077 and C-0076 #523

Merged
merged 9 commits into from
Oct 12, 2023
6 changes: 3 additions & 3 deletions rules/k8s-common-labels-usage/raw.rego
Original file line number Diff line number Diff line change
Expand Up @@ -87,21 +87,21 @@ no_K8s_label_usage(wl, podSpec, beggining_of_pod_path) = path{
no_K8s_label_or_no_K8s_label_usage(wl, start_of_path) = path{
not wl.metadata.labels
label_key := get_label_key("")
path = [{"path": sprintf("%vmetadata.labels.%v", [start_of_path, label_key]), "value": "YOUR_VALUE"}]
path = [{"path": sprintf("%vmetadata.labels[%v]", [start_of_path, label_key]), "value": "YOUR_VALUE"}]
}

no_K8s_label_or_no_K8s_label_usage(wl, start_of_path) = path{
metadata := wl.metadata
not metadata.labels
label_key := get_label_key("")
path = [{"path": sprintf("%vmetadata.labels.%v", [start_of_path, label_key]), "value": "YOUR_VALUE"}]
path = [{"path": sprintf("%vmetadata.labels[%v]", [start_of_path, label_key]), "value": "YOUR_VALUE"}]
}

no_K8s_label_or_no_K8s_label_usage(wl, start_of_path) = path{
labels := wl.metadata.labels
not all_kubernetes_labels(labels)
label_key := get_label_key("")
path = [{"path": sprintf("%vmetadata.labels.%v", [start_of_path, label_key]), "value": "YOUR_VALUE"}]
path = [{"path": sprintf("%vmetadata.labels[%v]", [start_of_path, label_key]), "value": "YOUR_VALUE"}]
}

all_kubernetes_labels(labels){
Expand Down
2 changes: 1 addition & 1 deletion rules/k8s-common-labels-usage/test/cronjob/expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"alertMessage": "the following cronjobs the kubernetes common labels are not defined: hello",
"failedPaths": [],
"fixPaths": [{
"path": "spec.jobTemplate.spec.template.metadata.labels.app.kubernetes.io/name",
"path": "spec.jobTemplate.spec.template.metadata.labels[app.kubernetes.io/name]",
"value": "YOUR_VALUE"
}],
"ruleStatus": "",
Expand Down
2 changes: 1 addition & 1 deletion rules/k8s-common-labels-usage/test/pod/expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"alertMessage": "in the following pod the kubernetes common labels are not defined: command-demo",
"failedPaths": [],
"fixPaths": [{
"path": "metadata.labels.YOUR_LABEL",
"path": "metadata.labels[YOUR_LABEL]",
"value": "YOUR_VALUE"
}],
"ruleStatus": "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"alertMessage": "Deployment: kubernetes-dashboard the kubernetes common labels are is not defined:",
"failedPaths": [],
"fixPaths": [{
"path": "spec.template.metadata.labels.app.kubernetes.io/name",
"path": "spec.template.metadata.labels[app.kubernetes.io/name]",
"value": "YOUR_VALUE"
}],
"ruleStatus": "",
Expand Down
6 changes: 3 additions & 3 deletions rules/label-usage-for-resources/raw.rego
Original file line number Diff line number Diff line change
Expand Up @@ -85,21 +85,21 @@ no_label_usage(wl, podSpec, beggining_of_pod_path) = path{
no_label_or_no_label_usage(wl, start_of_path) = path{
not wl.metadata
label_key := get_label_key("")
path = [{"path": sprintf("%vmetadata.labels.%v", [start_of_path, label_key]), "value": "YOUR_VALUE"}]
path = [{"path": sprintf("%vmetadata.labels[%v]", [start_of_path, label_key]), "value": "YOUR_VALUE"}]
}

no_label_or_no_label_usage(wl, start_of_path) = path{
metadata := wl.metadata
not metadata.labels
label_key := get_label_key("")
path = [{"path": sprintf("%vmetadata.labels.%v", [start_of_path, label_key]), "value": "YOUR_VALUE"}]
path = [{"path": sprintf("%vmetadata.labels[%v]", [start_of_path, label_key]), "value": "YOUR_VALUE"}]
}

no_label_or_no_label_usage(wl, start_of_path) = path{
labels := wl.metadata.labels
not is_desired_label(labels)
label_key := get_label_key("")
path = [{"path": sprintf("%vmetadata.labels.%v", [start_of_path, label_key]), "value": "YOUR_VALUE"}]
path = [{"path": sprintf("%vmetadata.labels[%v]", [start_of_path, label_key]), "value": "YOUR_VALUE"}]
}

is_desired_label(labels) {
Expand Down
4 changes: 2 additions & 2 deletions rules/label-usage-for-resources/test/cronjob/expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
"alertMessage": "the following cronjobs a certain set of labels is not defined: hello",
"failedPaths": [],
"fixPaths": [{
"path": "metadata.labels.YOUR_LABEL",
"path": "metadata.labels[YOUR_LABEL]",
"value": "YOUR_VALUE"
}, {
"path": "spec.jobTemplate.spec.template.metadata.labels.YOUR_LABEL",
"path": "spec.jobTemplate.spec.template.metadata.labels[YOUR_LABEL]",
"value": "YOUR_VALUE"
}],
"ruleStatus": "",
Expand Down
2 changes: 1 addition & 1 deletion rules/label-usage-for-resources/test/pod/expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"alertMessage": "in the following pods a certain set of labels is not defined: command-demo",
"failedPaths": [],
"fixPaths": [{
"path": "metadata.labels.app",
"path": "metadata.labels[app]",
"value": "YOUR_VALUE"
}],
"ruleStatus": "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"alertMessage": "Deployment: kubernetes-dashboard a certain set of labels is not defined:",
"failedPaths": [],
"fixPaths": [{
"path": "spec.template.metadata.labels.app",
"path": "spec.template.metadata.labels[app]",
"value": "YOUR_VALUE"
}],
"ruleStatus": "",
Expand Down