From c3cf655136aac5f5927efd6bf705511413c56dcd Mon Sep 17 00:00:00 2001 From: Zeort Date: Mon, 30 Sep 2024 15:05:41 +0300 Subject: [PATCH] add sap.ids: prefix to admin users --- controllers/cfapi_auth.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/controllers/cfapi_auth.go b/controllers/cfapi_auth.go index 135777c..4f7e7eb 100644 --- a/controllers/cfapi_auth.go +++ b/controllers/cfapi_auth.go @@ -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{} @@ -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",