Documentation ¶
Index ¶
- Constants
- Variables
- func DrawPeerGraph(ctx context.Context, g PeerGraph, w io.Writer) error
- func EvalRole(role Role, action *v1.RBACAction) bool
- func EvalRule(rule *v1.Rule, action *v1.RBACAction) bool
- func FeaturePortEqual(a, b *v1.FeaturePort) bool
- func FeaturePortsEqual(a, b []*v1.FeaturePort) bool
- func IsReservedPrefix(key []byte) bool
- func IsValidID(id string) bool
- func IsValidIDOrWildcard(id string) bool
- func IsValidNodeID(id string) bool
- func MeshNodesEqual(a, b MeshNode) bool
- func ToPrefixes(ss []string) []netip.Prefix
- func TruncateID(id string) string
- func TruncateIDTo(id string, length int) string
- func ValidateACL(acl NetworkACL) error
- func ValidateRoute(route Route) error
- func WireGuardPeerEqual(a, b *v1.WireGuardPeer) bool
- func WireGuardPeersEqual(a, b []*v1.WireGuardPeer) bool
- type AdjacencyMap
- type Edge
- type EdgeMap
- type Group
- type MeshEdge
- func (e MeshEdge) AsGraphEdge() graph.Edge[NodeID]
- func (e MeshEdge) DeepCopy() MeshEdge
- func (e MeshEdge) DeepCopyInto(edge *MeshEdge)
- func (e MeshEdge) EdgeProperties() graph.EdgeProperties
- func (e MeshEdge) MarshalProtoJSON() ([]byte, error)
- func (e MeshEdge) PutInto(ctx context.Context, g PeerGraph) error
- func (e MeshEdge) SourceID() NodeID
- func (e MeshEdge) TargetID() NodeID
- func (e MeshEdge) ToEdge() Edge
- func (e *MeshEdge) UnmarshalProtoJSON(data []byte) error
- type MeshNode
- func (n MeshNode) DNSPort() uint16
- func (n MeshNode) DeepCopy() MeshNode
- func (n MeshNode) DeepCopyInto(node *MeshNode)
- func (n MeshNode) DeepEqual(node MeshNode) bool
- func (n MeshNode) HasFeature(feature v1.Feature) bool
- func (n MeshNode) MarshalProtoJSON() ([]byte, error)
- func (n MeshNode) NodeID() NodeID
- func (n MeshNode) PortFor(feature v1.Feature) uint16
- func (n MeshNode) PrivateAddrV4() netip.Prefix
- func (n MeshNode) PrivateAddrV6() netip.Prefix
- func (n MeshNode) PrivateDNSAddrV4() netip.AddrPort
- func (n MeshNode) PrivateDNSAddrV6() netip.AddrPort
- func (n MeshNode) PrivateRPCAddrV4() netip.AddrPort
- func (n MeshNode) PrivateRPCAddrV6() netip.AddrPort
- func (n MeshNode) PrivateStorageAddrV4() netip.AddrPort
- func (n MeshNode) PrivateStorageAddrV6() netip.AddrPort
- func (n MeshNode) PrivateTURNAddrV4() netip.AddrPort
- func (n MeshNode) PrivateTURNAddrV6() netip.AddrPort
- func (n MeshNode) PublicDNSAddr() netip.AddrPort
- func (n MeshNode) PublicRPCAddr() netip.AddrPort
- func (n MeshNode) RPCPort() uint16
- func (n MeshNode) StoragePort() uint16
- func (n MeshNode) TURNPort() uint16
- func (n *MeshNode) UnmarshalProtoJSON(data []byte) error
- func (n MeshNode) WireGuardEndpoints() []netip.AddrPort
- func (n MeshNode) WireGuardPort() uint16
- type NetworkACL
- func (n NetworkACL) DeepCopy() NetworkACL
- func (n NetworkACL) DeepCopyInto(acl *NetworkACL)
- func (a NetworkACL) DestinationPrefixes() []netip.Prefix
- func (a NetworkACL) Equals(other NetworkACL) bool
- func (a NetworkACL) MarshalProtoJSON() ([]byte, error)
- func (acl NetworkACL) Matches(ctx context.Context, action NetworkAction) bool
- func (a NetworkACL) Proto() *v1.NetworkACL
- func (a NetworkACL) SourcePrefixes() []netip.Prefix
- func (a *NetworkACL) UnmarshalProtoJSON(data []byte) error
- func (a NetworkACL) Validate() error
- type NetworkACLs
- func (a NetworkACLs) Accept(ctx context.Context, action NetworkAction) bool
- func (a NetworkACLs) AllowNodesToCommunicate(ctx context.Context, nodeA, nodeB MeshNode) bool
- func (a NetworkACLs) Len() int
- func (a NetworkACLs) Less(i, j int) bool
- func (a NetworkACLs) Proto() []*v1.NetworkACL
- func (a NetworkACLs) Sort(direction SortDirection)
- func (a NetworkACLs) Swap(i, j int)
- type NetworkAction
- type NodeID
- type PeerGraph
- type PeerGraphStore
- type Prefix
- type Role
- type RoleBinding
- func (rb RoleBinding) ContainsID(id NodeID) bool
- func (rb RoleBinding) ContainsNodeID(nodeID NodeID) bool
- func (rb RoleBinding) ContainsUserID(userID NodeID) bool
- func (rb RoleBinding) DeepCopy() RoleBinding
- func (rb RoleBinding) DeepCopyInto(role *RoleBinding)
- func (rb RoleBinding) MarshalProtoJSON() ([]byte, error)
- func (rb RoleBinding) Proto() *v1.RoleBinding
- func (rb *RoleBinding) UnmarshalProtoJSON(data []byte) error
- func (rb RoleBinding) Validate() error
- type RolesList
- type Route
- func (n Route) DeepCopy() Route
- func (n Route) DeepCopyInto(route *Route)
- func (r *Route) DestinationPrefixes() []netip.Prefix
- func (r *Route) Equals(other *Route) bool
- func (r Route) MarshalProtoJSON() ([]byte, error)
- func (r *Route) Proto() *v1.Route
- func (r *Route) UnmarshalProtoJSON(data []byte) error
- func (r Route) Validate() error
- type Routes
- type SortDirection
- type SortedWireGuardPeers
Constants ¶
const (
// GroupReference is the prefix of a node name that indicates it is a group reference.
GroupReference = "group:"
)
const MaxIDLength = 63
MaxIDLength is the maximum length of a key ID.
Variables ¶
var InvalidIDChars = []rune{'/', '\\', ':', '*', '?', '"', '\'', '<', '>', '|', ','}
InvalidIDChars are the characters that are not allowed in node IDs.
var ReservedNodeIDs = []string{"self", "local", "localhost", "leader", "voters", "observers"}
ReservedNodeIDs are reserved node IDs.
var ReservedPrefixes = []Prefix{ RegistryPrefix, ConsensusPrefix, }
ReservedPrefixes is a list of all reserved prefixes.
Functions ¶
func DrawPeerGraph ¶
DrawPeerGraph draws a PeerGraph to the given writer in DOT format.
func EvalRole ¶
func EvalRole(role Role, action *v1.RBACAction) bool
EvalRole evaluates an action against a single role.
func EvalRule ¶
func EvalRule(rule *v1.Rule, action *v1.RBACAction) bool
EvalRule evaluates an action against a single rule.
func FeaturePortEqual ¶
func FeaturePortEqual(a, b *v1.FeaturePort) bool
FeaturePortEqual compares two feature ports for equality.
func FeaturePortsEqual ¶
func FeaturePortsEqual(a, b []*v1.FeaturePort) bool
FeaturePortsEqual compares two feature ports for equality.
func IsReservedPrefix ¶
IsReservedPrefix returns true if the given key is reserved.
func IsValidID ¶ added in v0.10.0
IsValidID returns true if the given identifier is valid and safe to be saved to storage.
func IsValidIDOrWildcard ¶ added in v0.11.0
IsValidIDOrWildcard returns true if the given identifier is valid and safe to be saved to storage. It also allows the wildcard character.
func IsValidNodeID ¶ added in v0.10.0
IsValidNodeID returns true if the given node ID is valid and safe to be saved to storage.
func MeshNodesEqual ¶
MeshNodesEqual compares two mesh nodes for equality.
func ToPrefixes ¶
ToPrefixes converts a list of CIDRs to a list of Prefixes. It silently ignores invalid CIDRs.
func TruncateID ¶ added in v0.10.4
TruncateID is a helper method to truncate IDs as needed when they are too long and can be safely truncated.
func TruncateIDTo ¶ added in v0.10.4
TruncateIDTo is a helper method to truncate IDs as needed when they are too long and can be safely truncated.
func WireGuardPeerEqual ¶
func WireGuardPeerEqual(a, b *v1.WireGuardPeer) bool
WireGuardPeerEqual compares two WireGuard peers for equality.
func WireGuardPeersEqual ¶
func WireGuardPeersEqual(a, b []*v1.WireGuardPeer) bool
WireGuardPeersEqual recurses the WireGuard peers and compares them for equality. Both lists are sorted by ID first.
Types ¶
type AdjacencyMap ¶
AdjacencyMap is a map of node names to a map of node names to edges.
func NewAdjacencyMap ¶
func NewAdjacencyMap(g PeerGraph) (AdjacencyMap, error)
NewAdjacencyMap returns a new adjacency map for the graph.
func (AdjacencyMap) DeepEqual ¶
func (a AdjacencyMap) DeepEqual(b AdjacencyMap) bool
DeepEqual returns true if the given AdjacencyMap is equal to this AdjacencyMap.
type Edge ¶
Edge is the graph.Edge implementation for the mesh network.
func (Edge) ToMeshEdge ¶
ToMeshEdge converts an Edge to a MeshEdge.
type Group ¶ added in v0.9.2
Group wraps a group.
func (Group) DeepCopyInto ¶ added in v0.9.2
DeepCopyInto copies the node into the given group.
func (Group) MarshalProtoJSON ¶ added in v0.10.0
MarshalProtoJSON marshals the group to JSON.
func (*Group) UnmarshalProtoJSON ¶ added in v0.10.0
UnmarshalProtoJSON unmarshals the group from JSON.
type MeshEdge ¶
MeshEdge wraps a mesh edge.
func (MeshEdge) AsGraphEdge ¶
AsGraphEdge converts a MeshEdge to a graph.Edge.
func (MeshEdge) DeepCopyInto ¶ added in v0.9.4
DeepCopyInto copies the edge into the given edge.
func (MeshEdge) EdgeProperties ¶
func (e MeshEdge) EdgeProperties() graph.EdgeProperties
EdgeProperties returns the edge's properties.
func (MeshEdge) MarshalProtoJSON ¶ added in v0.10.0
MarshalProtoJSON marshals a MeshEdge to JSON.
func (*MeshEdge) UnmarshalProtoJSON ¶ added in v0.10.0
UnmarshalProtoJSON unmarshals a MeshEdge from JSON.
type MeshNode ¶
MeshNode wraps a mesh node.
func ValidateMeshNode ¶ added in v0.11.0
ValidateMeshNode validates the mesh node. It also dedups wireguard endpoints, adds a joined timestamp, and returns the modified node.
func (MeshNode) DeepCopyInto ¶ added in v0.9.2
DeepCopyInto copies the node into the given node.
func (MeshNode) DeepEqual ¶ added in v0.9.2
DeepEqual returns true if the node is deeply equal to the given node.
func (MeshNode) HasFeature ¶
HasFeature returns true if the node has the given feature.
func (MeshNode) MarshalProtoJSON ¶ added in v0.10.0
MarshalProtoJSON marshals the node to JSON.
func (MeshNode) PortFor ¶
PortFor returns the port for the given feature, or 0 if the feature is not available on this node.
func (MeshNode) PrivateAddrV4 ¶
PrivateAddrV4 returns the node's private IPv4 address. Be sure to check if the returned Addr IsValid.
func (MeshNode) PrivateAddrV6 ¶
PrivateAddrV6 returns the node's private IPv6 address. Be sure to check if the returned Addr IsValid.
func (MeshNode) PrivateDNSAddrV4 ¶
PrivateDNSAddrV4 returns the private IPv4 address for the node's DNS server. Be sure to check if the returned AddrPort IsValid.
func (MeshNode) PrivateDNSAddrV6 ¶
PrivateDNSAddrV6 returns the private IPv6 address for the node's DNS server. Be sure to check if the returned AddrPort IsValid.
func (MeshNode) PrivateRPCAddrV4 ¶
PrivateRPCAddrV4 returns the private IPv4 address for the node's RPC server. Be sure to check if the returned AddrPort IsValid.
func (MeshNode) PrivateRPCAddrV6 ¶
PrivateRPCAddrV6 returns the private IPv6 address for the node's RPC server. Be sure to check if the returned AddrPort IsValid.
func (MeshNode) PrivateStorageAddrV4 ¶
PrivateStorageAddrV4 returns the private IPv4 address for the node's raft listener. Be sure to check if the returned AddrPort IsValid.
func (MeshNode) PrivateStorageAddrV6 ¶
PrivateStorageAddrV6 returns the private IPv6 address for the node's raft listener. Be sure to check if the returned AddrPort IsValid.
func (MeshNode) PrivateTURNAddrV4 ¶
PrivateTURNAddrV4 returns the private IPv4 address for the node's TURN server. Be sure to check if the returned AddrPort IsValid.
func (MeshNode) PrivateTURNAddrV6 ¶
PrivateTURNAddrV6 returns the private IPv6 address for the node's TURN server. Be sure to check if the returned AddrPort IsValid.
func (MeshNode) PublicDNSAddr ¶
PublicDNSAddr returns the public address for the node's DNS server. Be sure to check if the returned AddrPort IsValid.
func (MeshNode) PublicRPCAddr ¶
PublicRPCAddr returns the public address for the node's RPC server. Be sure to check if the returned AddrPort IsValid.
func (MeshNode) StoragePort ¶
StoragePort returns the node's Storage port.
func (*MeshNode) UnmarshalProtoJSON ¶ added in v0.10.0
UnmarshalProtoJSON unmarshals the node from JSON.
func (MeshNode) WireGuardEndpoints ¶ added in v0.10.1
WireGuardEndpoints returns all valid WireGuard endpoints as netip.AddrPorts.
func (MeshNode) WireGuardPort ¶ added in v0.10.1
WireGuardPort returns the first wireguard port encountered for this peer.
type NetworkACL ¶
type NetworkACL struct {
*v1.NetworkACL `json:",inline"`
}
NetworkACL is a Network ACL.
func (NetworkACL) DeepCopy ¶ added in v0.9.2
func (n NetworkACL) DeepCopy() NetworkACL
DeepCopy returns a deep copy of the network ACL.
func (NetworkACL) DeepCopyInto ¶ added in v0.9.2
func (n NetworkACL) DeepCopyInto(acl *NetworkACL)
DeepCopyInto copies the node into the given acl.
func (NetworkACL) DestinationPrefixes ¶
func (a NetworkACL) DestinationPrefixes() []netip.Prefix
DestinationPrefixes returns the destination prefixes for the ACL. Invalid prefixes will be ignored.
func (NetworkACL) Equals ¶
func (a NetworkACL) Equals(other NetworkACL) bool
Equals returns whether the ACLs are equal.
func (NetworkACL) MarshalProtoJSON ¶ added in v0.10.0
func (a NetworkACL) MarshalProtoJSON() ([]byte, error)
MarshalProtoJSON marshals the ACL to protobuf json.
func (NetworkACL) Matches ¶
func (acl NetworkACL) Matches(ctx context.Context, action NetworkAction) bool
Matches checks if an action matches this ACL.
func (NetworkACL) Proto ¶
func (a NetworkACL) Proto() *v1.NetworkACL
Proto returns the protobuf representation of the ACL.
func (NetworkACL) SourcePrefixes ¶
func (a NetworkACL) SourcePrefixes() []netip.Prefix
SourcePrefixes returns the source prefixes for the ACL. Invalid prefixes will be ignored.
func (*NetworkACL) UnmarshalProtoJSON ¶ added in v0.10.0
func (a *NetworkACL) UnmarshalProtoJSON(data []byte) error
UnmarshalProtoJSON unmarshals the ACL from a protobuf JSON.
func (NetworkACL) Validate ¶ added in v0.10.0
func (a NetworkACL) Validate() error
Validate validates the ACL.
type NetworkACLs ¶
type NetworkACLs []NetworkACL
ACLs is a list of Network ACLs. It contains methods for evaluating actions against contained permissions. It also allows for sorting by priority.
func (NetworkACLs) Accept ¶
func (a NetworkACLs) Accept(ctx context.Context, action NetworkAction) bool
Accept evaluates an action against the ACLs in the list. It assumes the ACLs are sorted by priority. The first ACL that matches the action will be used. If no ACL matches, the action is denied.
func (NetworkACLs) AllowNodesToCommunicate ¶
func (a NetworkACLs) AllowNodesToCommunicate(ctx context.Context, nodeA, nodeB MeshNode) bool
AllowNodesToCommunicate checks if the given nodes are allowed to communicate.
func (NetworkACLs) Less ¶
func (a NetworkACLs) Less(i, j int) bool
Less returns whether the ACL at index i should be sorted before the ACL at index j.
func (NetworkACLs) Proto ¶
func (a NetworkACLs) Proto() []*v1.NetworkACL
Proto returns the protobuf representation of the ACLs.
func (NetworkACLs) Sort ¶
func (a NetworkACLs) Sort(direction SortDirection)
Sort sorts the ACLs by priority.
func (NetworkACLs) Swap ¶
func (a NetworkACLs) Swap(i, j int)
Swap swaps the ACLs at the given indices.
type NetworkAction ¶
type NetworkAction struct {
*v1.NetworkAction `json:",inline"`
}
NetworkAction wraps a NetworkAction.
func (*NetworkAction) DestinationPrefix ¶
func (a *NetworkAction) DestinationPrefix() netip.Prefix
DestinationPrefix returns the destination prefix for the action if it is valid.
func (*NetworkAction) Proto ¶
func (a *NetworkAction) Proto() *v1.NetworkAction
Proto returns the protobuf representation of the action.
func (*NetworkAction) SourcePrefix ¶
func (a *NetworkAction) SourcePrefix() netip.Prefix
SourcePrefix returns the source prefix for the action if it is valid.
type NodeID ¶
type NodeID string
NodeID is the type of a node ID.
type PeerGraphStore ¶
PeerGraphStore is the graph.Store implementation for the mesh network.
type Prefix ¶
type Prefix []byte
Prefix is a prefix in the storage.
type Role ¶ added in v0.9.2
Role wraps a role.
func (Role) DeepCopyInto ¶ added in v0.9.2
DeepCopyInto copies the node into the given role.
func (Role) MarshalProtoJSON ¶ added in v0.10.0
MarshalProtoJSON marshals the role to JSON.
func (*Role) UnmarshalProtoJSON ¶ added in v0.10.0
UnmarshalProtoJSON unmarshals the role from JSON.
type RoleBinding ¶ added in v0.9.2
type RoleBinding struct {
*v1.RoleBinding `json:",inline"`
}
RoleBinding wraps a rolebinding.
func (RoleBinding) ContainsID ¶ added in v0.9.6
func (rb RoleBinding) ContainsID(id NodeID) bool
ContainsID returns true if the rolebinding contains the given id either as a node or user.
func (RoleBinding) ContainsNodeID ¶ added in v0.9.6
func (rb RoleBinding) ContainsNodeID(nodeID NodeID) bool
ContainsNodeID returns true if the rolebinding contains the given node id.
func (RoleBinding) ContainsUserID ¶ added in v0.9.6
func (rb RoleBinding) ContainsUserID(userID NodeID) bool
ContainsUserID returns true if the rolebinding contains the given user id.
func (RoleBinding) DeepCopy ¶ added in v0.9.2
func (rb RoleBinding) DeepCopy() RoleBinding
DeepCopy returns a deep copy of the rolebinding.
func (RoleBinding) DeepCopyInto ¶ added in v0.9.2
func (rb RoleBinding) DeepCopyInto(role *RoleBinding)
DeepCopyInto copies the node into the given rolebinding.
func (RoleBinding) MarshalProtoJSON ¶ added in v0.10.0
func (rb RoleBinding) MarshalProtoJSON() ([]byte, error)
MarshalProtoJSON marshals the rolebinding to JSON.
func (RoleBinding) Proto ¶ added in v0.9.2
func (rb RoleBinding) Proto() *v1.RoleBinding
Proto returns the underlying protobuf.
func (*RoleBinding) UnmarshalProtoJSON ¶ added in v0.10.0
func (rb *RoleBinding) UnmarshalProtoJSON(data []byte) error
UnmarshalProtoJSON unmarshals the rolebinding from JSON.
func (RoleBinding) Validate ¶ added in v0.10.0
func (rb RoleBinding) Validate() error
Validate returns an error if the rolebinding is invalid.
type RolesList ¶
type RolesList []Role
RolesList is a list of roles. It contains methods for evaluating actions against contained permissions.
type Route ¶
Route wraps a Route.
func (Route) DeepCopyInto ¶ added in v0.9.2
DeepCopyInto copies the node into the given route.
func (*Route) DestinationPrefixes ¶
DestinationPrefixes returns the destination prefixes for the route.
func (Route) MarshalProtoJSON ¶ added in v0.10.0
MarshalProtoJSON marshals the route to protobuf json.
func (*Route) UnmarshalProtoJSON ¶ added in v0.10.0
UnmarshalProtoJSON unmarshals the route from a protobuf.
type Routes ¶
type Routes []Route
Routes is a list of routes.
func (Routes) Less ¶
Less returns whether the name of the route at index i is less than the name of the route at index j.
type SortDirection ¶
type SortDirection int
SortDirection is the direction to sort ACLs.
const ( // SortDescending sorts ACLs in descending order. SortDescending SortDirection = iota // SortAscending sorts ACLs in ascending order. SortAscending )
type SortedWireGuardPeers ¶
type SortedWireGuardPeers []*v1.WireGuardPeer
SortedWireGuardPeers implements a sort.Interface for []*v1.WireGuardPeer.
func (SortedWireGuardPeers) Len ¶
func (s SortedWireGuardPeers) Len() int
func (SortedWireGuardPeers) Less ¶
func (s SortedWireGuardPeers) Less(i, j int) bool
func (SortedWireGuardPeers) Swap ¶
func (s SortedWireGuardPeers) Swap(i, j int)