Skip to content

Commit

Permalink
NET-1784: Migrate All Policies (#3245)
Browse files Browse the repository at this point in the history
* migrate all policies

* migrate all policies

* add acl policy type for any traffic

* use any service type for migration
  • Loading branch information
abhishek9686 authored Dec 10, 2024
1 parent a2c7c25 commit 7093373
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 31 deletions.
8 changes: 8 additions & 0 deletions controllers/acls.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ func aclPolicyTypes(w http.ResponseWriter, r *http.Request) {
// models.NetmakerSubNetRangeAClID,
},
ProtocolTypes: []models.ProtocolType{
{
Name: models.Any,
AllowedProtocols: []models.Protocol{
models.ALL,
},
PortRange: "All ports",
AllowPortSetting: false,
},
{
Name: models.Http,
AllowedProtocols: []models.Protocol{
Expand Down
40 changes: 10 additions & 30 deletions logic/acls.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,37 +18,17 @@ var (
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)
//}
func MigrateAclPolicies() {
acls := ListAcls()
for _, acl := range acls {
if acl.Proto.String() == "" {
acl.Proto = models.ALL
acl.ServiceType = models.Any
acl.Port = []string{}
UpsertAcl(acl)
}
}

}

// CreateDefaultAclNetworkPolicies - create default acl network policies
Expand Down
3 changes: 2 additions & 1 deletion migrate/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,7 @@ func createDefaultTagsAndPolicies() {
for _, network := range networks {
logic.CreateDefaultTags(models.NetworkID(network.NetID))
logic.CreateDefaultAclNetworkPolicies(models.NetworkID(network.NetID))
logic.MigrateDefaulAclPolicies(models.NetworkID(network.NetID))

}
logic.MigrateAclPolicies()
}
1 change: 1 addition & 0 deletions models/acl.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const (
AllUDP = "All UDP"
ICMPService = "ICMP"
Custom = "Custom"
Any = "Any"
)

func (p Protocol) String() string {
Expand Down

0 comments on commit 7093373

Please sign in to comment.