Quotas protect Stronghold from being overloaded by individual clients: a misconfigured application that authenticates on every request or creates leases uncontrollably can degrade the availability of the entire cluster.
Stronghold supports two quota types:
- rate limit quotas — limit the number of requests per unit of time;
- lease count quotas — limit the number of leases that exist at the same time. Available in Stronghold EE.
Managing quotas requires a token with permissions on sys/quotas/*.
Rate limit quotas
A quota applies globally, to a namespace, to a mount, or to an auth method role. Quota parameters are described in the /sys/quotas/rate-limit/{name} API reference:
| Parameter | Description |
|---|---|
rate | Maximum number of requests per interval. A positive number |
interval | Interval over which rate is counted. Default is 1s |
block_interval | If set, a client that exceeds the limit is blocked for this duration |
path | Mount or namespace path. An empty value means a global quota |
role | Auth method role the quota applies to. path must then point to an auth method mount that supports roles, without a subpath |
When a quota is exceeded, Stronghold returns HTTP code 429.
Examples
A global quota for the whole cluster:
d8 stronghold write sys/quotas/rate-limit/global rate=1000A quota on the AppRole auth method to protect against login storms:
d8 stronghold write sys/quotas/rate-limit/approle-login path=auth/approle rate=50 interval=1sA quota on a specific role that blocks the offender for a minute:
d8 stronghold write sys/quotas/rate-limit/ci-role path=auth/approle role=ci rate=10 interval=1s block_interval=60sA quota on a secrets engine mount:
d8 stronghold write sys/quotas/rate-limit/kv-apps path=secret/ rate=200A quota on a namespace (Stronghold EE):
d8 stronghold write sys/quotas/rate-limit/team-a path=team-a/ rate=300If several quotas match a request, the most specific one applies: role, then a path within a mount, then the mount, then the namespace, then the global quota.
Viewing and deleting
To list the quotas, read a quota and delete it, run the following commands:
d8 stronghold list sys/quotas/rate-limit
d8 stronghold read sys/quotas/rate-limit/approle-login
d8 stronghold delete sys/quotas/rate-limit/approle-loginGeneral quota settings
The /sys/quotas/config endpoint sets general parameters:
| Parameter | Description |
|---|---|
rate_limit_exempt_paths | Paths exempt from rate limit quotas |
enable_rate_limit_audit_logging | Log requests rejected by a quota to the audit log |
enable_rate_limit_response_headers | Add HTTP headers with rate limit information to responses |
By default, the following paths are exempt from rate limit quotas: sys/generate-recovery-token/attempt, sys/generate-recovery-token/update, sys/generate-root/attempt, sys/generate-root/update, sys/health, sys/seal-status and sys/unseal. Example: add sys/metrics to this list and enable response headers and audit logging:
d8 stronghold write sys/quotas/config rate_limit_exempt_paths="sys/generate-recovery-token/attempt,sys/generate-recovery-token/update,sys/generate-root/attempt,sys/generate-root/update,sys/health,sys/seal-status,sys/unseal,sys/metrics" enable_rate_limit_response_headers=true enable_rate_limit_audit_logging=trueA write to sys/quotas/config replaces all three parameters at once: an omitted parameter is reset (the booleans to false, the list of exempt paths to empty, that is, no exempt paths, including the default ones). Always pass the full set of parameters; read the current values first with d8 stronghold read sys/quotas/config.
Lease count quotas
Lease count quotas limit the number of leases that exist at the same time on a mount, in a namespace, or for a role. When the limit is reached, new requests that create leases are rejected until existing leases expire or are revoked. Lease count quotas are available in Stronghold EE.
Quotas are managed through the /sys/quotas/lease-count/{name} endpoints. Quota parameters are path, role and max_leases.
A quota that limits the number of leases on the database/ mount to 5000:
d8 stronghold write sys/quotas/lease-count/db-creds path=database/ max_leases=5000For accurate per-role lease counting, do not enable the imprecise_lease_role_tracking server parameter.
Choosing values
- Collect the actual load from the
stronghold_core_handle_requestandstronghold_expire_num_leasesmetrics over several weeks. The metrics are described in Monitoring. - Set limits with headroom above peak values.
- Enable
enable_rate_limit_audit_loggingand analyze rejected requests. - Gradually lower the limits for clients with abnormal load.