Skip to content

fix: auth failure metrics, command memory budget, migration progress - #323

Merged
kacy merged 1 commit into
mainfrom
fix/security-hardening
Feb 27, 2026
Merged

fix: auth failure metrics, command memory budget, migration progress#323
kacy merged 1 commit into
mainfrom
fix/security-hardening

Conversation

@kacy

@kacy kacy commented Feb 27, 2026

Copy link
Copy Markdown
Owner

summary

three security and reliability fixes identified in the audit.

auth failure visibility (H1): adds ember_auth_failures_total{reason} to prometheus. previously there was no way to alert on brute-force attempts or misconfigured clients flooding with NOAUTH errors. the counter is labeled by reason (wrongpass, noauth) and is incremented in both sharded and concurrent connection modes.

command payload budget (M1): validate_command_sizes checked individual key and value sizes but not the total payload of a bulk command. an MSET with 1M × 1-byte key-value pairs would pass all per-item checks while consuming 2MB of memory and CPU just to parse. a new max_command_memory field (128MB default) is added to ConnectionLimits. MSET, LPUSH, and RPUSH now accumulate total bytes and return ERR if the budget is exceeded.

migration progress arithmetic (M3): the old (keys_migrated.saturating_mul(100) / total).min(100) as u8 would silently jump to 100% when keys_migrated * 100 overflowed u64 (at ~1.8 × 10^17 keys). fixed by switching to f64 division.

note: M2 (incarnation counter saturation) was already addressed — MAX_INCARNATION_JUMP = 1000 is in gossip.rs since a prior PR.

what was tested

  • cargo build -p ember-server -p ember-cluster — clean
  • cargo test -p ember-server -p ember-cluster — 143 passed, 0 failed

design considerations

max_command_memory defaults to 128MB with no config flag today — it lives in ConnectionLimits so a follow-up PR can wire it to a TOML field if operators need to tune it.

**h1 — auth failure counter**: adds `ember_auth_failures_total{reason}`
prometheus counter. reason is `wrongpass` for bad credentials, `noauth`
for commands sent before authenticating. incremented in `try_auth` and
at the NOAUTH error path in both connection modes.

**m1 — per-command memory budget**: adds `max_command_memory` (128MB
default) to `ConnectionLimits`. `validate_command_sizes` now sums total
bytes across all keys and values in MSET/LPUSH/RPUSH and rejects with
ERR if the combined payload exceeds the budget. guards against DoS via
million-element commands that individually pass per-item limits.

**m3 — migration progress overflow**: replaces `saturating_mul(100) /
total` with f64 division in `Migration::progress()`. the old formula
silently reported 100% when `keys_migrated * 100` overflowed u64.
@kacy
kacy merged commit 00ef367 into main Feb 27, 2026
4 of 7 checks passed
@kacy
kacy deleted the fix/security-hardening branch February 27, 2026 01:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant