mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-30 19:35:06 +00:00
fix auth validation (#6696)
Signed-off-by: ShutingZhao <shuting@nirmata.com>
This commit is contained in:
parent
03220cd8a9
commit
81ec6c96a1
1 changed files with 5 additions and 6 deletions
|
@ -95,22 +95,21 @@ func (m *Mutate) validateAuth(ctx context.Context, targets []kyvernov1.ResourceS
|
|||
for _, target := range targets {
|
||||
if !regex.IsVariable(target.Namespace) {
|
||||
_, _, k, sub := kubeutils.ParseKindSelector(target.Kind)
|
||||
if ok, err := m.authChecker.CanICreate(ctx, k, target.Namespace, sub); err != nil {
|
||||
errs = append(errs, err)
|
||||
} else if !ok {
|
||||
errs = append(errs, fmt.Errorf("cannot %s %s/%s in namespace %s", "create", k, sub, target.Namespace))
|
||||
srcKey := k
|
||||
if sub != "" {
|
||||
srcKey = srcKey + "/" + sub
|
||||
}
|
||||
|
||||
if ok, err := m.authChecker.CanIUpdate(ctx, k, target.Namespace, sub); err != nil {
|
||||
errs = append(errs, err)
|
||||
} else if !ok {
|
||||
errs = append(errs, fmt.Errorf("cannot %s %s/%s in namespace %s", "update", k, sub, target.Namespace))
|
||||
errs = append(errs, fmt.Errorf("cannot %s %s in namespace %s", "update", srcKey, target.Namespace))
|
||||
}
|
||||
|
||||
if ok, err := m.authChecker.CanIGet(ctx, k, target.Namespace, sub); err != nil {
|
||||
errs = append(errs, err)
|
||||
} else if !ok {
|
||||
errs = append(errs, fmt.Errorf("cannot %s %s/%s in namespace %s", "get", k, sub, target.Namespace))
|
||||
errs = append(errs, fmt.Errorf("cannot %s %s in namespace %s", "get", srcKey, target.Namespace))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue