feat(system): add admin password reset with session revocation

Let system administrators reset another user's local password from the settings UI, revoke all active sessions, and record the action in the audit log.
This commit is contained in:
wizardchen
2026-07-13 20:05:08 +08:00
committed by lyingbug
parent 8554c422dc
commit 8ec65941a5
17 changed files with 1340 additions and 59 deletions
+5
View File
@@ -116,6 +116,11 @@ const (
// reader can distinguish a real revoke from a noop attempt.
// TenantID=0 because the change is system-scope.
AuditActionSystemAdminRevoked AuditAction = "system.admin_revoked"
// AuditActionSystemUserPasswordReset fires when a SystemAdmin replaces
// another user's local password. Details identify the target and record
// session revocation, but never contain the old or new password.
AuditActionSystemUserPasswordReset AuditAction = "system.user_password_reset"
)
// AuditOutcome distinguishes successful mutations from middleware-level
+6 -2
View File
@@ -37,6 +37,7 @@ func TestAuditAction_DotNamespaceConvention(t *testing.T) {
AuditActionSystemSettingChanged,
AuditActionSystemAdminPromoted,
AuditActionSystemAdminRevoked,
AuditActionSystemUserPasswordReset,
}
for _, a := range all {
s := string(a)
@@ -118,9 +119,10 @@ func TestAuditAction_NoCollisionsAcrossNamespaces(t *testing.T) {
register("AuditActionSystemSettingChanged", AuditActionSystemSettingChanged)
register("AuditActionSystemAdminPromoted", AuditActionSystemAdminPromoted)
register("AuditActionSystemAdminRevoked", AuditActionSystemAdminRevoked)
register("AuditActionSystemUserPasswordReset", AuditActionSystemUserPasswordReset)
}
// TestAuditAction_SystemNamespacePrefix pins the three system.* actions
// TestAuditAction_SystemNamespacePrefix pins the system.* actions
// added in this PR to their shared area prefix. The prefix is the
// contract by which the platform audit log endpoint
// (GET /system/admin/audit-log) filters out per-tenant rbac.* rows —
@@ -131,6 +133,7 @@ func TestAuditAction_SystemNamespacePrefix(t *testing.T) {
AuditActionSystemSettingChanged,
AuditActionSystemAdminPromoted,
AuditActionSystemAdminRevoked,
AuditActionSystemUserPasswordReset,
}
for _, a := range cases {
assert.True(t,
@@ -141,7 +144,7 @@ func TestAuditAction_SystemNamespacePrefix(t *testing.T) {
}
// TestAuditAction_SystemWireValues pins the exact wire strings for
// the three system.* actions. Audit-log consumers (Langfuse exporters,
// the system.* actions. Audit-log consumers (Langfuse exporters,
// the new frontend platform audit drawer, future SIEM integrations)
// match on these strings; changing them is a breaking change.
func TestAuditAction_SystemWireValues(t *testing.T) {
@@ -152,6 +155,7 @@ func TestAuditAction_SystemWireValues(t *testing.T) {
{AuditActionSystemSettingChanged, "system.setting_changed"},
{AuditActionSystemAdminPromoted, "system.admin_promoted"},
{AuditActionSystemAdminRevoked, "system.admin_revoked"},
{AuditActionSystemUserPasswordReset, "system.user_password_reset"},
}
for _, c := range cases {
assert.Equal(t, c.wire, string(c.constant))
+4
View File
@@ -37,6 +37,10 @@ type UserService interface {
DeleteUser(ctx context.Context, id string) error
// ChangePassword changes user password
ChangePassword(ctx context.Context, userID string, oldPassword, newPassword string) error
// AdminResetPassword replaces a user's password without requiring the old
// password and revokes all of that user's existing sessions. Callers must
// enforce the system-admin and cannot-reset-self guards before invoking it.
AdminResetPassword(ctx context.Context, userID string, newPassword string) error
// ValidatePassword validates user password
ValidatePassword(ctx context.Context, userID string, password string) error
// GenerateTokens generates access and refresh tokens for user