mirror of
https://github.com/gravitl/netmaker.git
synced 2025-10-05 16:57:51 +08:00
NET-1784: Adv Acl Rules (#3239)
* define direction on acl req * define protocol types and rule model * get rules for node * fetch acl rule for a node * redine acl firewall model * add json tags * update port,protocol, and direction * add json tags to acl options * convert protocol to string * simplify acl map * add json tags to acl rules * add networks to fw update * add acls rules * NET-1784: add allow all field * add allow all field on fw udpate * remove debug logs * fix port and protocol types * migrate default acl policies * define constants for service types * add adv options for user rules on ingress gw * debug log * allow whole network * add static nodes to acl rules * replace peers on acl updates * initiliase rule map * add user acl rules on target node * revert acl check on extclient * handle static node rules on ingress gw * update multiple policies for users * check allowed direction * remove debug logs
This commit is contained in:
@@ -52,6 +52,73 @@ func aclPolicyTypes(w http.ResponseWriter, r *http.Request) {
|
|||||||
// models.NetmakerIPAclID,
|
// models.NetmakerIPAclID,
|
||||||
// models.NetmakerSubNetRangeAClID,
|
// models.NetmakerSubNetRangeAClID,
|
||||||
},
|
},
|
||||||
|
ProtocolTypes: []models.ProtocolType{
|
||||||
|
{
|
||||||
|
Name: models.Http,
|
||||||
|
AllowedProtocols: []models.Protocol{
|
||||||
|
models.TCP,
|
||||||
|
},
|
||||||
|
PortRange: "80",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: models.Https,
|
||||||
|
AllowedProtocols: []models.Protocol{
|
||||||
|
models.TCP,
|
||||||
|
},
|
||||||
|
PortRange: "443",
|
||||||
|
},
|
||||||
|
// {
|
||||||
|
// Name: "MySQL",
|
||||||
|
// AllowedProtocols: []models.Protocol{
|
||||||
|
// models.TCP,
|
||||||
|
// },
|
||||||
|
// PortRange: "3306",
|
||||||
|
// },
|
||||||
|
// {
|
||||||
|
// Name: "DNS TCP",
|
||||||
|
// AllowedProtocols: []models.Protocol{
|
||||||
|
// models.TCP,
|
||||||
|
// },
|
||||||
|
// PortRange: "53",
|
||||||
|
// },
|
||||||
|
// {
|
||||||
|
// Name: "DNS UDP",
|
||||||
|
// AllowedProtocols: []models.Protocol{
|
||||||
|
// models.UDP,
|
||||||
|
// },
|
||||||
|
// PortRange: "53",
|
||||||
|
// },
|
||||||
|
{
|
||||||
|
Name: models.AllTCP,
|
||||||
|
AllowedProtocols: []models.Protocol{
|
||||||
|
models.TCP,
|
||||||
|
},
|
||||||
|
PortRange: "All ports",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: models.AllUDP,
|
||||||
|
AllowedProtocols: []models.Protocol{
|
||||||
|
models.UDP,
|
||||||
|
},
|
||||||
|
PortRange: "All ports",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: models.ICMPService,
|
||||||
|
AllowedProtocols: []models.Protocol{
|
||||||
|
models.ICMP,
|
||||||
|
},
|
||||||
|
PortRange: "",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: models.Custom,
|
||||||
|
AllowedProtocols: []models.Protocol{
|
||||||
|
models.UDP,
|
||||||
|
models.TCP,
|
||||||
|
},
|
||||||
|
PortRange: "All ports",
|
||||||
|
AllowPortSetting: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
logic.ReturnSuccessResponseWithJson(w, r, resp, "fetched acls types")
|
logic.ReturnSuccessResponseWithJson(w, r, resp, "fetched acls types")
|
||||||
}
|
}
|
||||||
@@ -69,7 +136,7 @@ func aclDebug(w http.ResponseWriter, r *http.Request) {
|
|||||||
logic.ReturnErrorResponse(w, r, logic.FormatError(err, "badrequest"))
|
logic.ReturnErrorResponse(w, r, logic.FormatError(err, "badrequest"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
allowed := logic.IsNodeAllowedToCommunicate(node, peer, true)
|
allowed, _ := logic.IsNodeAllowedToCommunicate(node, peer, true)
|
||||||
logic.ReturnSuccessResponseWithJson(w, r, allowed, "fetched all acls in the network ")
|
logic.ReturnSuccessResponseWithJson(w, r, allowed, "fetched all acls in the network ")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -132,11 +199,6 @@ func createAcl(w http.ResponseWriter, r *http.Request) {
|
|||||||
acl.CreatedBy = user.UserName
|
acl.CreatedBy = user.UserName
|
||||||
acl.CreatedAt = time.Now().UTC()
|
acl.CreatedAt = time.Now().UTC()
|
||||||
acl.Default = false
|
acl.Default = false
|
||||||
if acl.RuleType == models.DevicePolicy {
|
|
||||||
acl.AllowedDirection = models.TrafficDirectionBi
|
|
||||||
} else {
|
|
||||||
acl.AllowedDirection = models.TrafficDirectionUni
|
|
||||||
}
|
|
||||||
// validate create acl policy
|
// validate create acl policy
|
||||||
if !logic.IsAclPolicyValid(acl) {
|
if !logic.IsAclPolicyValid(acl) {
|
||||||
logic.ReturnErrorResponse(w, r, logic.FormatError(errors.New("invalid policy"), "badrequest"))
|
logic.ReturnErrorResponse(w, r, logic.FormatError(errors.New("invalid policy"), "badrequest"))
|
||||||
@@ -152,7 +214,7 @@ func createAcl(w http.ResponseWriter, r *http.Request) {
|
|||||||
logic.ReturnErrorResponse(w, r, logic.FormatError(err, "internal"))
|
logic.ReturnErrorResponse(w, r, logic.FormatError(err, "internal"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
go mq.PublishPeerUpdate(false)
|
go mq.PublishPeerUpdate(true)
|
||||||
logic.ReturnSuccessResponseWithJson(w, r, acl, "created acl successfully")
|
logic.ReturnSuccessResponseWithJson(w, r, acl, "created acl successfully")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -194,7 +256,7 @@ func updateAcl(w http.ResponseWriter, r *http.Request) {
|
|||||||
logic.ReturnErrorResponse(w, r, logic.FormatError(err, "badrequest"))
|
logic.ReturnErrorResponse(w, r, logic.FormatError(err, "badrequest"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
go mq.PublishPeerUpdate(false)
|
go mq.PublishPeerUpdate(true)
|
||||||
logic.ReturnSuccessResponse(w, r, "updated acl "+acl.Name)
|
logic.ReturnSuccessResponse(w, r, "updated acl "+acl.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -225,6 +287,6 @@ func deleteAcl(w http.ResponseWriter, r *http.Request) {
|
|||||||
logic.FormatError(errors.New("cannot delete default policy"), "internal"))
|
logic.FormatError(errors.New("cannot delete default policy"), "internal"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
go mq.PublishPeerUpdate(false)
|
go mq.PublishPeerUpdate(true)
|
||||||
logic.ReturnSuccessResponse(w, r, "deleted acl "+acl.Name)
|
logic.ReturnSuccessResponse(w, r, "deleted acl "+acl.Name)
|
||||||
}
|
}
|
||||||
|
373
logic/acls.go
373
logic/acls.go
@@ -18,6 +18,39 @@ var (
|
|||||||
aclCacheMap = make(map[string]models.Acl)
|
aclCacheMap = make(map[string]models.Acl)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func MigrateDefaulAclPolicies(netID models.NetworkID) {
|
||||||
|
if netID.String() == "" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
acl, err := GetAcl(fmt.Sprintf("%s.%s", netID, "all-nodes"))
|
||||||
|
if err == nil {
|
||||||
|
//if acl.Proto.String() == "" {
|
||||||
|
acl.Proto = models.ALL
|
||||||
|
acl.ServiceType = models.Custom
|
||||||
|
acl.Port = []string{}
|
||||||
|
UpsertAcl(acl)
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
acl, err = GetAcl(fmt.Sprintf("%s.%s", netID, "all-users"))
|
||||||
|
if err == nil {
|
||||||
|
//if acl.Proto.String() == "" {
|
||||||
|
acl.Proto = models.ALL
|
||||||
|
acl.ServiceType = models.Custom
|
||||||
|
acl.Port = []string{}
|
||||||
|
UpsertAcl(acl)
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
acl, err = GetAcl(fmt.Sprintf("%s.%s", netID, "all-remote-access-gws"))
|
||||||
|
if err == nil {
|
||||||
|
//if acl.Proto.String() == "" {
|
||||||
|
acl.Proto = models.ALL
|
||||||
|
acl.ServiceType = models.Custom
|
||||||
|
acl.Port = []string{}
|
||||||
|
UpsertAcl(acl)
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// CreateDefaultAclNetworkPolicies - create default acl network policies
|
// CreateDefaultAclNetworkPolicies - create default acl network policies
|
||||||
func CreateDefaultAclNetworkPolicies(netID models.NetworkID) {
|
func CreateDefaultAclNetworkPolicies(netID models.NetworkID) {
|
||||||
if netID.String() == "" {
|
if netID.String() == "" {
|
||||||
@@ -31,6 +64,8 @@ func CreateDefaultAclNetworkPolicies(netID models.NetworkID) {
|
|||||||
MetaData: "This Policy allows all nodes in the network to communicate with each other",
|
MetaData: "This Policy allows all nodes in the network to communicate with each other",
|
||||||
Default: true,
|
Default: true,
|
||||||
NetworkID: netID,
|
NetworkID: netID,
|
||||||
|
Proto: models.ALL,
|
||||||
|
Port: []string{},
|
||||||
RuleType: models.DevicePolicy,
|
RuleType: models.DevicePolicy,
|
||||||
Src: []models.AclPolicyTag{
|
Src: []models.AclPolicyTag{
|
||||||
{
|
{
|
||||||
@@ -56,6 +91,8 @@ func CreateDefaultAclNetworkPolicies(netID models.NetworkID) {
|
|||||||
Name: "All Users",
|
Name: "All Users",
|
||||||
MetaData: "This policy gives access to everything in the network for an user",
|
MetaData: "This policy gives access to everything in the network for an user",
|
||||||
NetworkID: netID,
|
NetworkID: netID,
|
||||||
|
Proto: models.ALL,
|
||||||
|
Port: []string{},
|
||||||
RuleType: models.UserPolicy,
|
RuleType: models.UserPolicy,
|
||||||
Src: []models.AclPolicyTag{
|
Src: []models.AclPolicyTag{
|
||||||
{
|
{
|
||||||
@@ -81,6 +118,8 @@ func CreateDefaultAclNetworkPolicies(netID models.NetworkID) {
|
|||||||
Default: true,
|
Default: true,
|
||||||
Name: "All Remote Access Gateways",
|
Name: "All Remote Access Gateways",
|
||||||
NetworkID: netID,
|
NetworkID: netID,
|
||||||
|
Proto: models.ALL,
|
||||||
|
Port: []string{},
|
||||||
RuleType: models.DevicePolicy,
|
RuleType: models.DevicePolicy,
|
||||||
Src: []models.AclPolicyTag{
|
Src: []models.AclPolicyTag{
|
||||||
{
|
{
|
||||||
@@ -202,7 +241,10 @@ func IsAclExists(aclID string) bool {
|
|||||||
// IsAclPolicyValid - validates if acl policy is valid
|
// IsAclPolicyValid - validates if acl policy is valid
|
||||||
func IsAclPolicyValid(acl models.Acl) bool {
|
func IsAclPolicyValid(acl models.Acl) bool {
|
||||||
//check if src and dst are valid
|
//check if src and dst are valid
|
||||||
|
if acl.AllowedDirection != models.TrafficDirectionBi &&
|
||||||
|
acl.AllowedDirection != models.TrafficDirectionUni {
|
||||||
|
return false
|
||||||
|
}
|
||||||
switch acl.RuleType {
|
switch acl.RuleType {
|
||||||
case models.UserPolicy:
|
case models.UserPolicy:
|
||||||
// src list should only contain users
|
// src list should only contain users
|
||||||
@@ -298,6 +340,10 @@ func UpdateAcl(newAcl, acl models.Acl) error {
|
|||||||
acl.Name = newAcl.Name
|
acl.Name = newAcl.Name
|
||||||
acl.Src = newAcl.Src
|
acl.Src = newAcl.Src
|
||||||
acl.Dst = newAcl.Dst
|
acl.Dst = newAcl.Dst
|
||||||
|
acl.AllowedDirection = newAcl.AllowedDirection
|
||||||
|
acl.Port = newAcl.Port
|
||||||
|
acl.Proto = newAcl.Proto
|
||||||
|
acl.ServiceType = newAcl.ServiceType
|
||||||
}
|
}
|
||||||
acl.Enabled = newAcl.Enabled
|
acl.Enabled = newAcl.Enabled
|
||||||
d, err := json.Marshal(acl)
|
d, err := json.Marshal(acl)
|
||||||
@@ -382,7 +428,6 @@ func ListAcls() (acls []models.Acl) {
|
|||||||
if err != nil && !database.IsEmptyRecord(err) {
|
if err != nil && !database.IsEmptyRecord(err) {
|
||||||
return []models.Acl{}
|
return []models.Acl{}
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, dataI := range data {
|
for _, dataI := range data {
|
||||||
acl := models.Acl{}
|
acl := models.Acl{}
|
||||||
err := json.Unmarshal([]byte(dataI), &acl)
|
err := json.Unmarshal([]byte(dataI), &acl)
|
||||||
@@ -463,6 +508,18 @@ func listDevicePolicies(netID models.NetworkID) []models.Acl {
|
|||||||
return deviceAcls
|
return deviceAcls
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// listUserPolicies - lists all user policies in a network
|
||||||
|
func listUserPolicies(netID models.NetworkID) []models.Acl {
|
||||||
|
allAcls := ListAcls()
|
||||||
|
deviceAcls := []models.Acl{}
|
||||||
|
for _, acl := range allAcls {
|
||||||
|
if acl.NetworkID == netID && acl.RuleType == models.UserPolicy {
|
||||||
|
deviceAcls = append(deviceAcls, acl)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return deviceAcls
|
||||||
|
}
|
||||||
|
|
||||||
// ListAcls - lists all acl policies
|
// ListAcls - lists all acl policies
|
||||||
func ListAclsByNetwork(netID models.NetworkID) ([]models.Acl, error) {
|
func ListAclsByNetwork(netID models.NetworkID) ([]models.Acl, error) {
|
||||||
|
|
||||||
@@ -485,19 +542,19 @@ func convAclTagToValueMap(acltags []models.AclPolicyTag) map[string]struct{} {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// IsUserAllowedToCommunicate - check if user is allowed to communicate with peer
|
// IsUserAllowedToCommunicate - check if user is allowed to communicate with peer
|
||||||
func IsUserAllowedToCommunicate(userName string, peer models.Node) bool {
|
func IsUserAllowedToCommunicate(userName string, peer models.Node) (bool, []models.Acl) {
|
||||||
if peer.IsStatic {
|
if peer.IsStatic {
|
||||||
peer = peer.StaticNode.ConvertToStaticNode()
|
peer = peer.StaticNode.ConvertToStaticNode()
|
||||||
}
|
}
|
||||||
acl, _ := GetDefaultPolicy(models.NetworkID(peer.Network), models.UserPolicy)
|
acl, _ := GetDefaultPolicy(models.NetworkID(peer.Network), models.UserPolicy)
|
||||||
if acl.Enabled {
|
if acl.Enabled {
|
||||||
return true
|
return true, []models.Acl{acl}
|
||||||
}
|
}
|
||||||
user, err := GetUser(userName)
|
user, err := GetUser(userName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false
|
return false, []models.Acl{}
|
||||||
}
|
}
|
||||||
|
allowedPolicies := []models.Acl{}
|
||||||
policies := listPoliciesOfUser(*user, models.NetworkID(peer.Network))
|
policies := listPoliciesOfUser(*user, models.NetworkID(peer.Network))
|
||||||
for _, policy := range policies {
|
for _, policy := range policies {
|
||||||
if !policy.Enabled {
|
if !policy.Enabled {
|
||||||
@@ -505,20 +562,25 @@ func IsUserAllowedToCommunicate(userName string, peer models.Node) bool {
|
|||||||
}
|
}
|
||||||
dstMap := convAclTagToValueMap(policy.Dst)
|
dstMap := convAclTagToValueMap(policy.Dst)
|
||||||
if _, ok := dstMap["*"]; ok {
|
if _, ok := dstMap["*"]; ok {
|
||||||
return true
|
allowedPolicies = append(allowedPolicies, policy)
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
for tagID := range peer.Tags {
|
for tagID := range peer.Tags {
|
||||||
if _, ok := dstMap[tagID.String()]; ok {
|
if _, ok := dstMap[tagID.String()]; ok {
|
||||||
return true
|
allowedPolicies = append(allowedPolicies, policy)
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return false
|
if len(allowedPolicies) > 0 {
|
||||||
|
return true, allowedPolicies
|
||||||
|
}
|
||||||
|
return false, []models.Acl{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsNodeAllowedToCommunicate - check node is allowed to communicate with the peer
|
// IsNodeAllowedToCommunicate - check node is allowed to communicate with the peer
|
||||||
func IsNodeAllowedToCommunicate(node, peer models.Node, checkDefaultPolicy bool) bool {
|
func IsNodeAllowedToCommunicate(node, peer models.Node, checkDefaultPolicy bool) (bool, []models.Acl) {
|
||||||
if node.IsStatic {
|
if node.IsStatic {
|
||||||
node = node.StaticNode.ConvertToStaticNode()
|
node = node.StaticNode.ConvertToStaticNode()
|
||||||
}
|
}
|
||||||
@@ -530,11 +592,11 @@ func IsNodeAllowedToCommunicate(node, peer models.Node, checkDefaultPolicy bool)
|
|||||||
defaultPolicy, err := GetDefaultPolicy(models.NetworkID(node.Network), models.DevicePolicy)
|
defaultPolicy, err := GetDefaultPolicy(models.NetworkID(node.Network), models.DevicePolicy)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
if defaultPolicy.Enabled {
|
if defaultPolicy.Enabled {
|
||||||
return true
|
return true, []models.Acl{defaultPolicy}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
allowedPolicies := []models.Acl{}
|
||||||
// list device policies
|
// list device policies
|
||||||
policies := listDevicePolicies(models.NetworkID(peer.Network))
|
policies := listDevicePolicies(models.NetworkID(peer.Network))
|
||||||
srcMap := make(map[string]struct{})
|
srcMap := make(map[string]struct{})
|
||||||
@@ -549,57 +611,88 @@ func IsNodeAllowedToCommunicate(node, peer models.Node, checkDefaultPolicy bool)
|
|||||||
}
|
}
|
||||||
srcMap = convAclTagToValueMap(policy.Src)
|
srcMap = convAclTagToValueMap(policy.Src)
|
||||||
dstMap = convAclTagToValueMap(policy.Dst)
|
dstMap = convAclTagToValueMap(policy.Dst)
|
||||||
// fmt.Printf("\n======> SRCMAP: %+v\n", srcMap)
|
|
||||||
// fmt.Printf("\n======> DSTMAP: %+v\n", dstMap)
|
|
||||||
// fmt.Printf("\n======> node Tags: %+v\n", node.Tags)
|
|
||||||
// fmt.Printf("\n======> peer Tags: %+v\n", peer.Tags)
|
|
||||||
for tagID := range node.Tags {
|
for tagID := range node.Tags {
|
||||||
if _, ok := dstMap[tagID.String()]; ok {
|
allowed := false
|
||||||
|
if _, ok := dstMap[tagID.String()]; policy.AllowedDirection == models.TrafficDirectionBi && ok {
|
||||||
if _, ok := srcMap["*"]; ok {
|
if _, ok := srcMap["*"]; ok {
|
||||||
return true
|
allowed = true
|
||||||
|
allowedPolicies = append(allowedPolicies, policy)
|
||||||
|
break
|
||||||
}
|
}
|
||||||
for tagID := range peer.Tags {
|
for tagID := range peer.Tags {
|
||||||
if _, ok := srcMap[tagID.String()]; ok {
|
if _, ok := srcMap[tagID.String()]; ok {
|
||||||
return true
|
allowed = true
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if allowed {
|
||||||
|
allowedPolicies = append(allowedPolicies, policy)
|
||||||
|
break
|
||||||
|
}
|
||||||
if _, ok := srcMap[tagID.String()]; ok {
|
if _, ok := srcMap[tagID.String()]; ok {
|
||||||
if _, ok := dstMap["*"]; ok {
|
if _, ok := dstMap["*"]; ok {
|
||||||
return true
|
allowed = true
|
||||||
|
allowedPolicies = append(allowedPolicies, policy)
|
||||||
|
break
|
||||||
}
|
}
|
||||||
for tagID := range peer.Tags {
|
for tagID := range peer.Tags {
|
||||||
if _, ok := dstMap[tagID.String()]; ok {
|
if _, ok := dstMap[tagID.String()]; ok {
|
||||||
return true
|
allowed = true
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if allowed {
|
||||||
|
allowedPolicies = append(allowedPolicies, policy)
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
for tagID := range peer.Tags {
|
for tagID := range peer.Tags {
|
||||||
|
allowed := false
|
||||||
if _, ok := dstMap[tagID.String()]; ok {
|
if _, ok := dstMap[tagID.String()]; ok {
|
||||||
if _, ok := srcMap["*"]; ok {
|
if _, ok := srcMap["*"]; ok {
|
||||||
return true
|
allowed = true
|
||||||
|
allowedPolicies = append(allowedPolicies, policy)
|
||||||
|
break
|
||||||
}
|
}
|
||||||
for tagID := range node.Tags {
|
for tagID := range node.Tags {
|
||||||
|
|
||||||
if _, ok := srcMap[tagID.String()]; ok {
|
if _, ok := srcMap[tagID.String()]; ok {
|
||||||
return true
|
allowed = true
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if _, ok := srcMap[tagID.String()]; ok {
|
if allowed {
|
||||||
|
allowedPolicies = append(allowedPolicies, policy)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, ok := srcMap[tagID.String()]; policy.AllowedDirection == models.TrafficDirectionBi && ok {
|
||||||
if _, ok := dstMap["*"]; ok {
|
if _, ok := dstMap["*"]; ok {
|
||||||
return true
|
allowed = true
|
||||||
|
allowedPolicies = append(allowedPolicies, policy)
|
||||||
|
break
|
||||||
}
|
}
|
||||||
for tagID := range node.Tags {
|
for tagID := range node.Tags {
|
||||||
if _, ok := dstMap[tagID.String()]; ok {
|
if _, ok := dstMap[tagID.String()]; ok {
|
||||||
return true
|
allowed = true
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if allowed {
|
||||||
|
allowedPolicies = append(allowedPolicies, policy)
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false
|
|
||||||
|
if len(allowedPolicies) > 0 {
|
||||||
|
return true, allowedPolicies
|
||||||
|
}
|
||||||
|
return false, allowedPolicies
|
||||||
}
|
}
|
||||||
|
|
||||||
// SortTagEntrys - Sorts slice of Tag entries by their id
|
// SortTagEntrys - Sorts slice of Tag entries by their id
|
||||||
@@ -648,7 +741,9 @@ func CheckIfTagAsActivePolicy(tagID models.TagID, netID models.NetworkID) bool {
|
|||||||
}
|
}
|
||||||
for _, dstTagI := range acl.Dst {
|
for _, dstTagI := range acl.Dst {
|
||||||
if dstTagI.ID == models.DeviceAclID {
|
if dstTagI.ID == models.DeviceAclID {
|
||||||
return true
|
if tagID.String() == dstTagI.Value {
|
||||||
|
return true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -682,3 +777,225 @@ func RemoveDeviceTagFromAclPolicies(tagID models.TagID, netID models.NetworkID)
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getUserAclRulesForNode(targetnode *models.Node,
|
||||||
|
rules map[string]models.AclRule) map[string]models.AclRule {
|
||||||
|
userNodes := GetStaticUserNodesByNetwork(models.NetworkID(targetnode.Network))
|
||||||
|
userGrpMap := GetUserGrpMap()
|
||||||
|
allowedUsers := make(map[string][]models.Acl)
|
||||||
|
acls := listUserPolicies(models.NetworkID(targetnode.Network))
|
||||||
|
for nodeTag := range targetnode.Tags {
|
||||||
|
for _, acl := range acls {
|
||||||
|
if !acl.Enabled {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
dstTags := convAclTagToValueMap(acl.Dst)
|
||||||
|
if _, ok := dstTags[nodeTag.String()]; ok {
|
||||||
|
// get all src tags
|
||||||
|
for _, srcAcl := range acl.Src {
|
||||||
|
if srcAcl.ID == models.UserAclID {
|
||||||
|
allowedUsers[srcAcl.Value] = append(allowedUsers[srcAcl.Value], acl)
|
||||||
|
} else if srcAcl.ID == models.UserGroupAclID {
|
||||||
|
// fetch all users in the group
|
||||||
|
if usersMap, ok := userGrpMap[models.UserGroupID(srcAcl.Value)]; ok {
|
||||||
|
for userName := range usersMap {
|
||||||
|
allowedUsers[userName] = append(allowedUsers[userName], acl)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, userNode := range userNodes {
|
||||||
|
if !userNode.StaticNode.Enabled {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
acls, ok := allowedUsers[userNode.StaticNode.OwnerID]
|
||||||
|
if !ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
for _, acl := range acls {
|
||||||
|
|
||||||
|
if !acl.Enabled {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
r := models.AclRule{
|
||||||
|
ID: acl.ID,
|
||||||
|
AllowedProtocol: acl.Proto,
|
||||||
|
AllowedPorts: acl.Port,
|
||||||
|
Direction: acl.AllowedDirection,
|
||||||
|
Allowed: true,
|
||||||
|
}
|
||||||
|
// Get peers in the tags and add allowed rules
|
||||||
|
if userNode.StaticNode.Address != "" {
|
||||||
|
r.IPList = append(r.IPList, userNode.StaticNode.AddressIPNet4())
|
||||||
|
}
|
||||||
|
if userNode.StaticNode.Address6 != "" {
|
||||||
|
r.IP6List = append(r.IP6List, userNode.StaticNode.AddressIPNet6())
|
||||||
|
}
|
||||||
|
if aclRule, ok := rules[acl.ID]; ok {
|
||||||
|
aclRule.IPList = append(aclRule.IPList, r.IPList...)
|
||||||
|
aclRule.IP6List = append(aclRule.IP6List, r.IP6List...)
|
||||||
|
rules[acl.ID] = aclRule
|
||||||
|
} else {
|
||||||
|
rules[acl.ID] = r
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return rules
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetAclRulesForNode(targetnode *models.Node) (rules map[string]models.AclRule) {
|
||||||
|
defer func() {
|
||||||
|
if !targetnode.IsIngressGateway {
|
||||||
|
rules = getUserAclRulesForNode(targetnode, rules)
|
||||||
|
}
|
||||||
|
|
||||||
|
}()
|
||||||
|
rules = make(map[string]models.AclRule)
|
||||||
|
var taggedNodes map[models.TagID][]models.Node
|
||||||
|
if targetnode.IsIngressGateway {
|
||||||
|
taggedNodes = GetTagMapWithNodesByNetwork(models.NetworkID(targetnode.Network), false)
|
||||||
|
} else {
|
||||||
|
taggedNodes = GetTagMapWithNodesByNetwork(models.NetworkID(targetnode.Network), true)
|
||||||
|
}
|
||||||
|
|
||||||
|
acls := listDevicePolicies(models.NetworkID(targetnode.Network))
|
||||||
|
for nodeTag := range targetnode.Tags {
|
||||||
|
for _, acl := range acls {
|
||||||
|
if !acl.Enabled {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
srcTags := convAclTagToValueMap(acl.Src)
|
||||||
|
dstTags := convAclTagToValueMap(acl.Dst)
|
||||||
|
aclRule := models.AclRule{
|
||||||
|
ID: acl.ID,
|
||||||
|
AllowedProtocol: acl.Proto,
|
||||||
|
AllowedPorts: acl.Port,
|
||||||
|
Direction: acl.AllowedDirection,
|
||||||
|
Allowed: true,
|
||||||
|
}
|
||||||
|
if acl.AllowedDirection == models.TrafficDirectionBi {
|
||||||
|
var existsInSrcTag bool
|
||||||
|
var existsInDstTag bool
|
||||||
|
|
||||||
|
if _, ok := srcTags[nodeTag.String()]; ok {
|
||||||
|
existsInSrcTag = true
|
||||||
|
}
|
||||||
|
if _, ok := dstTags[nodeTag.String()]; ok {
|
||||||
|
existsInDstTag = true
|
||||||
|
}
|
||||||
|
|
||||||
|
if existsInSrcTag && !existsInDstTag {
|
||||||
|
// get all dst tags
|
||||||
|
for dst := range dstTags {
|
||||||
|
if dst == nodeTag.String() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
// Get peers in the tags and add allowed rules
|
||||||
|
nodes := taggedNodes[models.TagID(dst)]
|
||||||
|
for _, node := range nodes {
|
||||||
|
if node.ID == targetnode.ID {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if node.Address.IP != nil {
|
||||||
|
aclRule.IPList = append(aclRule.IPList, node.AddressIPNet4())
|
||||||
|
}
|
||||||
|
if node.Address6.IP != nil {
|
||||||
|
aclRule.IP6List = append(aclRule.IP6List, node.AddressIPNet6())
|
||||||
|
}
|
||||||
|
if node.IsStatic && node.StaticNode.Address != "" {
|
||||||
|
aclRule.IPList = append(aclRule.IPList, node.StaticNode.AddressIPNet4())
|
||||||
|
}
|
||||||
|
if node.IsStatic && node.StaticNode.Address6 != "" {
|
||||||
|
aclRule.IP6List = append(aclRule.IP6List, node.StaticNode.AddressIPNet6())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if existsInDstTag && !existsInSrcTag {
|
||||||
|
// get all src tags
|
||||||
|
for src := range srcTags {
|
||||||
|
if src == nodeTag.String() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
// Get peers in the tags and add allowed rules
|
||||||
|
nodes := taggedNodes[models.TagID(src)]
|
||||||
|
for _, node := range nodes {
|
||||||
|
if node.ID == targetnode.ID {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if node.Address.IP != nil {
|
||||||
|
aclRule.IPList = append(aclRule.IPList, node.AddressIPNet4())
|
||||||
|
}
|
||||||
|
if node.Address6.IP != nil {
|
||||||
|
aclRule.IP6List = append(aclRule.IP6List, node.AddressIPNet6())
|
||||||
|
}
|
||||||
|
if node.IsStatic && node.StaticNode.Address != "" {
|
||||||
|
aclRule.IPList = append(aclRule.IPList, node.StaticNode.AddressIPNet4())
|
||||||
|
}
|
||||||
|
if node.IsStatic && node.StaticNode.Address6 != "" {
|
||||||
|
aclRule.IP6List = append(aclRule.IP6List, node.StaticNode.AddressIPNet6())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if existsInDstTag && existsInSrcTag {
|
||||||
|
nodes := taggedNodes[nodeTag]
|
||||||
|
for _, node := range nodes {
|
||||||
|
if node.ID == targetnode.ID {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if node.Address.IP != nil {
|
||||||
|
aclRule.IPList = append(aclRule.IPList, node.AddressIPNet4())
|
||||||
|
}
|
||||||
|
if node.Address6.IP != nil {
|
||||||
|
aclRule.IP6List = append(aclRule.IP6List, node.AddressIPNet6())
|
||||||
|
}
|
||||||
|
if node.IsStatic && node.StaticNode.Address != "" {
|
||||||
|
aclRule.IPList = append(aclRule.IPList, node.StaticNode.AddressIPNet4())
|
||||||
|
}
|
||||||
|
if node.IsStatic && node.StaticNode.Address6 != "" {
|
||||||
|
aclRule.IP6List = append(aclRule.IP6List, node.StaticNode.AddressIPNet6())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if _, ok := dstTags[nodeTag.String()]; ok {
|
||||||
|
// get all src tags
|
||||||
|
for src := range srcTags {
|
||||||
|
if src == nodeTag.String() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
// Get peers in the tags and add allowed rules
|
||||||
|
nodes := taggedNodes[models.TagID(src)]
|
||||||
|
for _, node := range nodes {
|
||||||
|
if node.ID == targetnode.ID {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if node.Address.IP != nil {
|
||||||
|
aclRule.IPList = append(aclRule.IPList, node.AddressIPNet4())
|
||||||
|
}
|
||||||
|
if node.Address6.IP != nil {
|
||||||
|
aclRule.IP6List = append(aclRule.IP6List, node.AddressIPNet6())
|
||||||
|
}
|
||||||
|
if node.IsStatic && node.StaticNode.Address != "" {
|
||||||
|
aclRule.IPList = append(aclRule.IPList, node.StaticNode.AddressIPNet4())
|
||||||
|
}
|
||||||
|
if node.IsStatic && node.StaticNode.Address6 != "" {
|
||||||
|
aclRule.IP6List = append(aclRule.IP6List, node.StaticNode.AddressIPNet6())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(aclRule.IPList) > 0 || len(aclRule.IP6List) > 0 {
|
||||||
|
rules[acl.ID] = aclRule
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return rules
|
||||||
|
}
|
||||||
|
@@ -456,6 +456,10 @@ func GetStaticNodeIps(node models.Node) (ips []net.IP) {
|
|||||||
|
|
||||||
func GetFwRulesOnIngressGateway(node models.Node) (rules []models.FwRule) {
|
func GetFwRulesOnIngressGateway(node models.Node) (rules []models.FwRule) {
|
||||||
// fetch user access to static clients via policies
|
// fetch user access to static clients via policies
|
||||||
|
defer func() {
|
||||||
|
logger.Log(0, fmt.Sprintf("node.ID: %s, Rules: %+v\n", node.ID, rules))
|
||||||
|
}()
|
||||||
|
|
||||||
defaultUserPolicy, _ := GetDefaultPolicy(models.NetworkID(node.Network), models.UserPolicy)
|
defaultUserPolicy, _ := GetDefaultPolicy(models.NetworkID(node.Network), models.UserPolicy)
|
||||||
defaultDevicePolicy, _ := GetDefaultPolicy(models.NetworkID(node.Network), models.DevicePolicy)
|
defaultDevicePolicy, _ := GetDefaultPolicy(models.NetworkID(node.Network), models.DevicePolicy)
|
||||||
nodes, _ := GetNetworkNodes(node.Network)
|
nodes, _ := GetNetworkNodes(node.Network)
|
||||||
@@ -468,36 +472,50 @@ func GetFwRulesOnIngressGateway(node models.Node) (rules []models.FwRule) {
|
|||||||
if peer.IsUserNode {
|
if peer.IsUserNode {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if IsUserAllowedToCommunicate(userNodeI.StaticNode.OwnerID, peer) {
|
if ok, allowedPolicies := IsUserAllowedToCommunicate(userNodeI.StaticNode.OwnerID, peer); ok {
|
||||||
if peer.IsStatic {
|
if peer.IsStatic {
|
||||||
if userNodeI.StaticNode.Address != "" {
|
if userNodeI.StaticNode.Address != "" {
|
||||||
if !defaultUserPolicy.Enabled {
|
if !defaultUserPolicy.Enabled {
|
||||||
rules = append(rules, models.FwRule{
|
for _, policy := range allowedPolicies {
|
||||||
SrcIP: userNodeI.StaticNode.AddressIPNet4(),
|
rules = append(rules, models.FwRule{
|
||||||
DstIP: peer.StaticNode.AddressIPNet4(),
|
SrcIP: userNodeI.StaticNode.AddressIPNet4(),
|
||||||
Allow: true,
|
DstIP: peer.StaticNode.AddressIPNet4(),
|
||||||
})
|
AllowedProtocol: policy.Proto,
|
||||||
|
AllowedPorts: policy.Port,
|
||||||
|
Allow: true,
|
||||||
|
})
|
||||||
|
rules = append(rules, models.FwRule{
|
||||||
|
SrcIP: peer.StaticNode.AddressIPNet4(),
|
||||||
|
DstIP: userNodeI.StaticNode.AddressIPNet4(),
|
||||||
|
AllowedProtocol: policy.Proto,
|
||||||
|
AllowedPorts: policy.Port,
|
||||||
|
Allow: true,
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
rules = append(rules, models.FwRule{
|
|
||||||
SrcIP: peer.StaticNode.AddressIPNet4(),
|
|
||||||
DstIP: userNodeI.StaticNode.AddressIPNet4(),
|
|
||||||
Allow: true,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
if userNodeI.StaticNode.Address6 != "" {
|
if userNodeI.StaticNode.Address6 != "" {
|
||||||
if !defaultUserPolicy.Enabled {
|
if !defaultUserPolicy.Enabled {
|
||||||
rules = append(rules, models.FwRule{
|
for _, policy := range allowedPolicies {
|
||||||
SrcIP: userNodeI.StaticNode.AddressIPNet6(),
|
rules = append(rules, models.FwRule{
|
||||||
DstIP: peer.StaticNode.AddressIPNet6(),
|
SrcIP: userNodeI.StaticNode.AddressIPNet6(),
|
||||||
Allow: true,
|
DstIP: peer.StaticNode.AddressIPNet6(),
|
||||||
})
|
Allow: true,
|
||||||
|
AllowedProtocol: policy.Proto,
|
||||||
|
AllowedPorts: policy.Port,
|
||||||
|
})
|
||||||
|
rules = append(rules, models.FwRule{
|
||||||
|
SrcIP: peer.StaticNode.AddressIPNet6(),
|
||||||
|
DstIP: userNodeI.StaticNode.AddressIPNet6(),
|
||||||
|
AllowedProtocol: policy.Proto,
|
||||||
|
AllowedPorts: policy.Port,
|
||||||
|
Allow: true,
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rules = append(rules, models.FwRule{
|
|
||||||
SrcIP: peer.StaticNode.AddressIPNet6(),
|
|
||||||
DstIP: userNodeI.StaticNode.AddressIPNet6(),
|
|
||||||
Allow: true,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
if len(peer.StaticNode.ExtraAllowedIPs) > 0 {
|
if len(peer.StaticNode.ExtraAllowedIPs) > 0 {
|
||||||
for _, additionalAllowedIPNet := range peer.StaticNode.ExtraAllowedIPs {
|
for _, additionalAllowedIPNet := range peer.StaticNode.ExtraAllowedIPs {
|
||||||
@@ -526,29 +544,39 @@ func GetFwRulesOnIngressGateway(node models.Node) (rules []models.FwRule) {
|
|||||||
|
|
||||||
if userNodeI.StaticNode.Address != "" {
|
if userNodeI.StaticNode.Address != "" {
|
||||||
if !defaultUserPolicy.Enabled {
|
if !defaultUserPolicy.Enabled {
|
||||||
rules = append(rules, models.FwRule{
|
for _, policy := range allowedPolicies {
|
||||||
SrcIP: userNodeI.StaticNode.AddressIPNet4(),
|
rules = append(rules, models.FwRule{
|
||||||
DstIP: net.IPNet{
|
SrcIP: userNodeI.StaticNode.AddressIPNet4(),
|
||||||
IP: peer.Address.IP,
|
DstIP: net.IPNet{
|
||||||
Mask: net.CIDRMask(32, 32),
|
IP: peer.Address.IP,
|
||||||
},
|
Mask: net.CIDRMask(32, 32),
|
||||||
Allow: true,
|
},
|
||||||
})
|
AllowedProtocol: policy.Proto,
|
||||||
|
AllowedPorts: policy.Port,
|
||||||
|
Allow: true,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if userNodeI.StaticNode.Address6 != "" {
|
if userNodeI.StaticNode.Address6 != "" {
|
||||||
rules = append(rules, models.FwRule{
|
if !defaultUserPolicy.Enabled {
|
||||||
SrcIP: userNodeI.StaticNode.AddressIPNet6(),
|
for _, policy := range allowedPolicies {
|
||||||
DstIP: net.IPNet{
|
rules = append(rules, models.FwRule{
|
||||||
IP: peer.Address6.IP,
|
SrcIP: userNodeI.StaticNode.AddressIPNet6(),
|
||||||
Mask: net.CIDRMask(128, 128),
|
DstIP: net.IPNet{
|
||||||
},
|
IP: peer.Address6.IP,
|
||||||
Allow: true,
|
Mask: net.CIDRMask(128, 128),
|
||||||
})
|
},
|
||||||
|
AllowedProtocol: policy.Proto,
|
||||||
|
AllowedPorts: policy.Port,
|
||||||
|
Allow: true,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -564,21 +592,48 @@ func GetFwRulesOnIngressGateway(node models.Node) (rules []models.FwRule) {
|
|||||||
if peer.StaticNode.ClientID == nodeI.StaticNode.ClientID || peer.IsUserNode {
|
if peer.StaticNode.ClientID == nodeI.StaticNode.ClientID || peer.IsUserNode {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if IsNodeAllowedToCommunicate(nodeI, peer, true) {
|
if ok, allowedPolicies := IsNodeAllowedToCommunicate(nodeI, peer, true); ok {
|
||||||
if peer.IsStatic {
|
if peer.IsStatic {
|
||||||
if nodeI.StaticNode.Address != "" {
|
if nodeI.StaticNode.Address != "" {
|
||||||
rules = append(rules, models.FwRule{
|
for _, policy := range allowedPolicies {
|
||||||
SrcIP: nodeI.StaticNode.AddressIPNet4(),
|
rules = append(rules, models.FwRule{
|
||||||
DstIP: peer.StaticNode.AddressIPNet4(),
|
SrcIP: nodeI.StaticNode.AddressIPNet4(),
|
||||||
Allow: true,
|
DstIP: peer.StaticNode.AddressIPNet4(),
|
||||||
})
|
AllowedProtocol: policy.Proto,
|
||||||
|
AllowedPorts: policy.Port,
|
||||||
|
Allow: true,
|
||||||
|
})
|
||||||
|
if policy.AllowedDirection == models.TrafficDirectionBi {
|
||||||
|
rules = append(rules, models.FwRule{
|
||||||
|
SrcIP: peer.StaticNode.AddressIPNet4(),
|
||||||
|
DstIP: nodeI.StaticNode.AddressIPNet4(),
|
||||||
|
AllowedProtocol: policy.Proto,
|
||||||
|
AllowedPorts: policy.Port,
|
||||||
|
Allow: true,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
if nodeI.StaticNode.Address6 != "" {
|
if nodeI.StaticNode.Address6 != "" {
|
||||||
rules = append(rules, models.FwRule{
|
for _, policy := range allowedPolicies {
|
||||||
SrcIP: nodeI.StaticNode.AddressIPNet6(),
|
rules = append(rules, models.FwRule{
|
||||||
DstIP: peer.StaticNode.AddressIPNet6(),
|
SrcIP: nodeI.StaticNode.AddressIPNet6(),
|
||||||
Allow: true,
|
DstIP: peer.StaticNode.AddressIPNet6(),
|
||||||
})
|
AllowedProtocol: policy.Proto,
|
||||||
|
AllowedPorts: policy.Port,
|
||||||
|
Allow: true,
|
||||||
|
})
|
||||||
|
if policy.AllowedDirection == models.TrafficDirectionBi {
|
||||||
|
rules = append(rules, models.FwRule{
|
||||||
|
SrcIP: peer.StaticNode.AddressIPNet6(),
|
||||||
|
DstIP: nodeI.StaticNode.AddressIPNet6(),
|
||||||
|
AllowedProtocol: policy.Proto,
|
||||||
|
AllowedPorts: policy.Port,
|
||||||
|
Allow: true,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if len(peer.StaticNode.ExtraAllowedIPs) > 0 {
|
if len(peer.StaticNode.ExtraAllowedIPs) > 0 {
|
||||||
for _, additionalAllowedIPNet := range peer.StaticNode.ExtraAllowedIPs {
|
for _, additionalAllowedIPNet := range peer.StaticNode.ExtraAllowedIPs {
|
||||||
@@ -605,24 +660,56 @@ func GetFwRulesOnIngressGateway(node models.Node) (rules []models.FwRule) {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if nodeI.StaticNode.Address != "" {
|
if nodeI.StaticNode.Address != "" {
|
||||||
rules = append(rules, models.FwRule{
|
for _, policy := range allowedPolicies {
|
||||||
SrcIP: nodeI.StaticNode.AddressIPNet4(),
|
rules = append(rules, models.FwRule{
|
||||||
DstIP: net.IPNet{
|
SrcIP: nodeI.StaticNode.AddressIPNet4(),
|
||||||
IP: peer.Address.IP,
|
DstIP: net.IPNet{
|
||||||
Mask: net.CIDRMask(32, 32),
|
IP: peer.Address.IP,
|
||||||
},
|
Mask: net.CIDRMask(32, 32),
|
||||||
Allow: true,
|
},
|
||||||
})
|
AllowedProtocol: policy.Proto,
|
||||||
|
AllowedPorts: policy.Port,
|
||||||
|
Allow: true,
|
||||||
|
})
|
||||||
|
if policy.AllowedDirection == models.TrafficDirectionBi {
|
||||||
|
rules = append(rules, models.FwRule{
|
||||||
|
SrcIP: net.IPNet{
|
||||||
|
IP: peer.Address.IP,
|
||||||
|
Mask: net.CIDRMask(32, 32),
|
||||||
|
},
|
||||||
|
DstIP: nodeI.StaticNode.AddressIPNet4(),
|
||||||
|
AllowedProtocol: policy.Proto,
|
||||||
|
AllowedPorts: policy.Port,
|
||||||
|
Allow: true,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if nodeI.StaticNode.Address6 != "" {
|
if nodeI.StaticNode.Address6 != "" {
|
||||||
rules = append(rules, models.FwRule{
|
for _, policy := range allowedPolicies {
|
||||||
SrcIP: nodeI.StaticNode.AddressIPNet6(),
|
rules = append(rules, models.FwRule{
|
||||||
DstIP: net.IPNet{
|
SrcIP: nodeI.StaticNode.AddressIPNet6(),
|
||||||
IP: peer.Address6.IP,
|
DstIP: net.IPNet{
|
||||||
Mask: net.CIDRMask(128, 128),
|
IP: peer.Address6.IP,
|
||||||
},
|
Mask: net.CIDRMask(128, 128),
|
||||||
Allow: true,
|
},
|
||||||
})
|
AllowedProtocol: policy.Proto,
|
||||||
|
AllowedPorts: policy.Port,
|
||||||
|
Allow: true,
|
||||||
|
})
|
||||||
|
if policy.AllowedDirection == models.TrafficDirectionBi {
|
||||||
|
rules = append(rules, models.FwRule{
|
||||||
|
SrcIP: net.IPNet{
|
||||||
|
IP: peer.Address6.IP,
|
||||||
|
Mask: net.CIDRMask(128, 128),
|
||||||
|
},
|
||||||
|
DstIP: nodeI.StaticNode.AddressIPNet6(),
|
||||||
|
AllowedProtocol: policy.Proto,
|
||||||
|
AllowedPorts: policy.Port,
|
||||||
|
Allow: true,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -650,11 +737,11 @@ func GetExtPeers(node, peer *models.Node) ([]wgtypes.PeerConfig, []models.IDandA
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if extPeer.RemoteAccessClientID == "" {
|
if extPeer.RemoteAccessClientID == "" {
|
||||||
if !IsNodeAllowedToCommunicate(extPeer.ConvertToStaticNode(), *peer, true) {
|
if ok, _ := IsNodeAllowedToCommunicate(extPeer.ConvertToStaticNode(), *peer, true); !ok {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if !IsUserAllowedToCommunicate(extPeer.OwnerID, *peer) {
|
if ok, _ := IsUserAllowedToCommunicate(extPeer.OwnerID, *peer); !ok {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -739,7 +826,7 @@ func getExtpeerEgressRanges(node models.Node) (ranges, ranges6 []net.IPNet) {
|
|||||||
if len(extPeer.ExtraAllowedIPs) == 0 {
|
if len(extPeer.ExtraAllowedIPs) == 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if !IsNodeAllowedToCommunicate(extPeer.ConvertToStaticNode(), node, true) {
|
if ok, _ := IsNodeAllowedToCommunicate(extPeer.ConvertToStaticNode(), node, true); !ok {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
for _, allowedRange := range extPeer.ExtraAllowedIPs {
|
for _, allowedRange := range extPeer.ExtraAllowedIPs {
|
||||||
@@ -766,7 +853,7 @@ func getExtpeersExtraRoutes(node models.Node) (egressRoutes []models.EgressNetwo
|
|||||||
if len(extPeer.ExtraAllowedIPs) == 0 {
|
if len(extPeer.ExtraAllowedIPs) == 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if !IsNodeAllowedToCommunicate(extPeer.ConvertToStaticNode(), node, true) {
|
if ok, _ := IsNodeAllowedToCommunicate(extPeer.ConvertToStaticNode(), node, true); !ok {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
egressRoutes = append(egressRoutes, getExtPeerEgressRoute(node, extPeer)...)
|
egressRoutes = append(egressRoutes, getExtPeerEgressRoute(node, extPeer)...)
|
||||||
|
@@ -818,7 +818,7 @@ func GetTagMapWithNodes() (tagNodesMap map[models.TagID][]models.Node) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetTagMapWithNodesByNetwork(netID models.NetworkID) (tagNodesMap map[models.TagID][]models.Node) {
|
func GetTagMapWithNodesByNetwork(netID models.NetworkID, withStaticNodes bool) (tagNodesMap map[models.TagID][]models.Node) {
|
||||||
tagNodesMap = make(map[models.TagID][]models.Node)
|
tagNodesMap = make(map[models.TagID][]models.Node)
|
||||||
nodes, _ := GetNetworkNodes(netID.String())
|
nodes, _ := GetNetworkNodes(netID.String())
|
||||||
for _, nodeI := range nodes {
|
for _, nodeI := range nodes {
|
||||||
@@ -829,6 +829,9 @@ func GetTagMapWithNodesByNetwork(netID models.NetworkID) (tagNodesMap map[models
|
|||||||
tagNodesMap[nodeTagID] = append(tagNodesMap[nodeTagID], nodeI)
|
tagNodesMap[nodeTagID] = append(tagNodesMap[nodeTagID], nodeI)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if !withStaticNodes {
|
||||||
|
return
|
||||||
|
}
|
||||||
return AddTagMapWithStaticNodes(netID, tagNodesMap)
|
return AddTagMapWithStaticNodes(netID, tagNodesMap)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -853,6 +856,27 @@ func AddTagMapWithStaticNodes(netID models.NetworkID,
|
|||||||
return tagNodesMap
|
return tagNodesMap
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func AddTagMapWithStaticNodesWithUsers(netID models.NetworkID,
|
||||||
|
tagNodesMap map[models.TagID][]models.Node) map[models.TagID][]models.Node {
|
||||||
|
extclients, err := GetNetworkExtClients(netID.String())
|
||||||
|
if err != nil {
|
||||||
|
return tagNodesMap
|
||||||
|
}
|
||||||
|
for _, extclient := range extclients {
|
||||||
|
if extclient.Tags == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
for tagID := range extclient.Tags {
|
||||||
|
tagNodesMap[tagID] = append(tagNodesMap[tagID], models.Node{
|
||||||
|
IsStatic: true,
|
||||||
|
StaticNode: extclient,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return tagNodesMap
|
||||||
|
}
|
||||||
|
|
||||||
func GetNodesWithTag(tagID models.TagID) map[string]models.Node {
|
func GetNodesWithTag(tagID models.TagID) map[string]models.Node {
|
||||||
nMap := make(map[string]models.Node)
|
nMap := make(map[string]models.Node)
|
||||||
tag, err := GetTag(tagID)
|
tag, err := GetTag(tagID)
|
||||||
|
@@ -74,8 +74,10 @@ func GetPeerUpdateForHost(network string, host *models.Host, allNodes []models.N
|
|||||||
ServerVersion: servercfg.GetVersion(),
|
ServerVersion: servercfg.GetVersion(),
|
||||||
ServerAddrs: []models.ServerAddr{},
|
ServerAddrs: []models.ServerAddr{},
|
||||||
FwUpdate: models.FwUpdate{
|
FwUpdate: models.FwUpdate{
|
||||||
|
AllowAll: true,
|
||||||
EgressInfo: make(map[string]models.EgressInfo),
|
EgressInfo: make(map[string]models.EgressInfo),
|
||||||
IngressInfo: make(map[string]models.IngressInfo),
|
IngressInfo: make(map[string]models.IngressInfo),
|
||||||
|
AclRules: make(map[string]models.AclRule),
|
||||||
},
|
},
|
||||||
PeerIDs: make(models.PeerMap, 0),
|
PeerIDs: make(models.PeerMap, 0),
|
||||||
Peers: []wgtypes.PeerConfig{},
|
Peers: []wgtypes.PeerConfig{},
|
||||||
@@ -96,8 +98,6 @@ func GetPeerUpdateForHost(network string, host *models.Host, allNodes []models.N
|
|||||||
if !node.Connected || node.PendingDelete || node.Action == models.NODE_DELETE {
|
if !node.Connected || node.PendingDelete || node.Action == models.NODE_DELETE {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// check default policy if all allowed return true
|
|
||||||
defaultPolicy, _ := GetDefaultPolicy(models.NetworkID(node.Network), models.DevicePolicy)
|
|
||||||
if host.OS == models.OS_Types.IoT {
|
if host.OS == models.OS_Types.IoT {
|
||||||
hostPeerUpdate.NodeAddrs = append(hostPeerUpdate.NodeAddrs, node.PrimaryAddressIPNet())
|
hostPeerUpdate.NodeAddrs = append(hostPeerUpdate.NodeAddrs, node.PrimaryAddressIPNet())
|
||||||
if node.IsRelayed {
|
if node.IsRelayed {
|
||||||
@@ -156,6 +156,19 @@ func GetPeerUpdateForHost(network string, host *models.Host, allNodes []models.N
|
|||||||
if !hostPeerUpdate.IsInternetGw {
|
if !hostPeerUpdate.IsInternetGw {
|
||||||
hostPeerUpdate.IsInternetGw = IsInternetGw(node)
|
hostPeerUpdate.IsInternetGw = IsInternetGw(node)
|
||||||
}
|
}
|
||||||
|
defaultUserPolicy, _ := GetDefaultPolicy(models.NetworkID(node.Network), models.UserPolicy)
|
||||||
|
defaultDevicePolicy, _ := GetDefaultPolicy(models.NetworkID(node.Network), models.DevicePolicy)
|
||||||
|
if node.NetworkRange.IP != nil {
|
||||||
|
hostPeerUpdate.FwUpdate.Networks = append(hostPeerUpdate.FwUpdate.Networks, node.NetworkRange)
|
||||||
|
}
|
||||||
|
if node.NetworkRange6.IP != nil {
|
||||||
|
hostPeerUpdate.FwUpdate.Networks = append(hostPeerUpdate.FwUpdate.Networks, node.NetworkRange6)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !defaultDevicePolicy.Enabled || !defaultUserPolicy.Enabled {
|
||||||
|
hostPeerUpdate.FwUpdate.AllowAll = false
|
||||||
|
}
|
||||||
|
hostPeerUpdate.FwUpdate.AclRules = GetAclRulesForNode(&node)
|
||||||
currentPeers := GetNetworkNodesMemory(allNodes, node.Network)
|
currentPeers := GetNetworkNodesMemory(allNodes, node.Network)
|
||||||
for _, peer := range currentPeers {
|
for _, peer := range currentPeers {
|
||||||
peer := peer
|
peer := peer
|
||||||
@@ -257,11 +270,12 @@ func GetPeerUpdateForHost(network string, host *models.Host, allNodes []models.N
|
|||||||
peerConfig.Endpoint.Port = peerHost.ListenPort
|
peerConfig.Endpoint.Port = peerHost.ListenPort
|
||||||
}
|
}
|
||||||
allowedips := GetAllowedIPs(&node, &peer, nil)
|
allowedips := GetAllowedIPs(&node, &peer, nil)
|
||||||
|
allowedToComm, _ := IsNodeAllowedToCommunicate(node, peer, false)
|
||||||
if peer.Action != models.NODE_DELETE &&
|
if peer.Action != models.NODE_DELETE &&
|
||||||
!peer.PendingDelete &&
|
!peer.PendingDelete &&
|
||||||
peer.Connected &&
|
peer.Connected &&
|
||||||
nodeacls.AreNodesAllowed(nodeacls.NetworkID(node.Network), nodeacls.NodeID(node.ID.String()), nodeacls.NodeID(peer.ID.String())) &&
|
nodeacls.AreNodesAllowed(nodeacls.NetworkID(node.Network), nodeacls.NodeID(node.ID.String()), nodeacls.NodeID(peer.ID.String())) &&
|
||||||
(defaultPolicy.Enabled || IsNodeAllowedToCommunicate(node, peer, false)) &&
|
(defaultDevicePolicy.Enabled || allowedToComm) &&
|
||||||
(deletedNode == nil || (deletedNode != nil && peer.ID.String() != deletedNode.ID.String())) {
|
(deletedNode == nil || (deletedNode != nil && peer.ID.String() != deletedNode.ID.String())) {
|
||||||
peerConfig.AllowedIPs = allowedips // only append allowed IPs if valid connection
|
peerConfig.AllowedIPs = allowedips // only append allowed IPs if valid connection
|
||||||
}
|
}
|
||||||
@@ -311,8 +325,6 @@ func GetPeerUpdateForHost(network string, host *models.Host, allNodes []models.N
|
|||||||
hostPeerUpdate.FwUpdate.IsIngressGw = true
|
hostPeerUpdate.FwUpdate.IsIngressGw = true
|
||||||
extPeers, extPeerIDAndAddrs, egressRoutes, err = GetExtPeers(&node, &node)
|
extPeers, extPeerIDAndAddrs, egressRoutes, err = GetExtPeers(&node, &node)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
defaultUserPolicy, _ := GetDefaultPolicy(models.NetworkID(node.Network), models.UserPolicy)
|
|
||||||
defaultDevicePolicy, _ := GetDefaultPolicy(models.NetworkID(node.Network), models.DevicePolicy)
|
|
||||||
if !defaultDevicePolicy.Enabled || !defaultUserPolicy.Enabled {
|
if !defaultDevicePolicy.Enabled || !defaultUserPolicy.Enabled {
|
||||||
ingFwUpdate := models.IngressInfo{
|
ingFwUpdate := models.IngressInfo{
|
||||||
IngressID: node.ID.String(),
|
IngressID: node.ID.String(),
|
||||||
|
@@ -85,7 +85,7 @@ func ListTagsWithNodes(netID models.NetworkID) ([]models.TagListResp, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return []models.TagListResp{}, err
|
return []models.TagListResp{}, err
|
||||||
}
|
}
|
||||||
tagsNodeMap := GetTagMapWithNodesByNetwork(netID)
|
tagsNodeMap := GetTagMapWithNodesByNetwork(netID, true)
|
||||||
resp := []models.TagListResp{}
|
resp := []models.TagListResp{}
|
||||||
for _, tagI := range tags {
|
for _, tagI := range tags {
|
||||||
tagRespI := models.TagListResp{
|
tagRespI := models.TagListResp{
|
||||||
|
@@ -98,6 +98,25 @@ func ListPlatformRoles() ([]models.UserRolePermissionTemplate, error) {
|
|||||||
return userRoles, nil
|
return userRoles, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetUserGrpMap() map[models.UserGroupID]map[string]struct{} {
|
||||||
|
grpUsersMap := make(map[models.UserGroupID]map[string]struct{})
|
||||||
|
users, _ := GetUsersDB()
|
||||||
|
for _, user := range users {
|
||||||
|
for gID := range user.UserGroups {
|
||||||
|
if grpUsers, ok := grpUsersMap[gID]; ok {
|
||||||
|
grpUsers[user.UserName] = struct{}{}
|
||||||
|
grpUsersMap[gID] = grpUsers
|
||||||
|
} else {
|
||||||
|
grpUsersMap[gID] = make(map[string]struct{})
|
||||||
|
grpUsersMap[gID][user.UserName] = struct{}{}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return grpUsersMap
|
||||||
|
}
|
||||||
|
|
||||||
func userRolesInit() {
|
func userRolesInit() {
|
||||||
d, _ := json.Marshal(SuperAdminPermissionTemplate)
|
d, _ := json.Marshal(SuperAdminPermissionTemplate)
|
||||||
database.Insert(SuperAdminPermissionTemplate.ID.String(), string(d), database.USER_PERMISSIONS_TABLE_NAME)
|
database.Insert(SuperAdminPermissionTemplate.ID.String(), string(d), database.USER_PERMISSIONS_TABLE_NAME)
|
||||||
|
@@ -437,5 +437,6 @@ func createDefaultTagsAndPolicies() {
|
|||||||
for _, network := range networks {
|
for _, network := range networks {
|
||||||
logic.CreateDefaultTags(models.NetworkID(network.NetID))
|
logic.CreateDefaultTags(models.NetworkID(network.NetID))
|
||||||
logic.CreateDefaultAclNetworkPolicies(models.NetworkID(network.NetID))
|
logic.CreateDefaultAclNetworkPolicies(models.NetworkID(network.NetID))
|
||||||
|
logic.MigrateDefaulAclPolicies(models.NetworkID(network.NetID))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
package models
|
package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"net"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -14,6 +15,31 @@ const (
|
|||||||
TrafficDirectionBi
|
TrafficDirectionBi
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Protocol - allowed protocol
|
||||||
|
type Protocol string
|
||||||
|
|
||||||
|
const (
|
||||||
|
ALL Protocol = "all"
|
||||||
|
UDP Protocol = "udp"
|
||||||
|
TCP Protocol = "tcp"
|
||||||
|
ICMP Protocol = "icmp"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ServiceType string
|
||||||
|
|
||||||
|
const (
|
||||||
|
Http = "HTTP"
|
||||||
|
Https = "HTTPS"
|
||||||
|
AllTCP = "All TCP"
|
||||||
|
AllUDP = "All UDP"
|
||||||
|
ICMPService = "ICMP"
|
||||||
|
Custom = "Custom"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (p Protocol) String() string {
|
||||||
|
return string(p)
|
||||||
|
}
|
||||||
|
|
||||||
type AclPolicyType string
|
type AclPolicyType string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -59,6 +85,9 @@ type Acl struct {
|
|||||||
RuleType AclPolicyType `json:"policy_type"`
|
RuleType AclPolicyType `json:"policy_type"`
|
||||||
Src []AclPolicyTag `json:"src_type"`
|
Src []AclPolicyTag `json:"src_type"`
|
||||||
Dst []AclPolicyTag `json:"dst_type"`
|
Dst []AclPolicyTag `json:"dst_type"`
|
||||||
|
Proto Protocol `json:"protocol"` // tcp, udp, etc.
|
||||||
|
ServiceType string `json:"type"`
|
||||||
|
Port []string `json:"ports"`
|
||||||
AllowedDirection AllowedTrafficDirection `json:"allowed_traffic_direction"`
|
AllowedDirection AllowedTrafficDirection `json:"allowed_traffic_direction"`
|
||||||
Enabled bool `json:"enabled"`
|
Enabled bool `json:"enabled"`
|
||||||
CreatedBy string `json:"created_by"`
|
CreatedBy string `json:"created_by"`
|
||||||
@@ -66,7 +95,25 @@ type Acl struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type AclPolicyTypes struct {
|
type AclPolicyTypes struct {
|
||||||
|
ProtocolTypes []ProtocolType
|
||||||
RuleTypes []AclPolicyType `json:"policy_types"`
|
RuleTypes []AclPolicyType `json:"policy_types"`
|
||||||
SrcGroupTypes []AclGroupType `json:"src_grp_types"`
|
SrcGroupTypes []AclGroupType `json:"src_grp_types"`
|
||||||
DstGroupTypes []AclGroupType `json:"dst_grp_types"`
|
DstGroupTypes []AclGroupType `json:"dst_grp_types"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ProtocolType struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
AllowedProtocols []Protocol `json:"allowed_protocols"`
|
||||||
|
PortRange string `json:"port_range"`
|
||||||
|
AllowPortSetting bool `json:"allow_port_setting"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type AclRule struct {
|
||||||
|
ID string `json:"id"`
|
||||||
|
IPList []net.IPNet `json:"ip_list"`
|
||||||
|
IP6List []net.IPNet `json:"ip6_list"`
|
||||||
|
AllowedProtocol Protocol `json:"allowed_protocols"` // tcp, udp, etc.
|
||||||
|
AllowedPorts []string `json:"allowed_ports"`
|
||||||
|
Direction AllowedTrafficDirection `json:"direction"` // single or two-way
|
||||||
|
Allowed bool
|
||||||
|
}
|
||||||
|
@@ -30,9 +30,11 @@ type HostPeerUpdate struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type FwRule struct {
|
type FwRule struct {
|
||||||
SrcIP net.IPNet
|
SrcIP net.IPNet `json:"src_ip"`
|
||||||
DstIP net.IPNet
|
DstIP net.IPNet `json:"dst_ip"`
|
||||||
Allow bool
|
AllowedProtocol Protocol `json:"allowed_protocols"` // tcp, udp, etc.
|
||||||
|
AllowedPorts []string `json:"allowed_ports"`
|
||||||
|
Allow bool `json:"allow"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// IngressInfo - struct for ingress info
|
// IngressInfo - struct for ingress info
|
||||||
@@ -92,10 +94,13 @@ type KeyUpdate struct {
|
|||||||
|
|
||||||
// FwUpdate - struct for firewall updates
|
// FwUpdate - struct for firewall updates
|
||||||
type FwUpdate struct {
|
type FwUpdate struct {
|
||||||
|
AllowAll bool `json:"allow_all"`
|
||||||
|
Networks []net.IPNet `json:"networks"`
|
||||||
IsEgressGw bool `json:"is_egress_gw"`
|
IsEgressGw bool `json:"is_egress_gw"`
|
||||||
IsIngressGw bool `json:"is_ingress_gw"`
|
IsIngressGw bool `json:"is_ingress_gw"`
|
||||||
EgressInfo map[string]EgressInfo `json:"egress_info"`
|
EgressInfo map[string]EgressInfo `json:"egress_info"`
|
||||||
IngressInfo map[string]IngressInfo `json:"ingress_info"`
|
IngressInfo map[string]IngressInfo `json:"ingress_info"`
|
||||||
|
AclRules map[string]AclRule `json:"acl_rules"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// FailOverMeReq - struct for failover req
|
// FailOverMeReq - struct for failover req
|
||||||
|
@@ -215,6 +215,19 @@ func (node *Node) PrimaryAddress() string {
|
|||||||
return node.Address6.IP.String()
|
return node.Address6.IP.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (node *Node) AddressIPNet4() net.IPNet {
|
||||||
|
return net.IPNet{
|
||||||
|
IP: node.Address.IP,
|
||||||
|
Mask: net.CIDRMask(32, 32),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
func (node *Node) AddressIPNet6() net.IPNet {
|
||||||
|
return net.IPNet{
|
||||||
|
IP: node.Address6.IP,
|
||||||
|
Mask: net.CIDRMask(128, 128),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ExtClient.PrimaryAddress - returns ipv4 IPNet format
|
// ExtClient.PrimaryAddress - returns ipv4 IPNet format
|
||||||
func (extPeer *ExtClient) AddressIPNet4() net.IPNet {
|
func (extPeer *ExtClient) AddressIPNet4() net.IPNet {
|
||||||
return net.IPNet{
|
return net.IPNet{
|
||||||
|
@@ -133,7 +133,8 @@ func checkPeerStatus(node *models.Node, defaultAclPolicy bool) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if !defaultAclPolicy && !logic.IsNodeAllowedToCommunicate(*node, peer, false) {
|
allowed, _ := logic.IsNodeAllowedToCommunicate(*node, peer, false)
|
||||||
|
if !defaultAclPolicy && !allowed {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -167,7 +168,8 @@ func checkPeerConnectivity(node *models.Node, metrics *models.Metrics, defaultAc
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if !defaultAclPolicy && !logic.IsNodeAllowedToCommunicate(*node, peer, false) {
|
allowed, _ := logic.IsNodeAllowedToCommunicate(*node, peer, false)
|
||||||
|
if !defaultAclPolicy && !allowed {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user