mirror of
https://github.com/coder/coder.git
synced 2026-09-21 20:51:01 +08:00
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.
This commit is contained in:
+10
-3
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user