mirror of
https://github.com/gravitl/netmaker.git
synced 2026-04-23 00:17:10 +08:00
NM-61: User group ACL fixes (#3546)
* feat(go): create default acl only for networks that are part of the group; * feat(go): update acls on user group update and delete; * feat(go): add migration for existing acls. * feat(go): check for network roles in migration.
This commit is contained in:
@@ -35,6 +35,7 @@ func Run() {
|
||||
updateHosts()
|
||||
updateNodes()
|
||||
updateAcls()
|
||||
updateNewAcls()
|
||||
logic.MigrateToGws()
|
||||
migrateToEgressV1()
|
||||
resync()
|
||||
@@ -441,6 +442,48 @@ func updateAcls() {
|
||||
}
|
||||
}
|
||||
|
||||
func updateNewAcls() {
|
||||
if servercfg.IsPro {
|
||||
userGroups, _ := logic.ListUserGroups()
|
||||
userGroupMap := make(map[models.UserGroupID]models.UserGroup)
|
||||
for _, userGroup := range userGroups {
|
||||
userGroupMap[userGroup.ID] = userGroup
|
||||
}
|
||||
|
||||
acls := logic.ListAcls()
|
||||
for _, acl := range acls {
|
||||
aclSrc := make([]models.AclPolicyTag, 0)
|
||||
for _, src := range acl.Src {
|
||||
if src.ID == models.UserGroupAclID {
|
||||
userGroup, ok := userGroupMap[models.UserGroupID(src.Value)]
|
||||
if !ok {
|
||||
// if the group doesn't exist, don't add it to the acl's src.
|
||||
continue
|
||||
} else {
|
||||
_, ok := userGroup.NetworkRoles[acl.NetworkID]
|
||||
if !ok {
|
||||
// if the group doesn't have permissions for the acl's
|
||||
// network, don't add it to the acl's src.
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
aclSrc = append(aclSrc, src)
|
||||
}
|
||||
|
||||
if len(aclSrc) == 0 {
|
||||
// if there are no acl sources, delete the acl.
|
||||
_ = logic.DeleteAcl(acl)
|
||||
} else if len(aclSrc) != len(acl.Src) {
|
||||
// if some user groups were removed from the acl source,
|
||||
// update the acl.
|
||||
acl.Src = aclSrc
|
||||
_ = logic.UpsertAcl(acl)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func MigrateEmqx() {
|
||||
|
||||
err := mq.SendPullSYN()
|
||||
|
||||
Reference in New Issue
Block a user