1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-28 02:18:15 +00:00

fix: mutate existing auth check (#7219)

* fix auth check when using variables in ns

Signed-off-by: ShutingZhao <shuting@nirmata.com>

* add kuttl tests

Signed-off-by: ShutingZhao <shuting@nirmata.com>

---------

Signed-off-by: ShutingZhao <shuting@nirmata.com>
This commit is contained in:
shuting 2023-05-18 00:20:34 +08:00 committed by GitHub
parent 1422fe6b44
commit d99c000b17
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 43 additions and 1 deletions

View file

@ -93,7 +93,7 @@ func (m *Mutate) hasPatchesJSON6902() bool {
func (m *Mutate) validateAuth(ctx context.Context, targets []kyvernov1.TargetResourceSpec) error {
var errs []error
for _, target := range targets {
if !regex.IsVariable(target.Namespace) {
if !regex.IsVariable(target.Kind) {
_, _, k, sub := kubeutils.ParseKindSelector(target.Kind)
srcKey := k
if sub != "" {

View file

@ -0,0 +1,12 @@
## Description
This test ensures that a mutate existing policy is denied when the target has the namespace defined as variable.
## Expected Behavior
The test fails if the policy creation is allowed, otherwise passes.
## Reference Issue(s)
https://github.com/kyverno/kyverno/issues/7213

View file

@ -0,0 +1,25 @@
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
name: cpol-namespace-variable
spec:
mutateExistingOnPolicyUpdate: false
rules:
- name: apply-flag
match:
any:
- resources:
kinds:
- Namespace
selector:
matchLabels:
policy.lan/flag: 'true'
mutate:
targets:
- kind: PersistentVolumeClaim
apiVersion: v1
namespace: "{{ request.object.metadata.name }}"
patchStrategicMerge:
metadata:
labels:
policy.lan/apply-flag: 'true'

View file

@ -0,0 +1,5 @@
apiVersion: kuttl.dev/v1beta1
kind: TestStep
apply:
- file: policy.yaml
shouldFail: true