Skip to content

feat: add more rate limit control flags #5570

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

Merged
merged 6 commits into from
Jan 5, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: add flag to disable all rate limits
  • Loading branch information
deansheather committed Jan 4, 2023
commit 91da46fdcc4900fc66e91bb2f4dd755a42be311d
6 changes: 6 additions & 0 deletions cli/deployment/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,12 @@ func newConfig() *codersdk.DeploymentConfig {
},
},
RateLimit: &codersdk.RateLimitConfig{
DisableAll: &codersdk.DeploymentConfigField[bool]{
Name: "Disable All Rate Limits",
Usage: "Disables all rate limits. This is not recommended in production.",
Flag: "dangerous-disable-rate-limits",
Default: false,
},
API: &codersdk.DeploymentConfigField[int]{
Name: "API Rate Limit",
Usage: "Maximum number of requests per minute allowed to the API per user, or per IP address for unauthenticated users. Negative values mean no rate limit. Some API endpoints have separate flags to control rate limits to help prevent denial-of-service attacks.",
Expand Down
8 changes: 8 additions & 0 deletions cli/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,14 @@ func Server(vip *viper.Viper, newAPI func(context.Context, *coderd.Options) (*co
return xerrors.Errorf("either HTTP or TLS must be enabled")
}

// Disable rate limits if the `--dangerous-disable-rate-limits` flag
// was specified.
if cfg.RateLimit.DisableAll.Value {
cfg.RateLimit.API.Value = -1
cfg.RateLimit.Login.Value = -1
cfg.RateLimit.Files.Value = -1
}

printLogo(cmd)
logger := slog.Make(sloghuman.Sink(cmd.ErrOrStderr()))
if ok, _ := cmd.Flags().GetBool(varVerbose); ok {
Expand Down
3 changes: 3 additions & 0 deletions cli/testdata/coder_server_--help.golden
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ Flags:
with systemd.
Consumes $CODER_CACHE_DIRECTORY (default
"/tmp/coder-cli-test-cache")
--dangerous-disable-rate-limits Disables all rate limits. This is not
recommended in production.
Consumes $CODER_RATE_LIMIT_DISABLE_ALL
--derp-config-path string Path to read a DERP mapping from. See:
https://tailscale.com/kb/1118/custom-derp-servers/
Consumes $CODER_DERP_CONFIG_PATH
Expand Down
7 changes: 4 additions & 3 deletions codersdk/deploymentconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,10 @@ type ProvisionerConfig struct {
}

type RateLimitConfig struct {
API *DeploymentConfigField[int] `json:"api" typescript:",notnull"`
Files *DeploymentConfigField[int] `json:"files" typescript:",notnull"`
Login *DeploymentConfigField[int] `json:"login" typescript:",notnull"`
DisableAll *DeploymentConfigField[bool] `json:"disable_all" typescript:",notnull"`
API *DeploymentConfigField[int] `json:"api" typescript:",notnull"`
Files *DeploymentConfigField[int] `json:"files" typescript:",notnull"`
Login *DeploymentConfigField[int] `json:"login" typescript:",notnull"`
}

type SwaggerConfig struct {
Expand Down