From 672359d8d01f1c14fa258ee3b2059d959c250641 Mon Sep 17 00:00:00 2001 From: Kristoffer Dalby Date: Fri, 10 Jan 2025 08:25:40 +0100 Subject: [PATCH] use headscale server url as domain instead of base_domain Fixes #2336 Signed-off-by: Kristoffer Dalby --- hscontrol/mapper/mapper.go | 5 ++--- hscontrol/types/config.go | 9 +++++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/hscontrol/mapper/mapper.go b/hscontrol/mapper/mapper.go index e18276ad6f..6821d5b69e 100644 --- a/hscontrol/mapper/mapper.go +++ b/hscontrol/mapper/mapper.go @@ -105,8 +105,7 @@ func generateUserProfiles( var profiles []tailcfg.UserProfile for _, user := range userMap { - profiles = append(profiles, - user.TailscaleUserProfile()) + profiles = append(profiles, user.TailscaleUserProfile()) } return profiles @@ -455,7 +454,7 @@ func (m *Mapper) baseWithConfigMapResponse( resp.DERPMap = m.derpMap - resp.Domain = m.cfg.BaseDomain + resp.Domain = m.cfg.Domain() // Do not instruct clients to collect services we do not // support or do anything with them diff --git a/hscontrol/types/config.go b/hscontrol/types/config.go index 815c7f69ce..b8f3fd18d4 100644 --- a/hscontrol/types/config.go +++ b/hscontrol/types/config.go @@ -242,6 +242,15 @@ func validatePKCEMethod(method string) error { return nil } +func (c *Config) Domain() string { + u, err := url.Parse(c.ServerURL) + if err != nil { + return c.BaseDomain + } + + return u.Hostname() +} + // LoadConfig prepares and loads the Headscale configuration into Viper. // This means it sets the default values, reads the configuration file and // environment variables, and handles deprecated configuration options.