fix: resolve admin registration failure on fresh Docker installs (#81)
Three bugs caused 403 errors when creating the first admin on fresh Docker deployments (Unraid, Komodo): 1. db.rs: Schema application failures were silently swallowed. The app started with no tables, causing all auth queries to fail. Now the startup aborts if schema cannot be applied, with a fallback statement-by-statement executor that handles dollar-quoted blocks. Retries increased to 5 with 2s intervals. 2. auth_application_service.rs: count_admin_users() used fragile string matching (contains "does not exist")) on multi-layer wrapped errors. count_all_users() rejected admin creation on any DB error. Both now allow admin creation on any error for bootstrap scenarios. 3. auth_handler.rs: Redundant 60-line handler-level admin detection duplicated service-layer logic and generated noisy ERROR logs on fresh installs. Removed entirely - service layer handles it all. Closes #81
This commit is contained in:
@@ -167,32 +167,18 @@ impl AuthApplicationService {
|
||||
tracing::info!("Allowing admin creation on clean install");
|
||||
},
|
||||
Err(e) => {
|
||||
tracing::error!("Error counting users: {}", e);
|
||||
// For security, if we cannot verify, we reject admin creation
|
||||
return Err(DomainError::new(
|
||||
ErrorKind::AccessDenied,
|
||||
"User",
|
||||
"Creating additional admin users is not allowed"
|
||||
));
|
||||
// Cannot verify user count — treat as bootstrap scenario
|
||||
tracing::warn!("Could not count users ({}). Allowing admin creation for bootstrap.", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
Err(e) => {
|
||||
let err_msg = e.to_string();
|
||||
// If the table doesn't exist, this is a fresh install - allow admin creation
|
||||
if err_msg.contains("does not exist") || err_msg.contains("relation") {
|
||||
tracing::info!("Database tables not yet ready, treating as fresh install - allowing admin creation");
|
||||
// Continue with registration - this is a fresh install
|
||||
} else {
|
||||
tracing::error!("Error counting admin users: {}", e);
|
||||
// For security, if we cannot verify, we reject admin creation
|
||||
return Err(DomainError::new(
|
||||
ErrorKind::AccessDenied,
|
||||
"User",
|
||||
"Creating additional admin users is not allowed"
|
||||
));
|
||||
}
|
||||
// Any DB error (table missing, connection issue, etc.) means we
|
||||
// cannot verify admin state. Allow admin creation so the user can
|
||||
// bootstrap the system. If the DB is truly broken the INSERT will
|
||||
// fail anyway with a clear error.
|
||||
tracing::warn!("Could not count admin users ({}). Allowing admin creation for bootstrap.", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user