Commit 5319021
committed
feat(security): fingerprint binding, rate limiting, and miss-spike detection on session handles
Refactor `session_handle.rs` into a module with four focused files:
`fingerprint.rs`, `rate_limit.rs`, `miss_tracker.rs`, and `store.rs`.
The store gains three new capabilities:
- **Fingerprint binding** (`FingerprintMode`: Strict / Subnet / Disabled):
`SessionHandleStore::create()` captures `(tenant_id, peer IP)` as a
`ClientFingerprint`; subsequent resolves from a mismatched origin are
rejected and emit a `SessionHandleFingerprintMismatch` audit event.
- **Per-connection rate limiting**: `resolve()` now takes a `conn_key`
string; each connection gets a sliding-window counter capped at
`resolve_attempts_per_window`. Exceeding the cap returns
`ResolveOutcome::RateLimited`, which the pgwire and HTTP handlers
convert into a fatal SQLSTATE 53300 error that closes the connection.
- **Miss-spike detection**: consecutive resolve misses on one connection
within `miss_spike_window_secs` beyond `miss_spike_threshold` emit a
`SessionHandleResolveMissSpike` audit event.
`SessionHandleStore::resolve()` now returns `ResolveOutcome` (Resolved /
Miss / RateLimited) instead of an `Option`; all call sites updated.
Two new audit events are added (`SessionHandleFingerprintMismatch` = 23,
`SessionHandleResolveMissSpike` = 24) at `AuditLevel::Standard`.
`AuditLog` is moved from `Mutex<AuditLog>` to `Arc<Mutex<AuditLog>>` in
`SharedState` so the session-handle store can hold a clone for its
emission path without calling back into `SharedState`. A
`wire_session_handle_audit` helper wires the audit hook at `new()` and
`from_persistent()` time.
`SessionHandleConfig` is added to `AuthConfig` (serde, defaults: 1h TTL,
Subnet fingerprint mode, 20 resolves / 60 s window, 10-miss / 60 s spike
threshold). `SharedState::from_persistent` constructs the store from
config.
HTTP server uses `into_make_service_with_connect_info` so the
`POST /api/auth/session` route can extract `ConnectInfo<SocketAddr>` for
fingerprint capture. pgwire handlers and `SET nodedb.auth_session` eager
validation both pass `ClientFingerprint` and `conn_key` into resolve.1 parent d14e440 commit 5319021
15 files changed
Lines changed: 1239 additions & 234 deletions
File tree
- nodedb/src
- config
- control
- security
- audit
- session_handle
- server
- http
- routes
- pgwire/handler
- routing
- state
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
271 | 271 | | |
272 | 272 | | |
273 | 273 | | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
274 | 368 | | |
275 | 369 | | |
276 | 370 | | |
| |||
289 | 383 | | |
290 | 384 | | |
291 | 385 | | |
| 386 | + | |
292 | 387 | | |
293 | 388 | | |
294 | 389 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
65 | 65 | | |
66 | 66 | | |
67 | 67 | | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
68 | 77 | | |
69 | 78 | | |
70 | 79 | | |
| |||
103 | 112 | | |
104 | 113 | | |
105 | 114 | | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
106 | 118 | | |
107 | 119 | | |
108 | 120 | | |
This file was deleted.
0 commit comments