@@ -19,17 +19,20 @@ import (
1919 "fmt"
2020 "os"
2121 "strings"
22+
23+ "github.com/AthenZ/athenz/clients/go/zms"
2224)
2325
2426// Util - struct with 2 fields adminDomain and list of system namespaces
2527type Util struct {
2628 adminDomain string
2729 systemNamespaces []string
2830 excludeNamespaces map [string ]bool
31+ excludeMSDRules bool
2932}
3033
3134// NewUtil - create new Util object
32- func NewUtil (adminDomain string , systemNamespaces []string , excludeNamespaces []string ) * Util {
35+ func NewUtil (adminDomain string , systemNamespaces []string , excludeNamespaces []string , excludeMSDRules bool ) * Util {
3336 excludedNamespaceMap := make (map [string ]bool )
3437 for _ , ns := range excludeNamespaces {
3538 excludedNamespaceMap [ns ] = true
@@ -39,6 +42,7 @@ func NewUtil(adminDomain string, systemNamespaces []string, excludeNamespaces []
3942 adminDomain : adminDomain ,
4043 systemNamespaces : systemNamespaces ,
4144 excludeNamespaces : excludedNamespaceMap ,
45+ excludeMSDRules : excludeMSDRules ,
4246 }
4347}
4448
@@ -124,3 +128,45 @@ func HomeDir() string {
124128 }
125129 return os .Getenv ("USERPROFILE" ) // windows
126130}
131+
132+ func filterMSDRules (domain * zms.DomainData ) * zms.DomainData {
133+ domainName := string (domain .Name )
134+ var filteredRoles []* zms.Role
135+ var filteredPolicies []* zms.Policy
136+ // Filter out roles where the names starts with "domainName:role.acl." which are MSD roles
137+ // Filter out roles that start with "domainName:role.msd-read-role-"
138+ for _ , role := range domain .Roles {
139+ roleName := string (role .Name )
140+ aclPrefix := domainName + ":role.acl."
141+ msdReadPrefix := domainName + ":role.msd-read-role-"
142+ if strings .HasPrefix (roleName , aclPrefix ) ||
143+ strings .HasPrefix (roleName , msdReadPrefix ) {
144+ continue
145+ }
146+ filteredRoles = append (filteredRoles , role )
147+ }
148+ domain .Roles = filteredRoles
149+
150+ // Filter out policies start with "domainName:policy.acl." which are MSD policies
151+ // Filter out policies start with "domainName:policy.msd-read-policy-"
152+ for _ , policy := range domain .Policies .Contents .Policies {
153+ policyName := string (policy .Name )
154+ aclPrefix := domainName + ":policy.acl."
155+ msdReadPrefix := domainName + ":policy.msd-read-policy-"
156+ if strings .HasPrefix (policyName , aclPrefix ) ||
157+ strings .HasPrefix (policyName , msdReadPrefix ) {
158+ continue
159+ }
160+ filteredPolicies = append (filteredPolicies , policy )
161+ }
162+ domain .Policies .Contents .Policies = filteredPolicies
163+
164+ return domain
165+ }
166+
167+ func (u * Util ) FilterMSDRules (domainData * zms.DomainData ) * zms.DomainData {
168+ if ! u .excludeMSDRules {
169+ return domainData
170+ }
171+ return filterMSDRules (domainData )
172+ }
0 commit comments