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 #522

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
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
2 changes: 1 addition & 1 deletion rules/label-usage-for-resources/test/cronjob/expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"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
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
Loading