Skip to content

Commit 72d68a3

Browse files
author
Jan Wozniak
committed
diagnostics: AggregatedLogging ClusterRoleBindings false positive fix
The clusterRoleBindings check can output false alarm even if `cluster-reader` role is assigned to fluentd service account and logging works as expected. The check used to query for `cluster-readers` CRB, but the common command `oc adm policy add-cluster-role-to-user cluster-reader system:serviceaccount:logging:aggregated-logging-fluentd` no longer appers to add the SA into `cluster-readers` group but instead creates cluster-reader-1 CRB. ``` $ oc get clusterrolebindings cluster-readers -o yaml ... roleRef: name: cluster-reader ... userNames: null $ oc get clusterrolebindings NAME ROLE USERS GROUPS SERVICE ACCOUNTS SUBJECTS ... cluster-reader /cluster-reader management-infra/management-admin cluster-reader-0 /cluster-reader default/router cluster-reader-1 /cluster-reader logging/aggregated-logging-fluentd cluster-readers /cluster-reader system:cluster-readers ... ``` This fix queries all clusterrolebindings, iterates over those, that have role `cluster-reader` and then validates there is a `cluster-reader` entry for `system:serviceaccount:logging:aggregated-logging-fluentd`
1 parent ddb6d36 commit 72d68a3

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

pkg/oc/admin/diagnostics/diagnostics/cluster/aggregated_logging/clusterrolebindings.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"k8s.io/kubernetes/pkg/apis/rbac"
88
)
99

10-
const clusterReaderRoleBindingName = "cluster-readers"
10+
const clusterReaderRoleBindingRoleName = "cluster-reader"
1111

1212
var clusterReaderRoleBindingNames = sets.NewString(fluentdServiceAccountName)
1313

@@ -22,15 +22,20 @@ the following:
2222

2323
func checkClusterRoleBindings(r diagnosticReporter, adapter clusterRoleBindingsAdapter, project string) {
2424
r.Debug("AGL0600", "Checking ClusterRoleBindings...")
25-
crb, err := adapter.getClusterRoleBinding(clusterReaderRoleBindingName)
25+
crbs, err := adapter.listClusterRoleBindings()
2626
if err != nil {
2727
r.Error("AGL0605", err, fmt.Sprintf("There was an error while trying to retrieve the ClusterRoleBindings for the logging stack: %s", err))
2828
return
2929
}
3030
boundServiceAccounts := sets.NewString()
31-
for _, subject := range crb.Subjects {
32-
if subject.Kind == rbac.ServiceAccountKind && subject.Namespace == project {
33-
boundServiceAccounts.Insert(subject.Name)
31+
for _, crb := range crbs.Items {
32+
if crb.RoleRef.Name != clusterReaderRoleBindingRoleName {
33+
continue
34+
}
35+
for _, subject := range crb.Subjects {
36+
if subject.Kind == rbac.ServiceAccountKind {
37+
boundServiceAccounts.Insert(subject.Name)
38+
}
3439
}
3540
}
3641
for _, name := range clusterReaderRoleBindingNames.List() {

pkg/oc/admin/diagnostics/diagnostics/cluster/aggregated_logging/diagnostic.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ func (d *AggregatedLogging) getScc(name string) (*securityapi.SecurityContextCon
8686
return d.SCCClient.SecurityContextConstraints().Get(name, metav1.GetOptions{})
8787
}
8888

89-
func (d *AggregatedLogging) getClusterRoleBinding(name string) (*authapi.ClusterRoleBinding, error) {
90-
return d.CRBClient.ClusterRoleBindings().Get(name, metav1.GetOptions{})
89+
func (d *AggregatedLogging) listClusterRoleBindings() (*authapi.ClusterRoleBindingList, error) {
90+
return d.CRBClient.ClusterRoleBindings().List(metav1.ListOptions{})
9191
}
9292

9393
func (d *AggregatedLogging) routes(project string, options metav1.ListOptions) (*routesapi.RouteList, error) {

pkg/oc/admin/diagnostics/diagnostics/cluster/aggregated_logging/interfaces.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ type sccAdapter interface {
2828
}
2929

3030
type clusterRoleBindingsAdapter interface {
31-
getClusterRoleBinding(name string) (*authapi.ClusterRoleBinding, error)
31+
listClusterRoleBindings() (*authapi.ClusterRoleBindingList, error)
3232
}
3333

3434
//deploymentConfigAdapter is an abstraction to retrieve resource for validating dcs

0 commit comments

Comments
 (0)