AUD-06: audit-log-verdrahtung-in-sicherheitsrelevante-core-handler
Supply-Chain-Scan (Go) / govulncheck (push) Canceled after 0s

Schliesst die in QA-05 gefundene Luecke: der zentrale Audit-Log (AUD-01/02)
existierte und war getestet, wurde aber von keinem Produktions-Handler
befuellt. Additive WithAudit(...)-Methode je Store (Konvention aus
lockout.Store.WithPolicy uebernommen, audit==nil bleibt gueltig, kein
Verhaltensbruch fuer bestehende Aufrufer):

- internal/policy.Store.Grant/Revoke -> policy.grant/policy.revoke
- internal/tenant.Registry (Suspend/Reactivate/ScheduleDeletion/
  CancelDeletion via transition) -> tenant.transition
- internal/lockout.Store.RecordFailure/Unlock -> auth.login_failed/
  auth.account_locked/auth.account_unlocked
- internal/kek.Store.RotateTenantKEK/RotateMasterKey -> kek.tenant_rotated/
  kek.master_rotated

Neues Testpaket internal/audit/wiring_test.go: fuer jeden der vier Bereiche
eine reale Aktion ausgefuehrt und per direkter audit_events-Abfrage
nachgewiesen (derselbe Nachweisstil wie der QA-05-Stichprobenabgleich, der
die Luecke fand). Alle bestehenden Tests der vier Pakete bleiben gruen.
51/51 Pakete gruen auf 192.168.1.131.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HhgFcLS8tYMhDJpP74C6AQ
This commit is contained in:
sysops
2026-08-29 17:24:26 +02:00
co-authored by Claude Sonnet 5
parent d8d5aaf3bc
commit 4de9310213
7 changed files with 447 additions and 6 deletions
+38 -2
View File
@@ -11,6 +11,8 @@ import (
"time"
"github.com/jackc/pgx/v5/pgxpool"
"gitea.perlbach24.de/scripte/nexarch/internal/audit"
)
// DefaultMaxFailedAttempts/DefaultLockoutDuration sind explizit benannte
@@ -24,6 +26,8 @@ type Store struct {
pool *pgxpool.Pool
maxFailed int
lockoutDuration time.Duration
audit *audit.Log
tenantSlug string
}
func NewStore(pool *pgxpool.Pool) *Store {
@@ -31,7 +35,17 @@ func NewStore(pool *pgxpool.Pool) *Store {
}
func (s *Store) WithPolicy(maxFailed int, lockoutDuration time.Duration) *Store {
return &Store{pool: s.pool, maxFailed: maxFailed, lockoutDuration: lockoutDuration}
return &Store{pool: s.pool, maxFailed: maxFailed, lockoutDuration: lockoutDuration, audit: s.audit, tenantSlug: s.tenantSlug}
}
// WithAudit liefert einen Store, der Fehlversuche sowie Sperrung/Entsperrung
// zusaetzlich im zentralen, unveraenderlichen Audit-Log protokolliert
// (AUD-06) — login_attempts liegt in der Tenant-Datenbank, audit_events in
// der Registry-Datenbank, daher ein eigener, an die Registry gebundener
// audit.Log UND der Tenant-Slug (fuer den Tenant-Bezug im Event) noetig.
// Rein additiv, log == nil bleibt gueltig (z.B. bestehende Tests).
func (s *Store) WithAudit(log *audit.Log, tenantSlug string) *Store {
return &Store{pool: s.pool, maxFailed: s.maxFailed, lockoutDuration: s.lockoutDuration, audit: log, tenantSlug: tenantSlug}
}
// IsLocked prueft, ob ein Konto aktuell gesperrt ist. Eine abgelaufene
@@ -71,8 +85,22 @@ func (s *Store) RecordFailure(ctx context.Context, email string) (locked bool, l
return false, time.Time{}, fmt.Errorf("fehlversuch erfassen: %w", err)
}
locked = lockedUntilPtr != nil && time.Now().Before(*lockedUntilPtr)
if s.audit != nil {
action := "auth.login_failed"
if locked {
action = "auth.account_locked"
}
_ = s.audit.Record(ctx, audit.Event{
TenantSlug: s.tenantSlug,
Actor: email,
Action: action,
Target: email,
Metadata: map[string]any{"failed_count": failedCount},
})
}
if lockedUntilPtr != nil {
return time.Now().Before(*lockedUntilPtr), *lockedUntilPtr, nil
return locked, *lockedUntilPtr, nil
}
return false, time.Time{}, nil
}
@@ -99,5 +127,13 @@ func (s *Store) Unlock(ctx context.Context, email string) error {
if err != nil {
return fmt.Errorf("konto entsperren: %w", err)
}
if s.audit != nil {
_ = s.audit.Record(ctx, audit.Event{
TenantSlug: s.tenantSlug,
Actor: "admin",
Action: "auth.account_unlocked",
Target: email,
})
}
return nil
}