summaryrefslogtreecommitdiffstats
path: root/packages/meshbay-hub/src/meshbay_hub/tasks
diff options
context:
space:
mode:
authorChristophe Besson <cbesson@gmail.com>2026-08-10 03:57:55 +0200
committerChristophe Besson <cbesson@gmail.com>2026-08-10 03:57:55 +0200
commit1a53eb4cc404ec94658fde0ae04cfe2ccf1810dc (patch)
tree04a23f81d3eea49de7414bf973600d33913795f9 /packages/meshbay-hub/src/meshbay_hub/tasks
parent4b3e8c3b8b9d10c8ac333dd8db614a7569052472 (diff)
downloadmeshbay-1a53eb4cc404ec94658fde0ae04cfe2ccf1810dc.tar.gz
feat(hub): Phase 8 — Hub v2 security hardening + production readiness
8.1 Config-based admin authz (require_admin on all admin endpoints) 8.2 Email encrypted at rest (AES-256-GCM, HKDF from hub Ed25519 key) 8.3 Refresh token rotation with family-based reuse detection 8.4 Federation persistence (HubPeer model replaces in-memory dict) 8.5 Federation token verification now async (DB-backed) 8.6 CSAM hash check wired into swarm registration flow 8.7 Rate limiting on auth endpoints (5/10/20 per minute) 8.8 Healthcheck endpoint (GET /v1/health, no auth) 8.9 IP log cleanup background task (365-day retention) 8.10 Argon2id params bumped to 256 MB (pw_version, rehash on login) Deployed to meshbay.org — schema migrated, existing emails encrypted. 117 tests pass (29 hub, 88 common+node). Resolves security review items S1, S2, S5. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Diffstat (limited to 'packages/meshbay-hub/src/meshbay_hub/tasks')
-rw-r--r--packages/meshbay-hub/src/meshbay_hub/tasks/__init__.py0
-rw-r--r--packages/meshbay-hub/src/meshbay_hub/tasks/cleanup.py40
2 files changed, 40 insertions, 0 deletions
diff --git a/packages/meshbay-hub/src/meshbay_hub/tasks/__init__.py b/packages/meshbay-hub/src/meshbay_hub/tasks/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/packages/meshbay-hub/src/meshbay_hub/tasks/__init__.py
diff --git a/packages/meshbay-hub/src/meshbay_hub/tasks/cleanup.py b/packages/meshbay-hub/src/meshbay_hub/tasks/cleanup.py
new file mode 100644
index 0000000..7674c6e
--- /dev/null
+++ b/packages/meshbay-hub/src/meshbay_hub/tasks/cleanup.py
@@ -0,0 +1,40 @@
+"""Scheduled cleanup tasks — IP log purge (1-year retention)."""
+
+import asyncio
+import logging
+from datetime import datetime, timedelta, timezone
+
+from sqlalchemy import delete
+from sqlalchemy.ext.asyncio import AsyncSession
+
+from meshbay_hub.db.models import IPLog
+
+log = logging.getLogger(__name__)
+
+RETENTION_DAYS = 365
+CLEANUP_INTERVAL_HOURS = 24
+
+
+async def purge_old_ip_logs(db: AsyncSession, retention_days: int = RETENTION_DAYS) -> int:
+ cutoff = datetime.now(timezone.utc) - timedelta(days=retention_days)
+ result = await db.execute(delete(IPLog).where(IPLog.timestamp < cutoff))
+ await db.commit()
+ return result.rowcount
+
+
+async def cleanup_loop(get_session):
+ """Run cleanup once at startup, then every 24 hours."""
+ try:
+ while True:
+ try:
+ async with get_session() as db:
+ deleted = await purge_old_ip_logs(db)
+ if deleted:
+ log.info("Purged %d IP log entries older than %d days", deleted, RETENTION_DAYS)
+ except asyncio.CancelledError:
+ raise
+ except Exception as e:
+ log.error("IP log cleanup failed: %s", e)
+ await asyncio.sleep(CLEANUP_INTERVAL_HOURS * 3600)
+ except asyncio.CancelledError:
+ return