Limit incoming request body size#21
Merged
Merged
Conversation
Wrap r.Body with http.MaxBytesReader (3 MiB cap) before reading the AdmissionReview, so an oversized or malicious request cannot exhaust server memory. Oversized bodies now return 413 Request Entity Too Large. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Grafana dashboard CRs can be large, and an AdmissionReview carries both the old and new object, so a fixed 3 MiB cap risked rejecting legitimate updates. Raise the default to 16 MiB and expose it via the --max-request-body-bytes flag so operators can tune it for their dashboards. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Wraps the request body with
http.MaxBytesReaderbefore reading theAdmissionReview, so an oversized or malicious request cannot exhaust server memory. Oversized bodies return413 Request Entity Too Large.The limit defaults to 16 MiB and is configurable via the
--max-request-body-bytesflag.Why
io.ReadAll(r.Body)previously had no upper bound. Grafana dashboard CRs can be large, and an AdmissionReview carries both the old and new object, so the cap needs generous headroom to avoid rejecting legitimate updates — hence a 16 MiB default plus a flag for operators to tune.Testing
go build ./...go test ./...— all pass, including a newTestHandleAdmissionReview_BodyTooLarge🤖 Generated with Claude Code