mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-10-29 17:52:32 +00:00
VAULT-6613 Add role support for rate limit quotas (OSS Changes) (#16115)
* VAULT-6613 add DetermineRoleFromLoginRequest function to Core * Fix body handling * Role resolution for rate limit quotas * VAULT-6613 update precedence test * Add changelog * Handle body error * VAULT-6613 Return early if error with json parsing
This commit is contained in:
15
http/util.go
15
http/util.go
@@ -1,7 +1,10 @@
|
||||
package http
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"net/http"
|
||||
"strings"
|
||||
@@ -47,11 +50,21 @@ func rateLimitQuotaWrapping(handler http.Handler, core *vault.Core) http.Handler
|
||||
respondError(w, status, err)
|
||||
return
|
||||
}
|
||||
mountPath := strings.TrimPrefix(core.MatchingMount(r.Context(), path), ns.Path)
|
||||
|
||||
// Clone body, so we do not close the request body reader
|
||||
bodyBytes, err := ioutil.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
respondError(w, http.StatusInternalServerError, errors.New("failed to read request body"))
|
||||
return
|
||||
}
|
||||
r.Body = ioutil.NopCloser(bytes.NewBuffer(bodyBytes))
|
||||
|
||||
quotaResp, err := core.ApplyRateLimitQuota(r.Context(), "as.Request{
|
||||
Type: quotas.TypeRateLimit,
|
||||
Path: path,
|
||||
MountPath: strings.TrimPrefix(core.MatchingMount(r.Context(), path), ns.Path),
|
||||
MountPath: mountPath,
|
||||
Role: core.DetermineRoleFromLoginRequest(mountPath, bodyBytes, r.Context()),
|
||||
NamespacePath: ns.Path,
|
||||
ClientAddress: parseRemoteIPAddress(r),
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user