#[non_exhaustive]pub struct RateLimitConfig {
pub max_attempts_per_minute: u32,
pub pre_auth_max_per_minute: Option<u32>,
pub max_tracked_keys: usize,
pub idle_eviction: Duration,
}Expand description
Rate limiting configuration for authentication attempts.
rmcp-server-kit uses two independent per-IP token-bucket limiters for auth:
- Pre-auth abuse gate (
Self::pre_auth_max_per_minute): consulted before any password-hash work. Throttles unauthenticated traffic from a single source IP so an attacker cannot pin the CPU on Argon2id by spraying invalid bearer tokens. Sized generously (default = 10× the post-failure quota) so legitimate clients are unaffected. mTLS- authenticated connections bypass this gate entirely (the TLS handshake already performed expensive crypto with a verified peer). - Post-failure backoff (
Self::max_attempts_per_minute): consulted after an authentication attempt fails. Provides explicit backpressure on bad credentials.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.max_attempts_per_minute: u32Maximum failed authentication attempts per source IP per minute. Successful authentications do not consume this budget.
pre_auth_max_per_minute: Option<u32>Maximum unauthenticated requests per source IP per minute admitted
to the password-hash verification path. When None, defaults to
max_attempts_per_minute * 10 at limiter-construction time.
Set higher than Self::max_attempts_per_minute so honest clients
retrying with the wrong key never trip this gate; its purpose is only
to bound CPU usage under spray attacks.
max_tracked_keys: usizeHard cap on the number of distinct source IPs tracked per limiter.
When reached, idle entries are pruned first; if still full, the
oldest (LRU) entry is evicted to make room for the new one. This
bounds memory under IP-spray attacks. Default: 10_000.
idle_eviction: DurationPer-IP entries idle for longer than this are eligible for opportunistic pruning. Default: 15 minutes.
Implementations§
Source§impl RateLimitConfig
impl RateLimitConfig
Sourcepub fn new(max_attempts_per_minute: u32) -> Self
pub fn new(max_attempts_per_minute: u32) -> Self
Create a rate limit config with the given max failed attempts per minute.
Pre-auth gate defaults to 10x this value at limiter-construction time.
Memory-bound defaults are 10_000 tracked keys with 15-minute idle eviction.
Sourcepub fn with_pre_auth_max_per_minute(self, quota: u32) -> Self
pub fn with_pre_auth_max_per_minute(self, quota: u32) -> Self
Override the pre-auth abuse-gate quota (per source IP per minute).
When unset, defaults to max_attempts_per_minute * 10.
Sourcepub fn with_max_tracked_keys(self, max: usize) -> Self
pub fn with_max_tracked_keys(self, max: usize) -> Self
Override the per-limiter cap on tracked source-IP keys (default 10_000).
Sourcepub fn with_idle_eviction(self, idle: Duration) -> Self
pub fn with_idle_eviction(self, idle: Duration) -> Self
Override the idle-eviction window (default 15 minutes).
Trait Implementations§
Source§impl Clone for RateLimitConfig
impl Clone for RateLimitConfig
Source§fn clone(&self) -> RateLimitConfig
fn clone(&self) -> RateLimitConfig
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more