Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NET-1784: Migrate All Policies #3245

Merged
merged 4 commits into from
Dec 10, 2024
Merged
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
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
Loading