From e4a3dcc3b884bc5f37775df04389cba04bb5990b Mon Sep 17 00:00:00 2001 From: Kristoffer Dalby Date: Thu, 16 Jan 2025 18:05:20 +0100 Subject: [PATCH] use headscale server url as domain instead of base_domain (#2338) --- hscontrol/mapper/mapper.go | 5 ++--- hscontrol/types/config.go | 11 +++++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/hscontrol/mapper/mapper.go b/hscontrol/mapper/mapper.go index e18276ad..6821d5b6 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 815c7f69..e86f014e 100644 --- a/hscontrol/types/config.go +++ b/hscontrol/types/config.go @@ -242,6 +242,17 @@ func validatePKCEMethod(method string) error { return nil } +// Domain returns the hostname/domain part of the ServerURL. +// If the ServerURL is not a valid URL, it returns the BaseDomain. +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.