Repository navigation
fix(acme): bound ACME response body size to prevent unbounded-body DoS - #9010
Conversation
ce217f0 to
4d95d80
Compare
| max-blank-identifiers: 4 | ||
| exhaustive: | ||
| default-signifies-exhaustive: true | ||
| forbidigo: |
There was a problem hiding this comment.
I would argue that this is beyond the scope of the PR.. if we do want this it should be in a different PR
There was a problem hiding this comment.
Good point, removed and split into seperate PR here.
cert-manager's ACME client contacts a tenant-controlled server (Issuer.spec.acme.server), so its responses must be treated as untrusted. Response bodies were read with no size limit: the vendored golang.org/x/crypto/acme fork buffers whole bodies into memory (io.ReadAll in responseError, json.Decode on every success path, and on each 5xx retry). A hostile or misconfigured ACME server can stream an unbounded body that is buffered onto the controller heap, OOM-killing the singleton controller and halting certificate issuance cluster-wide (CWE-770). Cap every ACME response body from the calling side, in cert-manager's instrumented RoundTripper, rather than patching the vendored fork: wrap resp.Body with io.LimitReader (16 MiB) so the ACME library cannot buffer more than the cap. The limit sits above the largest legitimate response (the certificate chain, ~5.4 MiB) and applies to every response, including retries. Co-Authored-By: Claude Opus 4.8 <[email protected]> Signed-off-by: Felix Phipps <[email protected]>
4d95d80 to
572272d
Compare
There was a problem hiding this comment.
Pull request overview
This PR hardens cert-manager’s ACME HTTP client against unbounded (potentially DoS) response bodies by adding a response body size cap at the instrumented Transport.RoundTrip layer, and adds tests to validate the behavior.
Changes:
- Add a 16 MiB cap for all ACME HTTP response bodies by wrapping
resp.Bodywith a limitingio.ReadCloser. - Add new tests around oversized vs within-limit response bodies.
- Minor comment/doc updates associated with the new transport behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| pkg/acme/client/http.go | Wraps ACME HTTP response bodies with a size-limited reader in the instrumented transport. |
| pkg/acme/client/http_test.go | Adds tests validating capped vs within-limit response body handling. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Replace the custom limitedReadCloser (backed by io.LimitReader) with the standard library's http.MaxBytesReader. LimitReader silently truncated an oversized body and returned io.EOF, making a hostile unbounded body indistinguishable from a legitimately short one. http.MaxBytesReader instead surfaces a distinct *http.MaxBytesError once the limit is exceeded, while still bounding memory, and removes the need for a custom ReadCloser type. It accepts a nil ResponseWriter since only the client-side cap is required. Update the oversized-body test to assert the *http.MaxBytesError and that bytes read stay bounded by the limit, and fix two grammar nits in doc comments. Co-Authored-By: Claude Opus 4.8 <[email protected]> Signed-off-by: Felix Phipps <[email protected]>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (1)
pkg/acme/client/http_test.go:198
- The PR description/test plan mentions a dedicated errACMEResponseBodyTooLarge, but this test (and the implementation) currently surfaces an oversized body as a *http.MaxBytesError. Please align the PR description/test plan with the actual error type (or, if a cert-manager-specific sentinel error is required, switch to a custom ReadCloser that returns it when the limit is exceeded).
var maxBytesErr *http.MaxBytesError
if !errors.As(err, &maxBytesErr) {
t.Fatalf("expected a *http.MaxBytesError reading an oversized body, got %T: %v", err, err)
}
|
/lgtm |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: ThatsMrTalbot The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
Needs a release note to merge |
|
/kind bug |
|
/cherry-pick release-1.21 |
|
@wallrj: new pull request created: #9222 DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
@FelixPhipps This change has been included in v1.21.2, which is now published. If you are able to install the release and verify that the change works as expected in your environment, that would be much appreciated. Thank you for the contribution. |
Description
Problem
The ACME client talks to whichever server a tenant configures via Issuer.spec.acme.server. The client reads response bodies with no size limit: the vendored golang.org/x/crypto/acme fork buffers entire bodies into memory (io.ReadAll in responseError, json.NewDecoder on every success path, and on every 5xx retry) with no io.LimitReader.
A hostile or misconfigured ACME server can return an infinite or multi-gigabyte body that is fully buffered on the controller heap, OOM-killing the singleton cert-manager controller and halting certificate issuance/renewal cluster-wide.
Solution
Fix it from the calling side rather than patching the vendored fork. Every ACME response already flows through cert-manager's instrumented Transport.RoundTrip, so wrap resp.Body there in a limitedReadCloser capped at 16 MiB — comfortably above the largest legitimate response.
Legitimate certs behave unchanged.
Test plan