Skip to content
This repository has been archived by the owner on Jan 12, 2023. It is now read-only.

Stopped collection of mutations on DELETE operations #130

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions policies/pod/mutate_default_seccomp_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ func (p PolicyDefaultSeccompPolicy) Name() string {

func (p PolicyDefaultSeccompPolicy) Validate(ctx context.Context, config policies.Config, ar *admissionv1.AdmissionRequest) ([]policies.ResourceViolation, []policies.PatchOperation) {

if ar.Operation == "DELETE" {
return nil, nil
}

podResource := resource.GetPodResource(ctx, ar)
if podResource == nil {
return nil, nil
Expand Down
37 changes: 20 additions & 17 deletions server/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,10 @@ func (s *Server) validateResources(ar admissionv1.AdmissionReview) admissionv1.A
val.Name(),
s.Exemptions,
) {
mutationPatches = append(mutationPatches, patches...)
// K8s will not allow the mutation of DELETE operations
if ar.Request.Operation != "DELETE" {
mutationPatches = append(mutationPatches, patches...)
}
}

// apply exempt and non-exempt violations
Expand Down Expand Up @@ -207,10 +210,10 @@ func (s *Server) validateResources(ar admissionv1.AdmissionReview) admissionv1.A

if s.Config.GlobalMetricsEnabled == true {
labels := prometheus.Labels{
"resource": v.ResourceName,
"namespace": v.Namespace,
"policy": v.Policy,
"enforced": "false"}
"resource": v.ResourceName,
"namespace": v.Namespace,
"policy": v.Policy,
"enforced": "false"}
policyViolations.With(labels).Inc()
}
}
Expand All @@ -228,10 +231,10 @@ func (s *Server) validateResources(ar admissionv1.AdmissionReview) admissionv1.A

if s.Config.GlobalMetricsEnabled == true {
labels := prometheus.Labels{
"resource": v.ResourceName,
"namespace": v.Namespace,
"policy": v.Policy,
"enforced": "false"}
"resource": v.ResourceName,
"namespace": v.Namespace,
"policy": v.Policy,
"enforced": "false"}
policyViolations.With(labels).Inc()
}
}
Expand All @@ -250,10 +253,10 @@ func (s *Server) validateResources(ar admissionv1.AdmissionReview) admissionv1.A

if s.Config.GlobalMetricsEnabled == true {
labels := prometheus.Labels{
"resource": v.ResourceName,
"namespace": v.Namespace,
"policy": v.Policy,
"enforced": "false"}
"resource": v.ResourceName,
"namespace": v.Namespace,
"policy": v.Policy,
"enforced": "false"}
policyViolations.With(labels).Inc()
}
}
Expand All @@ -274,10 +277,10 @@ func (s *Server) validateResources(ar admissionv1.AdmissionReview) admissionv1.A

if s.Config.GlobalMetricsEnabled == true {
labels := prometheus.Labels{
"resource": v.ResourceName,
"namespace": v.Namespace,
"policy": v.Policy,
"enforced": "true"}
"resource": v.ResourceName,
"namespace": v.Namespace,
"policy": v.Policy,
"enforced": "true"}
policyViolations.With(labels).Inc()
}

Expand Down