-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow max request size to be user-specified #4824
Conversation
This turned out to be way more impactful than I'd expected because I felt like the right granularity was per-listener, since an org may want to treat external clients differently from internal clients. It's pretty straightforward though. This also introduces actually using request contexts for values, which so far we have not done (using our own logical.Request struct instead), but this allows non-logical methods to still get this benefit.
Pretty trivially tested (the acutal limiting logic is the same, just the plumbing): Limiting to smaller than default:
Unlimited (ignore that I accidentally used
|
helper/forwarding/util.go
Outdated
} | ||
} | ||
|
||
buf := bytes.NewBuffer(nil) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could use ioutil.ReadAll()
here since you want []byte
later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's fair, I just kept that part of the logic that was there. Feel free to pull down the branch and change it yourself if you like, too!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
Thanks! |
@@ -792,7 +808,9 @@ CLUSTER_SYNTHESIS_COMPLETE: | |||
// This needs to happen before we first unseal, so before we trigger dev | |||
// mode if it's set | |||
core.SetClusterListenerAddrs(clusterAddrs) | |||
core.SetClusterHandler(vaulthttp.Handler(core)) | |||
core.SetClusterHandler(vaulthttp.Handler(&vault.HandlerProperties{ | |||
Core: core, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Won't we ever need a size limit on the cluster connection?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By the time we get to the HTTP handler we've already handshaked the cluster connection so we already know if the connection is authorized -- if so we shouldn't limit it.
return errors.New("could not parse max_request_size from request context") | ||
} | ||
if max > 0 { | ||
reader = http.MaxBytesReader(w, r.Body, max) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Out of curiosity, why do we use io.LimitReader
above and http.MaxBytesReader
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Different function signatures, based on what's available.
@@ -26,6 +26,13 @@ const ( | |||
replTimeout = 10 * time.Second | |||
) | |||
|
|||
// HanlderProperties is used to seed configuration into a vaulthttp.Handler. | |||
// It's in this package to avoid a circular dependency | |||
type HandlerProperties struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Nitpick] Can we call this HandlerOptions
instead, unless there was a reason to call this HandlerProperties
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I called it Properties since it's not just user-set options (e.g. Core).
This turned out to be way more impactful than I'd expected because I
felt like the right granularity was per-listener, since an org may want
to treat external clients differently from internal clients. It's pretty
straightforward though.
This also introduces actually using request contexts for values, which
so far we have not done (using our own logical.Request struct instead),
but this allows non-logical methods to still get this benefit.