Skip to content

Commit

Permalink
Display namespace when SUBJECT is a ServiceAccount (#113)
Browse files Browse the repository at this point in the history
* Display namespace when SUBJECT is a ServiceAccount

* Replace : with / in ServiceAccount name
  • Loading branch information
fjammes authored Oct 29, 2024
1 parent 4b6041b commit 83008e2
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions cmd/policyrules_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import (
"fmt"
"os"
"regexp"
"sigs.k8s.io/yaml"
"sort"
"strings"

"sigs.k8s.io/yaml"

"github.com/alcideio/rbac-tool/pkg/kube"
"github.com/alcideio/rbac-tool/pkg/rbac"
"github.com/olekukonko/tablewriter"
Expand Down Expand Up @@ -110,10 +111,18 @@ rbac-tool policy-rules -o json | jp "[? @.allowedTo[? (verb=='get' || verb=='*'
policies := rbac.NewSubjectPermissionsList(filteredPolicies)

for _, p := range policies {

var subject string
if p.Subject.Kind == "ServiceAccount" {
subject = fmt.Sprintf("%v/%v", p.Subject.Namespace, p.Subject.Name)
} else {
subject = p.Subject.Name
}

for _, allowedTo := range p.AllowedTo {
row := []string{
p.Kind,
p.Name,
subject,
allowedTo.Verb,
allowedTo.Namespace,
allowedTo.APIGroup,
Expand Down

0 comments on commit 83008e2

Please sign in to comment.