Skip to content

Commit

Permalink
Merge pull request #754 from Aluxima/expired-machine-registration
Browse files Browse the repository at this point in the history
Fix cli registration of expired machines
  • Loading branch information
juanfont authored Aug 20, 2022
2 parents 1945539 + e855622 commit 061e2fe
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## 0.17.0 (2022-XX-XX)

- Add ability to connect to PostgreSQL over TLS/SSL [#745](https://github.com/juanfont/headscale/pull/745)
- Fix CLI registration of expired machines [#754](https://github.com/juanfont/headscale/pull/754)

## 0.16.3 (2022-08-17)

Expand Down
7 changes: 7 additions & 0 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,13 @@ func (h *Headscale) RegistrationHandler(
// The machine has expired
h.handleMachineExpired(writer, req, machineKey, registerRequest, *machine)

machine.Expiry = &time.Time{}
h.registrationCache.Set(
NodePublicKeyStripPrefix(registerRequest.NodeKey),
*machine,
registerCacheExpiration,
)

return
}
}
Expand Down
10 changes: 10 additions & 0 deletions machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const (
)
ErrCouldNotConvertMachineInterface = Error("failed to convert machine interface")
ErrHostnameTooLong = Error("Hostname too long")
ErrDifferentRegisteredNamespace = Error("machine was previously registered with a different namespace")
MachineGivenNameHashLength = 8
MachineGivenNameTrimSize = 2
)
Expand Down Expand Up @@ -789,13 +790,22 @@ func (h *Headscale) RegisterMachineFromAuthCallback(
)
}

// Registration of expired machine with different namespace
if registrationMachine.ID != 0 && registrationMachine.NamespaceID != namespace.ID {
return nil, ErrDifferentRegisteredNamespace
}

registrationMachine.NamespaceID = namespace.ID
registrationMachine.RegisterMethod = registrationMethod

machine, err := h.RegisterMachine(
registrationMachine,
)

if err == nil {
h.registrationCache.Delete(nodeKeyStr)
}

return machine, err
} else {
return nil, ErrCouldNotConvertMachineInterface
Expand Down

0 comments on commit 061e2fe

Please sign in to comment.