Skip to content

Commit 83008e2

Browse files
authored
Display namespace when SUBJECT is a ServiceAccount (#113)
* Display namespace when SUBJECT is a ServiceAccount * Replace : with / in ServiceAccount name
1 parent 4b6041b commit 83008e2

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

cmd/policyrules_cmd.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ import (
66
"fmt"
77
"os"
88
"regexp"
9-
"sigs.k8s.io/yaml"
109
"sort"
1110
"strings"
1211

12+
"sigs.k8s.io/yaml"
13+
1314
"github.com/alcideio/rbac-tool/pkg/kube"
1415
"github.com/alcideio/rbac-tool/pkg/rbac"
1516
"github.com/olekukonko/tablewriter"
@@ -110,10 +111,18 @@ rbac-tool policy-rules -o json | jp "[? @.allowedTo[? (verb=='get' || verb=='*'
110111
policies := rbac.NewSubjectPermissionsList(filteredPolicies)
111112

112113
for _, p := range policies {
114+
115+
var subject string
116+
if p.Subject.Kind == "ServiceAccount" {
117+
subject = fmt.Sprintf("%v/%v", p.Subject.Namespace, p.Subject.Name)
118+
} else {
119+
subject = p.Subject.Name
120+
}
121+
113122
for _, allowedTo := range p.AllowedTo {
114123
row := []string{
115124
p.Kind,
116-
p.Name,
125+
subject,
117126
allowedTo.Verb,
118127
allowedTo.Namespace,
119128
allowedTo.APIGroup,

0 commit comments

Comments
 (0)