server

package
v0.14.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 23, 2023 License: BSD-3-Clause Imports: 52 Imported by: 17

Documentation

Index

Constants

View Source
const (
	PublicCategory             = "public"
	PrivateCategory            = "private"
	UnknownCategory            = "unknown"
	CacheExpirationMax         = 7 * 24 * 3600 * time.Second // 7 days
	CacheExpirationMin         = 3 * 24 * 3600 * time.Second // 3 days
	DefaultPeerLoginExpiration = 24 * time.Hour
)
View Source
const (
	UDP   Protocol = "udp"
	DTLS  Protocol = "dtls"
	TCP   Protocol = "tcp"
	HTTP  Protocol = "http"
	HTTPS Protocol = "https"
	NONE  Provider = "none"
)
View Source
const (
	// SubnetSize is a size of the subnet of the global network, e.g.  100.77.0.0/16
	SubnetSize = 16
	// NetSize is a global network size 100.64.0.0/10
	NetSize = 10

	// AllowedIPsFormat generates Wireguard AllowedIPs format (e.g. 100.64.30.1/32)
	AllowedIPsFormat = "%s/32"
)
View Source
const (
	// PATPrefix is the globally used, 4 char prefix for personal access tokens
	PATPrefix = "nbp_"
	// PATSecretLength number of characters used for the secret inside the token
	PATSecretLength = 30
	// PATChecksumLength number of characters used for the encoded checksum of the secret inside the token
	PATChecksumLength = 6
	// PATLength total number of characters used for the token
	PATLength = 40
)
View Source
const (
	// PolicyTrafficActionAccept indicates that the traffic is accepted
	PolicyTrafficActionAccept = PolicyTrafficActionType("accept")
	// PolicyTrafficActionDrop indicates that the traffic is dropped
	PolicyTrafficActionDrop = PolicyTrafficActionType("drop")
)
View Source
const (
	// TrafficFlowBidirect allows traffic to both direction
	TrafficFlowBidirect TrafficFlowType = iota
	// TrafficFlowBidirectString allows traffic to both direction
	TrafficFlowBidirectString = "bidirect"
	// DefaultRuleName is a name for the Default rule that is created for every account
	DefaultRuleName = "Default"
	// DefaultRuleDescription is a description for the Default rule that is created for every account
	DefaultRuleDescription = "This is a default rule that allows connections between all the resources"
	// DefaultPolicyName is a name for the Default policy that is created for every account
	DefaultPolicyName = "Default"
	// DefaultPolicyDescription is a description for the Default policy that is created for every account
	DefaultPolicyDescription = "This is a default policy that allows connections between all the resources"
)
View Source
const (
	// SetupKeyReusable is a multi-use key (can be used for multiple machines)
	SetupKeyReusable SetupKeyType = "reusable"
	// SetupKeyOneOff is a single use key (can be used only once)
	SetupKeyOneOff SetupKeyType = "one-off"

	// DefaultSetupKeyDuration = 1 month
	DefaultSetupKeyDuration = 24 * 30 * time.Hour
	// DefaultSetupKeyName is a default name of the default setup key
	DefaultSetupKeyName = "Default key"
	// SetupKeyUnlimitedUsage indicates an unlimited usage of a setup key
	SetupKeyUnlimitedUsage = 0
)
View Source
const (
	UserRoleAdmin   UserRole = "admin"
	UserRoleUser    UserRole = "user"
	UserRoleUnknown UserRole = "unknown"

	UserStatusActive   UserStatus = "active"
	UserStatusDisabled UserStatus = "disabled"
	UserStatusInvited  UserStatus = "invited"
)

Variables

This section is empty.

Functions

func AllocatePeerIP

func AllocatePeerIP(ipNet net.IPNet, takenIps []net.IP) (net.IP, error)

AllocatePeerIP pics an available IP from an net.IPNet. This method considers already taken IPs and reuses IPs if there are gaps in takenIps E.g. if ipNet=100.30.0.0/16 and takenIps=[100.30.0.1, 100.30.0.4] then the result would be 100.30.0.2 or 100.30.0.3

func Hash

func Hash(s string) uint32

func ToResponseProto

func ToResponseProto(configProto Protocol) proto.HostConfig_Protocol

Types

type Account

type Account struct {
	Id string
	// User.Id it was created by
	CreatedBy              string
	Domain                 string
	DomainCategory         string
	IsDomainPrimaryAccount bool
	SetupKeys              map[string]*SetupKey
	Network                *Network
	Peers                  map[string]*Peer
	Users                  map[string]*User
	Groups                 map[string]*Group
	Rules                  map[string]*Rule
	Policies               []*Policy
	Routes                 map[string]*route.Route
	NameServerGroups       map[string]*nbdns.NameServerGroup
	DNSSettings            *DNSSettings
	// Settings is a dictionary of Account settings
	Settings *Settings
}

Account represents a unique account of the system

func (*Account) Copy

func (a *Account) Copy() *Account

func (*Account) DeletePeer added in v0.10.6

func (a *Account) DeletePeer(peerID string)

DeletePeer deletes peer from the account cleaning up all the references

func (*Account) FindPeerByPubKey added in v0.10.6

func (a *Account) FindPeerByPubKey(peerPubKey string) (*Peer, error)

FindPeerByPubKey looks for a Peer by provided WireGuard public key in the Account or returns error if it wasn't found. It will return an object copy of the peer.

func (*Account) FindSetupKey added in v0.10.8

func (a *Account) FindSetupKey(setupKey string) (*SetupKey, error)

FindSetupKey looks for a given SetupKey in the Account or returns error if it wasn't found.

func (*Account) FindUser added in v0.10.5

func (a *Account) FindUser(userID string) (*User, error)

FindUser looks for a given user in the Account or returns error if user wasn't found.

func (*Account) FindUserPeers added in v0.13.0

func (a *Account) FindUserPeers(userID string) ([]*Peer, error)

FindUserPeers returns a list of peers that user owns (created)

func (*Account) GetExpiredPeers added in v0.14.2

func (a *Account) GetExpiredPeers() []*Peer

GetExpiredPeers returns peers that have been expired

func (*Account) GetGroup added in v0.12.0

func (a *Account) GetGroup(groupID string) *Group

GetGroup returns a group by ID if exists, nil otherwise

func (*Account) GetGroupAll

func (a *Account) GetGroupAll() (*Group, error)

func (*Account) GetNextPeerExpiration added in v0.14.2

func (a *Account) GetNextPeerExpiration() (time.Duration, bool)

GetNextPeerExpiration returns the minimum duration in which the next peer of the account will expire if it was found. If there is no peer that expires this function returns false and a duration of 0. This function only considers peers that haven't been expired yet and that are connected.

func (*Account) GetPeer added in v0.13.0

func (a *Account) GetPeer(peerID string) *Peer

GetPeer looks up a Peer by ID

func (*Account) GetPeerByIP added in v0.13.0

func (a *Account) GetPeerByIP(peerIP string) *Peer

GetPeerByIP returns peer by it's IP if exists under account or nil otherwise

func (*Account) GetPeerNetworkMap added in v0.14.3

func (a *Account) GetPeerNetworkMap(peerID, dnsDomain string) *NetworkMap

GetPeerNetworkMap returns a group by ID if exists, nil otherwise

func (*Account) GetPeers added in v0.10.6

func (a *Account) GetPeers() []*Peer

GetPeers returns a list of all Account peers

func (*Account) GetPeersWithExpiration added in v0.14.2

func (a *Account) GetPeersWithExpiration() []*Peer

GetPeersWithExpiration returns a list of peers that have Peer.LoginExpirationEnabled set to true and that were added by a user

func (*Account) GetRoutesByPrefix added in v0.10.6

func (a *Account) GetRoutesByPrefix(prefix netip.Prefix) []*route.Route

GetRoutesByPrefix return list of routes by account and route prefix

func (*Account) UpdatePeer added in v0.10.6

func (a *Account) UpdatePeer(update *Peer)

UpdatePeer saves new or replaces existing peer

func (*Account) UpdateSettings added in v0.14.0

func (a *Account) UpdateSettings(update *Settings) *Account

UpdateSettings saves new account settings

type AccountManager

type AccountManager interface {
	GetOrCreateAccountByUser(userId, domain string) (*Account, error)
	CreateSetupKey(accountID string, keyName string, keyType SetupKeyType, expiresIn time.Duration,
		autoGroups []string, usageLimit int, userID string) (*SetupKey, error)
	SaveSetupKey(accountID string, key *SetupKey, userID string) (*SetupKey, error)
	CreateUser(accountID, userID string, key *UserInfo) (*UserInfo, error)
	ListSetupKeys(accountID, userID string) ([]*SetupKey, error)
	SaveUser(accountID, userID string, update *User) (*UserInfo, error)
	GetSetupKey(accountID, userID, keyID string) (*SetupKey, error)
	GetAccountByUserOrAccountID(userID, accountID, domain string) (*Account, error)
	GetAccountFromToken(claims jwtclaims.AuthorizationClaims) (*Account, *User, error)
	GetAccountFromPAT(pat string) (*Account, *User, error)
	IsUserAdmin(claims jwtclaims.AuthorizationClaims) (bool, error)
	AccountExists(accountId string) (*bool, error)
	GetPeerByKey(peerKey string) (*Peer, error)
	GetPeers(accountID, userID string) ([]*Peer, error)
	MarkPeerConnected(peerKey string, connected bool) error
	DeletePeer(accountID, peerID, userID string) (*Peer, error)
	GetPeerByIP(accountId string, peerIP string) (*Peer, error)
	UpdatePeer(accountID, userID string, peer *Peer) (*Peer, error)
	GetNetworkMap(peerID string) (*NetworkMap, error)
	GetPeerNetwork(peerID string) (*Network, error)
	AddPeer(setupKey, userID string, peer *Peer) (*Peer, *NetworkMap, error)
	AddPATToUser(accountID string, userID string, pat *PersonalAccessToken) error
	DeletePAT(accountID string, userID string, tokenID string) error
	UpdatePeerSSHKey(peerID string, sshKey string) error
	GetUsersFromAccount(accountID, userID string) ([]*UserInfo, error)
	GetGroup(accountId, groupID string) (*Group, error)
	SaveGroup(accountID, userID string, group *Group) error
	UpdateGroup(accountID string, groupID string, operations []GroupUpdateOperation) (*Group, error)
	DeleteGroup(accountId, groupID string) error
	ListGroups(accountId string) ([]*Group, error)
	GroupAddPeer(accountId, groupID, peerID string) error
	GroupDeletePeer(accountId, groupID, peerKey string) error
	GroupListPeers(accountId, groupID string) ([]*Peer, error)
	GetPolicy(accountID, policyID, userID string) (*Policy, error)
	SavePolicy(accountID, userID string, policy *Policy) error
	DeletePolicy(accountID, policyID, userID string) error
	ListPolicies(accountID, userID string) ([]*Policy, error)
	GetRoute(accountID, routeID, userID string) (*route.Route, error)
	CreateRoute(accountID string, prefix, peerID, description, netID string, masquerade bool, metric int, groups []string, enabled bool, userID string) (*route.Route, error)
	SaveRoute(accountID, userID string, route *route.Route) error
	UpdateRoute(accountID, routeID string, operations []RouteUpdateOperation) (*route.Route, error)
	DeleteRoute(accountID, routeID, userID string) error
	ListRoutes(accountID, userID string) ([]*route.Route, error)
	GetNameServerGroup(accountID, nsGroupID string) (*nbdns.NameServerGroup, error)
	CreateNameServerGroup(accountID string, name, description string, nameServerList []nbdns.NameServer, groups []string, primary bool, domains []string, enabled bool, userID string) (*nbdns.NameServerGroup, error)
	SaveNameServerGroup(accountID, userID string, nsGroupToSave *nbdns.NameServerGroup) error
	UpdateNameServerGroup(accountID, nsGroupID, userID string, operations []NameServerGroupUpdateOperation) (*nbdns.NameServerGroup, error)
	DeleteNameServerGroup(accountID, nsGroupID, userID string) error
	ListNameServerGroups(accountID string) ([]*nbdns.NameServerGroup, error)
	GetDNSDomain() string
	GetEvents(accountID, userID string) ([]*activity.Event, error)
	GetDNSSettings(accountID string, userID string) (*DNSSettings, error)
	SaveDNSSettings(accountID string, userID string, dnsSettingsToSave *DNSSettings) error
	GetPeer(accountID, peerID, userID string) (*Peer, error)
	UpdateAccountSettings(accountID, userID string, newSettings *Settings) (*Account, error)
	LoginPeer(login PeerLogin) (*Peer, *NetworkMap, error) // used by peer gRPC API
	SyncPeer(sync PeerSync) (*Peer, *NetworkMap, error)    // used by peer gRPC API
}

type Config

type Config struct {
	Stuns      []*Host
	TURNConfig *TURNConfig
	Signal     *Host

	Datadir string

	HttpConfig *HttpServerConfig

	IdpManagerConfig *idp.Config

	DeviceAuthorizationFlow *DeviceAuthorizationFlow
}

Config of the Management service

type DNSSettings added in v0.12.0

type DNSSettings struct {
	// DisabledManagementGroups groups whose DNS management is disabled
	DisabledManagementGroups []string
}

DNSSettings defines dns settings at the account level

func (*DNSSettings) Copy added in v0.12.0

func (d *DNSSettings) Copy() *DNSSettings

Copy returns a copy of the DNS settings

type DefaultAccountManager

type DefaultAccountManager struct {
	Store Store
	// contains filtered or unexported fields
}

func BuildManager

func BuildManager(store Store, peersUpdateManager *PeersUpdateManager, idpManager idp.Manager,
	singleAccountModeDomain string, dnsDomain string, eventStore activity.Store,
) (*DefaultAccountManager, error)

BuildManager creates a new DefaultAccountManager with a provided Store

func (*DefaultAccountManager) AccountExists

func (am *DefaultAccountManager) AccountExists(accountID string) (*bool, error)

AccountExists checks whether account exists (returns true) or not (returns false)

func (*DefaultAccountManager) AddPATToUser added in v0.14.5

func (am *DefaultAccountManager) AddPATToUser(accountID string, userID string, pat *PersonalAccessToken) error

AddPATToUser takes the userID and the accountID the user belongs to and assigns a provided PersonalAccessToken to that user

func (*DefaultAccountManager) AddPeer

func (am *DefaultAccountManager) AddPeer(setupKey, userID string, peer *Peer) (*Peer, *NetworkMap, error)

AddPeer adds a new peer to the Store. Each Account has a list of pre-authorized SetupKey and if no Account has a given key err with a code status.PermissionDenied will be returned, meaning the setup key is invalid or not found. If a User ID is provided, it means that we passed the authentication using JWT, then we look for account by User ID and register the peer to it. We also add the User ID to the peer metadata to identify registrant. If no userID provided, then fail with status.PermissionDenied Each new Peer will be assigned a new next net.IP from the Account.Network and Account.Network.LastIP will be updated (IP's are not reused). The peer property is just a placeholder for the Peer properties to pass further

func (*DefaultAccountManager) CreateNameServerGroup added in v0.9.8

func (am *DefaultAccountManager) CreateNameServerGroup(accountID string, name, description string, nameServerList []nbdns.NameServer, groups []string, primary bool, domains []string, enabled bool, userID string) (*nbdns.NameServerGroup, error)

CreateNameServerGroup creates and saves a new nameserver group

func (*DefaultAccountManager) CreateRoute added in v0.8.9

func (am *DefaultAccountManager) CreateRoute(accountID string, network, peerID, description, netID string, masquerade bool, metric int, groups []string, enabled bool, userID string) (*route.Route, error)

CreateRoute creates and saves a new route

func (*DefaultAccountManager) CreateSetupKey added in v0.9.2

func (am *DefaultAccountManager) CreateSetupKey(accountID string, keyName string, keyType SetupKeyType,
	expiresIn time.Duration, autoGroups []string, usageLimit int, userID string) (*SetupKey, error)

CreateSetupKey generates a new setup key with a given name, type, list of groups IDs to auto-assign to peers registered with this key, and adds it to the specified account. A list of autoGroups IDs can be empty.

func (*DefaultAccountManager) CreateUser added in v0.9.8

func (am *DefaultAccountManager) CreateUser(accountID, userID string, invite *UserInfo) (*UserInfo, error)

CreateUser creates a new user under the given account. Effectively this is a user invite.

func (*DefaultAccountManager) DeleteGroup

func (am *DefaultAccountManager) DeleteGroup(accountID, groupID string) error

DeleteGroup object of the peers

func (*DefaultAccountManager) DeleteNameServerGroup added in v0.9.8

func (am *DefaultAccountManager) DeleteNameServerGroup(accountID, nsGroupID, userID string) error

DeleteNameServerGroup deletes nameserver group with nsGroupID

func (*DefaultAccountManager) DeletePAT added in v0.14.5

func (am *DefaultAccountManager) DeletePAT(accountID string, userID string, tokenID string) error

DeletePAT deletes a specific PAT from a user

func (*DefaultAccountManager) DeletePeer

func (am *DefaultAccountManager) DeletePeer(accountID, peerID, userID string) (*Peer, error)

DeletePeer removes peer from the account by its IP

func (*DefaultAccountManager) DeletePolicy added in v0.14.5

func (am *DefaultAccountManager) DeletePolicy(accountID, policyID, userID string) error

DeletePolicy from the store

func (*DefaultAccountManager) DeleteRoute added in v0.8.9

func (am *DefaultAccountManager) DeleteRoute(accountID, routeID, userID string) error

DeleteRoute deletes route with routeID

func (*DefaultAccountManager) GetAccountByUserOrAccountID added in v0.10.7

func (am *DefaultAccountManager) GetAccountByUserOrAccountID(userID, accountID, domain string) (*Account, error)

GetAccountByUserOrAccountID looks for an account by user or accountID, if no account is provided and userID doesn't have an account associated with it, one account is created

func (*DefaultAccountManager) GetAccountFromPAT added in v0.14.5

func (am *DefaultAccountManager) GetAccountFromPAT(token string) (*Account, *User, error)

GetAccountFromPAT returns Account and User associated with a personal access token

func (*DefaultAccountManager) GetAccountFromToken added in v0.9.8

func (am *DefaultAccountManager) GetAccountFromToken(claims jwtclaims.AuthorizationClaims) (*Account, *User, error)

GetAccountFromToken returns an account associated with this token

func (*DefaultAccountManager) GetDNSDomain added in v0.10.10

func (am *DefaultAccountManager) GetDNSDomain() string

GetDNSDomain returns the configured dnsDomain

func (*DefaultAccountManager) GetDNSSettings added in v0.12.0

func (am *DefaultAccountManager) GetDNSSettings(accountID string, userID string) (*DNSSettings, error)

GetDNSSettings validates a user role and returns the DNS settings for the provided account ID

func (*DefaultAccountManager) GetEvents added in v0.12.0

func (am *DefaultAccountManager) GetEvents(accountID, userID string) ([]*activity.Event, error)

GetEvents returns a list of activity events of an account

func (*DefaultAccountManager) GetGroup

func (am *DefaultAccountManager) GetGroup(accountID, groupID string) (*Group, error)

GetGroup object of the peers

func (*DefaultAccountManager) GetNameServerGroup added in v0.9.8

func (am *DefaultAccountManager) GetNameServerGroup(accountID, nsGroupID string) (*nbdns.NameServerGroup, error)

GetNameServerGroup gets a nameserver group object from account and nameserver group IDs

func (*DefaultAccountManager) GetNetworkMap

func (am *DefaultAccountManager) GetNetworkMap(peerID string) (*NetworkMap, error)

GetNetworkMap returns Network map for a given peer (omits original peer from the Peers result)

func (*DefaultAccountManager) GetOrCreateAccountByUser

func (am *DefaultAccountManager) GetOrCreateAccountByUser(userID, domain string) (*Account, error)

GetOrCreateAccountByUser returns an existing account for a given user id or creates a new one if doesn't exist

func (*DefaultAccountManager) GetPeer

func (am *DefaultAccountManager) GetPeer(accountID, peerID, userID string) (*Peer, error)

GetPeer for a given accountID, peerID and userID error if not found.

func (*DefaultAccountManager) GetPeerByIP

func (am *DefaultAccountManager) GetPeerByIP(accountID string, peerIP string) (*Peer, error)

GetPeerByIP returns peer by its IP

func (*DefaultAccountManager) GetPeerByKey added in v0.13.0

func (am *DefaultAccountManager) GetPeerByKey(peerPubKey string) (*Peer, error)

GetPeerByKey looks up peer by its public WireGuard key

func (*DefaultAccountManager) GetPeerNetwork added in v0.8.0

func (am *DefaultAccountManager) GetPeerNetwork(peerID string) (*Network, error)

GetPeerNetwork returns the Network for a given peer

func (*DefaultAccountManager) GetPeers added in v0.10.5

func (am *DefaultAccountManager) GetPeers(accountID, userID string) ([]*Peer, error)

GetPeers returns a list of peers under the given account filtering out peers that do not belong to a user if the current user is not an admin.

func (*DefaultAccountManager) GetPolicy added in v0.14.5

func (am *DefaultAccountManager) GetPolicy(accountID, policyID, userID string) (*Policy, error)

GetPolicy from the store

func (*DefaultAccountManager) GetRoute added in v0.8.9

func (am *DefaultAccountManager) GetRoute(accountID, routeID, userID string) (*route.Route, error)

GetRoute gets a route object from account and route IDs

func (*DefaultAccountManager) GetSetupKey added in v0.9.2

func (am *DefaultAccountManager) GetSetupKey(accountID, userID, keyID string) (*SetupKey, error)

GetSetupKey looks up a SetupKey by KeyID, returns NotFound error if not found.

func (*DefaultAccountManager) GetUsersFromAccount

func (am *DefaultAccountManager) GetUsersFromAccount(accountID, userID string) ([]*UserInfo, error)

GetUsersFromAccount performs a batched request for users from IDP by account ID apply filter on what data to return based on provided user role.

func (*DefaultAccountManager) GroupAddPeer

func (am *DefaultAccountManager) GroupAddPeer(accountID, groupID, peerID string) error

GroupAddPeer appends peer to the group

func (*DefaultAccountManager) GroupDeletePeer

func (am *DefaultAccountManager) GroupDeletePeer(accountID, groupID, peerKey string) error

GroupDeletePeer removes peer from the group

func (*DefaultAccountManager) GroupListPeers

func (am *DefaultAccountManager) GroupListPeers(accountID, groupID string) ([]*Peer, error)

GroupListPeers returns list of the peers from the group

func (*DefaultAccountManager) IsUserAdmin added in v0.6.0

func (am *DefaultAccountManager) IsUserAdmin(claims jwtclaims.AuthorizationClaims) (bool, error)

IsUserAdmin flag for current user authenticated by JWT token

func (*DefaultAccountManager) ListGroups

func (am *DefaultAccountManager) ListGroups(accountID string) ([]*Group, error)

ListGroups objects of the peers

func (*DefaultAccountManager) ListNameServerGroups added in v0.9.8

func (am *DefaultAccountManager) ListNameServerGroups(accountID string) ([]*nbdns.NameServerGroup, error)

ListNameServerGroups returns a list of nameserver groups from account

func (*DefaultAccountManager) ListPolicies added in v0.14.5

func (am *DefaultAccountManager) ListPolicies(accountID, userID string) ([]*Policy, error)

ListPolicies from the store

func (*DefaultAccountManager) ListRoutes added in v0.8.9

func (am *DefaultAccountManager) ListRoutes(accountID, userID string) ([]*route.Route, error)

ListRoutes returns a list of routes from account

func (*DefaultAccountManager) ListSetupKeys added in v0.9.2

func (am *DefaultAccountManager) ListSetupKeys(accountID, userID string) ([]*SetupKey, error)

ListSetupKeys returns a list of all setup keys of the account

func (*DefaultAccountManager) LoginPeer added in v0.14.3

func (am *DefaultAccountManager) LoginPeer(login PeerLogin) (*Peer, *NetworkMap, error)

LoginPeer logs in or registers a peer. If peer doesn't exist the function checks whether a setup key or a user is present and registers a new peer if so.

func (*DefaultAccountManager) MarkPeerConnected

func (am *DefaultAccountManager) MarkPeerConnected(peerPubKey string, connected bool) error

MarkPeerConnected marks peer as connected (true) or disconnected (false)

func (*DefaultAccountManager) SaveDNSSettings added in v0.12.0

func (am *DefaultAccountManager) SaveDNSSettings(accountID string, userID string, dnsSettingsToSave *DNSSettings) error

SaveDNSSettings validates a user role and updates the account's DNS settings

func (*DefaultAccountManager) SaveGroup

func (am *DefaultAccountManager) SaveGroup(accountID, userID string, newGroup *Group) error

SaveGroup object of the peers

func (*DefaultAccountManager) SaveNameServerGroup added in v0.9.8

func (am *DefaultAccountManager) SaveNameServerGroup(accountID, userID string, nsGroupToSave *nbdns.NameServerGroup) error

SaveNameServerGroup saves nameserver group

func (*DefaultAccountManager) SavePolicy added in v0.14.5

func (am *DefaultAccountManager) SavePolicy(accountID, userID string, policy *Policy) error

SavePolicy in the store

func (*DefaultAccountManager) SaveRoute added in v0.8.9

func (am *DefaultAccountManager) SaveRoute(accountID, userID string, routeToSave *route.Route) error

SaveRoute saves route

func (*DefaultAccountManager) SaveSetupKey added in v0.9.2

func (am *DefaultAccountManager) SaveSetupKey(accountID string, keyToSave *SetupKey, userID string) (*SetupKey, error)

SaveSetupKey saves the provided SetupKey to the database overriding the existing one. Due to the unique nature of a SetupKey certain properties must not be overwritten (e.g. the key itself, creation date, ID, etc). These properties are overwritten: Name, AutoGroups, Revoked. The rest is copied from the existing key.

func (*DefaultAccountManager) SaveUser added in v0.9.4

func (am *DefaultAccountManager) SaveUser(accountID, userID string, update *User) (*UserInfo, error)

SaveUser saves updates a given user. If the user doesn't exit it will throw status.NotFound error. Only User.AutoGroups field is allowed to be updated for now.

func (*DefaultAccountManager) SyncPeer added in v0.14.3

func (am *DefaultAccountManager) SyncPeer(sync PeerSync) (*Peer, *NetworkMap, error)

SyncPeer checks whether peer is eligible for receiving NetworkMap (authenticated) and returns its NetworkMap if eligible

func (*DefaultAccountManager) UpdateAccountSettings added in v0.14.0

func (am *DefaultAccountManager) UpdateAccountSettings(accountID, userID string, newSettings *Settings) (*Account, error)

UpdateAccountSettings updates Account settings. Only users with role UserRoleAdmin can update the account. User that performs the update has to belong to the account. Returns an updated Account

func (*DefaultAccountManager) UpdateGroup added in v0.7.0

func (am *DefaultAccountManager) UpdateGroup(accountID string,
	groupID string, operations []GroupUpdateOperation,
) (*Group, error)

UpdateGroup updates a group using a list of operations

func (*DefaultAccountManager) UpdateNameServerGroup added in v0.9.8

func (am *DefaultAccountManager) UpdateNameServerGroup(accountID, nsGroupID, userID string, operations []NameServerGroupUpdateOperation) (*nbdns.NameServerGroup, error)

UpdateNameServerGroup updates existing nameserver group with set of operations

func (*DefaultAccountManager) UpdatePeer added in v0.8.0

func (am *DefaultAccountManager) UpdatePeer(accountID, userID string, update *Peer) (*Peer, error)

UpdatePeer updates peer. Only Peer.Name, Peer.SSHEnabled, and Peer.LoginExpirationEnabled can be updated.

func (*DefaultAccountManager) UpdatePeerSSHKey added in v0.8.0

func (am *DefaultAccountManager) UpdatePeerSSHKey(peerID string, sshKey string) error

UpdatePeerSSHKey updates peer's public SSH key

func (*DefaultAccountManager) UpdateRoute added in v0.8.9

func (am *DefaultAccountManager) UpdateRoute(accountID, routeID string, operations []RouteUpdateOperation) (*route.Route, error)

UpdateRoute updates existing route with set of operations

type DefaultScheduler added in v0.14.2

type DefaultScheduler struct {
	// contains filtered or unexported fields
}

DefaultScheduler is a generic structure that allows to schedule jobs (functions) to run in the future and cancel them.

func NewDefaultScheduler added in v0.14.2

func NewDefaultScheduler() *DefaultScheduler

NewDefaultScheduler creates an instance of a DefaultScheduler

func (*DefaultScheduler) Cancel added in v0.14.2

func (wm *DefaultScheduler) Cancel(IDs []string)

Cancel cancels the scheduled job by ID if present. If job wasn't found the function returns false.

func (*DefaultScheduler) Schedule added in v0.14.2

func (wm *DefaultScheduler) Schedule(in time.Duration, ID string, job func() (nextRunIn time.Duration, reschedule bool))

Schedule a job to run in some time in the future. If job returns true then it will be scheduled one more time. If job with the provided ID already exists, a new one won't be scheduled.

type DeviceAuthorizationFlow

type DeviceAuthorizationFlow struct {
	Provider       string
	ProviderConfig ProviderConfig
}

DeviceAuthorizationFlow represents Device Authorization Flow information that can be used by the client to login initiate a Oauth 2.0 device authorization grant flow see https://datatracker.ietf.org/doc/html/rfc8628

type FileStore

type FileStore struct {
	Accounts                map[string]*Account
	SetupKeyID2AccountID    map[string]string `json:"-"`
	PeerKeyID2AccountID     map[string]string `json:"-"`
	PeerID2AccountID        map[string]string `json:"-"`
	UserID2AccountID        map[string]string `json:"-"`
	PrivateDomain2AccountID map[string]string `json:"-"`
	HashedPAT2TokenID       map[string]string `json:"-"`
	TokenID2UserID          map[string]string `json:"-"`
	InstallationID          string
	// contains filtered or unexported fields
}

FileStore represents an account storage backed by a file persisted to disk

func NewFileStore added in v0.10.7

func NewFileStore(dataDir string) (*FileStore, error)

NewFileStore restores a store from the file located in the datadir

func (*FileStore) AcquireAccountLock added in v0.10.7

func (s *FileStore) AcquireAccountLock(accountID string) (unlock func())

AcquireAccountLock acquires account lock and returns a function that releases the lock

func (*FileStore) AcquireGlobalLock added in v0.10.7

func (s *FileStore) AcquireGlobalLock() (unlock func())

AcquireGlobalLock acquires global lock across all the accounts and returns a function that releases the lock

func (*FileStore) Close added in v0.10.7

func (s *FileStore) Close() error

Close the FileStore persisting data to disk

func (*FileStore) DeleteHashedPAT2TokenIDIndex added in v0.14.5

func (s *FileStore) DeleteHashedPAT2TokenIDIndex(hashedToken string) error

DeleteHashedPAT2TokenIDIndex removes an entry from the indexing map HashedPAT2TokenID

func (*FileStore) DeleteTokenID2UserIDIndex added in v0.14.5

func (s *FileStore) DeleteTokenID2UserIDIndex(tokenID string) error

DeleteTokenID2UserIDIndex removes an entry from the indexing map TokenID2UserID

func (*FileStore) GetAccount

func (s *FileStore) GetAccount(accountID string) (*Account, error)

GetAccount returns an account for ID

func (*FileStore) GetAccountByPeerID added in v0.13.0

func (s *FileStore) GetAccountByPeerID(peerID string) (*Account, error)

GetAccountByPeerID returns an account for a given peer ID

func (*FileStore) GetAccountByPeerPubKey added in v0.10.6

func (s *FileStore) GetAccountByPeerPubKey(peerKey string) (*Account, error)

GetAccountByPeerPubKey returns an account for a given peer WireGuard public key

func (*FileStore) GetAccountByPrivateDomain

func (s *FileStore) GetAccountByPrivateDomain(domain string) (*Account, error)

GetAccountByPrivateDomain returns account by private domain

func (*FileStore) GetAccountBySetupKey

func (s *FileStore) GetAccountBySetupKey(setupKey string) (*Account, error)

GetAccountBySetupKey returns account by setup key id

func (*FileStore) GetAccountByUser added in v0.10.6

func (s *FileStore) GetAccountByUser(userID string) (*Account, error)

GetAccountByUser returns a user account

func (*FileStore) GetAllAccounts

func (s *FileStore) GetAllAccounts() (all []*Account)

GetAllAccounts returns all accounts

func (*FileStore) GetInstallationID added in v0.10.0

func (s *FileStore) GetInstallationID() string

GetInstallationID returns the installation ID from the store

func (*FileStore) GetTokenIDByHashedToken added in v0.14.5

func (s *FileStore) GetTokenIDByHashedToken(token string) (string, error)

GetTokenIDByHashedToken returns the id of a personal access token by its hashed secret

func (*FileStore) GetUserByTokenID added in v0.14.5

func (s *FileStore) GetUserByTokenID(tokenID string) (*User, error)

GetUserByTokenID returns a User object a tokenID belongs to

func (*FileStore) SaveAccount

func (s *FileStore) SaveAccount(account *Account) error

func (*FileStore) SaveInstallationID added in v0.10.0

func (s *FileStore) SaveInstallationID(ID string) error

SaveInstallationID saves the installation ID

func (*FileStore) SavePeerStatus added in v0.10.7

func (s *FileStore) SavePeerStatus(accountID, peerID string, peerStatus PeerStatus) error

SavePeerStatus stores the PeerStatus in memory. It doesn't attempt to persist data to speed up things. PeerStatus will be saved eventually when some other changes occur.

type FirewallRule added in v0.14.5

type FirewallRule struct {
	// PeerID of the peer
	PeerID string

	// PeerIP of the peer
	PeerIP string

	// Direction of the traffic
	Direction string

	// Action of the traffic
	Action string

	// Port of the traffic
	Port string
}

FirewallRule is a rule of the firewall.

type GRPCServer added in v0.8.5

type GRPCServer struct {
	proto.UnimplementedManagementServiceServer
	// contains filtered or unexported fields
}

GRPCServer an instance of a Management gRPC API server

func NewServer

func NewServer(config *Config, accountManager AccountManager, peersUpdateManager *PeersUpdateManager,
	turnCredentialsManager TURNCredentialsManager, appMetrics telemetry.AppMetrics,
) (*GRPCServer, error)

NewServer creates a new Management server

func (*GRPCServer) GetDeviceAuthorizationFlow added in v0.8.5

func (s *GRPCServer) GetDeviceAuthorizationFlow(ctx context.Context, req *proto.EncryptedMessage) (*proto.EncryptedMessage, error)

GetDeviceAuthorizationFlow returns a device authorization flow information This is used for initiating an Oauth 2 device authorization grant flow which will be used by our clients to Login

func (*GRPCServer) GetServerKey added in v0.8.5

func (s *GRPCServer) GetServerKey(ctx context.Context, req *proto.Empty) (*proto.ServerKeyResponse, error)

func (*GRPCServer) IsHealthy added in v0.8.5

func (s *GRPCServer) IsHealthy(ctx context.Context, req *proto.Empty) (*proto.Empty, error)

IsHealthy indicates whether the service is healthy

func (*GRPCServer) Login added in v0.8.5

Login endpoint first checks whether peer is registered under any account In case it is, the login is successful In case it isn't, the endpoint checks whether setup key is provided within the request and tries to register a peer. In case of the successful registration login is also successful

func (*GRPCServer) Sync added in v0.8.5

Sync validates the existence of a connecting peer, sends an initial state (all available for the connecting peers) and notifies the connected peer of any updates (e.g. new peers under the same account)

type Group

type Group struct {
	// ID of the group
	ID string

	// Name visible in the UI
	Name string

	// Peers list of the group
	Peers []string
}

Group of the peers for ACL

func (*Group) Copy

func (g *Group) Copy() *Group

func (*Group) EventMeta added in v0.12.0

func (g *Group) EventMeta() map[string]any

EventMeta returns activity event meta related to the group

type GroupUpdateOperation added in v0.7.0

type GroupUpdateOperation struct {
	Type   GroupUpdateOperationType
	Values []string
}

GroupUpdateOperation operation object with type and values to be applied

type GroupUpdateOperationType added in v0.7.0

type GroupUpdateOperationType int

GroupUpdateOperationType operation type

const (
	// UpdateGroupName indicates a name update operation
	UpdateGroupName GroupUpdateOperationType = iota
	// InsertPeersToGroup indicates insert peers to group operation
	InsertPeersToGroup
	// RemovePeersFromGroup indicates a remove peers from group operation
	RemovePeersFromGroup
	// UpdateGroupPeers indicates a replacement of group peers list
	UpdateGroupPeers
)

type Host

type Host struct {
	Proto Protocol
	// URI e.g. turns://stun.wiretrustee.com:4430 or signal.wiretrustee.com:10000
	URI      string
	Username string
	Password string
}

Host represents a Wiretrustee host (e.g. STUN, TURN, Signal)

type HttpServerConfig

type HttpServerConfig struct {
	LetsEncryptDomain string
	// CertFile is the location of the certificate
	CertFile string
	// CertKey is the location of the certificate private key
	CertKey string
	// AuthAudience identifies the recipients that the JWT is intended for (aud in JWT)
	AuthAudience string
	// AuthIssuer identifies principal that issued the JWT
	AuthIssuer string
	// AuthUserIDClaim is the name of the claim that used as user ID
	AuthUserIDClaim string
	// AuthKeysLocation is a location of JWT key set containing the public keys used to verify JWT
	AuthKeysLocation string
	// OIDCConfigEndpoint is the endpoint of an IDP manager to get OIDC configuration
	OIDCConfigEndpoint string
}

HttpServerConfig is a config of the HTTP Management service server

type MockScheduler added in v0.14.2

type MockScheduler struct {
	CancelFunc   func(IDs []string)
	ScheduleFunc func(in time.Duration, ID string, job func() (nextRunIn time.Duration, reschedule bool))
}

MockScheduler is a mock implementation of Scheduler

func (*MockScheduler) Cancel added in v0.14.2

func (mock *MockScheduler) Cancel(IDs []string)

Cancel mocks the Cancel function of the Scheduler interface

func (*MockScheduler) Schedule added in v0.14.2

func (mock *MockScheduler) Schedule(in time.Duration, ID string, job func() (nextRunIn time.Duration, reschedule bool))

Schedule mocks the Schedule function of the Scheduler interface

type NameServerGroupUpdateOperation added in v0.9.8

type NameServerGroupUpdateOperation struct {
	Type   NameServerGroupUpdateOperationType
	Values []string
}

NameServerGroupUpdateOperation operation object with type and values to be applied

type NameServerGroupUpdateOperationType added in v0.9.8

type NameServerGroupUpdateOperationType int

NameServerGroupUpdateOperationType operation type

const (
	// UpdateNameServerGroupName indicates a nameserver group name update operation
	UpdateNameServerGroupName NameServerGroupUpdateOperationType = iota
	// UpdateNameServerGroupDescription indicates a nameserver group description update operation
	UpdateNameServerGroupDescription
	// UpdateNameServerGroupNameServers indicates a nameserver group nameservers list update operation
	UpdateNameServerGroupNameServers
	// UpdateNameServerGroupGroups indicates a nameserver group' groups update operation
	UpdateNameServerGroupGroups
	// UpdateNameServerGroupEnabled indicates a nameserver group status update operation
	UpdateNameServerGroupEnabled
	// UpdateNameServerGroupPrimary indicates a nameserver group primary status update operation
	UpdateNameServerGroupPrimary
	// UpdateNameServerGroupDomains indicates a nameserver group' domains update operation
	UpdateNameServerGroupDomains
)

func (NameServerGroupUpdateOperationType) String added in v0.9.8

type Network

type Network struct {
	Id  string
	Net net.IPNet
	Dns string
	// Serial is an ID that increments by 1 when any change to the network happened (e.g. new peer has been added).
	// Used to synchronize state to the client apps.
	Serial uint64
	// contains filtered or unexported fields
}

func NewNetwork

func NewNetwork() *Network

NewNetwork creates a new Network initializing it with a Serial=0 It takes a random /16 subnet from 100.64.0.0/10 (64 different subnets)

func (*Network) Copy

func (n *Network) Copy() *Network

func (*Network) CurrentSerial

func (n *Network) CurrentSerial() uint64

CurrentSerial returns the Network.Serial of the network (latest state id)

func (*Network) IncSerial

func (n *Network) IncSerial()

IncSerial increments Serial by 1 reflecting that the network state has been changed

type NetworkMap

type NetworkMap struct {
	Peers        []*Peer
	Network      *Network
	Routes       []*route.Route
	DNSConfig    nbdns.Config
	OfflinePeers []*Peer
}

type Peer

type Peer struct {
	// ID is an internal ID of the peer
	ID string
	// WireGuard public key
	Key string
	// A setup key this peer was registered with
	SetupKey string
	// IP address of the Peer
	IP net.IP
	// Meta is a Peer system meta data
	Meta PeerSystemMeta
	// Name is peer's name (machine name)
	Name string
	// DNSLabel is the parsed peer name for domain resolution. It is used to form an FQDN by appending the account's
	// domain to the peer label. e.g. peer-dns-label.netbird.cloud
	DNSLabel string
	// Status peer's management connection status
	Status *PeerStatus
	// The user ID that registered the peer
	UserID string
	// SSHKey is a public SSH key of the peer
	SSHKey string
	// SSHEnabled indicates whether SSH server is enabled on the peer
	SSHEnabled bool
	// LoginExpirationEnabled indicates whether peer's login expiration is enabled and once expired the peer has to re-login.
	// Works with LastLogin
	LoginExpirationEnabled bool
	// LastLogin the time when peer performed last login operation
	LastLogin time.Time
}

Peer represents a machine connected to the network. The Peer is a WireGuard peer identified by a public key

func (*Peer) AddedWithSSOLogin added in v0.14.0

func (p *Peer) AddedWithSSOLogin() bool

AddedWithSSOLogin indicates whether this peer has been added with an SSO login by a user.

func (*Peer) Copy

func (p *Peer) Copy() *Peer

Copy copies Peer object

func (*Peer) EventMeta added in v0.12.0

func (p *Peer) EventMeta(dnsDomain string) map[string]any

EventMeta returns activity event meta related to the peer

func (*Peer) FQDN added in v0.12.0

func (p *Peer) FQDN(dnsDomain string) string

FQDN returns peers FQDN combined of the peer's DNS label and the system's DNS domain

func (*Peer) LoginExpired added in v0.14.0

func (p *Peer) LoginExpired(expiresIn time.Duration) (bool, time.Duration)

LoginExpired indicates whether the peer's login has expired or not. If Peer.LastLogin plus the expiresIn duration has happened already; then login has expired. Return true if a login has expired, false otherwise, and time left to expiration (negative when expired). Login expiration can be disabled/enabled on a Peer level via Peer.LoginExpirationEnabled property. Login expiration can also be disabled/enabled globally on the Account level via Settings.PeerLoginExpirationEnabled. Only peers added by interactive SSO login can be expired.

func (*Peer) MarkLoginExpired added in v0.14.2

func (p *Peer) MarkLoginExpired(expired bool)

MarkLoginExpired marks peer's status expired or not

func (*Peer) UpdateLastLogin added in v0.14.4

func (p *Peer) UpdateLastLogin() *Peer

UpdateLastLogin and set login expired false

func (*Peer) UpdateMeta added in v0.14.3

func (p *Peer) UpdateMeta(meta PeerSystemMeta)

UpdateMeta updates peer's system meta data

type PeerLogin added in v0.14.3

type PeerLogin struct {
	// WireGuardPubKey is a peers WireGuard public key
	WireGuardPubKey string
	// SSHKey is a peer's ssh key. Can be empty (e.g., old version do not provide it, or this feature is disabled)
	SSHKey string
	// Meta is the system information passed by peer, must be always present.
	Meta PeerSystemMeta
	// UserID indicates that JWT was used to log in, and it was valid. Can be empty when SetupKey is used or auth is not required.
	UserID string
	// SetupKey references to a server.SetupKey to log in. Can be empty when UserID is used or auth is not required.
	SetupKey string
}

PeerLogin used as a data object between the gRPC API and AccountManager on Login request.

type PeerStatus

type PeerStatus struct {
	// LastSeen is the last time peer was connected to the management service
	LastSeen time.Time
	// Connected indicates whether peer is connected to the management service or not
	Connected bool
	// LoginExpired
	LoginExpired bool
}

func (*PeerStatus) Copy added in v0.10.7

func (p *PeerStatus) Copy() *PeerStatus

Copy PeerStatus

type PeerSync added in v0.14.3

type PeerSync struct {
	// WireGuardPubKey is a peers WireGuard public key
	WireGuardPubKey string
}

PeerSync used as a data object between the gRPC API and AccountManager on Sync request.

type PeerSystemMeta

type PeerSystemMeta struct {
	Hostname  string
	GoOS      string
	Kernel    string
	Core      string
	Platform  string
	OS        string
	WtVersion string
	UIVersion string
}

PeerSystemMeta is a metadata of a Peer machine system

type PeersUpdateManager

type PeersUpdateManager struct {
	// contains filtered or unexported fields
}

func NewPeersUpdateManager

func NewPeersUpdateManager() *PeersUpdateManager

NewPeersUpdateManager returns a new instance of PeersUpdateManager

func (*PeersUpdateManager) CloseChannel

func (p *PeersUpdateManager) CloseChannel(peerID string)

CloseChannel closes updates channel of a given peer

func (*PeersUpdateManager) CloseChannels added in v0.14.2

func (p *PeersUpdateManager) CloseChannels(peerIDs []string)

CloseChannels closes updates channel for each given peer

func (*PeersUpdateManager) CreateChannel

func (p *PeersUpdateManager) CreateChannel(peerID string) chan *UpdateMessage

CreateChannel creates a go channel for a given peer used to deliver updates relevant to the peer.

func (*PeersUpdateManager) GetAllConnectedPeers added in v0.10.0

func (p *PeersUpdateManager) GetAllConnectedPeers() map[string]struct{}

GetAllConnectedPeers returns a copy of the connected peers map

func (*PeersUpdateManager) SendUpdate

func (p *PeersUpdateManager) SendUpdate(peerID string, update *UpdateMessage) error

SendUpdate sends update message to the peer's channel

type PersonalAccessToken added in v0.14.5

type PersonalAccessToken struct {
	ID             string
	Description    string
	HashedToken    string
	ExpirationDate time.Time
	// scope could be added in future
	CreatedBy string
	CreatedAt time.Time
	LastUsed  time.Time
}

PersonalAccessToken holds all information about a PAT including a hashed version of it for verification

func CreateNewPAT added in v0.14.5

func CreateNewPAT(description string, expirationInDays int, createdBy string) (*PersonalAccessToken, string, error)

CreateNewPAT will generate a new PersonalAccessToken that can be assigned to a User. Additionally, it will return the token in plain text once, to give to the user and only save a hashed version

type Policy added in v0.14.5

type Policy struct {
	// ID of the policy
	ID string

	// Name of the Policy
	Name string

	// Description of the policy visible in the UI
	Description string

	// Enabled status of the policy
	Enabled bool

	// Query of Rego the policy
	Query string

	// Rules of the policy
	Rules []*PolicyRule
}

Policy of the Rego query

func RuleToPolicy added in v0.14.5

func RuleToPolicy(rule *Rule) (*Policy, error)

RuleToPolicy converts a Rule to a Policy query object

func (*Policy) Copy added in v0.14.5

func (p *Policy) Copy() *Policy

Copy returns a copy of the policy.

func (*Policy) EventMeta added in v0.14.5

func (p *Policy) EventMeta() map[string]any

EventMeta returns activity event meta related to this policy

func (*Policy) UpdateQueryFromRules added in v0.14.5

func (p *Policy) UpdateQueryFromRules() error

UpdateQueryFromRules marshals policy rules to Rego string and set it to Query

type PolicyRule added in v0.14.5

type PolicyRule struct {
	// ID of the policy rule
	ID string

	// Name of the rule visible in the UI
	Name string

	// Description of the rule visible in the UI
	Description string

	// Enabled status of rule in the system
	Enabled bool

	// Action policy accept or drops packets
	Action PolicyTrafficActionType

	// Destinations policy destination groups
	Destinations []string

	// Sources policy source groups
	Sources []string
}

PolicyRule is the metadata of the policy

func (*PolicyRule) Copy added in v0.14.5

func (pm *PolicyRule) Copy() *PolicyRule

Copy returns a copy of a policy rule

func (*PolicyRule) ToRule added in v0.14.5

func (pm *PolicyRule) ToRule() *Rule

ToRule converts the PolicyRule to a legacy representation of the Rule (for backwards compatibility)

type PolicyTrafficActionType added in v0.14.5

type PolicyTrafficActionType string

PolicyTrafficActionType action type for the firewall

type PolicyUpdateOperation added in v0.14.5

type PolicyUpdateOperation struct {
	Type   PolicyUpdateOperationType
	Values []string
}

PolicyUpdateOperation operation object with type and values to be applied

type PolicyUpdateOperationType added in v0.14.5

type PolicyUpdateOperationType int

PolicyUpdateOperationType operation type

type Protocol

type Protocol string

Protocol type

type Provider

type Provider string

Provider authorization flow type

type ProviderConfig

type ProviderConfig struct {
	// ClientID An IDP application client id
	ClientID string
	// ClientSecret An IDP application client secret
	ClientSecret string
	// Domain An IDP API domain
	// Deprecated. Use TokenEndpoint and DeviceAuthEndpoint
	Domain string
	// Audience An Audience for to authorization validation
	Audience string
	// TokenEndpoint is the endpoint of an IDP manager where clients can obtain access token
	TokenEndpoint string
	// DeviceAuthEndpoint is the endpoint of an IDP manager where clients can obtain device authorization code
	DeviceAuthEndpoint string
}

ProviderConfig has all attributes needed to initiate a device authorization flow

type RouteUpdateOperation added in v0.8.9

type RouteUpdateOperation struct {
	Type   RouteUpdateOperationType
	Values []string
}

RouteUpdateOperation operation object with type and values to be applied

type RouteUpdateOperationType added in v0.8.9

type RouteUpdateOperationType int

RouteUpdateOperationType operation type

const (
	// UpdateRouteDescription indicates a route description update operation
	UpdateRouteDescription RouteUpdateOperationType = iota
	// UpdateRouteNetwork indicates a route IP update operation
	UpdateRouteNetwork
	// UpdateRoutePeer indicates a route peer update operation
	UpdateRoutePeer
	// UpdateRouteMetric indicates a route metric update operation
	UpdateRouteMetric
	// UpdateRouteMasquerade indicates a route masquerade update operation
	UpdateRouteMasquerade
	// UpdateRouteEnabled indicates a route enabled update operation
	UpdateRouteEnabled
	// UpdateRouteNetworkIdentifier indicates a route net ID update operation
	UpdateRouteNetworkIdentifier
	// UpdateRouteGroups indicates a group list update operation
	UpdateRouteGroups
)

func (RouteUpdateOperationType) String added in v0.8.9

func (t RouteUpdateOperationType) String() string

type Rule

type Rule struct {
	// ID of the rule
	ID string

	// Name of the rule visible in the UI
	Name string

	// Description of the rule visible in the UI
	Description string

	// Disabled status of rule in the system
	Disabled bool

	// Source list of groups IDs of peers
	Source []string

	// Destination list of groups IDs of peers
	Destination []string

	// Flow of the traffic allowed by the rule
	Flow TrafficFlowType
}

Rule of ACL for groups

func (*Rule) Copy

func (r *Rule) Copy() *Rule

func (*Rule) EventMeta added in v0.12.0

func (r *Rule) EventMeta() map[string]any

EventMeta returns activity event meta related to this rule

func (*Rule) ToPolicyRule added in v0.14.5

func (r *Rule) ToPolicyRule() *PolicyRule

ToPolicyRule converts a Rule to a PolicyRule object

type Scheduler added in v0.14.2

type Scheduler interface {
	Cancel(IDs []string)
	Schedule(in time.Duration, ID string, job func() (nextRunIn time.Duration, reschedule bool))
}

Scheduler is an interface which implementations can schedule and cancel jobs

type Settings added in v0.14.0

type Settings struct {
	// PeerLoginExpirationEnabled globally enables or disables peer login expiration
	PeerLoginExpirationEnabled bool
	// PeerLoginExpiration is a setting that indicates when peer login expires.
	// Applies to all peers that have Peer.LoginExpirationEnabled set to true.
	PeerLoginExpiration time.Duration
}

Settings represents Account settings structure that can be modified via API and Dashboard

func (*Settings) Copy added in v0.14.0

func (s *Settings) Copy() *Settings

Copy copies the Settings struct

type SetupKey

type SetupKey struct {
	Id        string
	Key       string
	Name      string
	Type      SetupKeyType
	CreatedAt time.Time
	ExpiresAt time.Time
	UpdatedAt time.Time
	// Revoked indicates whether the key was revoked or not (we don't remove them for tracking purposes)
	Revoked bool
	// UsedTimes indicates how many times the key was used
	UsedTimes int
	// LastUsed last time the key was used for peer registration
	LastUsed time.Time
	// AutoGroups is a list of Group IDs that are auto assigned to a Peer when it uses this key to register
	AutoGroups []string
	// UsageLimit indicates the number of times this key can be used to enroll a machine.
	// The value of 0 indicates the unlimited usage.
	UsageLimit int
}

SetupKey represents a pre-authorized key used to register machines (peers)

func GenerateDefaultSetupKey

func GenerateDefaultSetupKey() *SetupKey

GenerateDefaultSetupKey generates a default reusable setup key with an unlimited usage and 30 days expiration

func GenerateSetupKey

func GenerateSetupKey(name string, t SetupKeyType, validFor time.Duration, autoGroups []string,
	usageLimit int) *SetupKey

GenerateSetupKey generates a new setup key

func (*SetupKey) Copy

func (key *SetupKey) Copy() *SetupKey

Copy copies SetupKey to a new object

func (*SetupKey) EventMeta added in v0.12.0

func (key *SetupKey) EventMeta() map[string]any

EventMeta returns activity event meta related to the setup key

func (*SetupKey) HiddenCopy added in v0.10.5

func (key *SetupKey) HiddenCopy(length int) *SetupKey

HiddenCopy returns a copy of the key with a Key value hidden with "*" and a 5 character prefix. E.g., "831F6*******************************"

func (*SetupKey) IncrementUsage

func (key *SetupKey) IncrementUsage() *SetupKey

IncrementUsage makes a copy of a key, increments the UsedTimes by 1 and sets LastUsed to now

func (*SetupKey) IsExpired

func (key *SetupKey) IsExpired() bool

IsExpired if key was expired

func (*SetupKey) IsOverUsed

func (key *SetupKey) IsOverUsed() bool

IsOverUsed if the key was used too many times. SetupKey.UsageLimit == 0 indicates the unlimited usage.

func (*SetupKey) IsRevoked

func (key *SetupKey) IsRevoked() bool

IsRevoked if key was revoked

func (*SetupKey) IsValid

func (key *SetupKey) IsValid() bool

IsValid is true if the key was not revoked, is not expired and used not more than it was supposed to

type SetupKeyType

type SetupKeyType string

SetupKeyType is the type of setup key

type SetupKeyUpdateOperation added in v0.9.2

type SetupKeyUpdateOperation struct {
	Type   SetupKeyUpdateOperationType
	Values []string
}

SetupKeyUpdateOperation operation object with type and values to be applied

type SetupKeyUpdateOperationType added in v0.9.2

type SetupKeyUpdateOperationType int

SetupKeyUpdateOperationType operation type

const (
	// UpdateSetupKeyName indicates a setup key name update operation
	UpdateSetupKeyName SetupKeyUpdateOperationType = iota
	// UpdateSetupKeyRevoked indicates a setup key revoked filed update operation
	UpdateSetupKeyRevoked
	// UpdateSetupKeyAutoGroups indicates a setup key auto-assign groups update operation
	UpdateSetupKeyAutoGroups
	// UpdateSetupKeyExpiresAt indicates a setup key expiration time update operation
	UpdateSetupKeyExpiresAt
)

func (SetupKeyUpdateOperationType) String added in v0.9.2

type Store

type Store interface {
	GetAllAccounts() []*Account
	GetAccount(accountID string) (*Account, error)
	GetAccountByUser(userID string) (*Account, error)
	GetAccountByPeerPubKey(peerKey string) (*Account, error)
	GetAccountByPeerID(peerID string) (*Account, error)
	GetAccountBySetupKey(setupKey string) (*Account, error) // todo use key hash later
	GetAccountByPrivateDomain(domain string) (*Account, error)
	GetTokenIDByHashedToken(secret string) (string, error)
	GetUserByTokenID(tokenID string) (*User, error)
	SaveAccount(account *Account) error
	DeleteHashedPAT2TokenIDIndex(hashedToken string) error
	DeleteTokenID2UserIDIndex(tokenID string) error
	GetInstallationID() string
	SaveInstallationID(ID string) error
	// AcquireAccountLock should attempt to acquire account lock and return a function that releases the lock
	AcquireAccountLock(accountID string) func()
	// AcquireGlobalLock should attempt to acquire a global lock and return a function that releases the lock
	AcquireGlobalLock() func()
	SavePeerStatus(accountID, peerID string, status PeerStatus) error
	// Close should close the store persisting all unsaved data.
	Close() error
}

type StoredAccount

type StoredAccount struct{}

type TURNConfig

type TURNConfig struct {
	TimeBasedCredentials bool
	CredentialsTTL       util.Duration
	Secret               string
	Turns                []*Host
}

TURNConfig is a config of the TURNCredentialsManager

type TURNCredentials

type TURNCredentials struct {
	Username string
	Password string
}

type TURNCredentialsManager

type TURNCredentialsManager interface {
	GenerateCredentials() TURNCredentials
	SetupRefresh(peerKey string)
	CancelRefresh(peerKey string)
}

TURNCredentialsManager used to manage TURN credentials

type TimeBasedAuthSecretsManager

type TimeBasedAuthSecretsManager struct {
	// contains filtered or unexported fields
}

TimeBasedAuthSecretsManager generates credentials with TTL and using pre-shared secret known to TURN server

func NewTimeBasedAuthSecretsManager

func NewTimeBasedAuthSecretsManager(updateManager *PeersUpdateManager, config *TURNConfig) *TimeBasedAuthSecretsManager

func (*TimeBasedAuthSecretsManager) CancelRefresh

func (m *TimeBasedAuthSecretsManager) CancelRefresh(peerID string)

CancelRefresh cancels scheduled peer credentials refresh

func (*TimeBasedAuthSecretsManager) GenerateCredentials

func (m *TimeBasedAuthSecretsManager) GenerateCredentials() TURNCredentials

GenerateCredentials generates new time-based secret credentials - basically username is a unix timestamp and password is a HMAC hash of a timestamp with a preshared TURN secret

func (*TimeBasedAuthSecretsManager) SetupRefresh

func (m *TimeBasedAuthSecretsManager) SetupRefresh(peerID string)

SetupRefresh starts peer credentials refresh. Since credentials are expiring (TTL) it is necessary to always generate them and send to the peer. A goroutine is created and put into TimeBasedAuthSecretsManager.cancelMap. This routine should be cancelled if peer is gone.

type TrafficFlowType

type TrafficFlowType int

TrafficFlowType defines allowed direction of the traffic in the rule

type UpdateMessage

type UpdateMessage struct {
	Update *proto.SyncResponse
}

type User

type User struct {
	Id   string
	Role UserRole
	// AutoGroups is a list of Group IDs to auto-assign to peers registered by this user
	AutoGroups []string
	PATs       map[string]*PersonalAccessToken
}

User represents a user of the system

func NewAdminUser

func NewAdminUser(id string) *User

NewAdminUser creates a new user with role UserRoleAdmin

func NewRegularUser

func NewRegularUser(id string) *User

NewRegularUser creates a new user with role UserRoleAdmin

func NewUser

func NewUser(id string, role UserRole) *User

NewUser creates a new user

func (*User) Copy

func (u *User) Copy() *User

Copy the user

func (*User) IsAdmin added in v0.10.5

func (u *User) IsAdmin() bool

IsAdmin returns true if user is an admin, false otherwise

type UserInfo

type UserInfo struct {
	ID         string   `json:"id"`
	Email      string   `json:"email"`
	Name       string   `json:"name"`
	Role       string   `json:"role"`
	AutoGroups []string `json:"auto_groups"`
	Status     string   `json:"-"`
}

type UserRole

type UserRole string

UserRole is the role of a User

func StrRoleToUserRole added in v0.9.5

func StrRoleToUserRole(strRole string) UserRole

StrRoleToUserRole returns UserRole for a given strRole or UserRoleUnknown if the specified role is unknown

type UserStatus added in v0.9.8

type UserStatus string

UserStatus is the status of a User

Directories

Path Synopsis
api
Package api provides primitives to interact with the openapi HTTP API.
Package api provides primitives to interact with the openapi HTTP API.
Package metrics gather anonymous information about the usage of NetBird management
Package metrics gather anonymous information about the usage of NetBird management

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL