Skip to content
This repository has been archived by the owner on Sep 2, 2022. It is now read-only.

RBAC report: Fixes index out of range case #472

Merged
merged 1 commit into from Mar 26, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 3 additions & 4 deletions pkg/transform/cluster/cluster.go
Expand Up @@ -523,18 +523,17 @@ func (clusterReport *Report) ReportRBAC(apiResources api.Resources) {
continue
}

// if second element is serviceaccount then next element is namespace name
if splitUsername[1] == "serviceaccount" {
// if second element is serviceaccount then next element, if exists, is namespace name
if splitUsername[1] == "serviceaccount" && len(splitUsername) > 2 {
reportedSCC.Namespaces = append(reportedSCC.Namespaces, splitUsername[2])

// binary search for namespace in report and add current SCC name to it
idx = sort.Search(len(clusterReport.Namespaces), func(i int) bool {
return clusterReport.Namespaces[i].Name >= splitUsername[2]
})

if idx < len(clusterReport.Namespaces) {
clusterReport.Namespaces[idx].SecurityContextConstraints = append(clusterReport.Namespaces[idx].SecurityContextConstraints, scc.Name)
} else {
continue
}
}
}
Expand Down