mirror of
https://github.com/projectcapsule/capsule.git
synced 2026-08-19 04:26:45 +00:00
feat: providing utility for webhook auth identification
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
|
||||
|
||||
"github.com/clastix/capsule/api/v1alpha1"
|
||||
"github.com/clastix/capsule/pkg/utils"
|
||||
)
|
||||
|
||||
func RequestFromOwnerOrSA(tenant v1alpha1.Tenant, req admission.Request, userGroups []string) bool {
|
||||
switch {
|
||||
case tenant.Spec.Owner.Kind == "User" && req.UserInfo.Username == tenant.Spec.Owner.Name:
|
||||
return true
|
||||
case tenant.Spec.Owner.Kind == "Group":
|
||||
groupList := utils.NewUserGroupList(req.UserInfo.Groups)
|
||||
for _, group := range userGroups {
|
||||
if groupList.Find(group) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
default:
|
||||
for _, group := range req.UserInfo.Groups {
|
||||
if len(req.Namespace) > 0 && strings.HasPrefix(group, "system:serviceaccounts:"+req.Namespace) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
Reference in New Issue
Block a user