From 9c5d485fdda4dc93ac47b0b0e5e9c626cb9ef235 Mon Sep 17 00:00:00 2001 From: Jiang Zhu Date: Sun, 12 Jun 2022 17:01:17 +0800 Subject: [PATCH 01/11] fix issue 635 --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 3327fe66..404c3c01 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ # Calculate version -version = $(git describe --always --tags --dirty) +version ?= $(shell git describe --always --tags --dirty) rwildcard=$(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2) $(filter $(subst *,%,$2),$d)) From a050158d11e618b37bf8c9c9b27599d2578cc498 Mon Sep 17 00:00:00 2001 From: Kristoffer Dalby Date: Sun, 12 Jun 2022 12:27:37 +0000 Subject: [PATCH 02/11] Use new update state logic for derp maps --- derp.go | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/derp.go b/derp.go index 7abce683..293cf81a 100644 --- a/derp.go +++ b/derp.go @@ -152,16 +152,7 @@ func (h *Headscale) scheduledDERPMapUpdateWorker(cancelChan <-chan struct{}) { h.DERPMap.Regions[h.DERPServer.region.RegionID] = &h.DERPServer.region } - namespaces, err := h.ListNamespaces() - if err != nil { - log.Error(). - Err(err). - Msg("Failed to fetch namespaces") - } - - for _, namespace := range namespaces { - h.setLastStateChangeToNow(namespace.Name) - } + h.setLastStateChangeToNow() } } } From 95824ac2ec1d029a137e9c7eb4b1e93525722296 Mon Sep 17 00:00:00 2001 From: Kristoffer Dalby Date: Sun, 12 Jun 2022 13:12:43 +0000 Subject: [PATCH 03/11] MOve ephemeral inactivity config check to all the other config check --- cmd/headscale/cli/utils.go | 17 ----------------- config.go | 11 +++++++++++ 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/cmd/headscale/cli/utils.go b/cmd/headscale/cli/utils.go index f5c679c2..327c8c14 100644 --- a/cmd/headscale/cli/utils.go +++ b/cmd/headscale/cli/utils.go @@ -7,12 +7,10 @@ import ( "fmt" "os" "reflect" - "time" "github.com/juanfont/headscale" v1 "github.com/juanfont/headscale/gen/go/headscale/v1" "github.com/rs/zerolog/log" - "github.com/spf13/viper" "google.golang.org/grpc" "google.golang.org/grpc/credentials" "google.golang.org/grpc/credentials/insecure" @@ -29,21 +27,6 @@ func getHeadscaleApp() (*headscale.Headscale, error) { return nil, fmt.Errorf("failed to load configuration while creating headscale instance: %w", err) } - // Minimum inactivity time out is keepalive timeout (60s) plus a few seconds - // to avoid races - minInactivityTimeout, _ := time.ParseDuration("65s") - if viper.GetDuration("ephemeral_node_inactivity_timeout") <= minInactivityTimeout { - // TODO: Find a better way to return this text - //nolint - err := fmt.Errorf( - "ephemeral_node_inactivity_timeout (%s) is set too low, must be more than %s", - viper.GetString("ephemeral_node_inactivity_timeout"), - minInactivityTimeout, - ) - - return nil, err - } - app, err := headscale.NewHeadscale(cfg) if err != nil { return nil, err diff --git a/config.go b/config.go index 917b4734..0c600c20 100644 --- a/config.go +++ b/config.go @@ -202,6 +202,17 @@ func LoadConfig(path string, isFile bool) error { EnforcedClientAuth) } + // Minimum inactivity time out is keepalive timeout (60s) plus a few seconds + // to avoid races + minInactivityTimeout, _ := time.ParseDuration("65s") + if viper.GetDuration("ephemeral_node_inactivity_timeout") <= minInactivityTimeout { + errorText += fmt.Sprintf( + "Fatal config error: ephemeral_node_inactivity_timeout (%s) is set too low, must be more than %s", + viper.GetString("ephemeral_node_inactivity_timeout"), + minInactivityTimeout, + ) + } + if errorText != "" { //nolint return errors.New(strings.TrimSuffix(errorText, "\n")) From fd3a1c13e31586a7f4e38ec5d6209cfae6162df6 Mon Sep 17 00:00:00 2001 From: Kristoffer Dalby Date: Sun, 12 Jun 2022 13:12:53 +0000 Subject: [PATCH 04/11] Add a default to ephemeral_node_inactivity_timeout --- config.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/config.go b/config.go index 0c600c20..212fe154 100644 --- a/config.go +++ b/config.go @@ -160,6 +160,8 @@ func LoadConfig(path string, isFile bool) error { viper.SetDefault("logtail.enabled", false) viper.SetDefault("randomize_client_port", false) + viper.SetDefault("ephemeral_node_inactivity_timeout", "120s") + if err := viper.ReadInConfig(); err != nil { return fmt.Errorf("fatal error reading config file: %w", err) } From c95bce4aea6cdd104a5f0119cfaa80606850424f Mon Sep 17 00:00:00 2001 From: Kristoffer Dalby Date: Sun, 12 Jun 2022 13:18:49 +0000 Subject: [PATCH 05/11] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c34e6f54..04af6306 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,7 @@ - Use new ACL syntax [#618](https://github.com/juanfont/headscale/pull/618) - Add -c option to specify config file from command line [#285](https://github.com/juanfont/headscale/issues/285) [#612](https://github.com/juanfont/headscale/pull/601) - Add configuration option to allow Tailscale clients to use a random WireGuard port. [kb/1181/firewalls](https://tailscale.com/kb/1181/firewalls) [#624](https://github.com/juanfont/headscale/pull/624) +- Improve obtuse UX regarding missing configuration (`ephemeral_node_inactivity_timeout` not set) [#639](https://github.com/juanfont/headscale/pull/639) ## 0.15.0 (2022-03-20) From 76195bb3ac98dfdd38aea37ef6e11cb36542019d Mon Sep 17 00:00:00 2001 From: Kristoffer Dalby Date: Sun, 12 Jun 2022 13:32:16 +0000 Subject: [PATCH 06/11] Add warn if configuration could not be found --- config.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/config.go b/config.go index 212fe154..332f79f7 100644 --- a/config.go +++ b/config.go @@ -163,9 +163,13 @@ func LoadConfig(path string, isFile bool) error { viper.SetDefault("ephemeral_node_inactivity_timeout", "120s") if err := viper.ReadInConfig(); err != nil { + log.Warn().Err(err).Msg("Failed to read configuration from disk") + return fmt.Errorf("fatal error reading config file: %w", err) } + log.Debug().Str("path", viper.ConfigFileUsed()).Msg("Read configuration from disk") + // Collect any validation errors and return them all at once var errorText string if (viper.GetString("tls_letsencrypt_hostname") != "") && From 86503289226265f719e98490d26d5f4110a9108f Mon Sep 17 00:00:00 2001 From: Kristoffer Dalby Date: Sun, 12 Jun 2022 16:39:16 +0000 Subject: [PATCH 07/11] Remove debug output, it runs before we disable it --- config.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/config.go b/config.go index 332f79f7..9e71a750 100644 --- a/config.go +++ b/config.go @@ -168,8 +168,6 @@ func LoadConfig(path string, isFile bool) error { return fmt.Errorf("fatal error reading config file: %w", err) } - log.Debug().Str("path", viper.ConfigFileUsed()).Msg("Read configuration from disk") - // Collect any validation errors and return them all at once var errorText string if (viper.GetString("tls_letsencrypt_hostname") != "") && From 28a3a5bd612126f13786f8de0552b457093a7b2f Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Sun, 12 Jun 2022 17:00:23 +0000 Subject: [PATCH 08/11] docs(README): update contributors --- README.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index b3ade6ff..7f68041a 100644 --- a/README.md +++ b/README.md @@ -195,6 +195,15 @@ make build Nico + + + Jiang +
+ Jiang Zhu +
+ + + e-zk/ @@ -202,8 +211,6 @@ make build e-zk - - Justin @@ -218,13 +225,6 @@ make build Alessandro (Ale) Segala - - - Jiang -
- Jiang Zhu -
- unreality/ From c02819ab9fa77618c22c0e77229affa538dca75f Mon Sep 17 00:00:00 2001 From: Kristoffer Dalby Date: Sun, 12 Jun 2022 17:26:44 +0000 Subject: [PATCH 09/11] Ignore new dump file --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 2a03df9f..783e3c1d 100644 --- a/.gitignore +++ b/.gitignore @@ -31,3 +31,5 @@ test_output/ # Nix build output result .direnv/ + +integration_test/etc/config.dump.yaml From 8f31ed51e18e80d8e9ceaadf11e03899290a7286 Mon Sep 17 00:00:00 2001 From: Anton Schubert Date: Tue, 14 Jun 2022 11:33:01 +0200 Subject: [PATCH 10/11] fix occasional panic on registration GenerateRandomStringDNSSafe will panic occasionally if the random base64 string contains too many - and _ due to the replacement. Fix by looping. --- utils.go | 14 ++++++++++---- utils_test.go | 18 +++++++++++++++--- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/utils.go b/utils.go index 8d9dec5b..fd4cda86 100644 --- a/utils.go +++ b/utils.go @@ -325,11 +325,17 @@ func GenerateRandomStringURLSafe(n int) (string, error) { // number generator fails to function correctly, in which // case the caller should not continue. func GenerateRandomStringDNSSafe(n int) (string, error) { - str, err := GenerateRandomStringURLSafe(n) + var str string + var err error + for len(str) < n { + str, err = GenerateRandomStringURLSafe(n) + if err != nil { + return "", err + } + str = strings.ToLower(strings.ReplaceAll(strings.ReplaceAll(str, "_", ""), "-", "")) + } - str = strings.ToLower(strings.ReplaceAll(strings.ReplaceAll(str, "_", ""), "-", "")) - - return str[:n], err + return str[:n], nil } func IsStringInSlice(slice []string, str string) bool { diff --git a/utils_test.go b/utils_test.go index ff85ac8a..07fa62d8 100644 --- a/utils_test.go +++ b/utils_test.go @@ -34,7 +34,7 @@ func (s *Suite) TestGetUsedIps(c *check.C) { MachineKey: "foo", NodeKey: "bar", DiscoKey: "faa", - Hostname: "testmachine", + Hostname: "testmachine", NamespaceID: namespace.ID, RegisterMethod: RegisterMethodAuthKey, AuthKeyID: uint(pak.ID), @@ -82,7 +82,7 @@ func (s *Suite) TestGetMultiIp(c *check.C) { MachineKey: "foo", NodeKey: "bar", DiscoKey: "faa", - Hostname: "testmachine", + Hostname: "testmachine", NamespaceID: namespace.ID, RegisterMethod: RegisterMethodAuthKey, AuthKeyID: uint(pak.ID), @@ -172,7 +172,7 @@ func (s *Suite) TestGetAvailableIpMachineWithoutIP(c *check.C) { MachineKey: "foo", NodeKey: "bar", DiscoKey: "faa", - Hostname: "testmachine", + Hostname: "testmachine", NamespaceID: namespace.ID, RegisterMethod: RegisterMethodAuthKey, AuthKeyID: uint(pak.ID), @@ -185,3 +185,15 @@ func (s *Suite) TestGetAvailableIpMachineWithoutIP(c *check.C) { c.Assert(len(ips2), check.Equals, 1) c.Assert(ips2[0].String(), check.Equals, expected.String()) } + +func (s *Suite) TestGenerateRandomStringDNSSafe(c *check.C) { + for i := 0; i < 100000; i++ { + str, err := GenerateRandomStringDNSSafe(8) + if err != nil { + c.Error(err) + } + if len(str) != 8 { + c.Error("invalid length", len(str), str) + } + } +} From 360488abb437d76cf5cb1aac1bd6d9140a53cb50 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 16 Jun 2022 13:08:07 +0000 Subject: [PATCH 11/11] docs(README): update contributors --- README.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 7f68041a..714a8053 100644 --- a/README.md +++ b/README.md @@ -292,6 +292,13 @@ make build + + + Anton +
+ Anton Schubert +
+ Deon @@ -327,13 +334,6 @@ make build Stefan Majer - - - Anton -
- Anton Schubert -
-