Skip to content

Commit

Permalink
Add groups in impersonate clusterrole (#23)
Browse files Browse the repository at this point in the history
Signed-off-by: Rokibul Hasan <mdrokibulhasan@appscode.com>
  • Loading branch information
RokibulHasan7 authored Sep 9, 2024
1 parent c6df803 commit b972916
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
20 changes: 13 additions & 7 deletions pkg/agent/controller/managedclusterrolebinding_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,7 @@ func (r *ManagedClusterRoleBindingReconciler) Reconcile(ctx context.Context, req
}

// now give actual permission to the User
sub := []rbac.Subject{
{
APIGroup: "",
Kind: "User",
Name: managedCRB.Subjects[0].Name,
},
}
sub := getSubject(managedCRB)

if managedCRB.RoleRef.Namespaces == nil {
givenClusterRolebinding := &rbac.ClusterRoleBinding{
Expand Down Expand Up @@ -210,6 +204,18 @@ func (r *ManagedClusterRoleBindingReconciler) SetupWithManager(mgr ctrl.Manager)
Complete(r)
}

func getSubject(managedCRB authzv1alpah1.ManagedClusterRoleBinding) []rbac.Subject {
subs := make([]rbac.Subject, 0, len(managedCRB.Subjects))
for _, sub := range managedCRB.Subjects {
subs = append(subs, rbac.Subject{
APIGroup: sub.APIGroup,
Kind: sub.Kind,
Name: sub.Name,
})
}
return subs
}

/*
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
Expand Down
6 changes: 6 additions & 0 deletions pkg/manager/controller/authentication/account_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,12 @@ func (r *AccountReconciler) createClusterRoleAndClusterRoleBindingToImpersonate(
Verbs: []string{"impersonate"},
ResourceNames: []string{acc.Name},
},
{
APIGroups: []string{""},
Resources: []string{"groups"},
Verbs: []string{"impersonate"},
ResourceNames: acc.Spec.Groups,
},
},
}

Expand Down

0 comments on commit b972916

Please sign in to comment.