mirror of
https://github.com/kyverno/kyverno.git
synced 2025-04-08 10:04:25 +00:00
fix DENY pending for DELETE request
This commit is contained in:
parent
962b8f9865
commit
0e803ae532
4 changed files with 36 additions and 4 deletions
|
@ -114,6 +114,13 @@ func matchSubjects(ruleSubjects []rbacv1.Subject, userInfo authenticationv1.User
|
|||
const SaPrefix = "system:serviceaccount:"
|
||||
|
||||
userGroups := append(userInfo.Groups, userInfo.Username)
|
||||
|
||||
ruleSubjects = append(ruleSubjects,
|
||||
rbacv1.Subject{Kind: "Group", Name: "system:serviceaccounts:kube-system"},
|
||||
rbacv1.Subject{Kind: "Group", Name: "system:nodes"},
|
||||
rbacv1.Subject{Kind: "Group", Name: "system:kube-scheduler"},
|
||||
)
|
||||
|
||||
for _, subject := range ruleSubjects {
|
||||
switch subject.Kind {
|
||||
case "ServiceAccount":
|
||||
|
|
|
@ -167,3 +167,13 @@ func convertResource(raw []byte, group, version, kind, namespace string) (unstru
|
|||
obj.SetNamespace(namespace)
|
||||
return *obj, nil
|
||||
}
|
||||
|
||||
func excludeKyvernoResources(kind string) bool {
|
||||
switch kind {
|
||||
case "ClusterPolicy", "ClusterPolicyViolation", "PolicyViolation", "GenerateRequest":
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -199,6 +199,15 @@ func writeResponse(rw http.ResponseWriter, admissionReview *v1beta1.AdmissionRev
|
|||
}
|
||||
|
||||
func (ws *WebhookServer) resourceMutation(request *v1beta1.AdmissionRequest) *v1beta1.AdmissionResponse {
|
||||
if excludeKyvernoResources(request.Kind.Kind) {
|
||||
return &v1beta1.AdmissionResponse{
|
||||
Allowed: true,
|
||||
Result: &metav1.Status{
|
||||
Status: "Success",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
logger := ws.log.WithName("resourceMutation").WithValues("uid", request.UID, "kind", request.Kind.Kind, "namespace", request.Namespace, "name", request.Name, "operation", request.Operation)
|
||||
policies, err := ws.pMetaStore.ListAll()
|
||||
if err != nil {
|
||||
|
@ -322,6 +331,15 @@ func (ws *WebhookServer) resourceMutation(request *v1beta1.AdmissionRequest) *v1
|
|||
}
|
||||
|
||||
func (ws *WebhookServer) resourceValidation(request *v1beta1.AdmissionRequest) *v1beta1.AdmissionResponse {
|
||||
if excludeKyvernoResources(request.Kind.Kind) {
|
||||
return &v1beta1.AdmissionResponse{
|
||||
Allowed: true,
|
||||
Result: &metav1.Status{
|
||||
Status: "Success",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
logger := ws.log.WithName("resourceValidation").WithValues("uid", request.UID, "kind", request.Kind.Kind, "namespace", request.Namespace, "name", request.Name, "operation", request.Operation)
|
||||
policies, err := ws.pMetaStore.ListAll()
|
||||
if err != nil {
|
||||
|
|
|
@ -33,10 +33,6 @@ func (ws *WebhookServer) HandleValidation(
|
|||
|
||||
logger := ws.log.WithValues("action", "validate", "resource", resourceName, "operation", request.Operation)
|
||||
|
||||
if val, err := ctx.Query("request.object.metadata.deletionTimestamp"); val != nil && err == nil {
|
||||
return true, ""
|
||||
}
|
||||
|
||||
// Get new and old resource
|
||||
newR, oldR, err := utils.ExtractResources(patchedResource, request)
|
||||
if err != nil {
|
||||
|
@ -51,6 +47,7 @@ func (ws *WebhookServer) HandleValidation(
|
|||
Context: ctx,
|
||||
AdmissionInfo: userRequestInfo,
|
||||
}
|
||||
|
||||
var engineResponses []response.EngineResponse
|
||||
for _, policy := range policies {
|
||||
logger.V(3).Info("evaluating policy", "policy", policy.Name)
|
||||
|
|
Loading…
Add table
Reference in a new issue