Skip to content

Commit

Permalink
add sap.ids: prefix to admin users
Browse files Browse the repository at this point in the history
  • Loading branch information
szeort committed Sep 30, 2024
1 parent 95bb5a7 commit c3cf655
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions controllers/cfapi_auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import (
"sigs.k8s.io/controller-runtime/pkg/log"
)

const OIDC_USER_PREFIX = "sap.ids:"

func (r *CFAPIReconciler) getUserClusterAdmins(ctx context.Context) ([]rbacv1.Subject, error) {
subjects := []rbacv1.Subject{}
crblist := &rbacv1.ClusterRoleBindingList{}
Expand Down Expand Up @@ -67,6 +69,13 @@ func (r *CFAPIReconciler) assignCfAdministrators(ctx context.Context, subjects [
}
}

//add prefix sap.ids: for all user names without prefix
for _, subject := range _subjects {
if subject.Kind == "User" && !strings.HasPrefix(subject.Name, OIDC_USER_PREFIX) {
subject.Name = OIDC_USER_PREFIX + subject.Name
}
}

rb := &rbacv1.RoleBinding{
ObjectMeta: metav1.ObjectMeta{
Name: "cfapi-admins-binding",
Expand Down

0 comments on commit c3cf655

Please sign in to comment.