mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-05 23:46:56 +00:00
* feat: support authorizer variable in CEL expressions Signed-off-by: Mariam Fahmy <mariam.fahmy@nirmata.com> * feat: add the auth reason Signed-off-by: Mariam Fahmy <mariam.fahmy@nirmata.com> * feat: add kuttl tests Signed-off-by: Mariam Fahmy <mariam.fahmy@nirmata.com> * fix lint issue Signed-off-by: Mariam Fahmy <mariam.fahmy@nirmata.com> * fix kuttl test Signed-off-by: Mariam Fahmy <mariam.fahmy@nirmata.com> * fix: add helpers Signed-off-by: Mariam Fahmy <mariam.fahmy@nirmata.com> --------- Signed-off-by: Mariam Fahmy <mariam.fahmy@nirmata.com>
34 lines
1.1 KiB
Go
34 lines
1.1 KiB
Go
package mutate
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/kyverno/kyverno/pkg/auth"
|
|
"github.com/kyverno/kyverno/pkg/clients/dclient"
|
|
)
|
|
|
|
type authChecker struct {
|
|
client dclient.Interface
|
|
user string
|
|
}
|
|
|
|
type AuthChecker interface {
|
|
CanIUpdate(ctx context.Context, gvks, namespace, subresource string) (bool, error)
|
|
CanIGet(ctx context.Context, gvks, namespace, subresource string) (bool, error)
|
|
}
|
|
|
|
func newAuthChecker(client dclient.Interface, user string) AuthChecker {
|
|
return &authChecker{client: client, user: user}
|
|
}
|
|
|
|
func (a *authChecker) CanIUpdate(ctx context.Context, gvk, namespace, subresource string) (bool, error) {
|
|
checker := auth.NewCanI(a.client.Discovery(), a.client.GetKubeClient().AuthorizationV1().SubjectAccessReviews(), gvk, namespace, "update", subresource, a.user)
|
|
ok, _, err := checker.RunAccessCheck(ctx)
|
|
return ok, err
|
|
}
|
|
|
|
func (a *authChecker) CanIGet(ctx context.Context, gvk, namespace, subresource string) (bool, error) {
|
|
checker := auth.NewCanI(a.client.Discovery(), a.client.GetKubeClient().AuthorizationV1().SubjectAccessReviews(), gvk, namespace, "get", subresource, a.user)
|
|
ok, _, err := checker.RunAccessCheck(ctx)
|
|
return ok, err
|
|
}
|