fix(security): API import no longer replaces user accounts
Cluster-secret holder could POST a backup with their own admin key to /api/backup/import, replacing all users — privilege escalation from cluster-auth to admin. Also, Kuma imports produced zero users but ImportWipe unconditionally deleted the users table — locking out all accounts until restart reseeded UPTOP_ADMIN_KEY. - Server handlers strip data.Users (set nil) before calling ImportData - ImportData only wipes+replaces users when data.Users != nil - New ImportWipeUsers dialect method separates user wipe from data wipe - CLI restore (main.go) unchanged — full import still replaces users
This commit is contained in:
@@ -276,6 +276,31 @@ func TestImportData_WipesHistory(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestImportData_NilUsersPreservesExisting(t *testing.T) {
|
||||
s := newTestStore(t)
|
||||
|
||||
if err := s.AddUser(context.Background(), "admin", "ssh-ed25519 ADMINKEY", "admin"); err != nil {
|
||||
t.Fatalf("AddUser: %v", err)
|
||||
}
|
||||
|
||||
backup := models.Backup{
|
||||
Sites: []models.SiteConfig{{ID: 1, Name: "New", URL: "https://new.com", Type: "http", Interval: 30}},
|
||||
Alerts: []models.AlertConfig{{ID: 1, Name: "a", Type: "webhook", Settings: map[string]string{"url": "https://h.com"}}},
|
||||
Users: nil,
|
||||
}
|
||||
if err := s.ImportData(context.Background(), backup); err != nil {
|
||||
t.Fatalf("ImportData: %v", err)
|
||||
}
|
||||
|
||||
users, err := s.GetAllUsers(context.Background())
|
||||
if err != nil {
|
||||
t.Fatalf("GetAllUsers: %v", err)
|
||||
}
|
||||
if len(users) != 1 || users[0].Username != "admin" {
|
||||
t.Errorf("expected existing admin user preserved, got %d users", len(users))
|
||||
}
|
||||
}
|
||||
|
||||
func TestCheckHistory(t *testing.T) {
|
||||
s := newTestStore(t)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user