mirror of
https://github.com/kyverno/kyverno.git
synced 2024-12-14 11:57:48 +00:00
fix: namespaced policy not validated in engine (#4653)
* fix: namespaced policy not validated in engine Signed-off-by: Charles-Edouard Brétéché <charled.breteche@gmail.com> * fix test Signed-off-by: Charles-Edouard Brétéché <charled.breteche@gmail.com> Signed-off-by: Charles-Edouard Brétéché <charled.breteche@gmail.com> Co-authored-by: Vyankatesh Kudtarkar <vyankateshkd@gmail.com> Co-authored-by: Prateek Pandey <prateek.pandey@nirmata.com>
This commit is contained in:
parent
e8839a3ff7
commit
4d7e1281de
2 changed files with 11 additions and 2 deletions
|
@ -99,6 +99,16 @@ func validateResource(log logr.Logger, ctx *PolicyContext) *response.EngineRespo
|
|||
matchCount := 0
|
||||
applyRules := ctx.Policy.GetSpec().GetApplyRules()
|
||||
|
||||
if ctx.Policy.IsNamespaced() {
|
||||
polNs := ctx.Policy.GetNamespace()
|
||||
if ctx.NewResource.Object != nil && (ctx.NewResource.GetNamespace() != polNs || ctx.NewResource.GetNamespace() == "") {
|
||||
return resp
|
||||
}
|
||||
if ctx.OldResource.Object != nil && (ctx.OldResource.GetNamespace() != polNs || ctx.OldResource.GetNamespace() == "") {
|
||||
return resp
|
||||
}
|
||||
}
|
||||
|
||||
for i := range rules {
|
||||
rule := &rules[i]
|
||||
hasValidate := rule.HasValidate()
|
||||
|
|
|
@ -25,10 +25,9 @@ spec:
|
|||
test: ""
|
||||
---
|
||||
apiVersion: kyverno.io/v1
|
||||
kind: Policy
|
||||
kind: ClusterPolicy
|
||||
metadata:
|
||||
name: namespace-validation
|
||||
namespace: kyverno
|
||||
spec:
|
||||
validationFailureAction: enforce
|
||||
background: false
|
||||
|
|
Loading…
Reference in a new issue