Skip to content

api: keep the OpenAPI validator off upload bodies so kin-openapi can be upgraded - #10531

Open
drewmaring wants to merge 1 commit into
treeverse:masterfrom
obin-ai:fix/validator-bodiless-request-on-excluded-routes
Open

api: keep the OpenAPI validator off upload bodies so kin-openapi can be upgraded#10531
drewmaring wants to merge 1 commit into
treeverse:masterfrom
obin-ai:fix/validator-bodiless-request-on-excluded-routes

Conversation

@drewmaring

Copy link
Copy Markdown

Related: #9409 (the regression this removes), #10505 (the kin-openapi bump this unblocks)

Change Description

Background

Since #9408 lakeFS pins github.com/getkin/kin-openapi at 0.131.0 because 0.132+ made uploads read the whole object into memory. That pin now carries a CRITICAL advisory (GHSA-r277-6w6q-xmqw) and two HIGH ones, and blocks the dependabot bump in #10505. Root-causing the memory growth showed it is not in request-body validation at all, so it can be fixed on the lakeFS side without waiting for kin-openapi.

Bug Fix

  1. Problem — with kin-openapi ≥ 0.132, a 300 MB uploadObject drives the lakefs process from ~215 MB to ~990 MB RSS, and an unauthenticated upload is read in full before the 401 (lakeFS memory grows while upload object #9409).
  2. Root causeopenapi3filter.ValidateSecurityRequirements reads the entire request body up front so that an AuthenticationFunc can re-read it (openapi3filter: don't consume request body in AuthenticatorFunc getkin/kin-openapi#1064). It runs before request-body validation, so Options.ExcludeRequestBody and the x-validation-exclude-body extension never get a chance to skip it.
  3. Solution — in validateRequest, for routes marked x-validation-exclude-body and for any application/octet-stream / multipart/form-data request, give the validator a body-less clone of the request (Body = http.NoBody). The handler still receives the original request and streams the body to the block store as before. lakeFS uses NoopAuthenticationFunc, so nothing in the validator needs the body. JSON bodies are unchanged and still validated.

Testing Details

  • New pkg/api/validate_request_test.go: the validator reads zero bytes of an upload body and the handler still receives all of it; a malformed JSON body still yields 400. Fails on kin-openapi 0.149.0 without the change, passes with it (and on 0.131.0).
  • go test ./pkg/api -run TestValidateRequest, go vet ./pkg/api, gofmt clean.
  • Memory measured on a built image (lakefs run --quickstart, 300 MB uploadObject, VmRSS of PID 1 sampled during the upload): v1.86.0 217 MB peak; v1.86.0 + kin-openapi 0.149.0 990 MB; v1.86.0 + kin-openapi 0.149.0 + this change 215 MB. Unauthenticated upload with the change: 401 in ~6 ms, no growth.

This PR deliberately does not bump kin-openapi itself, so it is safe on the current pin; with it merged, #10505 (or a fresh bump to 0.149.0, which also needs apache/thrift 0.24.0 and grpc 1.83.1 for the remaining advisories) should be clear to land.

Breaking Change?

No. Behaviour only changes for requests whose body the validator was already told to skip.

…be upgraded

kin-openapi >= 0.132 reads the entire request body in
openapi3filter.ValidateSecurityRequirements, before any AuthenticationFunc
runs, so that an authenticator could re-read it (getkin/kin-openapi#1064).
For lakeFS that means every uploadObject body is buffered in memory, and
even unauthenticated uploads are read in full before the 401. That is the
regression behind treeverse#9409, which pinned kin-openapi at 0.131.0 and blocks
the dependabot bump in treeverse#10505. Options.ExcludeRequestBody does not help
because the read happens earlier.

lakeFS never needs the validator to see an upload body: uploadObject is
marked x-validation-exclude-body and the handler streams the body to the
block store itself. So for routes with that extension, and for any
application/octet-stream or multipart/form-data request, hand the
validator a body-less clone of the request. The handler still receives the
original request. JSON bodies are still validated.

Measured on a 300 MB upload (VmRSS peak of the lakefs process): v1.86.0
217 MB; v1.86.0 with kin-openapi 0.149.0 990 MB; the same with this
change 215 MB. An unauthenticated upload is rejected in ~6 ms with no
growth. Malformed JSON still returns 400.

The new test asserts the validator reads zero bytes of an upload body and
that the handler still gets the whole body; it fails on kin-openapi
0.149.0 without this change and passes with it.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


Drew Maring seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@github-actions github-actions Bot added the area/testing Improvements or additions to tests label Sep 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/testing Improvements or additions to tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants