From 58fd6c4ba5d23684113493db43b542719bc15c3d Mon Sep 17 00:00:00 2001 From: Kristoffer Dalby Date: Fri, 26 Nov 2021 07:13:00 +0000 Subject: [PATCH 1/2] Revert postgres constant value changes "postgresql" to "postgres" --- app.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app.go b/app.go index 0d3332dd..0a12d965 100644 --- a/app.go +++ b/app.go @@ -48,7 +48,7 @@ import ( const ( AuthPrefix = "Bearer " - Postgres = "postgresql" + Postgres = "postgres" Sqlite = "sqlite3" updateInterval = 5000 HTTPReadTimeout = 30 * time.Second From c7f3e0632bf7adfe7d5e6bd98deb19ad89510b63 Mon Sep 17 00:00:00 2001 From: Ward Vandewege Date: Thu, 25 Nov 2021 19:23:10 -0500 Subject: [PATCH 2/2] When creating a preauthkey, the default expiration was passed through as a nil value, instead of the default value (1h). This resulted in the preauthkey being created with expiration key '0001-01-01 00:00:00', which meant the key would not work, because it was already expired. This commit applies the default expiration time (1h) when a preauthkey is created without a specific expiration. It also updates an integration test to make sure this bug does not reoccur. --- cmd/headscale/cli/preauthkeys.go | 12 +++++------- integration_cli_test.go | 7 ++++++- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/cmd/headscale/cli/preauthkeys.go b/cmd/headscale/cli/preauthkeys.go index 9d5c838f..5342085c 100644 --- a/cmd/headscale/cli/preauthkeys.go +++ b/cmd/headscale/cli/preauthkeys.go @@ -13,7 +13,7 @@ import ( ) const ( - DefaultPreAuthKeyExpiry = 24 * time.Hour + DefaultPreAuthKeyExpiry = 1 * time.Hour ) func init() { @@ -145,14 +145,12 @@ var createPreAuthKeyCmd = &cobra.Command{ Ephemeral: ephemeral, } - if cmd.Flags().Changed("expiration") { - duration, _ := cmd.Flags().GetDuration("expiration") - expiration := time.Now().UTC().Add(duration) + duration, _ := cmd.Flags().GetDuration("expiration") + expiration := time.Now().UTC().Add(duration) - log.Trace().Dur("expiration", duration).Msg("expiration has been set") + log.Trace().Dur("expiration", duration).Msg("expiration has been set") - request.Expiration = timestamppb.New(expiration) - } + request.Expiration = timestamppb.New(expiration) ctx, client, conn, cancel := getHeadscaleCLIClient() defer cancel() diff --git a/integration_cli_test.go b/integration_cli_test.go index ee940542..92d497a9 100644 --- a/integration_cli_test.go +++ b/integration_cli_test.go @@ -426,7 +426,12 @@ func (s *IntegrationCLITestSuite) TestPreAuthKeyCommandWithoutExpiry() { assert.Nil(s.T(), err) assert.Len(s.T(), listedPreAuthKeys, 1) - assert.True(s.T(), time.Time{}.Equal(listedPreAuthKeys[0].Expiration.AsTime())) + + assert.True(s.T(), listedPreAuthKeys[0].Expiration.AsTime().After(time.Now())) + assert.True( + s.T(), + listedPreAuthKeys[0].Expiration.AsTime().Before(time.Now().Add(time.Minute*70)), + ) } func (s *IntegrationCLITestSuite) TestPreAuthKeyCommandReusableEphemeral() {