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:
parent
1422fe6b44
commit
d99c000b17
11 changed files with 43 additions and 1 deletions
|
@ -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 != "" {
|
||||
|
|
|
@ -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
|
|
@ -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'
|
|
@ -0,0 +1,5 @@
|
|||
apiVersion: kuttl.dev/v1beta1
|
||||
kind: TestStep
|
||||
apply:
|
||||
- file: policy.yaml
|
||||
shouldFail: true
|
Loading…
Add table
Reference in a new issue