Skip to content

Commit

Permalink
NET-1784: Adv Acl Rules (#3239)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
abhishek9686 authored Dec 10, 2024
1 parent 31c2311 commit f124b10
Show file tree
Hide file tree
Showing 12 changed files with 707 additions and 118 deletions.
80 changes: 71 additions & 9 deletions controllers/acls.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,73 @@ func aclPolicyTypes(w http.ResponseWriter, r *http.Request) {
// models.NetmakerIPAclID,
// 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")
}
Expand All @@ -69,7 +136,7 @@ func aclDebug(w http.ResponseWriter, r *http.Request) {
logic.ReturnErrorResponse(w, r, logic.FormatError(err, "badrequest"))
return
}
allowed := logic.IsNodeAllowedToCommunicate(node, peer, true)
allowed, _ := logic.IsNodeAllowedToCommunicate(node, peer, true)
logic.ReturnSuccessResponseWithJson(w, r, allowed, "fetched all acls in the network ")
}

Expand Down Expand Up @@ -132,11 +199,6 @@ func createAcl(w http.ResponseWriter, r *http.Request) {
acl.CreatedBy = user.UserName
acl.CreatedAt = time.Now().UTC()
acl.Default = false
if acl.RuleType == models.DevicePolicy {
acl.AllowedDirection = models.TrafficDirectionBi
} else {
acl.AllowedDirection = models.TrafficDirectionUni
}
// validate create acl policy
if !logic.IsAclPolicyValid(acl) {
logic.ReturnErrorResponse(w, r, logic.FormatError(errors.New("invalid policy"), "badrequest"))
Expand All @@ -152,7 +214,7 @@ func createAcl(w http.ResponseWriter, r *http.Request) {
logic.ReturnErrorResponse(w, r, logic.FormatError(err, "internal"))
return
}
go mq.PublishPeerUpdate(false)
go mq.PublishPeerUpdate(true)
logic.ReturnSuccessResponseWithJson(w, r, acl, "created acl successfully")
}

Expand Down Expand Up @@ -194,7 +256,7 @@ func updateAcl(w http.ResponseWriter, r *http.Request) {
logic.ReturnErrorResponse(w, r, logic.FormatError(err, "badrequest"))
return
}
go mq.PublishPeerUpdate(false)
go mq.PublishPeerUpdate(true)
logic.ReturnSuccessResponse(w, r, "updated acl "+acl.Name)
}

Expand Down Expand Up @@ -225,6 +287,6 @@ func deleteAcl(w http.ResponseWriter, r *http.Request) {
logic.FormatError(errors.New("cannot delete default policy"), "internal"))
return
}
go mq.PublishPeerUpdate(false)
go mq.PublishPeerUpdate(true)
logic.ReturnSuccessResponse(w, r, "deleted acl "+acl.Name)
}
Loading

0 comments on commit f124b10

Please sign in to comment.