mirror of
https://github.com/netbirdio/netbird.git
synced 2026-09-06 15:01:28 +02:00
[client] Rebuild the overlay listeners when the TUN is renewed (#7397)
This commit is contained in:
@@ -3,6 +3,7 @@ package auth
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"slices"
|
||||
"sync"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
@@ -155,6 +156,24 @@ func (a *Authorizer) GetUserIDClaim() string {
|
||||
return a.userIDClaim
|
||||
}
|
||||
|
||||
// Config returns the authorization currently in force. The user list and the
|
||||
// machine-user map are copies; the originals stay in use here.
|
||||
func (a *Authorizer) Config() *Config {
|
||||
a.mu.RLock()
|
||||
defer a.mu.RUnlock()
|
||||
|
||||
machineUsers := make(map[string][]uint32, len(a.machineUsers))
|
||||
for osUser, indexes := range a.machineUsers {
|
||||
machineUsers[osUser] = slices.Clone(indexes)
|
||||
}
|
||||
|
||||
return &Config{
|
||||
UserIDClaim: a.userIDClaim,
|
||||
AuthorizedUsers: slices.Clone(a.authorizedUsers),
|
||||
MachineUsers: machineUsers,
|
||||
}
|
||||
}
|
||||
|
||||
// findUserIndex finds the index of a hashed user ID in the authorized users list
|
||||
// Returns the index and true if found, 0 and false if not found
|
||||
func (a *Authorizer) findUserIndex(hashedUserID sshuserhash.UserIDHash) (int, bool) {
|
||||
|
||||
@@ -197,6 +197,12 @@ type Config struct {
|
||||
|
||||
// HostKey is the SSH server host key in PEM format
|
||||
HostKeyPEM []byte
|
||||
|
||||
// Auth is the fine-grained authorization to open with. Nil starts with an
|
||||
// empty authorizer, which authorizes nobody until UpdateSSHAuth is called.
|
||||
// Setting it here rather than afterwards means the server never accepts a
|
||||
// login before it knows who is allowed.
|
||||
Auth *sshauth.Config
|
||||
}
|
||||
|
||||
// SessionInfo contains information about an active SSH session
|
||||
@@ -220,7 +226,11 @@ func New(config *Config) *Server {
|
||||
connections: make(map[connKey]*connState),
|
||||
jwtEnabled: config.JWT != nil,
|
||||
jwtConfig: config.JWT,
|
||||
authorizer: sshauth.NewAuthorizer(), // Initialize with empty config
|
||||
authorizer: sshauth.NewAuthorizer(),
|
||||
}
|
||||
|
||||
if config.Auth != nil {
|
||||
s.authorizer.Update(config.Auth)
|
||||
}
|
||||
|
||||
return s
|
||||
@@ -461,6 +471,27 @@ func (s *Server) UpdateSSHAuth(config *sshauth.Config) {
|
||||
s.authorizer.Update(config)
|
||||
}
|
||||
|
||||
// JWTConfig returns the JWT authentication this server was built with, or nil
|
||||
// when JWT authentication is disabled.
|
||||
func (s *Server) JWTConfig() *JWTConfig {
|
||||
s.mu.RLock()
|
||||
defer s.mu.RUnlock()
|
||||
return s.jwtConfig
|
||||
}
|
||||
|
||||
// AuthConfig returns the fine-grained authorization currently in force, or nil
|
||||
// when the server has no authorizer.
|
||||
func (s *Server) AuthConfig() *sshauth.Config {
|
||||
s.mu.RLock()
|
||||
authorizer := s.authorizer
|
||||
s.mu.RUnlock()
|
||||
|
||||
if authorizer == nil {
|
||||
return nil
|
||||
}
|
||||
return authorizer.Config()
|
||||
}
|
||||
|
||||
// ensureJWTValidator initializes the JWT validator and extractor if not already initialized
|
||||
func (s *Server) ensureJWTValidator() error {
|
||||
s.mu.RLock()
|
||||
|
||||
Reference in New Issue
Block a user