Skip to content

Handle HTTP 422 as unconditional deny in webhook middleware #4663

@JAORMX

Description

@JAORMX

Summary

Per RFC THV-0017's failure modes table, HTTP 422 from a webhook should always deny the request regardless of the configured failure policy (fail or ignore). Currently, both the validating and mutating webhook middleware treat all errors uniformly via the failure policy, meaning a 422 with ignore policy would fall back to the original body instead of denying.

This affects both middleware types:

  • pkg/webhook/validating/middleware.go
  • pkg/webhook/mutating/middleware.go

Context

Identified during review of #4372 (Phase 3: Mutating webhook middleware). The InvalidResponseError in client.go already surfaces the status code, so the middleware just needs to check for 422 before applying the failure policy.

Expected behavior

When a webhook endpoint returns HTTP 422 (Unprocessable Entity), the middleware must deny the request unconditionally, regardless of whether the failure policy is set to fail or ignore.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or requestkubernetesItems related to Kubernetes

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions