mirror of
https://github.com/juanfont/headscale.git
synced 2026-11-02 03:34:06 +09:00
policy/v2: revoke stale SSH access and recheck authentication
Updates #3517, #3508
(cherry picked from commit 4fd4da75f2)
This commit is contained in:
1 parent
00f670213a
commit
5fb2d4e089
21 files changed
+1202
-121
No files matched your search
@@ -3,6 +3,7 @@ package mapper
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strconv"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
@@ -55,6 +56,9 @@ type connectionEntry struct {
|
||||
// established connection must go through [multiChannelNodeConn.send]
|
||||
// to keep it current.
|
||||
lastSelf atomic.Pointer[tailcfg.Node]
|
||||
|
||||
// lastSSHPolicy is the last non-nil policy delivered to this connection.
|
||||
lastSSHPolicy atomic.Pointer[tailcfg.SSHPolicy]
|
||||
}
|
||||
|
||||
// withSelfDelta returns data without its Node when this client already
|
||||
@@ -70,6 +74,21 @@ func (entry *connectionEntry) withSelfDelta(data *tailcfg.MapResponse) *tailcfg.
|
||||
return &stripped
|
||||
}
|
||||
|
||||
// withSSHPolicyDelta returns data without its SSHPolicy when this client
|
||||
// already holds an equal one: any non-nil SSHPolicy forces a full client
|
||||
// netmap rebuild. Equal content arrives in fresh pointers after every
|
||||
// policy reload, so compare deeply.
|
||||
func (entry *connectionEntry) withSSHPolicyDelta(data *tailcfg.MapResponse) *tailcfg.MapResponse {
|
||||
if data.SSHPolicy == nil || !reflect.DeepEqual(entry.lastSSHPolicy.Load(), data.SSHPolicy) {
|
||||
return data
|
||||
}
|
||||
|
||||
stripped := *data
|
||||
stripped.SSHPolicy = nil
|
||||
|
||||
return &stripped
|
||||
}
|
||||
|
||||
// multiChannelNodeConn manages multiple concurrent connections for a single node.
|
||||
type multiChannelNodeConn struct {
|
||||
id types.NodeID
|
||||
@@ -342,7 +361,7 @@ func (mc *multiChannelNodeConn) send(data *tailcfg.MapResponse) error {
|
||||
)
|
||||
|
||||
for _, conn := range snapshot {
|
||||
err := conn.send(conn.withSelfDelta(data))
|
||||
err := conn.send(conn.withSSHPolicyDelta(conn.withSelfDelta(data)))
|
||||
if err != nil {
|
||||
lastErr = err
|
||||
|
||||
@@ -357,6 +376,10 @@ func (mc *multiChannelNodeConn) send(data *tailcfg.MapResponse) error {
|
||||
if data.Node != nil {
|
||||
conn.lastSelf.Store(data.Node)
|
||||
}
|
||||
|
||||
if data.SSHPolicy != nil {
|
||||
conn.lastSSHPolicy.Store(data.SSHPolicy)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user