Skip to content

Commit 678c358

Browse files
committed
fix(vpn): force lowercase DNS hostnames
1 parent 566e3de commit 678c358

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

tailnet/controllers.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -883,23 +883,30 @@ type Workspace struct {
883883
}
884884

885885
// updateDNSNames updates the DNS names for all agents in the workspace.
886+
// DNS hosts must be all lowercase, or the resolver won't be able to find them.
887+
// Usernames are globally unique & case-insensitive.
888+
// Workspace names are unique per-user & case-insensitive.
889+
// Agent names are unique per-workspace & case-insensitive.
886890
func (w *Workspace) updateDNSNames() error {
891+
wsName := strings.ToLower(w.Name)
892+
username := strings.ToLower(w.ownerUsername)
887893
for id, a := range w.agents {
894+
agentName := strings.ToLower(a.Name)
888895
names := make(map[dnsname.FQDN][]netip.Addr)
889896
// TODO: technically, DNS labels cannot start with numbers, but the rules are often not
890897
// strictly enforced.
891-
fqdn, err := dnsname.ToFQDN(fmt.Sprintf("%s.%s.me.coder.", a.Name, w.Name))
898+
fqdn, err := dnsname.ToFQDN(fmt.Sprintf("%s.%s.me.coder.", agentName, wsName))
892899
if err != nil {
893900
return err
894901
}
895902
names[fqdn] = []netip.Addr{CoderServicePrefix.AddrFromUUID(a.ID)}
896-
fqdn, err = dnsname.ToFQDN(fmt.Sprintf("%s.%s.%s.coder.", a.Name, w.Name, w.ownerUsername))
903+
fqdn, err = dnsname.ToFQDN(fmt.Sprintf("%s.%s.%s.coder.", agentName, wsName, username))
897904
if err != nil {
898905
return err
899906
}
900907
names[fqdn] = []netip.Addr{CoderServicePrefix.AddrFromUUID(a.ID)}
901908
if len(w.agents) == 1 {
902-
fqdn, err := dnsname.ToFQDN(fmt.Sprintf("%s.coder.", w.Name))
909+
fqdn, err := dnsname.ToFQDN(fmt.Sprintf("%s.coder.", wsName))
903910
if err != nil {
904911
return err
905912
}

0 commit comments

Comments
 (0)