Add audit logging expansion, health endpoint, and request logging
- Expand audit logging: server actions (restart, scale), login/logout with success/failure tracking - Add sensitive data filtering to audit logs before file writes (passwords, keys, tokens) - Add /api/health endpoint for monitoring (checks DB, SSH, K8s, miner protection, uptime) - Add request logging middleware with timing for API/server routes - Add X-Response-Time header to responses
This commit is contained in:
1 parent
6b05dbb643
commit
3dc98c2fc3
4 files changed
+136
-5
No files matched your search
+13
-1
@@ -13,7 +13,7 @@ class AdminUser(UserMixin):
|
||||
def __init__(self, username):
|
||||
self.id = username
|
||||
|
||||
def init_auth(app, settings, limiter=None):
|
||||
def init_auth(app, settings, limiter=None, audit_svc=None):
|
||||
login_manager.init_app(app)
|
||||
|
||||
@login_manager.user_loader
|
||||
@@ -39,6 +39,8 @@ def init_auth(app, settings, limiter=None):
|
||||
|
||||
# Verify username matches
|
||||
if u != cfg_u:
|
||||
if audit_svc:
|
||||
audit_svc.log('login_failed', {'username': u, 'reason': 'invalid_username'}, user='unknown', severity='warning')
|
||||
flash('Invalid username or password')
|
||||
return render_template('login.html')
|
||||
|
||||
@@ -49,8 +51,15 @@ def init_auth(app, settings, limiter=None):
|
||||
ph = PasswordHasher()
|
||||
if ph.verify(password_hash, p):
|
||||
login_user(AdminUser(u))
|
||||
if audit_svc:
|
||||
audit_svc.log('login_success', {'username': u}, user=u, severity='info')
|
||||
return redirect(url_for('overview'))
|
||||
else:
|
||||
if audit_svc:
|
||||
audit_svc.log('login_failed', {'username': u, 'reason': 'invalid_password'}, user=u, severity='warning')
|
||||
except exceptions.VerifyMismatchError:
|
||||
if audit_svc:
|
||||
audit_svc.log('login_failed', {'username': u, 'reason': 'invalid_password'}, user=u, severity='warning')
|
||||
pass
|
||||
except Exception:
|
||||
flash('Authentication error. Please try again.')
|
||||
@@ -66,5 +75,8 @@ def init_auth(app, settings, limiter=None):
|
||||
@app.route('/logout')
|
||||
@login_required
|
||||
def logout():
|
||||
user = current_user.id if current_user.is_authenticated else 'unknown'
|
||||
logout_user()
|
||||
if audit_svc:
|
||||
audit_svc.log('logout', {}, user=user, severity='info')
|
||||
return redirect(url_for('login'))
|
||||
Reference in new issue
Block a user