From a17569b0025d410284bc7df28f3a66a3057d8f21 Mon Sep 17 00:00:00 2001 From: Zac Bergquist Date: Tue, 29 Aug 2023 12:05:34 -0400 Subject: [PATCH] desktop discovery: unmap IPv6 addresses We request only IPv4 addresses when doing DNS queries for Windows desktops. In some circumstances, we can get addresses that are represented ("mapped") as IPv6 addresses. Unmap them so that Teleport always stores the IPv4 format. --- lib/srv/desktop/discovery.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/srv/desktop/discovery.go b/lib/srv/desktop/discovery.go index 499abf9a7ff97..be20ff61c76cc 100644 --- a/lib/srv/desktop/discovery.go +++ b/lib/srv/desktop/discovery.go @@ -208,8 +208,16 @@ func (s *WindowsService) lookupDesktop(ctx context.Context, hostname string) ([] hostname, resolverName, err) } - ch <- addrs + // even though we requested "ip4" it's possible to get IPv4 + // addresses mapped to IPv6 addresses, so we unmap them here + result := make([]netip.Addr, 0, len(addrs)) + for _, addr := range addrs { + if addr.Is4() || addr.Is4In6() { + result = append(result, addr.Unmap()) + } + } + ch <- result }() return ch }