mirror of
https://github.com/juanfont/headscale.git
synced 2025-11-20 01:40:21 -05:00
fix: preserve node expiry when tailscaled restarts
When tailscaled restarts, it sends RegisterRequest with Auth=nil and
Expiry=zero. Previously this was treated as a logout because
time.Time{}.Before(time.Now()) returns true.
Add early return in handleRegister() to detect this case and preserve
the existing node state without modification.
Fixes #2862
This commit is contained in:
committed by
Kristoffer Dalby
parent
3455d1cb59
commit
3bd4ecd9cd
@@ -71,6 +71,13 @@ func (h *Headscale) handleRegister(
|
|||||||
// We do not look up nodes by [key.MachinePublic] as it might belong to multiple
|
// We do not look up nodes by [key.MachinePublic] as it might belong to multiple
|
||||||
// nodes, separated by users and this path is handling expiring/logout paths.
|
// nodes, separated by users and this path is handling expiring/logout paths.
|
||||||
if node, ok := h.state.GetNodeByNodeKey(req.NodeKey); ok {
|
if node, ok := h.state.GetNodeByNodeKey(req.NodeKey); ok {
|
||||||
|
// When tailscaled restarts, it sends RegisterRequest with Auth=nil and Expiry=zero.
|
||||||
|
// Return the current node state without modification.
|
||||||
|
// See: https://github.com/juanfont/headscale/issues/2862
|
||||||
|
if req.Expiry.IsZero() && node.Expiry().Valid() && !node.IsExpired() {
|
||||||
|
return nodeToRegisterResponse(node), nil
|
||||||
|
}
|
||||||
|
|
||||||
resp, err := h.handleLogout(node, req, machineKey)
|
resp, err := h.handleLogout(node, req, machineKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("handling existing node: %w", err)
|
return nil, fmt.Errorf("handling existing node: %w", err)
|
||||||
@@ -173,6 +180,7 @@ func (h *Headscale) handleLogout(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If the request expiry is in the past, we consider it a logout.
|
// If the request expiry is in the past, we consider it a logout.
|
||||||
|
// Zero expiry is handled in handleRegister() before calling this function.
|
||||||
if req.Expiry.Before(time.Now()) {
|
if req.Expiry.Before(time.Now()) {
|
||||||
log.Debug().
|
log.Debug().
|
||||||
Uint64("node.id", node.ID().Uint64()).
|
Uint64("node.id", node.ID().Uint64()).
|
||||||
|
|||||||
Reference in New Issue
Block a user