From 92870f06422c591e9368b3dfcdd842d4e49a6c35 Mon Sep 17 00:00:00 2001 From: Ethan <39577870+ethanndickson@users.noreply.github.com> Date: Thu, 20 Feb 2025 13:02:45 +1100 Subject: [PATCH] fix: force lowercase DNS hostnames for VPN (#16613) Closes https://github.com/coder/coder-desktop-macos/issues/54 I've also double checked that agents with hyphens & underscores play nice once programmed, as do workspaces with hyphens: ``` $ ping6 main_agent-1.main-workspace.admin.coder PING6(56=40+8+8 bytes) fd60:627a:a42b:4e91:88c0:da4a:df4f:b54e --> fd60:627a:a42b:46d4:8b55:e549:e498:e6f5 ``` also fine in Firefox & Safari, though I'm a little surprised underscores work. --- tailnet/controllers.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/tailnet/controllers.go b/tailnet/controllers.go index e0a5766062..832baf09cd 100644 --- a/tailnet/controllers.go +++ b/tailnet/controllers.go @@ -883,23 +883,30 @@ type Workspace struct { } // updateDNSNames updates the DNS names for all agents in the workspace. +// DNS hosts must be all lowercase, or the resolver won't be able to find them. +// Usernames are globally unique & case-insensitive. +// Workspace names are unique per-user & case-insensitive. +// Agent names are unique per-workspace & case-insensitive. func (w *Workspace) updateDNSNames() error { + wsName := strings.ToLower(w.Name) + username := strings.ToLower(w.ownerUsername) for id, a := range w.agents { + agentName := strings.ToLower(a.Name) names := make(map[dnsname.FQDN][]netip.Addr) // TODO: technically, DNS labels cannot start with numbers, but the rules are often not // strictly enforced. - fqdn, err := dnsname.ToFQDN(fmt.Sprintf("%s.%s.me.coder.", a.Name, w.Name)) + fqdn, err := dnsname.ToFQDN(fmt.Sprintf("%s.%s.me.coder.", agentName, wsName)) if err != nil { return err } names[fqdn] = []netip.Addr{CoderServicePrefix.AddrFromUUID(a.ID)} - fqdn, err = dnsname.ToFQDN(fmt.Sprintf("%s.%s.%s.coder.", a.Name, w.Name, w.ownerUsername)) + fqdn, err = dnsname.ToFQDN(fmt.Sprintf("%s.%s.%s.coder.", agentName, wsName, username)) if err != nil { return err } names[fqdn] = []netip.Addr{CoderServicePrefix.AddrFromUUID(a.ID)} if len(w.agents) == 1 { - fqdn, err := dnsname.ToFQDN(fmt.Sprintf("%s.coder.", w.Name)) + fqdn, err := dnsname.ToFQDN(fmt.Sprintf("%s.coder.", wsName)) if err != nil { return err }