mirror of
https://github.com/netbirdio/netbird.git
synced 2026-04-22 18:26:41 +00:00
Fix known hosts entries
This commit is contained in:
@@ -434,24 +434,14 @@ func (m *Manager) UpdatePeerHostKeys(peerKeys []PeerHostKey) error {
|
|||||||
return fmt.Errorf("setup known_hosts file: %w", err)
|
return fmt.Errorf("setup known_hosts file: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build new entries map for efficient lookup
|
|
||||||
newEntries := make(map[string]string)
|
|
||||||
for _, peerKey := range peerKeys {
|
|
||||||
entry := m.formatKnownHostsEntry(peerKey)
|
|
||||||
// Use all possible hostnames as keys
|
|
||||||
hostnames := m.getHostnameVariants(peerKey)
|
|
||||||
for _, hostname := range hostnames {
|
|
||||||
newEntries[hostname] = entry
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create updated known_hosts content - NetBird file should only contain NetBird entries
|
// Create updated known_hosts content - NetBird file should only contain NetBird entries
|
||||||
var updatedContent strings.Builder
|
var updatedContent strings.Builder
|
||||||
updatedContent.WriteString("# NetBird SSH known hosts\n")
|
updatedContent.WriteString("# NetBird SSH known hosts\n")
|
||||||
updatedContent.WriteString("# Generated automatically - do not edit manually\n\n")
|
updatedContent.WriteString("# Generated automatically - do not edit manually\n\n")
|
||||||
|
|
||||||
// Add new NetBird entries
|
// Add new NetBird entries - one entry per peer with all hostnames
|
||||||
for _, entry := range newEntries {
|
for _, peerKey := range peerKeys {
|
||||||
|
entry := m.formatKnownHostsEntry(peerKey)
|
||||||
updatedContent.WriteString(entry)
|
updatedContent.WriteString(entry)
|
||||||
updatedContent.WriteString("\n")
|
updatedContent.WriteString("\n")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user