@@ -81,7 +81,7 @@ func NewConstraint() *constraint {
81
81
// any change that claims the pod is no longer privileged will be removed. That should hold until
82
82
// we get a true old/new set of objects in.
83
83
func (c * constraint ) Admit (ctx context.Context , a admission.Attributes , _ admission.ObjectInterfaces ) error {
84
- if ignore , err := shouldIgnore (a ); err != nil {
84
+ if ignore , err := shouldSkipSCCEvaluation (a ); err != nil {
85
85
return err
86
86
} else if ignore {
87
87
return nil
@@ -131,7 +131,7 @@ func (c *constraint) Admit(ctx context.Context, a admission.Attributes, _ admiss
131
131
}
132
132
133
133
func (c * constraint ) Validate (ctx context.Context , a admission.Attributes , _ admission.ObjectInterfaces ) error {
134
- if ignore , err := shouldIgnore (a ); err != nil {
134
+ if ignore , err := shouldSkipSCCEvaluation (a ); err != nil {
135
135
return err
136
136
} else if ignore {
137
137
return nil
@@ -420,7 +420,14 @@ var ignoredAnnotations = sets.NewString(
420
420
"k8s.ovn.org/pod-networks" ,
421
421
)
422
422
423
- func shouldIgnore (a admission.Attributes ) (bool , error ) {
423
+ // shouldSkipSCCEvaluation skips evaluation for:
424
+ // - non-Pod resources,
425
+ // - specific subresources that don't affect Pod security context (e.g., exec, attach, log),
426
+ // - Windows Pods (SCC is not applied),
427
+ // - update operations that only change fields like SchedulingGates or non-critical metadata.
428
+ // If the request is malformed (e.g., object can't be cast to a Pod), it fails closed to avoid
429
+ // bypassing security enforcement unintentionally.
430
+ func shouldSkipSCCEvaluation (a admission.Attributes ) (bool , error ) {
424
431
if a .GetResource ().GroupResource () != coreapi .Resource ("pods" ) {
425
432
return true , nil
426
433
}
@@ -448,24 +455,27 @@ func shouldIgnore(a admission.Attributes) (bool, error) {
448
455
return false , admission .NewForbidden (a , fmt .Errorf ("object was marked as kind pod but was unable to be converted: %v" , a .GetOldObject ()))
449
456
}
450
457
451
- // never ignore any spec changes
452
- if ! kapihelper .Semantic .DeepEqual (pod .Spec , oldPod .Spec ) {
458
+ // Create deep copies to avoid mutating the original objects
459
+ podWithoutSchedulingGates := pod .DeepCopy ()
460
+ // Skip SchedulingGates when comparing specs
461
+ podWithoutSchedulingGates .Spec .SchedulingGates = oldPod .Spec .SchedulingGates
462
+ if ! kapihelper .Semantic .DeepEqual (podWithoutSchedulingGates .Spec , oldPod .Spec ) {
453
463
return false , nil
454
464
}
455
465
456
466
// see if we are only doing meta changes that should be ignored during admission
457
467
// for example, the OVN controller adds informative networking annotations that shouldn't cause the pod to go through admission again
458
- if shouldIgnoreMetaChanges (pod , oldPod ) {
468
+ if shouldIgnoreMetaChanges (podWithoutSchedulingGates , oldPod ) {
459
469
return true , nil
460
470
}
461
471
}
462
472
463
473
return false , nil
464
474
}
465
475
466
- func shouldIgnoreMetaChanges (newPod , oldPod * coreapi.Pod ) bool {
476
+ func shouldIgnoreMetaChanges (newPodCopy , oldPod * coreapi.Pod ) bool {
467
477
// check if we're adding or changing only annotations from the ignore list
468
- for key , newVal := range newPod .ObjectMeta .Annotations {
478
+ for key , newVal := range newPodCopy .ObjectMeta .Annotations {
469
479
if oldVal , ok := oldPod .ObjectMeta .Annotations [key ]; ok && newVal == oldVal {
470
480
continue
471
481
}
@@ -477,7 +487,7 @@ func shouldIgnoreMetaChanges(newPod, oldPod *coreapi.Pod) bool {
477
487
478
488
// check if we're removing only annotations from the ignore list
479
489
for key := range oldPod .ObjectMeta .Annotations {
480
- if _ , ok := newPod .ObjectMeta .Annotations [key ]; ok {
490
+ if _ , ok := newPodCopy .ObjectMeta .Annotations [key ]; ok {
481
491
continue
482
492
}
483
493
@@ -486,12 +496,11 @@ func shouldIgnoreMetaChanges(newPod, oldPod *coreapi.Pod) bool {
486
496
}
487
497
}
488
498
489
- newPodCopy := newPod .DeepCopyObject ()
490
- newPodCopyMeta , err := meta .Accessor (newPodCopy )
499
+ newPodCopyWithoutSchedulingGatesCopyMeta , err := meta .Accessor (newPodCopy )
491
500
if err != nil {
492
501
return false
493
502
}
494
- newPodCopyMeta .SetAnnotations (oldPod .ObjectMeta .Annotations )
503
+ newPodCopyWithoutSchedulingGatesCopyMeta .SetAnnotations (oldPod .ObjectMeta .Annotations )
495
504
496
505
// see if we are only updating the ownerRef. Garbage collection does this
497
506
// and we should allow it in general, since you had the power to update and the power to delete.
0 commit comments