Documentation ¶
Index ¶
- Constants
- Variables
- type HSDatabase
- func (hsdb *HSDatabase) AssignNodeToUser(node *types.Node, username string) error
- func (hsdb *HSDatabase) Close() error
- func (hsdb *HSDatabase) CreateAPIKey(expiration *time.Time) (string, *types.APIKey, error)
- func (hsdb *HSDatabase) CreatePreAuthKey(userName string, reusable bool, ephemeral bool, expiration *time.Time, ...) (*types.PreAuthKey, error)
- func (hsdb *HSDatabase) CreateUser(name string) (*types.User, error)
- func (hsdb *HSDatabase) DeleteNode(node *types.Node) error
- func (hsdb *HSDatabase) DeleteRoute(id uint64) error
- func (hsdb *HSDatabase) DestroyAPIKey(key types.APIKey) error
- func (hsdb *HSDatabase) DestroyPreAuthKey(pak types.PreAuthKey) error
- func (hsdb *HSDatabase) DestroyUser(name string) error
- func (hsdb *HSDatabase) DisableRoute(id uint64) error
- func (hsdb *HSDatabase) EnableAutoApprovedRoutes(aclPolicy *policy.ACLPolicy, node *types.Node) error
- func (hsdb *HSDatabase) EnableRoute(id uint64) error
- func (hsdb *HSDatabase) EnsureFailoverRouteIsAvailable(node *types.Node) error
- func (hsdb *HSDatabase) ExpireAPIKey(key *types.APIKey) error
- func (hsdb *HSDatabase) ExpireEphemeralNodes(inactivityThreshhold time.Duration)
- func (hsdb *HSDatabase) ExpireExpiredNodes(lastCheck time.Time) time.Time
- func (hsdb *HSDatabase) ExpirePreAuthKey(k *types.PreAuthKey) error
- func (hsdb *HSDatabase) FailoverNodeRoutesWithNotify(node *types.Node) error
- func (hsdb *HSDatabase) GenerateGivenName(mkey key.MachinePublic, suppliedName string) (string, error)
- func (hsdb *HSDatabase) GetAPIKey(prefix string) (*types.APIKey, error)
- func (hsdb *HSDatabase) GetAPIKeyByID(id uint64) (*types.APIKey, error)
- func (hsdb *HSDatabase) GetAdvertisedRoutes(node *types.Node) ([]netip.Prefix, error)
- func (hsdb *HSDatabase) GetEnabledRoutes(node *types.Node) ([]netip.Prefix, error)
- func (hsdb *HSDatabase) GetNode(user string, name string) (*types.Node, error)
- func (hsdb *HSDatabase) GetNodeAdvertisedRoutes(node *types.Node) (types.Routes, error)
- func (hsdb *HSDatabase) GetNodeByAnyKey(machineKey key.MachinePublic, nodeKey key.NodePublic, ...) (*types.Node, error)
- func (hsdb *HSDatabase) GetNodeByGivenName(user string, givenName string) (*types.Node, error)
- func (hsdb *HSDatabase) GetNodeByID(id uint64) (*types.Node, error)
- func (hsdb *HSDatabase) GetNodeByMachineKey(machineKey key.MachinePublic) (*types.Node, error)
- func (hsdb *HSDatabase) GetNodeByNodeKey(nodeKey key.NodePublic) (*types.Node, error)
- func (hsdb *HSDatabase) GetNodePrimaryRoutes(node *types.Node) (types.Routes, error)
- func (hsdb *HSDatabase) GetNodeRoutes(node *types.Node) (types.Routes, error)
- func (hsdb *HSDatabase) GetPreAuthKey(user string, key string) (*types.PreAuthKey, error)
- func (hsdb *HSDatabase) GetRoute(id uint64) (*types.Route, error)
- func (hsdb *HSDatabase) GetRoutes() (types.Routes, error)
- func (hsdb *HSDatabase) GetUser(name string) (*types.User, error)
- func (hsdb *HSDatabase) IsRoutesEnabled(node *types.Node, routeStr string) bool
- func (hsdb *HSDatabase) ListAPIKeys() ([]types.APIKey, error)
- func (hsdb *HSDatabase) ListNodes() ([]types.Node, error)
- func (hsdb *HSDatabase) ListNodesByGivenName(givenName string) (types.Nodes, error)
- func (hsdb *HSDatabase) ListNodesByUser(name string) (types.Nodes, error)
- func (hsdb *HSDatabase) ListPeers(node *types.Node) (types.Nodes, error)
- func (hsdb *HSDatabase) ListPreAuthKeys(userName string) ([]types.PreAuthKey, error)
- func (hsdb *HSDatabase) ListUsers() ([]types.User, error)
- func (hsdb *HSDatabase) NodeReloadFromDatabase(node *types.Node) error
- func (hsdb *HSDatabase) NodeSave(node *types.Node) error
- func (hsdb *HSDatabase) NodeSetExpiry(node *types.Node, expiry time.Time) error
- func (hsdb *HSDatabase) NodeSetMachineKey(node *types.Node, machineKey key.MachinePublic) error
- func (hsdb *HSDatabase) NodeSetNodeKey(node *types.Node, nodeKey key.NodePublic) error
- func (hsdb *HSDatabase) PingDB(ctx context.Context) error
- func (hsdb *HSDatabase) RegisterNode(node types.Node) (*types.Node, error)
- func (hsdb *HSDatabase) RegisterNodeFromAuthCallback(cache *cache.Cache, mkey key.MachinePublic, userName string, ...) (*types.Node, error)
- func (hsdb *HSDatabase) RenameNode(node *types.Node, newName string) error
- func (hsdb *HSDatabase) RenameUser(oldName, newName string) error
- func (hsdb *HSDatabase) SaveNodeRoutes(node *types.Node) (bool, error)
- func (hsdb *HSDatabase) SetTags(node *types.Node, tags []string) error
- func (hsdb *HSDatabase) UpdateLastSeen(node *types.Node) error
- func (hsdb *HSDatabase) UsePreAuthKey(k *types.PreAuthKey) error
- func (hsdb *HSDatabase) ValidateAPIKey(keyStr string) (bool, error)
- func (hsdb *HSDatabase) ValidatePreAuthKey(k string) (*types.PreAuthKey, error)
- type KV
Constants ¶
const ( Postgres = "postgres" Sqlite = "sqlite3" )
const ( NodeGivenNameHashLength = 8 NodeGivenNameTrimSize = 2 )
Variables ¶
var ( ErrNodeNotFound = errors.New("node not found") ErrNodeRouteIsNotAvailable = errors.New("route is not available on node") ErrNodeNotFoundRegistrationCache = errors.New( "node not found in registration cache", ) ErrCouldNotConvertNodeInterface = errors.New("failed to convert node interface") ErrDifferentRegisteredUser = errors.New( "node was previously registered with a different user", ) )
var ( ErrPreAuthKeyNotFound = errors.New("AuthKey not found") ErrPreAuthKeyExpired = errors.New("AuthKey expired") ErrSingleUseAuthKeyHasBeenUsed = errors.New("AuthKey has already been used") ErrUserMismatch = errors.New("user mismatch") ErrPreAuthKeyACLTagInvalid = errors.New("AuthKey tag is invalid") )
var ( ErrUserExists = errors.New("user already exists") ErrUserNotFound = errors.New("user not found") ErrUserStillHasNodes = errors.New("user not empty: node(s) found") )
var ErrAPIKeyFailedToParse = errors.New("failed to parse ApiKey")
var ErrCouldNotAllocateIP = errors.New("could not find any suitable IP")
var ErrRouteIsNotAvailable = errors.New("route is not available")
Functions ¶
This section is empty.
Types ¶
type HSDatabase ¶
type HSDatabase struct {
// contains filtered or unexported fields
}
func NewHeadscaleDatabase ¶
func NewHeadscaleDatabase( dbType, connectionAddr string, debug bool, notifier *notifier.Notifier, ipPrefixes []netip.Prefix, baseDomain string, ) (*HSDatabase, error)
TODO(kradalby): assemble this struct from toptions or something typed rather than arguments.
func (*HSDatabase) AssignNodeToUser ¶
func (hsdb *HSDatabase) AssignNodeToUser(node *types.Node, username string) error
AssignNodeToUser assigns a Node to a user.
func (*HSDatabase) Close ¶
func (hsdb *HSDatabase) Close() error
func (*HSDatabase) CreateAPIKey ¶
CreateAPIKey creates a new ApiKey in a user, and returns it.
func (*HSDatabase) CreatePreAuthKey ¶
func (hsdb *HSDatabase) CreatePreAuthKey( userName string, reusable bool, ephemeral bool, expiration *time.Time, aclTags []string, ) (*types.PreAuthKey, error)
CreatePreAuthKey creates a new PreAuthKey in a user, and returns it.
func (*HSDatabase) CreateUser ¶
func (hsdb *HSDatabase) CreateUser(name string) (*types.User, error)
CreateUser creates a new User. Returns error if could not be created or another user already exists.
func (*HSDatabase) DeleteNode ¶
func (hsdb *HSDatabase) DeleteNode(node *types.Node) error
DeleteNode deletes a Node from the database.
func (*HSDatabase) DeleteRoute ¶
func (hsdb *HSDatabase) DeleteRoute(id uint64) error
func (*HSDatabase) DestroyAPIKey ¶
func (hsdb *HSDatabase) DestroyAPIKey(key types.APIKey) error
DestroyAPIKey destroys a ApiKey. Returns error if the ApiKey does not exist.
func (*HSDatabase) DestroyPreAuthKey ¶
func (hsdb *HSDatabase) DestroyPreAuthKey(pak types.PreAuthKey) error
DestroyPreAuthKey destroys a preauthkey. Returns error if the PreAuthKey does not exist.
func (*HSDatabase) DestroyUser ¶
func (hsdb *HSDatabase) DestroyUser(name string) error
DestroyUser destroys a User. Returns error if the User does not exist or if there are nodes associated with it.
func (*HSDatabase) DisableRoute ¶
func (hsdb *HSDatabase) DisableRoute(id uint64) error
func (*HSDatabase) EnableAutoApprovedRoutes ¶
func (hsdb *HSDatabase) EnableAutoApprovedRoutes( aclPolicy *policy.ACLPolicy, node *types.Node, ) error
EnableAutoApprovedRoutes enables any routes advertised by a node that match the ACL autoApprovers policy.
func (*HSDatabase) EnableRoute ¶
func (hsdb *HSDatabase) EnableRoute(id uint64) error
func (*HSDatabase) EnsureFailoverRouteIsAvailable ¶
func (hsdb *HSDatabase) EnsureFailoverRouteIsAvailable(node *types.Node) error
EnsureFailoverRouteIsAvailable takes a node and checks if the node's route currently have a functioning host that exposes the network.
func (*HSDatabase) ExpireAPIKey ¶
func (hsdb *HSDatabase) ExpireAPIKey(key *types.APIKey) error
ExpireAPIKey marks a ApiKey as expired.
func (*HSDatabase) ExpireEphemeralNodes ¶
func (hsdb *HSDatabase) ExpireEphemeralNodes(inactivityThreshhold time.Duration)
func (*HSDatabase) ExpireExpiredNodes ¶
func (hsdb *HSDatabase) ExpireExpiredNodes(lastCheck time.Time) time.Time
func (*HSDatabase) ExpirePreAuthKey ¶
func (hsdb *HSDatabase) ExpirePreAuthKey(k *types.PreAuthKey) error
MarkExpirePreAuthKey marks a PreAuthKey as expired.
func (*HSDatabase) FailoverNodeRoutesWithNotify ¶
func (hsdb *HSDatabase) FailoverNodeRoutesWithNotify(node *types.Node) error
func (*HSDatabase) GenerateGivenName ¶
func (hsdb *HSDatabase) GenerateGivenName( mkey key.MachinePublic, suppliedName string, ) (string, error)
func (*HSDatabase) GetAPIKey ¶
func (hsdb *HSDatabase) GetAPIKey(prefix string) (*types.APIKey, error)
GetAPIKey returns a ApiKey for a given key.
func (*HSDatabase) GetAPIKeyByID ¶
func (hsdb *HSDatabase) GetAPIKeyByID(id uint64) (*types.APIKey, error)
GetAPIKeyByID returns a ApiKey for a given id.
func (*HSDatabase) GetAdvertisedRoutes ¶
GetAdvertisedRoutes returns the routes that are be advertised by the given node.
func (*HSDatabase) GetEnabledRoutes ¶
GetEnabledRoutes returns the routes that are enabled for the node.
func (*HSDatabase) GetNodeAdvertisedRoutes ¶
func (*HSDatabase) GetNodeByAnyKey ¶
func (hsdb *HSDatabase) GetNodeByAnyKey( machineKey key.MachinePublic, nodeKey key.NodePublic, oldNodeKey key.NodePublic, ) (*types.Node, error)
GetNodeByAnyKey finds a Node by its MachineKey, its current NodeKey or the old one, and returns the Node struct.
func (*HSDatabase) GetNodeByGivenName ¶
GetNodeByGivenName finds a Node by given name and user and returns the Node struct.
func (*HSDatabase) GetNodeByID ¶
func (hsdb *HSDatabase) GetNodeByID(id uint64) (*types.Node, error)
GetNodeByID finds a Node by ID and returns the Node struct.
func (*HSDatabase) GetNodeByMachineKey ¶
func (hsdb *HSDatabase) GetNodeByMachineKey( machineKey key.MachinePublic, ) (*types.Node, error)
GetNodeByMachineKey finds a Node by its MachineKey and returns the Node struct.
func (*HSDatabase) GetNodeByNodeKey ¶
func (hsdb *HSDatabase) GetNodeByNodeKey( nodeKey key.NodePublic, ) (*types.Node, error)
GetNodeByNodeKey finds a Node by its current NodeKey.
func (*HSDatabase) GetNodePrimaryRoutes ¶
getNodePrimaryRoutes returns the routes that are enabled and marked as primary (for subnet failover) Exit nodes are not considered for this, as they are never marked as Primary.
func (*HSDatabase) GetNodeRoutes ¶
func (*HSDatabase) GetPreAuthKey ¶
func (hsdb *HSDatabase) GetPreAuthKey(user string, key string) (*types.PreAuthKey, error)
GetPreAuthKey returns a PreAuthKey for a given key.
func (*HSDatabase) GetUser ¶
func (hsdb *HSDatabase) GetUser(name string) (*types.User, error)
GetUser fetches a user by name.
func (*HSDatabase) IsRoutesEnabled ¶
func (hsdb *HSDatabase) IsRoutesEnabled(node *types.Node, routeStr string) bool
func (*HSDatabase) ListAPIKeys ¶
func (hsdb *HSDatabase) ListAPIKeys() ([]types.APIKey, error)
ListAPIKeys returns the list of ApiKeys for a user.
func (*HSDatabase) ListNodesByGivenName ¶
func (hsdb *HSDatabase) ListNodesByGivenName(givenName string) (types.Nodes, error)
func (*HSDatabase) ListNodesByUser ¶
func (hsdb *HSDatabase) ListNodesByUser(name string) (types.Nodes, error)
ListNodesByUser gets all the nodes in a given user.
func (*HSDatabase) ListPeers ¶
ListPeers returns all peers of node, regardless of any Policy or if the node is expired.
func (*HSDatabase) ListPreAuthKeys ¶
func (hsdb *HSDatabase) ListPreAuthKeys(userName string) ([]types.PreAuthKey, error)
ListPreAuthKeys returns the list of PreAuthKeys for a user.
func (*HSDatabase) ListUsers ¶
func (hsdb *HSDatabase) ListUsers() ([]types.User, error)
ListUsers gets all the existing users.
func (*HSDatabase) NodeReloadFromDatabase ¶
func (hsdb *HSDatabase) NodeReloadFromDatabase(node *types.Node) error
func (*HSDatabase) NodeSave ¶
func (hsdb *HSDatabase) NodeSave(node *types.Node) error
NodeSave saves a node object to the database, prefer to use a specific save method rather than this. It is intended to be used when we are changing or.
func (*HSDatabase) NodeSetExpiry ¶
NodeSetExpiry takes a Node struct and a new expiry time.
func (*HSDatabase) NodeSetMachineKey ¶
func (hsdb *HSDatabase) NodeSetMachineKey( node *types.Node, machineKey key.MachinePublic, ) error
NodeSetMachineKey sets the node key of a node and saves it to the database.
func (*HSDatabase) NodeSetNodeKey ¶
func (hsdb *HSDatabase) NodeSetNodeKey(node *types.Node, nodeKey key.NodePublic) error
NodeSetNodeKey sets the node key of a node and saves it to the database.
func (*HSDatabase) RegisterNode ¶
RegisterNode is executed from the CLI to register a new Node using its MachineKey.
func (*HSDatabase) RegisterNodeFromAuthCallback ¶
func (hsdb *HSDatabase) RegisterNodeFromAuthCallback( cache *cache.Cache, mkey key.MachinePublic, userName string, nodeExpiry *time.Time, registrationMethod string, ) (*types.Node, error)
func (*HSDatabase) RenameNode ¶
func (hsdb *HSDatabase) RenameNode(node *types.Node, newName string) error
RenameNode takes a Node struct and a new GivenName for the nodes and renames it.
func (*HSDatabase) RenameUser ¶
func (hsdb *HSDatabase) RenameUser(oldName, newName string) error
RenameUser renames a User. Returns error if the User does not exist or if another User exists with the new name.
func (*HSDatabase) SaveNodeRoutes ¶
func (hsdb *HSDatabase) SaveNodeRoutes(node *types.Node) (bool, error)
SaveNodeRoutes takes a node and updates the database with the new routes. It returns a bool whether an update should be sent as the saved route impacts nodes.
func (*HSDatabase) SetTags ¶
func (hsdb *HSDatabase) SetTags( node *types.Node, tags []string, ) error
SetTags takes a Node struct pointer and update the forced tags.
func (*HSDatabase) UpdateLastSeen ¶
func (hsdb *HSDatabase) UpdateLastSeen(node *types.Node) error
UpdateLastSeen sets a node's last seen field indicating that we have recently communicating with this node. This is mostly used to indicate if a node is online and is not extremely important to make sure is fully correct and to avoid holding up the hot path, does not contain any locks and isnt concurrency safe. But that should be ok.
func (*HSDatabase) UsePreAuthKey ¶
func (hsdb *HSDatabase) UsePreAuthKey(k *types.PreAuthKey) error
UsePreAuthKey marks a PreAuthKey as used.
func (*HSDatabase) ValidateAPIKey ¶
func (hsdb *HSDatabase) ValidateAPIKey(keyStr string) (bool, error)
func (*HSDatabase) ValidatePreAuthKey ¶
func (hsdb *HSDatabase) ValidatePreAuthKey(k string) (*types.PreAuthKey, error)
ValidatePreAuthKey does the heavy lifting for validation of the PreAuthKey coming from a node If returns no error and a PreAuthKey, it can be used.