Skip to content
Merged

Master #3661

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions logic/acls.go
Original file line number Diff line number Diff line change
Expand Up @@ -1465,6 +1465,18 @@ func GetDefaultPolicy(netID models.NetworkID, ruleType models.AclPolicyType) (mo
return acl, nil
}

// ListUserPolicies - lists all user policies in a network
func ListUserPolicies(netID models.NetworkID) []models.Acl {
allAcls := ListAcls()
userAcls := []models.Acl{}
for _, acl := range allAcls {
if acl.NetworkID == netID && acl.RuleType == models.UserPolicy {
userAcls = append(userAcls, acl)
}
}
return userAcls
}

// ListAcls - lists all acl policies
func ListAclsByNetwork(netID models.NetworkID) ([]models.Acl, error) {

Expand Down
4 changes: 1 addition & 3 deletions logic/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,7 @@ func GetGwDNS(node *models.Node) string {
}

func SetDNSOnWgConfig(gwNode *models.Node, extclient *models.ExtClient) {
if extclient.DNS == "" {
extclient.DNS = GetGwDNS(gwNode)
}
extclient.DNS = GetGwDNS(gwNode)
}

// GetCustomDNS - gets the custom DNS of a network
Expand Down
28 changes: 26 additions & 2 deletions logic/extpeers.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,35 @@ func GetEgressRangesOnNetwork(client *models.ExtClient) ([]string, error) {

var result []string
eli, _ := (&schema.Egress{Network: client.Network}).ListByNetwork(db.WithContext(context.TODO()))
staticNode := client.ConvertToStaticNode()
userPolicies := ListUserPolicies(models.NetworkID(client.Network))
for _, eI := range eli {
if !eI.Status || eI.Range == "" {
if !eI.Status {
continue
}
result = append(result, eI.Range)
if eI.Domain == "" && eI.Range == "" {
continue
}
if eI.Domain != "" && len(eI.DomainAns) == 0 {
continue
}
rangesToBeAdded := []string{}
if eI.Domain != "" {
rangesToBeAdded = append(rangesToBeAdded, eI.DomainAns...)
} else {
rangesToBeAdded = append(rangesToBeAdded, eI.Range)
}
if staticNode.IsUserNode && staticNode.StaticNode.OwnerID != "" {
user, err := GetUser(staticNode.StaticNode.OwnerID)
if err != nil {
return []string{}, errors.New("user not found")
}
if DoesUserHaveAccessToEgress(user, &eI, userPolicies) {
result = append(result, rangesToBeAdded...)
}
} else {
result = append(result, rangesToBeAdded...)
}
}
extclients, _ := GetNetworkExtClients(client.Network)
for _, extclient := range extclients {
Expand Down
2 changes: 1 addition & 1 deletion models/extclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (ext *ExtClient) ConvertToStaticNode() Node {
Tags: ext.Tags,
IsStatic: true,
StaticNode: *ext,
IsUserNode: ext.RemoteAccessClientID != "",
IsUserNode: ext.RemoteAccessClientID != "" || ext.DeviceID != "",
Mutex: ext.Mutex,
}
}