Skip to content

Commit

Permalink
Merge pull request #283 from GrahamDumpleton/fix-kyverno-rule-selectors
Browse files Browse the repository at this point in the history
Fix namespace selectors on Kyverno rules.
  • Loading branch information
GrahamDumpleton authored Jan 26, 2024
2 parents 5f5982d + 8a85238 commit fd4cb92
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
8 changes: 8 additions & 0 deletions project-docs/release-notes/version-2.7.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,11 @@ Bugs Fixed
definition after the initial workshop environment had been created for a
workshop, were not being reflected in subsequent workshop sessions created
after that point.

* Processing of Kyverno rules was not correctly injecting a namespace selector
targeting workshop session namespaces when the Kyverno rule used a `match.any`
or `match.all` condition. Consequence was that these rules were being applied
to all namespaces and thus could have affected other applications deployed to
the Kubernetes cluster besides Educates. The affected rules were
`disallow-ingress-nginx-custom-snippets`, `restrict-annotations`
`restrict-ingress-paths` and `prevent-cr8escape`.
8 changes: 6 additions & 2 deletions session-manager/handlers/kyverno_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,14 @@ def kyverno_environment_rules(workshop_spec, environment_name):
else:
rule["name"] = policy_name

resources = xget(rule, "match.all", [])
# Add a namespace selector to each resource which is a target of the
# rule. This is to ensure that the rule is only applied to the
# namespaces which are created for a workshop session.

resources = [condition.get("resources", {}) for condition in xget(rule, "match.all", [])]

if not resources:
resources = xget(rule, "match.any", [])
resources = [condition.get("resources", {}) for condition in xget(rule, "match.any", [])]

if not resources:
resources = [xget(rule, "match.resources", {})]
Expand Down

0 comments on commit fd4cb92

Please sign in to comment.