Skip to content

Commit c450bb0

Browse files
authored
add egress ips by access to user configs (#3659) (#3660)
2 parents fbc0f69 + d1b82aa commit c450bb0

File tree

4 files changed

+40
-6
lines changed

4 files changed

+40
-6
lines changed

logic/acls.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1465,6 +1465,18 @@ func GetDefaultPolicy(netID models.NetworkID, ruleType models.AclPolicyType) (mo
14651465
return acl, nil
14661466
}
14671467

1468+
// ListUserPolicies - lists all user policies in a network
1469+
func ListUserPolicies(netID models.NetworkID) []models.Acl {
1470+
allAcls := ListAcls()
1471+
userAcls := []models.Acl{}
1472+
for _, acl := range allAcls {
1473+
if acl.NetworkID == netID && acl.RuleType == models.UserPolicy {
1474+
userAcls = append(userAcls, acl)
1475+
}
1476+
}
1477+
return userAcls
1478+
}
1479+
14681480
// ListAcls - lists all acl policies
14691481
func ListAclsByNetwork(netID models.NetworkID) ([]models.Acl, error) {
14701482

logic/dns.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,9 +226,7 @@ func GetGwDNS(node *models.Node) string {
226226
}
227227

228228
func SetDNSOnWgConfig(gwNode *models.Node, extclient *models.ExtClient) {
229-
if extclient.DNS == "" {
230-
extclient.DNS = GetGwDNS(gwNode)
231-
}
229+
extclient.DNS = GetGwDNS(gwNode)
232230
}
233231

234232
// GetCustomDNS - gets the custom DNS of a network

logic/extpeers.go

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,35 @@ func GetEgressRangesOnNetwork(client *models.ExtClient) ([]string, error) {
7171

7272
var result []string
7373
eli, _ := (&schema.Egress{Network: client.Network}).ListByNetwork(db.WithContext(context.TODO()))
74+
staticNode := client.ConvertToStaticNode()
75+
userPolicies := ListUserPolicies(models.NetworkID(client.Network))
7476
for _, eI := range eli {
75-
if !eI.Status || eI.Range == "" {
77+
if !eI.Status {
7678
continue
7779
}
78-
result = append(result, eI.Range)
80+
if eI.Domain == "" && eI.Range == "" {
81+
continue
82+
}
83+
if eI.Domain != "" && len(eI.DomainAns) == 0 {
84+
continue
85+
}
86+
rangesToBeAdded := []string{}
87+
if eI.Domain != "" {
88+
rangesToBeAdded = append(rangesToBeAdded, eI.DomainAns...)
89+
} else {
90+
rangesToBeAdded = append(rangesToBeAdded, eI.Range)
91+
}
92+
if staticNode.IsUserNode && staticNode.StaticNode.OwnerID != "" {
93+
user, err := GetUser(staticNode.StaticNode.OwnerID)
94+
if err != nil {
95+
return []string{}, errors.New("user not found")
96+
}
97+
if DoesUserHaveAccessToEgress(user, &eI, userPolicies) {
98+
result = append(result, rangesToBeAdded...)
99+
}
100+
} else {
101+
result = append(result, rangesToBeAdded...)
102+
}
79103
}
80104
extclients, _ := GetNetworkExtClients(client.Network)
81105
for _, extclient := range extclients {

models/extclient.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func (ext *ExtClient) ConvertToStaticNode() Node {
6666
Tags: ext.Tags,
6767
IsStatic: true,
6868
StaticNode: *ext,
69-
IsUserNode: ext.RemoteAccessClientID != "",
69+
IsUserNode: ext.RemoteAccessClientID != "" || ext.DeviceID != "",
7070
Mutex: ext.Mutex,
7171
}
7272
}

0 commit comments

Comments
 (0)