feat: add SQLite storage for login attempts and sessions

Adds persistent storage using modernc.org/sqlite (pure Go). Login
attempts are deduplicated by (username, password, ip) with counts.
Sessions and session logs are tracked with UUID IDs. Includes embedded
SQL migrations, configurable retention with background pruning, and
an in-memory store for tests.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-14 17:33:45 +01:00
parent 75bac814d4
commit d655968216
21 changed files with 1131 additions and 10 deletions

View File

@@ -0,0 +1,36 @@
CREATE TABLE login_attempts (
id INTEGER PRIMARY KEY AUTOINCREMENT,
username TEXT NOT NULL,
password TEXT NOT NULL,
ip TEXT NOT NULL,
count INTEGER NOT NULL DEFAULT 1,
first_seen TEXT NOT NULL,
last_seen TEXT NOT NULL,
UNIQUE(username, password, ip)
);
CREATE INDEX idx_login_attempts_last_seen ON login_attempts(last_seen);
CREATE INDEX idx_login_attempts_ip ON login_attempts(ip);
CREATE TABLE sessions (
id TEXT PRIMARY KEY,
ip TEXT NOT NULL,
username TEXT NOT NULL,
shell_name TEXT NOT NULL DEFAULT '',
connected_at TEXT NOT NULL,
disconnected_at TEXT,
human_score REAL
);
CREATE INDEX idx_sessions_connected_at ON sessions(connected_at);
CREATE TABLE session_logs (
id INTEGER PRIMARY KEY AUTOINCREMENT,
session_id TEXT NOT NULL REFERENCES sessions(id) ON DELETE CASCADE,
timestamp TEXT NOT NULL,
input TEXT NOT NULL DEFAULT '',
output TEXT NOT NULL DEFAULT ''
);
CREATE INDEX idx_session_logs_session_id ON session_logs(session_id);
CREATE INDEX idx_session_logs_timestamp ON session_logs(timestamp);