Skip to content

[Bug] Mutating webhook allows pods with privileged containers when other containers request GPU resources #2138

Description

@Jay2006sawant

What happened

When a pod contains both a privileged container and a GPU-requesting container, the mutating admission webhook logs that it is denying admission for the privileged container, but still allows the pod and applies scheduler/GPU patches.

What you expected to happen

Any pod with a privileged container should be rejected with admission.Denied(...).

How to reproduce

  1. Configure the HAMi webhook with a GPU resource name (e.g. hami.io/gpu).
  2. Submit a pod with two containers:
    • Container A: securityContext.privileged: true
    • Container B: requests hami.io/gpu: "1"
  3. Observe the webhook response: Allowed: true with patches applied.

Minimal pod spec:

apiVersion: v1
kind: Pod
metadata:
  name: privileged-gpu-mixed
  namespace: default
spec:
  containers:
  - name: privileged-sidecar
    image: busybox
    securityContext:
      privileged: true
  - name: gpu-workload
    image: busybox
    resources:
      limits:
        hami.io/gpu: "1"

Root cause

In pkg/scheduler/webhook.go, the privileged-container check uses continue instead of returning admission.Denied:

if ctr.SecurityContext.Privileged != nil && *ctr.SecurityContext.Privileged {
    klog.Warningf(..., "Denying admission as container %s is privileged", ...)
    continue  // should return admission.Denied(...)
}

The loop continues to the next container, GPU resources are mutated, and the pod is admitted.

Impact

  • Security/policy bypass for mixed privileged + GPU pods
  • Webhook logs say "Denying admission" but the request is allowed

Environment

  • HAMi master @ c343242
  • Verified locally with a unit test against pkg/scheduler/webhook.go

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions