Documentation
¶
Index ¶
- Constants
- func AllocateIPv6Subnet(r *rand.Rand) net.IPNet
- func AllocatePeerIP(prefix netip.Prefix, takenIps []netip.Addr) (netip.Addr, error)
- func AllocateRandomPeerIP(prefix netip.Prefix) (netip.Addr, error)
- func AllocateRandomPeerIPv6(prefix netip.Prefix) (netip.Addr, error)
- func ParseRuleString(rule string) (PolicyRuleProtocolType, RulePortRange, error)
- func PolicyRuleImpliesLegacySSH(rule *PolicyRule) bool
- type AccountSettingsInfo
- type ComponentGroup
- type ComponentPeer
- type ComponentResource
- type ComponentResourceType
- type ComponentRouter
- type DNSSettings
- type FirewallRule
- type FirewallRuleContext
- type ForwardingRule
- type GroupCompact
- type LookupMap
- type Network
- type NetworkMap
- type NetworkMapComponents
- func (c *NetworkMapComponents) Calculate(ctx context.Context) *NetworkMap
- func (c *NetworkMapComponents) GetGroupInfo(groupID string) *ComponentGroup
- func (c *NetworkMapComponents) GetPeerGroups(peerID string) map[string]struct{}
- func (c *NetworkMapComponents) GetPeerInfo(peerID string) *ComponentPeer
- func (c *NetworkMapComponents) GetRouterPeerInfo(peerID string) *ComponentPeer
- func (c *NetworkMapComponents) IsEmpty() bool
- func (c *NetworkMapComponents) IsPeerInGroup(peerID, groupID string) bool
- func (c *NetworkMapComponents) ToCompact() *NetworkMapComponentsCompact
- func (c *NetworkMapComponents) ValidatePostureChecksOnPeer(peerID string, postureCheckIDs []string) bool
- type NetworkMapComponentsCompact
- type Policy
- type PolicyRule
- type PolicyRuleDirection
- type PolicyRuleProtocolType
- type PolicyTrafficActionType
- type PolicyUpdateOperation
- type PolicyUpdateOperationType
- type Resource
- type ResourceType
- type RouteFirewallRule
- type RulePortRange
Constants ¶
const ( FirewallRuleDirectionIN = 0 FirewallRuleDirectionOUT = 1 )
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" // AllowedIPsV6Format generates AllowedIPs format for v6 (e.g. fd12:3456:7890::1/128) AllowedIPsV6Format = "%s/128" // IPv6SubnetSize is the prefix length of per-account IPv6 subnets. // Each account gets a /64 from its unique /48 ULA prefix. IPv6SubnetSize = 64 )
const ( // PolicyTrafficActionAccept indicates that the traffic is accepted PolicyTrafficActionAccept = PolicyTrafficActionType("accept") // PolicyTrafficActionDrop indicates that the traffic is dropped PolicyTrafficActionDrop = PolicyTrafficActionType("drop") )
const ( // PolicyRuleProtocolALL type of traffic PolicyRuleProtocolALL = PolicyRuleProtocolType("all") // PolicyRuleProtocolTCP type of traffic PolicyRuleProtocolTCP = PolicyRuleProtocolType("tcp") // PolicyRuleProtocolUDP type of traffic PolicyRuleProtocolUDP = PolicyRuleProtocolType("udp") // PolicyRuleProtocolICMP type of traffic PolicyRuleProtocolICMP = PolicyRuleProtocolType("icmp") // PolicyRuleProtocolNetbirdSSH type of traffic PolicyRuleProtocolNetbirdSSH = PolicyRuleProtocolType("netbird-ssh") )
const ( // PolicyRuleFlowDirect allows traffic from source to destination PolicyRuleFlowDirect = PolicyRuleDirection("direct") // PolicyRuleFlowBidirect allows traffic to both directions PolicyRuleFlowBidirect = PolicyRuleDirection("bidirect") )
const ( // 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" )
const GroupAllName = "All"
GroupAllName is the reserved name of the default group that contains every peer in an account.
Variables ¶
This section is empty.
Functions ¶
func AllocateIPv6Subnet ¶
AllocateIPv6Subnet generates a random RFC 4193 ULA /64 prefix. The format follows RFC 4193 section 3.1: fd + 40-bit Global ID + 16-bit Subnet ID. The Global ID and Subnet ID are randomized (simplified from the SHA-1 algorithm in section 3.2.2), giving 2^56 possible /64 subnets across all accounts.
func AllocatePeerIP ¶
AllocatePeerIP picks an available IP from a netip.Prefix. This method considers already taken IPs and reuses IPs if there are gaps in takenIps. E.g. if prefix=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 AllocateRandomPeerIP ¶
AllocateRandomPeerIP picks a random available IP from a netip.Prefix.
func AllocateRandomPeerIPv6 ¶
AllocateRandomPeerIPv6 picks a random host address within the given IPv6 prefix. Only the host bits (after the prefix length) are randomized.
func ParseRuleString ¶
func ParseRuleString(rule string) (PolicyRuleProtocolType, RulePortRange, error)
func PolicyRuleImpliesLegacySSH ¶
func PolicyRuleImpliesLegacySSH(rule *PolicyRule) bool
Types ¶
type AccountSettingsInfo ¶
type ComponentGroup ¶
ComponentGroup is the self-contained group representation used by NetworkMapComponents: just the membership view the network-map calculation needs, without the server's storage fields.
func (*ComponentGroup) IsGroupAll ¶
func (g *ComponentGroup) IsGroupAll() bool
IsGroupAll checks if the group is a default "All" group.
type ComponentPeer ¶
type ComponentPeer struct {
ID string
Key string
IP netip.Addr
IPv6 netip.Addr
DNSLabel string
SSHKey string
SSHEnabled bool
ServerSSHAllowed bool
AgentVersion string
SupportsSourcePrefixes bool
SupportsIPv6 bool
LoginExpirationEnabled bool
AddedWithSSOLogin bool
LastLogin time.Time
}
ComponentPeer is the self-contained peer representation used by NetworkMapComponents and the calculated NetworkMap. It carries exactly the subset of peer data that crosses the components wire format, so the shared calculation layer stays independent of the management server's domain types.
func (*ComponentPeer) FQDN ¶
func (p *ComponentPeer) FQDN(dnsDomain string) string
FQDN returns the peer's FQDN combined of the peer's DNS label and the system's DNS domain.
func (*ComponentPeer) LoginExpired ¶
LoginExpired indicates whether the peer's login has expired, mirroring the server-side peer semantics: only SSO-added peers with login expiration enabled can expire.
type ComponentResource ¶
type ComponentResource struct {
ID string
PublicID string
NetworkID string
AccountID string
Name string
Description string
Type ComponentResourceType
Address string
Domain string
Prefix netip.Prefix
Enabled bool
}
ComponentResource is the self-contained network-resource representation used by NetworkMapComponents.
type ComponentResourceType ¶
type ComponentResourceType string
ComponentResourceType mirrors the network-resource type enum on the components wire format.
const ( ComponentResourceHost ComponentResourceType = "host" ComponentResourceSubnet ComponentResourceType = "subnet" ComponentResourceDomain ComponentResourceType = "domain" )
type ComponentRouter ¶
type ComponentRouter struct {
NetworkID string
PublicID string
Peer string
PeerGroups []string
Masquerade bool
Metric int
Enabled bool
}
ComponentRouter is the self-contained network-router representation used by NetworkMapComponents.
type DNSSettings ¶
type DNSSettings struct {
// DisabledManagementGroups groups whose DNS management is disabled
DisabledManagementGroups []string `gorm:"serializer:json"`
}
DNSSettings defines dns settings at the account level
func (DNSSettings) Copy ¶
func (d DNSSettings) Copy() DNSSettings
Copy returns a copy of the DNS settings
type FirewallRule ¶
type FirewallRule struct {
// PolicyID is the ID of the policy this rule is derived from
PolicyID string
// PeerIP of the peer
PeerIP string
// Direction of the traffic
Direction int
// Action of the traffic
Action string
// Protocol of the traffic
Protocol string
// Port of the traffic
Port string
// PortRange represents the range of ports for a firewall rule
PortRange RulePortRange
}
FirewallRule is a rule of the firewall.
func AppendIPv6FirewallRule ¶
func AppendIPv6FirewallRule(rules []*FirewallRule, rulesExists map[string]struct{}, peer, targetPeer *ComponentPeer, rule *PolicyRule, rc FirewallRuleContext) []*FirewallRule
func ExpandPortsAndRanges ¶
func ExpandPortsAndRanges(base FirewallRule, rule *PolicyRule, peer *ComponentPeer) []*FirewallRule
ExpandPortsAndRanges expands Ports and PortRanges of a rule into individual firewall rules.
func (*FirewallRule) Equal ¶
func (r *FirewallRule) Equal(other *FirewallRule) bool
Equal checks if two firewall rules are equal.
type FirewallRuleContext ¶
type ForwardingRule ¶
type ForwardingRule struct {
RuleProtocol string
DestinationPorts RulePortRange
TranslatedAddress net.IP
TranslatedPorts RulePortRange
}
func (*ForwardingRule) Equal ¶
func (f *ForwardingRule) Equal(other *ForwardingRule) bool
func (*ForwardingRule) ToProto ¶
func (f *ForwardingRule) ToProto() *proto.ForwardingRule
type GroupCompact ¶
type Network ¶
type Network struct {
Identifier string `json:"id"`
Net net.IPNet `gorm:"serializer:json"`
// NetV6 is the IPv6 ULA subnet for this account's overlay. Empty if not yet allocated.
NetV6 net.IPNet `gorm:"serializer:json"`
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
Mu sync.Mutex `json:"-" gorm:"-"`
}
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) and a random /64 subnet from fd00:4e42::/32 for IPv6.
func (*Network) CurrentSerial ¶
CurrentSerial returns the Network.Serial of the network (latest state id)
type NetworkMap ¶
type NetworkMap struct {
Peers []*ComponentPeer
Network *Network
Routes []*route.Route
DNSConfig nbdns.Config
OfflinePeers []*ComponentPeer
FirewallRules []*FirewallRule
RoutesFirewallRules []*RouteFirewallRule
ForwardingRules []*ForwardingRule
AuthorizedUsers map[string]map[string]struct{}
EnableSSH bool
}
func CalculateNetworkMapFromComponents ¶
func CalculateNetworkMapFromComponents(ctx context.Context, components *NetworkMapComponents) *NetworkMap
func (*NetworkMap) Merge ¶
func (nm *NetworkMap) Merge(other *NetworkMap)
type NetworkMapComponents ¶
type NetworkMapComponents struct {
PeerID string
Network *Network
AccountSettings *AccountSettingsInfo
DNSSettings *DNSSettings
CustomZoneDomain string
Peers map[string]*ComponentPeer
Groups map[string]*ComponentGroup
Policies []*Policy
Routes []*route.Route
NameServerGroups []*nbdns.NameServerGroup
AllDNSRecords []nbdns.SimpleRecord
AccountZones []nbdns.CustomZone
ResourcePoliciesMap map[string][]*Policy
RoutersMap map[string]map[string]*ComponentRouter
NetworkResources []*ComponentResource
GroupIDToUserIDs map[string][]string
AllowedUserIDs map[string]struct{}
PostureFailedPeers map[string]map[string]struct{}
RouterPeers map[string]*ComponentPeer
// NetworkXIDToPublicID maps Network.ID (xid) → PublicID.
// Consumed by the envelope encoder to
// translate RoutersMap keys and NetworkResource.NetworkID references
// to compact uint32 ids. Legacy Calculate() doesn't consult it.
NetworkXIDToPublicID map[string]string
// PostureCheckXIDToPublicID maps posture.Checks.ID (xid) → PublicID.
// Same role as NetworkXIDToPublicID, used for PostureFailedPeers keys and
// policy SourcePostureChecks references.
PostureCheckXIDToPublicID map[string]string
// contains filtered or unexported fields
}
func EmptyNetworkMapComponents ¶
func EmptyNetworkMapComponents(nm *NetworkMapComponents) *NetworkMapComponents
func (*NetworkMapComponents) Calculate ¶
func (c *NetworkMapComponents) Calculate(ctx context.Context) *NetworkMap
func (*NetworkMapComponents) GetGroupInfo ¶
func (c *NetworkMapComponents) GetGroupInfo(groupID string) *ComponentGroup
func (*NetworkMapComponents) GetPeerGroups ¶
func (c *NetworkMapComponents) GetPeerGroups(peerID string) map[string]struct{}
func (*NetworkMapComponents) GetPeerInfo ¶
func (c *NetworkMapComponents) GetPeerInfo(peerID string) *ComponentPeer
func (*NetworkMapComponents) GetRouterPeerInfo ¶
func (c *NetworkMapComponents) GetRouterPeerInfo(peerID string) *ComponentPeer
func (*NetworkMapComponents) IsEmpty ¶
func (c *NetworkMapComponents) IsEmpty() bool
func (*NetworkMapComponents) IsPeerInGroup ¶
func (c *NetworkMapComponents) IsPeerInGroup(peerID, groupID string) bool
func (*NetworkMapComponents) ToCompact ¶
func (c *NetworkMapComponents) ToCompact() *NetworkMapComponentsCompact
func (*NetworkMapComponents) ValidatePostureChecksOnPeer ¶
func (c *NetworkMapComponents) ValidatePostureChecksOnPeer(peerID string, postureCheckIDs []string) bool
type NetworkMapComponentsCompact ¶
type NetworkMapComponentsCompact struct {
PeerID string
Network *Network
AccountSettings *AccountSettingsInfo
DNSSettings *DNSSettings
CustomZoneDomain string
AllPeers []*ComponentPeer
PeerIndexes []int
RouterPeerIndexes []int
Groups map[string]*GroupCompact
AllPolicies []*Policy
PolicyIndexes []int
ResourcePoliciesMap map[string][]int
Routes []*route.Route
NameServerGroups []*nbdns.NameServerGroup
AllDNSRecords []nbdns.SimpleRecord
AccountZones []nbdns.CustomZone
RoutersMap map[string]map[string]*ComponentRouter
NetworkResources []*ComponentResource
GroupIDToUserIDs map[string][]string
AllowedUserIDs map[string]struct{}
PostureFailedPeers map[string]map[string]struct{}
}
func (*NetworkMapComponentsCompact) ToFull ¶
func (c *NetworkMapComponentsCompact) ToFull() *NetworkMapComponents
type Policy ¶
type Policy struct {
// ID of the policy'
ID string `gorm:"primaryKey"`
PublicID string `json:"-"`
// AccountID is a reference to Account that this object belongs
AccountID string `json:"-" gorm:"index"`
// Name of the Policy
Name string
// Description of the policy visible in the UI
Description string
// Enabled status of the policy
Enabled bool
// Rules of the policy
Rules []*PolicyRule `gorm:"foreignKey:PolicyID;references:id;constraint:OnDelete:CASCADE;"`
// SourcePostureChecks are ID references to Posture checks for policy source groups
SourcePostureChecks []string `gorm:"serializer:json"`
}
Policy of the Rego query
func (*Policy) RuleGroups ¶
RuleGroups returns a list of all groups referenced in the policy's rules, including sources and destinations.
func (*Policy) SourceGroups ¶
SourceGroups returns a slice of all unique source groups referenced in the policy's rules.
func (*Policy) UpgradeAndFix ¶
func (p *Policy) UpgradeAndFix()
UpgradeAndFix different version of policies to latest version
type PolicyRule ¶
type PolicyRule struct {
// ID of the policy rule
ID string `gorm:"primaryKey"`
// PolicyID is a reference to Policy that this object belongs
PolicyID string `json:"-" gorm:"index"`
// 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 `gorm:"serializer:json"`
// DestinationResource policy destination resource that the rule is applied to
DestinationResource Resource `gorm:"serializer:json"`
// Sources policy source groups
Sources []string `gorm:"serializer:json"`
// SourceResource policy source resource that the rule is applied to
SourceResource Resource `gorm:"serializer:json"`
// Bidirectional define if the rule is applicable in both directions, sources, and destinations
Bidirectional bool
// Protocol type of the traffic
Protocol PolicyRuleProtocolType
// Ports or it ranges list
Ports []string `gorm:"serializer:json"`
// PortRanges a list of port ranges.
PortRanges []RulePortRange `gorm:"serializer:json"`
// AuthorizedGroups is a map of groupIDs and their respective access to local users via ssh
AuthorizedGroups map[string][]string `gorm:"serializer:json"`
// AuthorizedUser is a list of userIDs that are authorized to access local resources via ssh
AuthorizedUser string
}
PolicyRule is the metadata of the policy
func (*PolicyRule) Copy ¶
func (pm *PolicyRule) Copy() *PolicyRule
Copy returns a copy of a policy rule
func (*PolicyRule) Equal ¶
func (pm *PolicyRule) Equal(other *PolicyRule) bool
type PolicyRuleProtocolType ¶
type PolicyRuleProtocolType string
PolicyRuleProtocolType type of traffic
type PolicyTrafficActionType ¶
type PolicyTrafficActionType string
PolicyTrafficActionType action type for the firewall
type PolicyUpdateOperation ¶
type PolicyUpdateOperation struct {
Type PolicyUpdateOperationType
Values []string
}
PolicyUpdateOperation operation object with type and values to be applied
type PolicyUpdateOperationType ¶
type PolicyUpdateOperationType int
PolicyUpdateOperationType operation type
type Resource ¶
type Resource struct {
ID string
Type ResourceType
}
func (*Resource) FromAPIRequest ¶
func (*Resource) ToAPIResponse ¶
type ResourceType ¶
type ResourceType string
const ( ResourceTypePeer ResourceType = "peer" ResourceTypeDomain ResourceType = "domain" ResourceTypeHost ResourceType = "host" ResourceTypeSubnet ResourceType = "subnet" )
type RouteFirewallRule ¶
type RouteFirewallRule struct {
// PolicyID is the ID of the policy this rule is derived from
PolicyID string
// RouteID is the ID of the route this rule belongs to.
RouteID route.ID
// SourceRanges IP ranges of the routing peers.
SourceRanges []string
// Action of the traffic when the rule is applicable
Action string
// Destination a network prefix for the routed traffic
Destination string
// Protocol of the traffic
Protocol string
// Port of the traffic
Port uint16
// PortRange represents the range of ports for a firewall rule
PortRange RulePortRange
// Domains list of network domains for the routed traffic
Domains domain.List
// isDynamic indicates whether the rule is for DNS routing
IsDynamic bool
}
RouteFirewallRule a firewall rule applicable for a routed network.
func GenerateRouteFirewallRules ¶
func GenerateRouteFirewallRules(ctx context.Context, route *nbroute.Route, rule *PolicyRule, groupPeers []*ComponentPeer, direction int, includeIPv6 bool) []*RouteFirewallRule
GenerateRouteFirewallRules generates a list of firewall rules for a given route. For static routes, source ranges match the destination family (v4 or v6). For dynamic routes (domain-based), separate v4 and v6 rules are generated so the routing peer's forwarding chain allows both address families.
func (*RouteFirewallRule) Equal ¶
func (r *RouteFirewallRule) Equal(other *RouteFirewallRule) bool
type RulePortRange ¶
RulePortRange represents a range of ports for a firewall rule.
func (*RulePortRange) Equal ¶
func (r *RulePortRange) Equal(other *RulePortRange) bool
func (*RulePortRange) ToProto ¶
func (r *RulePortRange) ToProto() *proto.PortInfo