Skip to content

Commit

Permalink
Fix fixpath for controls C-0077 and C-0076 (#523)
Browse files Browse the repository at this point in the history
* SUB-2185 - improve C-0262

Signed-off-by: YiscahLevySilas1 <[email protected]>

* minor fix

Signed-off-by: YiscahLevySilas1 <[email protected]>

* add [] to fixpath

Signed-off-by: YiscahLevySilas1 <[email protected]>

* add [] to fixpath

Signed-off-by: YiscahLevySilas1 <[email protected]>

* add [] to fixpath

Signed-off-by: YiscahLevySilas1 <[email protected]>

---------

Signed-off-by: YiscahLevySilas1 <[email protected]>
  • Loading branch information
YiscahLevySilas1 authored Oct 12, 2023
1 parent 46cdc49 commit e07de44
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 13 deletions.
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

0 comments on commit e07de44

Please sign in to comment.