Merge pull request #254 from opengenesislink/fix/audit-console-noise-controls-20261020
feat(ROBUST): quiet configurable NEX-AUDIT console without disabling persistent security audit
This commit is contained in:
8 files changed
+288
-9
No files matched your search
@@ -265,6 +265,10 @@ jobs:
|
||||
shell: bash
|
||||
run: dotnet run --configuration Release --project tools/ci/NexAuditRegression/NexAuditRegression.csproj
|
||||
|
||||
- name: Verify quiet ROBUST audit console and durable audit separation
|
||||
shell: bash
|
||||
run: python3 tools/ci/verify_audit_console.py
|
||||
|
||||
- name: Verify idempotency store
|
||||
shell: bash
|
||||
run: dotnet run --configuration Release --project tools/ci/NexIdempotencyRegression/NexIdempotencyRegression.csproj
|
||||
|
||||
@@ -269,7 +269,21 @@ namespace NexVerse.Server.Api
|
||||
eventBus,
|
||||
nodeStaleAfterSeconds);
|
||||
|
||||
INexAuditSink publicAuditSink = new LogNexAuditSink();
|
||||
// Console verbosity is independent of the persistent audit
|
||||
// store: suppress routine health checks without losing audited
|
||||
// privileged actions in data/nexverse-audit.jsonl.
|
||||
string auditConsoleMode = apiConfig.GetString("AuditConsoleMode", "important");
|
||||
bool auditConsolePublicReads =
|
||||
apiConfig.GetBoolean("AuditConsolePublicReads", false);
|
||||
bool auditConsoleShowIds =
|
||||
apiConfig.GetBoolean("AuditConsoleShowIds", false);
|
||||
INexAuditSink publicAuditSink = new LogNexAuditSink(
|
||||
auditConsoleMode,
|
||||
auditConsolePublicReads,
|
||||
auditConsoleShowIds);
|
||||
m_Log.InfoFormat(
|
||||
"[NEX-WORLD-API]: Auditkonsole={0}, öffentliche Lesezugriffe={1}, IDs={2}; persistentes Audit bleibt unabhängig.",
|
||||
auditConsoleMode, auditConsolePublicReads, auditConsoleShowIds);
|
||||
INexAuthorizationService authorization = new NexAuthorizationService();
|
||||
|
||||
NexApiRequestGate apiGate = new NexApiRequestGate(
|
||||
@@ -1360,22 +1374,119 @@ namespace NexVerse.Server.Api
|
||||
}
|
||||
}
|
||||
|
||||
// Console-only filtering. Do NOT wrap/filter PersistentNexAuditStore:
|
||||
// administrative accountability must survive quiet/off console modes.
|
||||
internal sealed class LogNexAuditSink : INexAuditSink
|
||||
{
|
||||
private static readonly ILog m_Log = LogManager.GetLogger(typeof(LogNexAuditSink));
|
||||
|
||||
private readonly string m_Mode;
|
||||
private readonly bool m_PublicReads;
|
||||
private readonly bool m_ShowIds;
|
||||
|
||||
public LogNexAuditSink(string mode = "important",
|
||||
bool publicReads = false, bool showIds = false)
|
||||
{
|
||||
string normalized = (mode ?? string.Empty).Trim().ToLowerInvariant();
|
||||
if (normalized != "important" && normalized != "all" && normalized != "off")
|
||||
{
|
||||
m_Log.WarnFormat(
|
||||
"[NEX-AUDIT]: Ungültiger AuditConsoleMode '{0}'; verwende 'important'.",
|
||||
mode);
|
||||
normalized = "important";
|
||||
}
|
||||
m_Mode = normalized;
|
||||
m_PublicReads = publicReads;
|
||||
m_ShowIds = showIds;
|
||||
}
|
||||
|
||||
// Public API reads, particularly /api/v1/health polling every
|
||||
// 15 seconds, aren't security-relevant writes. Keep their metrics
|
||||
// and events but stop spamming ROBUST's standard console.
|
||||
private static bool IsPublicRoutine(NexAuditEvent auditEvent)
|
||||
{
|
||||
string action = auditEvent.Action ?? string.Empty;
|
||||
return action.Equals("worldapi.root", StringComparison.OrdinalIgnoreCase) ||
|
||||
action.StartsWith("worldapi.", StringComparison.OrdinalIgnoreCase) &&
|
||||
(action.EndsWith(".read", StringComparison.OrdinalIgnoreCase) ||
|
||||
action.EndsWith(".list", StringComparison.OrdinalIgnoreCase));
|
||||
}
|
||||
|
||||
private static bool IsRoutine(NexAuditEvent auditEvent)
|
||||
{
|
||||
if (IsPublicRoutine(auditEvent))
|
||||
return true;
|
||||
string action = auditEvent.Action ?? string.Empty;
|
||||
foreach (string ending in new[] {
|
||||
".read", ".list", ".search", ".query", ".status", ".view", ".check"
|
||||
})
|
||||
{
|
||||
if (action.EndsWith(ending, StringComparison.OrdinalIgnoreCase))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private bool ShouldLog(NexAuditEvent auditEvent)
|
||||
{
|
||||
if (m_Mode == "off")
|
||||
return false;
|
||||
if (!m_PublicReads && IsPublicRoutine(auditEvent))
|
||||
return false;
|
||||
return m_Mode != "important" || !IsRoutine(auditEvent);
|
||||
}
|
||||
|
||||
private static string Category(string action)
|
||||
{
|
||||
string area = (action ?? string.Empty).Split('.')[0].ToLowerInvariant();
|
||||
switch (area)
|
||||
{
|
||||
case "worldapi": return "World API";
|
||||
case "users": return "Benutzer";
|
||||
case "auth":
|
||||
case "oauth": return "Anmeldung";
|
||||
case "security": return "Sicherheit";
|
||||
case "economy":
|
||||
case "ledger":
|
||||
case "banking": return "NV$ / Finanzen";
|
||||
case "inventory": return "Inventar";
|
||||
case "regions":
|
||||
case "region": return "Regionen";
|
||||
case "estates":
|
||||
case "estate": return "Grundstücke";
|
||||
case "relationship":
|
||||
case "relationships":
|
||||
case "friends": return "Freundschaften";
|
||||
case "portal": return "Stadtportal";
|
||||
case "groups":
|
||||
case "group": return "Gruppen";
|
||||
default: return "System";
|
||||
}
|
||||
}
|
||||
|
||||
public void Record(NexAuditEvent auditEvent)
|
||||
{
|
||||
if (auditEvent == null)
|
||||
if (auditEvent == null || !ShouldLog(auditEvent))
|
||||
return;
|
||||
|
||||
m_Log.InfoFormat(
|
||||
"[NEX-AUDIT]: id={0} actor={1} action={2} resource={3} correlation={4}",
|
||||
auditEvent.EventId,
|
||||
auditEvent.Actor,
|
||||
auditEvent.Action,
|
||||
auditEvent.Resource,
|
||||
auditEvent.CorrelationId);
|
||||
// Compact, consistent German-language console presentation.
|
||||
// Correlation/event IDs remain fully available in JSONL and
|
||||
// are optionally displayed for live incident investigation.
|
||||
if (m_ShowIds)
|
||||
{
|
||||
m_Log.InfoFormat(
|
||||
"[NEX-AUDIT] {0} | Aktion: {1} | Akteur: {2} | Ziel: {3} | Vorgang: {4} | ID: {5}",
|
||||
Category(auditEvent.Action), auditEvent.Action,
|
||||
auditEvent.Actor, auditEvent.Resource,
|
||||
auditEvent.CorrelationId, auditEvent.EventId);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_Log.InfoFormat(
|
||||
"[NEX-AUDIT] {0} | Aktion: {1} | Akteur: {2} | Ziel: {3}",
|
||||
Category(auditEvent.Action), auditEvent.Action,
|
||||
auditEvent.Actor, auditEvent.Resource);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -811,6 +811,15 @@
|
||||
RateLimitWindowSeconds = 60
|
||||
TrustForwardedFor = false
|
||||
AuditStorePath = "data/nexverse-audit.jsonl"
|
||||
; AuditConsoleMode = important (Standard), all oder off.
|
||||
; important = nur Aktionen mit Änderungen und wichtige Ereignisse,
|
||||
; all = auch reguläre Leseaufrufe, off = keine [NEX-AUDIT]-Konsolenzeilen.
|
||||
; Die persistente administrative Audit-Datei bleibt IMMER erhalten.
|
||||
AuditConsoleMode = "important"
|
||||
; Öffentliche GETs wie /api/v1/health auch bei all standardmäßig ausblenden.
|
||||
AuditConsolePublicReads = false
|
||||
; Lange Korrelations- und Ereignis-UUIDs nur bei Diagnose einblenden.
|
||||
AuditConsoleShowIds = false
|
||||
ApiKeyStorePath = "data/nexverse-api-keys.json"
|
||||
IdempotencyStorePath = "data/nexverse-idempotency.json"
|
||||
IdempotencyTtlSeconds = 86400
|
||||
|
||||
@@ -708,6 +708,15 @@
|
||||
RateLimitWindowSeconds = 60
|
||||
TrustForwardedFor = false
|
||||
AuditStorePath = "data/nexverse-audit.jsonl"
|
||||
; AuditConsoleMode = important (Standard), all oder off.
|
||||
; important = nur Aktionen mit Änderungen und wichtige Ereignisse,
|
||||
; all = auch reguläre Leseaufrufe, off = keine [NEX-AUDIT]-Konsolenzeilen.
|
||||
; Die persistente administrative Audit-Datei bleibt IMMER erhalten.
|
||||
AuditConsoleMode = "important"
|
||||
; Öffentliche GETs wie /api/v1/health auch bei all standardmäßig ausblenden.
|
||||
AuditConsolePublicReads = false
|
||||
; Lange Korrelations- und Ereignis-UUIDs nur bei Diagnose einblenden.
|
||||
AuditConsoleShowIds = false
|
||||
ApiKeyStorePath = "data/nexverse-api-keys.json"
|
||||
IdempotencyStorePath = "data/nexverse-idempotency.json"
|
||||
IdempotencyTtlSeconds = 86400
|
||||
|
||||
@@ -753,6 +753,15 @@
|
||||
RateLimitWindowSeconds = 60
|
||||
TrustForwardedFor = false
|
||||
AuditStorePath = "data/nexverse-audit.jsonl"
|
||||
; AuditConsoleMode = important (Standard), all oder off.
|
||||
; important = nur Aktionen mit Änderungen und wichtige Ereignisse,
|
||||
; all = auch reguläre Leseaufrufe, off = keine [NEX-AUDIT]-Konsolenzeilen.
|
||||
; Die persistente administrative Audit-Datei bleibt IMMER erhalten.
|
||||
AuditConsoleMode = "important"
|
||||
; Öffentliche GETs wie /api/v1/health auch bei all standardmäßig ausblenden.
|
||||
AuditConsolePublicReads = false
|
||||
; Lange Korrelations- und Ereignis-UUIDs nur bei Diagnose einblenden.
|
||||
AuditConsoleShowIds = false
|
||||
ApiKeyStorePath = "data/nexverse-api-keys.json"
|
||||
IdempotencyStorePath = "data/nexverse-idempotency.json"
|
||||
IdempotencyTtlSeconds = 86400
|
||||
|
||||
@@ -662,6 +662,15 @@
|
||||
RateLimitWindowSeconds = 60
|
||||
TrustForwardedFor = false
|
||||
AuditStorePath = "data/nexverse-audit.jsonl"
|
||||
; AuditConsoleMode = important (Standard), all oder off.
|
||||
; important = nur Aktionen mit Änderungen und wichtige Ereignisse,
|
||||
; all = auch reguläre Leseaufrufe, off = keine [NEX-AUDIT]-Konsolenzeilen.
|
||||
; Die persistente administrative Audit-Datei bleibt IMMER erhalten.
|
||||
AuditConsoleMode = "important"
|
||||
; Öffentliche GETs wie /api/v1/health auch bei all standardmäßig ausblenden.
|
||||
AuditConsolePublicReads = false
|
||||
; Lange Korrelations- und Ereignis-UUIDs nur bei Diagnose einblenden.
|
||||
AuditConsoleShowIds = false
|
||||
ApiKeyStorePath = "data/nexverse-api-keys.json"
|
||||
IdempotencyStorePath = "data/nexverse-idempotency.json"
|
||||
IdempotencyTtlSeconds = 86400
|
||||
|
||||
@@ -630,6 +630,70 @@ Default runtime path:
|
||||
|
||||
The path can be changed with `AuditStorePath` in `[NexVerseWorldApi]`. Runtime audit data is excluded from Git.
|
||||
|
||||
|
||||
### ROBUST-Auditkonsole: lesbar und ohne Healthcheck-Spam
|
||||
|
||||
Der Endpunkt `/api/v1/health` wird bei Monitoring-Systemen haeufig
|
||||
(z. B. alle 15 Sekunden) abgerufen. Solche anonymen, oeffentlichen
|
||||
Lesezugriffe muessen nicht als langformatierte
|
||||
`[NEX-AUDIT]`-Zeile die ROBUST-Konsole fuellen. Der Healthcheck
|
||||
selbst, dessen HTTP-Antwort, die Request-Metriken und das
|
||||
`api.request`-Event bleiben unveraendert.
|
||||
|
||||
Die **Konsolenausgabe** wird ausschliesslich durch diese Einstellungen
|
||||
gesteuert (in der aktiven `[NexVerseWorldApi]`-Sektion):
|
||||
|
||||
```ini
|
||||
[NexVerseWorldApi]
|
||||
AuditConsoleMode = "important"
|
||||
AuditConsolePublicReads = false
|
||||
AuditConsoleShowIds = false
|
||||
AuditStorePath = "data/nexverse-audit.jsonl"
|
||||
```
|
||||
|
||||
- `AuditConsoleMode = "important"` (**Standard**): zeigt Aktionen
|
||||
mit Aenderungscharakter und andere nicht-routinemaessige Ereignisse.
|
||||
Regelmaessige `*.read`-, `*.list`-, `*.search`-,
|
||||
`*.query`-, `*.status`-, `*.view`- und `*.check`-Ereignisse
|
||||
werden in der Konsole ausgeblendet.
|
||||
- `AuditConsoleMode = "all"`: schreibt alle Audit-Ereignisse in
|
||||
die Konsole, **ausser** oeffentlichen World-API-Lesezugriffen,
|
||||
solange `AuditConsolePublicReads = false` ist.
|
||||
- `AuditConsoleMode = "off"`: keine Konsoleneintraege mit
|
||||
`[NEX-AUDIT]`, unabhaengig von den anderen Einstellungen.
|
||||
- `AuditConsolePublicReads = true` schaltet bei `all` auch
|
||||
die oeffentlichen `worldapi.*.read`-Ereignisse wieder ein,
|
||||
einschliesslich `worldapi.health.read`. Bei `important`
|
||||
bleiben reine Lesevorgaenge unterdrueckt.
|
||||
- `AuditConsoleShowIds = true`: zeigt zusaetzlich die
|
||||
vollstaendige `correlation_id` und `event_id` bei
|
||||
den noch ausgegebenen Ereignissen an.
|
||||
|
||||
Die Darstellung ist kompakt, auf Deutsch beschriftet und nach
|
||||
Funktionsbereich gruppiert, beispielsweise:
|
||||
|
||||
```text
|
||||
[NEX-AUDIT] Benutzer | Aktion: users.update | Akteur: admin | Ziel: user:...
|
||||
```
|
||||
|
||||
**Sicherheit und Nachvollziehbarkeit:** Diese Schalter beeinflussen
|
||||
nur `LogNexAuditSink` und **nicht**
|
||||
`PersistentNexAuditStore`. Auch wenn die Konsolenausgabe
|
||||
komplett abgeschaltet ist, werden privilegierte
|
||||
World-API-, OAuth- und Verwaltungsereignisse weiter in
|
||||
`data/nexverse-audit.jsonl` gespeichert und koennen per
|
||||
`GET /api/v1/audit` mit `admin:*` abgefragt werden.
|
||||
Ausserdem bleiben unabhaengige `WARN`-/`ERROR`-Meldungen
|
||||
anderer Module und die bestehenden HTTP-Sicherheitskontrollen
|
||||
aktiv. Oeffentliche, anonyme Healthchecks wurden bislang
|
||||
nur an den Konsolen-Sink uebergeben; ihre Unterdrueckung
|
||||
erzeugt daher keinen Verlust privilegierter Audit-Historie.
|
||||
|
||||
Nach einer Aenderung der INI ist ROBUST neu zu starten.
|
||||
`AuditConsoleMode` ist ein Konsolenfilter, kein Schalter
|
||||
zum Loeschen, Deaktivieren oder Rueckgaengigmachen der
|
||||
persistenten Audit-Historie.
|
||||
|
||||
Administrative query endpoints:
|
||||
|
||||
- `GET /api/v1/audit`
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Guard readable, low-noise ROBUST console auditing without losing durable history."""
|
||||
from pathlib import Path
|
||||
|
||||
root = Path(__file__).resolve().parents[2]
|
||||
connector = (root / "NexVerse/Server/Api/NexVerseWorldApiConnector.cs").read_text(encoding="utf-8")
|
||||
handlers = (root / "NexVerse/Server/Api/NexVerseWorldApiHandlers.cs").read_text(encoding="utf-8")
|
||||
audit = (root / "NexVerse/Core/Audit/NexAudit.cs").read_text(encoding="utf-8")
|
||||
|
||||
for path in (
|
||||
"bin/Robust.HG.ini",
|
||||
"bin/Robust.HG.ini.example",
|
||||
"bin/Robust.HG.OGLAsset.ini.example",
|
||||
"bin/Robust.ini.example",
|
||||
):
|
||||
config = (root / path).read_text(encoding="utf-8")
|
||||
section = config.split("\n[NexVerseWorldApi]\n", 1)[1].split("\n[", 1)[0]
|
||||
for setting in (
|
||||
'AuditConsoleMode = "important"',
|
||||
"AuditConsolePublicReads = false",
|
||||
"AuditConsoleShowIds = false",
|
||||
'AuditStorePath = "data/nexverse-audit.jsonl"',
|
||||
):
|
||||
assert setting in section, (path, setting)
|
||||
|
||||
for marker in (
|
||||
'apiConfig.GetString("AuditConsoleMode", "important")',
|
||||
'apiConfig.GetBoolean("AuditConsolePublicReads", false)',
|
||||
'apiConfig.GetBoolean("AuditConsoleShowIds", false)',
|
||||
'new LogNexAuditSink(',
|
||||
'new PersistentNexAuditStore(auditStorePath)',
|
||||
'new CompositeNexAuditSink(',
|
||||
'publicAuditSink,\n auditStore)',
|
||||
'normalized != "important" && normalized != "all" && normalized != "off"',
|
||||
'if (m_Mode == "off")',
|
||||
'if (!m_PublicReads && IsPublicRoutine(auditEvent))',
|
||||
'return m_Mode != "important" || !IsRoutine(auditEvent);',
|
||||
'action.Equals("worldapi.root", StringComparison.OrdinalIgnoreCase)',
|
||||
'action.StartsWith("worldapi.", StringComparison.OrdinalIgnoreCase)',
|
||||
'action.EndsWith(".read", StringComparison.OrdinalIgnoreCase)',
|
||||
'auditEvent.CorrelationId, auditEvent.EventId',
|
||||
'[NEX-AUDIT] {0} | Aktion: {1} | Akteur: {2} | Ziel: {3}',
|
||||
):
|
||||
assert marker in connector, "Audit console/persistence regression: " + marker
|
||||
|
||||
assert connector.index("new LogNexAuditSink(") < connector.index("new PersistentNexAuditStore(")
|
||||
assert connector.index("new PersistentNexAuditStore(") < connector.index("new CompositeNexAuditSink(")
|
||||
assert 'BeginRequest(response, "worldapi.health.read", "/api/v1/health")' in handlers
|
||||
assert 'm_AuditSink.Record(new NexAuditEvent(' in handlers
|
||||
assert "NexMetricsRegistry.Default.IncrementCounter(" in handlers
|
||||
assert "foreach (INexAuditSink sink in m_Sinks)" in audit
|
||||
|
||||
# Explicitly verify control-plane actions are excluded only from console,
|
||||
# never from the persisted administrative audit store.
|
||||
console = connector.split("internal sealed class LogNexAuditSink", 1)[1]
|
||||
assert "PersistentNexAuditStore" not in console
|
||||
assert "m_Log.InfoFormat(" in console
|
||||
assert "public void Record(NexAuditEvent auditEvent)" in console
|
||||
assert console.index("if (auditEvent == null || !ShouldLog(auditEvent))") < console.index(
|
||||
"m_Log.InfoFormat(",
|
||||
console.index("public void Record(NexAuditEvent auditEvent)")
|
||||
)
|
||||
|
||||
print("Audit console modes/quiet health checks/JSONL persistence: OK")
|
||||
Reference in new issue
Block a user