Skip to content

Commit 3f9089a

Browse files
committed
fix: update impersonated username to use user email, and avoid project creation if user is not active
1 parent 9201dc7 commit 3f9089a

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

internal/controller/resourcemanager/personal_organization_controller.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"encoding/hex"
88
"fmt"
99
"hash/fnv"
10+
"time"
1011

1112
apierrors "k8s.io/apimachinery/pkg/api/errors"
1213
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -129,6 +130,13 @@ func (r *PersonalOrganizationController) Reconcile(ctx context.Context, req ctrl
129130
return ctrl.Result{}, fmt.Errorf("failed to create or update organization membership: %w", err)
130131
}
131132

133+
// If the user is not active, we should not create a personal project,
134+
// as the impersonated client will not have the correct permissions.
135+
if user.Status.RegistrationApproval != iamv1alpha1.RegistrationApprovalStateApproved {
136+
logger.Info("User is not active, skipping personal project creation", "user", user.Name, "state", user.Status.State)
137+
return ctrl.Result{RequeueAfter: 5 * time.Second}, nil
138+
}
139+
132140
// Create a default personal project in the personal organization.
133141
personalProjectID := hashPersonalOrgName(string(user.UID))
134142
personalProject := &resourcemanagerv1alpha1.Project{
@@ -153,7 +161,7 @@ func (r *PersonalOrganizationController) Reconcile(ctx context.Context, req ctrl
153161
// sees the correct identity and creates the right PolicyBinding.
154162
impersonatedConfig := rest.CopyConfig(r.RestConfig)
155163
impersonatedConfig.Impersonate = rest.ImpersonationConfig{
156-
UserName: user.Name,
164+
UserName: user.Spec.Email,
157165
UID: user.Name,
158166
Groups: []string{"system:authenticated"},
159167
Extra: map[string][]string{

0 commit comments

Comments
 (0)