Documentation
¶
Index ¶
- Constants
- func ApplyResolvedRuleToState[P any](rule *nmdata.PolicyRule, sourcePeers []P, destPeers []P, peerInSources bool, ...)
- func EnsureWildcardUser(target map[string]map[string]struct{}, authorizedUser string)
- func MarkerScopedPorts(protocol PolicyRuleProtocolType) ([]string, bool)
- func MergeAuthorizedGroupUsers(ctx context.Context, authorizedGroups map[string][]string, ...)
- func MergeWildcardUsers(dst map[string]map[string]struct{}, users map[string]struct{})
- func ParseRuleString(rule string) (PolicyRuleProtocolType, RulePortRange, error)
- func SSHScopedPorts() []string
- func VNCScopedPorts() []string
- type AccountSettingsInfo
- type FirewallRule
- type FirewallRuleContext
- type GroupCompact
- type LookupMap
- type NetworkMap
- type NetworkMapComponents
- func (c *NetworkMapComponents) Calculate(ctx context.Context) *NetworkMap
- func (c *NetworkMapComponents) GetGroupInfo(groupID string) *nmdata.Group
- func (c *NetworkMapComponents) GetPeerGroups(peerID string) map[string]struct{}
- func (c *NetworkMapComponents) GetPeerInfo(peerID string) *nmdata.Peer
- func (c *NetworkMapComponents) GetRouterPeerInfo(peerID string) *nmdata.Peer
- func (c *NetworkMapComponents) IsAuthorizedUserDenied(rule *nmdata.PolicyRule) bool
- func (c *NetworkMapComponents) IsEmpty() bool
- func (c *NetworkMapComponents) IsLoginExpired(p *nmdata.Peer) 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 PeerConnResolveState
- type PolicyRuleProtocolType
- type PolicyTrafficActionType
- type ResourceType
- type RouteFirewallRule
- type RuleAuthCallbacks
- type RulePortRange
- type VNCSessionPubKey
Constants ¶
const ( FirewallRuleDirectionIN = 0 FirewallRuleDirectionOUT = 1 )
const ( // 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" )
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") // PolicyRuleProtocolNetbirdVNC type of traffic PolicyRuleProtocolNetbirdVNC = PolicyRuleProtocolType("netbird-vnc") )
const VNCInternalPort = 25900
VNCInternalPort is the internal port the VNC server listens on (behind DNAT from 5900).
Variables ¶
This section is empty.
Functions ¶
func ApplyResolvedRuleToState ¶ added in v0.84.0
func ApplyResolvedRuleToState[P any]( rule *nmdata.PolicyRule, sourcePeers []P, destPeers []P, peerInSources bool, peerInDestinations bool, targetPeerSSHEnabled bool, generateResources func(*nmdata.PolicyRule, []P, int), cb RuleAuthCallbacks, state *PeerConnResolveState, )
ApplyResolvedRuleToState emits firewall rules in the rule's directions and records authorized users into state according to the rule's protocol. The callbacks supply the auth-collection behaviour specific to the calling resolver (Account vs NetworkMapComponents), which also decide the peer representation the resource generator works with.
func EnsureWildcardUser ¶ added in v0.84.0
EnsureWildcardUser ensures the wildcard local-user entry exists in target and adds the given authorized user to it.
func MarkerScopedPorts ¶ added in v0.84.0
func MarkerScopedPorts(protocol PolicyRuleProtocolType) ([]string, bool)
MarkerScopedPorts returns the ports the NetBird marker protocols imply, for a rule that declares none of its own. ok is false for every other protocol, which carries no implied port.
func MergeAuthorizedGroupUsers ¶ added in v0.84.0
func MergeAuthorizedGroupUsers( ctx context.Context, authorizedGroups map[string][]string, groupIDToUserIDs map[string][]string, target map[string]map[string]struct{}, )
MergeAuthorizedGroupUsers expands AuthorizedGroups (group ID to local user list) into target, mapping each local user to the set of user IDs in the referenced group. Used by both Account and NetworkMapComponents auth resolution paths.
func MergeWildcardUsers ¶ added in v0.84.0
MergeWildcardUsers adds every user in users to the wildcard local-user entry of dst, allocating the entry on demand.
func ParseRuleString ¶
func ParseRuleString(rule string) (PolicyRuleProtocolType, RulePortRange, error)
func SSHScopedPorts ¶ added in v0.84.0
func SSHScopedPorts() []string
SSHScopedPorts returns the ports a netbird-ssh rule is scoped to when it declares none of its own: the standard SSH port, which the firewall rule expansion pairs with the native SSH port for peers that support it.
func VNCScopedPorts ¶ added in v0.84.0
func VNCScopedPorts() []string
VNCScopedPorts returns the ports a netbird-vnc rule is scoped to when it declares none of its own, so a VNC-only rule doesn't degrade into an unscoped TCP allow.
Types ¶
type AccountSettingsInfo ¶
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 *nmdata.Peer, rule *nmdata.PolicyRule, rc FirewallRuleContext) []*FirewallRule
func ExpandPortsAndRanges ¶
func ExpandPortsAndRanges(base FirewallRule, rule *nmdata.PolicyRule, peer *nmdata.Peer) []*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 GroupCompact ¶
type NetworkMap ¶
type NetworkMap struct {
Peers []*nmdata.Peer
Network *nmdata.Network
Routes []*nmdata.Route
DNSConfig nbdns.Config
OfflinePeers []*nmdata.Peer
FirewallRules []*FirewallRule
RoutesFirewallRules []*RouteFirewallRule
AuthorizedUsers map[string]map[string]struct{}
VNCAuthorizedUsers map[string]map[string]struct{}
VNCSessionPubKeys []VNCSessionPubKey
EnableSSH bool
// ForceRoutingPeerDNSResolution forces the peer to run/use routing-peer DNS
// resolution regardless of the account-global setting, for reverse-proxy
// domain targets.
ForceRoutingPeerDNSResolution bool
}
func CalculateNetworkMapFromComponents ¶
func CalculateNetworkMapFromComponents(ctx context.Context, components *NetworkMapComponents) *NetworkMap
type NetworkMapComponents ¶
type NetworkMapComponents struct {
PeerID string
Network *nmdata.Network
AccountSettings *nmdata.AccountSettingsInfo
DNSSettings *nmdata.DNSSettings
CustomZoneDomain string
Peers map[string]*nmdata.Peer
Groups map[string]*nmdata.Group
Policies []*nmdata.Policy
Routes []*nmdata.Route
NameServerGroups []*nmdata.NameServerGroup
AllDNSRecords []nmdata.SimpleRecord
AccountZones []nmdata.CustomZone
ResourcePoliciesMap map[string][]*nmdata.Policy
RoutersMap map[string]map[string]*nmdata.NetworkRouter
NetworkResources []*nmdata.NetworkResource
GroupIDToUserIDs map[string][]string
AllowedUserIDs map[string]struct{}
PostureFailedPeers map[string]map[string]struct{}
RouterPeers map[string]*nmdata.Peer
// 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
// ForceRoutingPeerDNSResolution forces the peer to run/use routing-peer DNS
// resolution regardless of the account-global setting, for reverse-proxy
// domain targets.
ForceRoutingPeerDNSResolution bool
// SkipRouteFirewallRules drops the route firewall rule computation from
// Calculate. A receiver without a firewall manager never reads
// RoutesFirewallRules, and on a routing peer with many network resources
// building them dominates the cost of a sync. Defaults to false so the
// management server keeps producing them.
SkipRouteFirewallRules bool
// 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) *nmdata.Group
func (*NetworkMapComponents) GetPeerGroups ¶
func (c *NetworkMapComponents) GetPeerGroups(peerID string) map[string]struct{}
func (*NetworkMapComponents) GetPeerInfo ¶
func (c *NetworkMapComponents) GetPeerInfo(peerID string) *nmdata.Peer
func (*NetworkMapComponents) GetRouterPeerInfo ¶
func (c *NetworkMapComponents) GetRouterPeerInfo(peerID string) *nmdata.Peer
func (*NetworkMapComponents) IsAuthorizedUserDenied ¶ added in v0.84.0
func (c *NetworkMapComponents) IsAuthorizedUserDenied(rule *nmdata.PolicyRule) bool
IsAuthorizedUserDenied reports whether a rule pinned to a single authorized user names a user that is not allowed.
func (*NetworkMapComponents) IsEmpty ¶
func (c *NetworkMapComponents) IsEmpty() bool
func (*NetworkMapComponents) IsLoginExpired ¶ added in v0.84.0
func (c *NetworkMapComponents) IsLoginExpired(p *nmdata.Peer) bool
IsLoginExpired reports whether the peer is flagged as login-expired or its login has run out under the account's expiration settings.
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 *nmdata.Network
AccountSettings *nmdata.AccountSettingsInfo
DNSSettings *nmdata.DNSSettings
CustomZoneDomain string
AllPeers []*nmdata.Peer
PeerIndexes []int
RouterPeerIndexes []int
Groups map[string]*GroupCompact
AllPolicies []*nmdata.Policy
PolicyIndexes []int
ResourcePoliciesMap map[string][]int
Routes []*nmdata.Route
NameServerGroups []*nmdata.NameServerGroup
AllDNSRecords []nmdata.SimpleRecord
AccountZones []nmdata.CustomZone
RoutersMap map[string]map[string]*nmdata.NetworkRouter
NetworkResources []*nmdata.NetworkResource
GroupIDToUserIDs map[string][]string
AllowedUserIDs map[string]struct{}
PostureFailedPeers map[string]map[string]struct{}
}
func (*NetworkMapComponentsCompact) ToFull ¶
func (c *NetworkMapComponentsCompact) ToFull() *NetworkMapComponents
type PeerConnResolveState ¶ added in v0.84.0
type PeerConnResolveState struct {
AuthorizedUsers map[string]map[string]struct{}
VNCAuthorizedUsers map[string]map[string]struct{}
VNCSessionPubKeys []VNCSessionPubKey
SSHEnabled bool
}
PeerConnResolveState carries the in-progress maps mutated by per-rule resolution while walking an account's policies.
func NewPeerConnResolveState ¶ added in v0.84.0
func NewPeerConnResolveState() *PeerConnResolveState
NewPeerConnResolveState returns a state with its maps allocated.
type PolicyRuleProtocolType ¶
type PolicyRuleProtocolType string
PolicyRuleProtocolType type of traffic
func NormalizePolicyRuleProtocol ¶ added in v0.84.0
func NormalizePolicyRuleProtocol(rule *nmdata.PolicyRule) (*nmdata.PolicyRule, PolicyRuleProtocolType)
NormalizePolicyRuleProtocol maps a rule's protocol with WirePolicyRuleProtocol and scopes a portless marker-protocol rule to the port that protocol implies, so it doesn't degrade into an unscoped TCP allow. It returns the effective rule, which is a shallow copy only when the ports had to be overridden.
func WirePolicyRuleProtocol ¶ added in v0.84.0
func WirePolicyRuleProtocol(protocol PolicyRuleProtocolType) PolicyRuleProtocolType
WirePolicyRuleProtocol maps the NetBird virtual protocols (netbird-ssh, netbird-vnc) to the protocol that goes on the wire, and leaves every other protocol as it is.
type PolicyTrafficActionType ¶
type PolicyTrafficActionType string
PolicyTrafficActionType action type for the firewall
type ResourceType ¶
type ResourceType string
const ( ResourceTypePeer ResourceType = "peer" ResourceTypeDomain ResourceType = "domain" ResourceTypeHost ResourceType = "host" ResourceTypeSubnet ResourceType = "subnet" )
func (ResourceType) Valid ¶ added in v0.78.0
func (t ResourceType) Valid() bool
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 *nmdata.Route, rule *nmdata.PolicyRule, groupPeers []*nmdata.Peer, 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 RuleAuthCallbacks ¶ added in v0.84.0
type RuleAuthCallbacks struct {
CollectSSHUsers func(*nmdata.PolicyRule, map[string]map[string]struct{})
CollectVNCUsers func(*nmdata.PolicyRule, map[string]map[string]struct{})
GetAllowedUserIDs func() map[string]struct{}
// SSHUserDenied, when set, reports an SSH rule pinned to a user that must
// not be authorized. Such a rule neither enables SSH nor authorizes anyone.
SSHUserDenied func(*nmdata.PolicyRule) bool
}
RuleAuthCallbacks lets Account and NetworkMapComponents share the per-rule direction-and-auth logic while keeping their own context/state plumbing for authorized-user collection and allowed-user lookups.
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
type VNCSessionPubKey ¶ added in v0.84.0
type VNCSessionPubKey struct {
// PubKey is the base64-encoded 32-byte X25519 public key.
PubKey string
// UserID is the unhashed user identity the pubkey authenticates as.
UserID string
// DisplayName is a human-readable label for UserID, used by the host
// peer's approval prompt. Empty when not provided.
DisplayName string
}
VNCSessionPubKey carries an ephemeral X25519 static public key the dashboard registered via temporary-access. The daemon uses it as the allowed-client side of a Noise_IK handshake; a successful handshake authenticates the connection as UserID.