Skip to content

Commit

Permalink
Merge pull request #18888 from openshift-cherrypick-robot/cherry-pick…
Browse files Browse the repository at this point in the history
…-18641-to-release-3.9

Automatic merge from submit-queue.

[release-3.9] diagnostics: AggregatedLogging ClusterRoleBindings false negative fix

This is an automated cherry-pick of #18641

/assign sosiouxme
  • Loading branch information
openshift-merge-robot authored Mar 8, 2018
2 parents 1c027c1 + 59a7133 commit 60c4264
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"k8s.io/kubernetes/pkg/apis/rbac"
)

const clusterReaderRoleBindingName = "cluster-readers"
const clusterReaderRoleBindingRoleName = "cluster-reader"

var clusterReaderRoleBindingNames = sets.NewString(fluentdServiceAccountName)

Expand All @@ -22,15 +22,20 @@ the following:

func checkClusterRoleBindings(r diagnosticReporter, adapter clusterRoleBindingsAdapter, project string) {
r.Debug("AGL0600", "Checking ClusterRoleBindings...")
crb, err := adapter.getClusterRoleBinding(clusterReaderRoleBindingName)
crbs, err := adapter.listClusterRoleBindings()
if err != nil {
r.Error("AGL0605", err, fmt.Sprintf("There was an error while trying to retrieve the ClusterRoleBindings for the logging stack: %s", err))
return
}
boundServiceAccounts := sets.NewString()
for _, subject := range crb.Subjects {
if subject.Kind == rbac.ServiceAccountKind && subject.Namespace == project {
boundServiceAccounts.Insert(subject.Name)
for _, crb := range crbs.Items {
if crb.RoleRef.Name != clusterReaderRoleBindingRoleName {
continue
}
for _, subject := range crb.Subjects {
if subject.Kind == rbac.ServiceAccountKind && subject.Namespace == project {
boundServiceAccounts.Insert(subject.Name)
}
}
}
for _, name := range clusterReaderRoleBindingNames.List() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,36 @@ import (

type fakeRoleBindingDiagnostic struct {
fakeDiagnostic
fakeClusterRoleBinding authapi.ClusterRoleBinding
fakeClusterRoleBindingList authapi.ClusterRoleBindingList
}

func newFakeRoleBindingDiagnostic(t *testing.T) *fakeRoleBindingDiagnostic {
return &fakeRoleBindingDiagnostic{
fakeDiagnostic: *newFakeDiagnostic(t),
fakeDiagnostic: *newFakeDiagnostic(t),
fakeClusterRoleBindingList: authapi.ClusterRoleBindingList{},
}
}

func (f *fakeRoleBindingDiagnostic) getClusterRoleBinding(name string) (*authapi.ClusterRoleBinding, error) {
func (f *fakeRoleBindingDiagnostic) listClusterRoleBindings() (*authapi.ClusterRoleBindingList, error) {
if f.err != nil {
return nil, f.err
}
return &f.fakeClusterRoleBinding, nil
return &f.fakeClusterRoleBindingList, nil
}
func (f *fakeRoleBindingDiagnostic) addBinding(name string, namespace string) {
ref := kapi.ObjectReference{
Name: name,
Kind: rbac.ServiceAccountKind,
Namespace: namespace,
}
f.fakeClusterRoleBinding.Subjects = append(f.fakeClusterRoleBinding.Subjects, ref)
if len(f.fakeClusterRoleBindingList.Items) == 0 {
f.fakeClusterRoleBindingList.Items = append(f.fakeClusterRoleBindingList.Items, authapi.ClusterRoleBinding{
RoleRef: kapi.ObjectReference{
Name: clusterReaderRoleBindingRoleName,
},
})
}
f.fakeClusterRoleBindingList.Items[0].Subjects = append(f.fakeClusterRoleBindingList.Items[0].Subjects, ref)
}

// Test error when client error
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ func (d *AggregatedLogging) getScc(name string) (*securityapi.SecurityContextCon
return d.SCCClient.SecurityContextConstraints().Get(name, metav1.GetOptions{})
}

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

func (d *AggregatedLogging) routes(project string, options metav1.ListOptions) (*routesapi.RouteList, error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type sccAdapter interface {
}

type clusterRoleBindingsAdapter interface {
getClusterRoleBinding(name string) (*authapi.ClusterRoleBinding, error)
listClusterRoleBindings() (*authapi.ClusterRoleBindingList, error)
}

//deploymentConfigAdapter is an abstraction to retrieve resource for validating dcs
Expand Down

0 comments on commit 60c4264

Please sign in to comment.