Skip to content

Commit f5fe442

Browse files
committed
Printing rbac policies per namespace
1 parent e2748c7 commit f5fe442

File tree

1 file changed

+10
-15
lines changed

1 file changed

+10
-15
lines changed

pkg/collect/cluster_resources.go

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/replicatedhq/troubleshoot/pkg/redact"
1010
authorizationv1 "k8s.io/api/authorization/v1"
1111
corev1 "k8s.io/api/core/v1"
12+
rbacv1 "k8s.io/api/rbac/v1"
1213
apiextensionsv1beta1clientset "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset/typed/apiextensions/v1beta1"
1314
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1415
"k8s.io/client-go/kubernetes"
@@ -33,8 +34,10 @@ type ClusterResourcesOutput struct {
3334
ImagePullSecretsErrors []byte `json:"cluster-resources/image-pull-secrets-errors.json,omitempty"`
3435
Nodes []byte `json:"cluster-resources/nodes.json,omitempty"`
3536
NodesErrors []byte `json:"cluster-resources/nodes-errors.json,omitempty"`
36-
AuthCanI map[string][]byte `json:"cluster-resources/auth-cani-list,omitempty"`
37-
AuthCanIErrors []byte `json:"cluster-resources/auth-cani-list-errors.json,omitempty"`
37+
38+
// TODO these should be considered for relocation to an rbac or auth package. cluster resources might not be the right place
39+
AuthCanI map[string][]byte `json:"cluster-resources/auth-cani-list,omitempty"`
40+
AuthCanIErrors []byte `json:"cluster-resources/auth-cani-list-errors.json,omitempty"`
3841
}
3942

4043
func ClusterResources(ctx *Context) ([]byte, error) {
@@ -378,7 +381,6 @@ func authCanI(client *kubernetes.Clientset, namespaces []string) (map[string][]b
378381
errorsByNamespace := make(map[string]string)
379382

380383
for _, namespace := range namespaces {
381-
fmt.Println(namespace)
382384
sar := &authorizationv1.SelfSubjectRulesReview{
383385
Spec: authorizationv1.SelfSubjectRulesReviewSpec{
384386
Namespace: namespace,
@@ -390,24 +392,17 @@ func authCanI(client *kubernetes.Clientset, namespaces []string) (map[string][]b
390392
continue
391393
}
392394

393-
// // breakdownRules := []rbacv1.PolicyRule{}
394-
// // for _, rule := range convertToPolicyRule(response.Status) {
395-
// // breakdownRules = append(breakdownRules, rbacutil.BreakdownRule(rule)...)
396-
// // }
397-
398-
// // compactRules, err := rbacutil.CompactRules(breakdownRules)
399-
// // if err != nil {
400-
// // errorsByNamespace[namespace] = err.Error()
401-
// // continue
402-
// // }
395+
rules := []rbacv1.PolicyRule{}
396+
for _, rule := range convertToPolicyRule(response.Status) {
397+
rules = append(rules, rule)
398+
}
403399

404-
b, err := json.MarshalIndent(response.Status, "", " ")
400+
b, err := json.MarshalIndent(rules, "", " ")
405401
if err != nil {
406402
errorsByNamespace[namespace] = err.Error()
407403
continue
408404
}
409405

410-
fmt.Printf("%s\n", b)
411406
authListByNamespace[namespace+".json"] = b
412407
}
413408

0 commit comments

Comments
 (0)