Skip to content

Enforce response body limits in kubelet-to-gcm#1201

Open
courageJ wants to merge 1 commit into
GoogleCloudPlatform:masterfrom
courageJ:fix-response-body-limits
Open

Enforce response body limits in kubelet-to-gcm#1201
courageJ wants to merge 1 commit into
GoogleCloudPlatform:masterfrom
courageJ:fix-response-body-limits

Conversation

@courageJ
Copy link
Copy Markdown
Contributor

This PR implements size limits when reading HTTP response bodies in the kubelet-to-gcm monitoring daemon to prevent potential unbounded memory allocation.

Key changes:

  • Added io.LimitReader to getGCEMetaData, doRequestAndParse, and doRequestAndUnmarshal.
  • Set specific limits: 10MB for GCE metadata and Prometheus metrics, 50MB for Kubelet stats summaries.
  • Replaced deprecated ioutil.ReadAll with io.ReadAll.
  • Added unit tests in monitor/controller and monitor/kubelet to verify size limiting behavior and ensure success cases continue to work.

Tested locally with go test ./monitor/... in kubelet-to-gcm.

@courageJ courageJ requested a review from erain May 21, 2026 12:13
- Added io.LimitReader to response body reads in controller, kubelet, and config packages.
- Prevents unbounded memory allocation from potentially large responses.
- Switched from deprecated ioutil.ReadAll to io.ReadAll.
- Added unit tests for size limiting and success cases.
@courageJ courageJ force-pushed the fix-response-body-limits branch from 9e09848 to d0d9650 Compare May 21, 2026 12:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant