Problem: When users changed host authentication credentials, the main SSH
connection worked fine, but metrics collection failed with "All configured
authentication methods failed" error.
Root Cause: The metrics collection system (server-stats.ts) had its own
separate authentication implementation that only supported legacy password/key
fields and didn't integrate with the credential-based authentication system.
Solution:
- Remove duplicate HostRecord type, use unified SSHHostWithCredentials
- Import and use ssh-host.service for consistent credential resolution
- Update fetchAllHosts() to properly resolve credentials using getHostWithCredentials()
- Enhance buildSshConfig() with same authentication logic as main connections
- Add proper error handling for missing credentials
- Support both credential-based and legacy authentication methods
Benefits:
- Eliminates authentication logic duplication (follows "good taste" principle)
- Metrics collection now works after changing host credentials
- Uses single source of truth for credential resolution
- Maintains backward compatibility with legacy authentication
- Better error messages for debugging authentication issues
Now both main SSH connections and metrics collection use the same robust
authentication system, eliminating the authentication divergence that caused
the metrics failures.
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>