API rate limiting

API rate limiting is typically used to restrict the number of API calls that users can make in a set span of time, thereby helping to manage the rate of API traffic. For security purposes, rate limiting features, by restricting failed login attempts, have the potential to defend against denial of service (DoS) attacks or repeated login attempts intended to gain access through trial and error.

You have the option to configure the Security plugin for username rate limiting, IP address rate limiting, or both. These configurations are made in the config.yml file. See the following sections for information about each type of rate limiting configuration.

Username rate limiting

The username rate limiting configuration limits login attempts by username. When a login fails, the username is blocked from use by any machine in the network. The following example shows config.yml file settings configured for username rate limiting:

  1. auth_failure_listeners:
  2. internal_authentication_backend_limiting:
  3. type: username
  4. authentication_backend: internal
  5. allowed_tries: 3
  6. time_window_seconds: 60
  7. block_expiry_seconds: 60
  8. max_blocked_clients: 100000
  9. max_tracked_clients: 100000

copy

The following table describes the individual settings for this type of configuration.

SettingDescription
typeThe type of rate limiting. In this case, username.
authentication_backendThe internal backend. Enter internal.
allowed_triesThe number of login attempts allowed before login attempts are blocked. Be aware that increasing the number increases heap usage.
time_window_secondsThe window of time during which the value for allowed_tries is enforced. For example, if allowed_tries is 3 and time_window_seconds is 60, a username has 3 attempts to log in successfully within a 60-second time span before login attempts are blocked.
block_expiry_secondsThe window of time during which login attempts remain blocked after a failed login. After this time elapses, login is reset and the username can attempt to log in again.
max_blocked_clientsThe maximum number of blocked usernames. This limits heap usage to avoid a potential DoS attack.
max_tracked_clientsThe maximum number of tracked usernames with failed login attempts. This limits heap usage to avoid a potential DoS attack.

IP address rate limiting

The IP address rate limiting configuration limits login attempts by IP address. When a login fails, the IP address specific to the machine being used for login is blocked.

Configuring IP address rate limiting involves two steps. First, set the challenge setting to false in the http_authenticator section of the config.yml file:

  1. http_authenticator:
  2. type: basic
  3. challenge: false

For more information about this setting, see HTTP basic authentication.

Second, configure the IP address rate limiting settings. The following example shows a completed configuration:

  1. auth_failure_listeners:
  2. ip_rate_limiting:
  3. type: ip
  4. allowed_tries: 1
  5. time_window_seconds: 20
  6. block_expiry_seconds: 180
  7. max_blocked_clients: 100000
  8. max_tracked_clients: 100000

copy

The following table describes the individual settings for this type of configuration.

SettingDescription
typeThe type of rate limiting. In this case, ip.
allowed_triesThe number of login attempts allowed before login attempts are blocked. Be aware that increasing the number increases heap usage.
time_window_secondsThe window of time during which the value for allowed_tries is enforced. For example, if allowed_tries is 3 and time_window_seconds is 60, an IP address has 3 attempts to log in successfully within a 60-second time span before login attempts are blocked.
block_expiry_secondsThe window of time during which login attempts remain blocked after a failed login. After this time elapses, login is reset and the IP address can attempt to log in again.
max_blocked_clientsThe maximum number of blocked IP addresses. This limits heap usage to avoid a potential DoS attack.
max_tracked_clientsThe maximum number of tracked IP addresses with failed login attempts. This limits heap usage to avoid a potential DoS attack.
ignore_hostsA list of IP addresses or hostname patterns to ignore for rate limiting. config.dynamic.hosts_resolver_mode must be set to ip-hostname to support hostname matching.