From 3d8472c4ef8117ad47352ff3a153495d2b392e4b Mon Sep 17 00:00:00 2001 From: Kristoffer Dalby Date: Tue, 17 Nov 2026 14:13:54 +0000 Subject: [PATCH] types: add Node.KeyExpiryDisabled Switch beside Expiry, as on Tailscale. Views regenerated in the same commit: the clone check does not compile without them. --- hscontrol/types/node.go | 24 ++++++++++++++++++++---- hscontrol/types/types_clone.go | 1 + hscontrol/types/types_view.go | 6 ++++++ 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/hscontrol/types/node.go b/hscontrol/types/node.go index c632de16f..2a81db435 100644 --- a/hscontrol/types/node.go +++ b/hscontrol/types/node.go @@ -186,6 +186,11 @@ type Node struct { Expiry *time.Time + // KeyExpiryDisabled keeps the node from expiring while it is set; Expiry + // is kept, and counts again once it is cleared. Tailscale stores the two + // apart the same way. + KeyExpiryDisabled bool `gorm:"default:false"` + // LastSeen is when the node was last in contact with // headscale. It is best effort and not persisted. LastSeen *time.Time `gorm:"column:last_seen"` @@ -262,6 +267,10 @@ func (node *Node) IsExpired() bool { // IsExpiredAt reports whether the node registration has expired at now. func (node *Node) IsExpiredAt(now time.Time) bool { + if node.KeyExpiryDisabled { + return false + } + // If Expiry is not set, the client has not indicated that // it wants an expiry time, it is therefore considered // to mean "not expired" @@ -1142,6 +1151,16 @@ func (nv NodeView) IsExpiredAt(now time.Time) bool { return nv.ж.IsExpiredAt(now) } +// KeyExpiry is the expiry clients are sent: none while expiry is disabled, +// whatever time is kept for when it is enabled again. +func (nv NodeView) KeyExpiry() (time.Time, bool) { + if !nv.Valid() || nv.KeyExpiryDisabled() { + return time.Time{}, false + } + + return nv.Expiry().GetOk() +} + // Online reports the node's last known connectivity. func (nv NodeView) Online() bool { if !nv.Valid() { @@ -1375,10 +1394,7 @@ func (nv NodeView) TailNode( derp = nv.Hostinfo().NetInfo().PreferredDERP() } - var keyExpiry time.Time - if nv.Expiry().Valid() { - keyExpiry = nv.Expiry().Get() - } + keyExpiry, _ := nv.KeyExpiry() // Fail here, where the mapper drops just this peer, rather than in // json.Marshal, which fails the whole response. diff --git a/hscontrol/types/types_clone.go b/hscontrol/types/types_clone.go index 76408a494..7fcf14716 100644 --- a/hscontrol/types/types_clone.go +++ b/hscontrol/types/types_clone.go @@ -105,6 +105,7 @@ var _NodeCloneNeedsRegeneration = Node(struct { AuthKey *Credential Ephemeral bool Expiry *time.Time + KeyExpiryDisabled bool LastSeen *time.Time ApprovedRoutes Prefixes AutoApprovedRoutes Prefixes diff --git a/hscontrol/types/types_view.go b/hscontrol/types/types_view.go index 182827b3b..6c0c58aed 100644 --- a/hscontrol/types/types_view.go +++ b/hscontrol/types/types_view.go @@ -250,6 +250,11 @@ func (v NodeView) AuthKey() CredentialView { return v.ж.AuthKey.View() } func (v NodeView) Ephemeral() bool { return v.ж.Ephemeral } func (v NodeView) Expiry() views.ValuePointer[time.Time] { return views.ValuePointerOf(v.ж.Expiry) } +// KeyExpiryDisabled keeps the node from expiring while it is set; Expiry +// is kept, and counts again once it is cleared. Tailscale stores the two +// apart the same way. +func (v NodeView) KeyExpiryDisabled() bool { return v.ж.KeyExpiryDisabled } + // LastSeen is when the node was last in contact with // headscale. It is best effort and not persisted. func (v NodeView) LastSeen() views.ValuePointer[time.Time] { @@ -336,6 +341,7 @@ var _NodeViewNeedsRegeneration = Node(struct { AuthKey *Credential Ephemeral bool Expiry *time.Time + KeyExpiryDisabled bool LastSeen *time.Time ApprovedRoutes Prefixes AutoApprovedRoutes Prefixes