security: harden admin auth, reconciler locking, and connection pooling

- Use secrets.compare_digest for timing-safe admin key comparison
- Strip whitespace from ADMIN_API_KEY env var
- Add PostgreSQL advisory locks per-invoice in reconciler to prevent
  duplicate processing during deployments
- Add wallet-RPC retry with backoff (3 attempts: 0.5s, 1s, 2s)
- Raise MAX_SUBADDRESS_INDEX from 100 to 300
- Tune DB connection pool (pool_size=20, max_overflow=10, recycle=3600)
- Add 1-hour admin session timeout
- Regenerate UI lockfile
This commit is contained in:
jwinterm
2026-03-15 10:49:55 -04:00
parent 20eff23335
commit 00e04c74bb
7 changed files with 131 additions and 10 deletions
+3 -1
View File
@@ -3,6 +3,8 @@
Protected by ADMIN_API_KEY — separate from per-user API keys.
"""
import secrets
from fastapi import APIRouter, Depends, Header, HTTPException, status
from pydantic import BaseModel
from sqlalchemy import func
@@ -46,7 +48,7 @@ def require_admin(
if key is None:
key = x_admin_key
if key != ADMIN_API_KEY:
if not secrets.compare_digest(key or "", ADMIN_API_KEY):
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
detail="Invalid admin key",