feat(controller): Add ratelimiter http middleware
This commit is contained in:
2 files changed
+15
-1
No files matched your search
@@ -50,6 +50,7 @@ import (
|
||||
external_plugins "github.com/hashicorp/boundary/sdk/plugins"
|
||||
"github.com/hashicorp/boundary/version"
|
||||
"github.com/hashicorp/go-hclog"
|
||||
"github.com/hashicorp/go-rate"
|
||||
"github.com/hashicorp/go-secure-stdlib/mlock"
|
||||
"github.com/hashicorp/go-secure-stdlib/pluginutil/v2"
|
||||
"github.com/hashicorp/nodeenrollment"
|
||||
@@ -119,6 +120,8 @@ type Controller struct {
|
||||
apiGrpcServerListener grpcServerListener
|
||||
apiGrpcGatewayTicket string
|
||||
|
||||
rateLimiter *rate.Limiter
|
||||
|
||||
// Repo factory methods
|
||||
AuthTokenRepoFn common.AuthTokenRepoFactory
|
||||
VaultCredentialRepoFn common.VaultCredentialRepoFactory
|
||||
@@ -245,6 +248,16 @@ func New(ctx context.Context, conf *Config) (*Controller, error) {
|
||||
}
|
||||
c.clusterListener = clusterListeners[0]
|
||||
|
||||
rateLimits, err := conf.RawConfig.Controller.ApiRateLimits.Limits(c.baseContext)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error parsing rate limit configuration: %w", err)
|
||||
}
|
||||
|
||||
c.rateLimiter, err = rate.NewLimiter(rateLimits, conf.RawConfig.Controller.ApiRateLimiterMaxEntries)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error initializing rate limiter: %w", err)
|
||||
}
|
||||
|
||||
var pluginLogger hclog.Logger
|
||||
for _, enabledPlugin := range c.enabledPlugins {
|
||||
if pluginLogger == nil {
|
||||
|
||||
Reference in new issue
Block a user