Fix client ssh file

This commit is contained in:
Viktor Liu
2025-07-11 22:08:28 +02:00
parent cdded8c22e
commit 9a7daa132e

View File

@@ -451,19 +451,11 @@ func (m *Manager) UpdatePeerHostKeys(peerKeys []PeerHostKey) error {
}
}
// Create updated known_hosts content
// Create updated known_hosts content - NetBird file should only contain NetBird entries
var updatedContent strings.Builder
updatedContent.WriteString("# NetBird SSH known hosts\n")
updatedContent.WriteString("# Generated automatically - do not edit manually\n\n")
// Add existing non-NetBird entries
for _, entry := range existingEntries {
if !m.isNetBirdEntry(entry) {
updatedContent.WriteString(entry)
updatedContent.WriteString("\n")
}
}
// Add new NetBird entries
for _, entry := range newEntries {
updatedContent.WriteString(entry)
@@ -539,14 +531,6 @@ func (m *Manager) getHostnameVariants(peerKey PeerHostKey) []string {
return hostnames
}
// isNetBirdEntry checks if a known_hosts entry appears to be NetBird-managed
func (m *Manager) isNetBirdEntry(entry string) bool {
// Check if entry contains NetBird IP ranges or domains
return strings.Contains(entry, "100.125.") ||
strings.Contains(entry, ".nb.internal") ||
strings.Contains(entry, "netbird")
}
// GetKnownHostsPath returns the path to the NetBird known_hosts file
func (m *Manager) GetKnownHostsPath() (string, error) {
return m.setupKnownHostsFile()