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

Rename deny rule to violation #169

Merged
merged 3 commits into from
Jul 8, 2019
Merged
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
4 changes: 2 additions & 2 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ spec:
rego: |
package k8srequiredlabels

deny[{"msg": msg, "details": {"missing_labels": missing}}] {
violation[{"msg": msg, "details": {"missing_labels": missing}}] {
provided := {label | input.review.object.metadata.labels[label]}
required := {label | label := input.constraint.spec.parameters.labels[_]}
missing := required - provided
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ spec:
rego: |
package k8sbannedimagetags

deny[{"msg": msg}] {
violation[{"msg": msg}] {
container := input.review.object.spec.containers[_]
img_split := split(container.image, ":")
tag := img_split[count(img_split) - 1]
Expand Down
2 changes: 1 addition & 1 deletion demo/agilebank/templates/k8sallowedrepos_template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ spec:
rego: |
package k8sallowedrepos

deny[{"msg": msg}] {
violation[{"msg": msg}] {
container := input.review.object.spec.containers[_]
satisfied := [good | repo = input.constraint.spec.parameters.repos[_] ; good = startswith(container.image, repo)]
not any(satisfied)
Expand Down
16 changes: 8 additions & 8 deletions demo/agilebank/templates/k8scontainterlimits_template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -124,45 +124,45 @@ spec:
new := to_number(raw) * mem_multiple(suffix)
}

deny[{"msg": msg}] {
violation[{"msg": msg}] {
container := input.review.object.spec.containers[_]
cpu_orig := container.resources.limits.cpu
not canonify_cpu(cpu_orig)
msg := sprintf("container <%v> cpu limit <%v> could not be parsed", [container.name, cpu_orig])
}

deny[{"msg": msg}] {
violation[{"msg": msg}] {
container := input.review.object.spec.containers[_]
mem_orig := container.resources.limits.memory
not canonify_mem(mem_orig)
msg := sprintf("container <%v> memory limit <%v> could not be parsed", [container.name, mem_orig])
}

deny[{"msg": msg}] {
violation[{"msg": msg}] {
container := input.review.object.spec.containers[_]
not container.resources
msg := sprintf("container <%v> has no resource limits", [container.name])
}

deny[{"msg": msg}] {
violation[{"msg": msg}] {
container := input.review.object.spec.containers[_]
not container.resources.limits
msg := sprintf("container <%v> has no resource limits", [container.name])
}

deny[{"msg": msg}] {
violation[{"msg": msg}] {
container := input.review.object.spec.containers[_]
missing(container.resources.limits, "cpu")
msg := sprintf("container <%v> has no cpu limit", [container.name])
}

deny[{"msg": msg}] {
violation[{"msg": msg}] {
container := input.review.object.spec.containers[_]
missing(container.resources.limits, "memory")
msg := sprintf("container <%v> has no memory limit", [container.name])
}

deny[{"msg": msg}] {
violation[{"msg": msg}] {
container := input.review.object.spec.containers[_]
cpu_orig := container.resources.limits.cpu
cpu := canonify_cpu(cpu_orig)
Expand All @@ -172,7 +172,7 @@ spec:
msg := sprintf("container <%v> cpu limit <%v> is higher than the maximum allowed of <%v>", [container.name, cpu_orig, max_cpu_orig])
}

deny[{"msg": msg}] {
violation[{"msg": msg}] {
container := input.review.object.spec.containers[_]
mem_orig := container.resources.limits.memory
mem := canonify_mem(mem_orig)
Expand Down
4 changes: 2 additions & 2 deletions demo/agilebank/templates/k8srequiredlabels_template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ spec:
msg := constraint.spec.parameters.message
}

deny[{"msg": msg, "details": {"missing_labels": missing}}] {
violation[{"msg": msg, "details": {"missing_labels": missing}}] {
provided := {label | input.review.object.metadata.labels[label]}
required := {label | label := input.constraint.spec.parameters.labels[_].key}
missing := required - provided
Expand All @@ -48,7 +48,7 @@ spec:
msg := get_message(input.constraint, def_msg)
}

deny[{"msg": msg}] {
violation[{"msg": msg}] {
value := input.review.object.metadata.labels[key]
expected := input.constraint.spec.parameters.labels[_]
expected.key == key
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
apiVersion: templates.gatekeeper.sh/v1alpha1
kind: ConstraintTemplate
metadata:
name: k8suniqueserviceselectors
name: k8suniqueserviceselector
spec:
crd:
spec:
names:
kind: K8sUniqueServiceSelector
listKind: K8sUniqueServiceSelectorList
plural: k8suniqueserviceselectors
plural: k8suniqueserviceselector
singular: k8suniqueserviceselector
targets:
- target: admission.k8s.gatekeeper.sh
Expand Down Expand Up @@ -39,7 +39,7 @@ spec:
flattened := concat(",", sort(selectors))
}

deny[{"msg": msg}] {
violation[{"msg": msg}] {
input.review.kind.kind == "Service"
input.review.kind.version == "v1"
input.review.kind.group == ""
Expand Down
2 changes: 1 addition & 1 deletion demo/basic/bad/bad_template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ spec:
obj.apiVersion == make_apiversion(review.kind)
}

deny[{"msg": msg, "details": {"value": val, "label": label}}]
violation[{"msg": msg, "details": {"value": val, "label": label}}]
label := input.constraint.spec.parameters.label
val := input.review.object.metadata.labels[label]
cluster_objs := [o | o = data.inventory.cluster[_][_][_]; not identical_cluster(o, input.review)]
Expand Down
2 changes: 1 addition & 1 deletion demo/basic/templates/k8srequiredlabels_template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ spec:
rego: |
package k8srequiredlabels

deny[{"msg": msg, "details": {"missing_labels": missing}}] {
violation[{"msg": msg, "details": {"missing_labels": missing}}] {
provided := {label | input.review.object.metadata.labels[label]}
required := {label | label := input.constraint.spec.parameters.labels[_]}
missing := required - provided
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ spec:
rego: |
package k8srequiredlabels

deny[{"msg": msg, "details": {"missing_labels": missing}}] {
violation[{"msg": msg, "details": {"missing_labels": missing}}] {
provided := {label | input.review.object.metadata.labels[label]}
required := {label | label := input.constraint.spec.parameters.labels[_]}
missing := required - provided
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
apiVersion: templates.gatekeeper.sh/v1alpha1
kind: ConstraintTemplate
metadata:
name: k8suniquelabels
name: k8suniquelabel
spec:
crd:
spec:
names:
kind: K8sUniqueLabel
listKind: K8sUniqueLabelList
plural: k8suniquelabels
plural: k8suniquelabel
singular: k8suniquelabel
validation:
# Schema for the `parameters` field
Expand Down Expand Up @@ -46,7 +46,7 @@ spec:
obj.apiVersion == make_apiversion(review.kind)
}

deny[{"msg": msg, "details": {"value": val, "label": label}}] {
violation[{"msg": msg, "details": {"value": val, "label": label}}] {
label := input.constraint.spec.parameters.label
val := input.review.object.metadata.labels[label]
cluster_objs := [o | o = data.inventory.cluster[_][_][_]; not identical_cluster(o, input.review)]
Expand Down
2 changes: 1 addition & 1 deletion example/templates/k8srequiredlabels_template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ spec:
rego: |
package k8srequiredlabels

deny[{"msg": msg, "details": {"missing_labels": missing}}] {
violation[{"msg": msg, "details": {"missing_labels": missing}}] {
provided := {label | input.review.object.metadata.labels[label]}
required := {label | label := input.constraint.spec.parameters.labels[_]}
missing := required - provided
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func TestReconcile(t *testing.T) {
Rego: `
package foo

deny[{"msg": "denied!"}] {
violation[{"msg": "denied!"}] {
1 == 1
}
`},
Expand Down Expand Up @@ -219,7 +219,7 @@ deny[{"msg": "denied!"}] {
Rego: `
package foo

deny[}}}//invalid//rego
violation[}}}//invalid//rego
`},
},
},
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading