Skip to content

Conversation

ahmadhamzh
Copy link
Contributor

@ahmadhamzh ahmadhamzh commented Oct 1, 2025

What this PR does / why we need it:
Use email in lowercase to generate name when creating a user object.

Which issue(s) this PR fixes:
Fixes #7617

What type of PR is this?
/kind bug

Special notes for your reviewer:
I tried to reproduce the issue but couldn’t.
I signed in with GitHub using an email with capital initials, granted a viewer role, then logged out and logged in again with Google using the same email in lowercase.
No new user was created, and the role was preserved across both logins, so both logins are treated as the same user.

I also tried adding two dummy users in the Dex config. Both had the same email, but one with capital initials. When I tried adding them to the same project, I got the error: user is already in the project. However, when I log in with either user, I can see that both are granted the same role.

project members

image

add an existing member with capital initials

Screenshot from 2025-10-02 10-44-04

Does this PR introduce a user-facing change? Then add your Release Note here:

NONE

Documentation:

NONE

@kubermatic-bot kubermatic-bot added release-note-none Denotes a PR that doesn't merit a release note. docs/none Denotes a PR that doesn't need documentation (changes). kind/bug Categorizes issue or PR as related to a bug. dco-signoff: yes Denotes that all commits in the pull request have the valid DCO signoff message. do-not-merge/code-freeze Indicates that a PR should not merge because it has not been approved for code freeze yet. sig/api Denotes a PR or issue as being assigned to SIG API. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Oct 1, 2025
@ahmadhamzh ahmadhamzh requested a review from Waseem826 October 1, 2025 13:19
@ahmadhamzh ahmadhamzh force-pushed the 7617-save-user-using-lowercase-email branch from 94f98ed to 15d62bf Compare October 2, 2025 07:51
Comment on lines 104 to 113
user := &kubermaticv1.User{
ObjectMeta: metav1.ObjectMeta{
Name: fmt.Sprintf("%x", sha256.Sum256([]byte(email))),
Name: fmt.Sprintf("%x", sha256.Sum256([]byte(strings.ToLower(email)))),
},
Spec: kubermaticv1.UserSpec{
Name: name,
Email: email,
Email: strings.ToLower(email),
Groups: groups,
},
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move the lower case conversion on top of the method after:

	if len(name) == 0 || len(email) == 0 {
		return nil, apierrors.NewBadRequest("Email, ID and Name cannot be empty when creating a new user resource")
	}

email = strings.ToLower(email)

...
...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also copy this change over to https://github.com/kubermatic/dashboard/blob/main/modules/api/pkg/provider/kubernetes/user.go#L136

// UpdateUser updates user.
func (p *UserProvider) UpdateUser(ctx context.Context, user *kubermaticv1.User) (*kubermaticv1.User, error) {
	// make sure the first patch doesn't override the status
	status := user.Status.DeepCopy()
	user.Spec.Email = strings.ToLower(user.Spec.Email)

	if err := p.runtimeClient.Update(ctx, user); err != nil {
		return nil, err
	}

...
...

@ahmadhamzh ahmadhamzh force-pushed the 7617-save-user-using-lowercase-email branch from 15d62bf to f8a59fe Compare October 6, 2025 07:28
@ahmadhamzh
Copy link
Contributor Author

/cherry-pick release/v2.28
/cherry-pick release/v2.27

@kubermatic-bot
Copy link
Contributor

@ahmadhamzh: once the present PR merges, I will cherry-pick it on top of release/v2.27, release/v2.28 in new PRs and assign them to you.

In response to this:

/cherry-pick release/v2.28
/cherry-pick release/v2.27

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

Copy link
Member

@ahmedwaleedmalik ahmedwaleedmalik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/approve

@kubermatic-bot kubermatic-bot added the lgtm Indicates that a PR is ready to be merged. label Oct 6, 2025
@kubermatic-bot
Copy link
Contributor

LGTM label has been added.

Git tree hash: 8d1bb13fff8e3084138a116714b2d58e5167147e

@kubermatic-bot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ahmedwaleedmalik

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kubermatic-bot kubermatic-bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Oct 6, 2025
@Waseem826 Waseem826 added the code-freeze-approved Indicates a PR has been approved by release managers during code freeze. label Oct 6, 2025
@kubermatic-bot kubermatic-bot removed the do-not-merge/code-freeze Indicates that a PR should not merge because it has not been approved for code freeze yet. label Oct 6, 2025
@ahmadhamzh
Copy link
Contributor Author

/retest

@kubermatic-bot kubermatic-bot merged commit 9a3d771 into kubermatic:main Oct 6, 2025
9 checks passed
@kubermatic-bot kubermatic-bot added this to the KKP 2.29 milestone Oct 6, 2025
@kubermatic-bot
Copy link
Contributor

@ahmadhamzh: new pull request created: #7634

In response to this:

/cherry-pick release/v2.28
/cherry-pick release/v2.27

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@kubermatic-bot
Copy link
Contributor

@ahmadhamzh: new pull request created: #7635

In response to this:

/cherry-pick release/v2.28
/cherry-pick release/v2.27

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. code-freeze-approved Indicates a PR has been approved by release managers during code freeze. dco-signoff: yes Denotes that all commits in the pull request have the valid DCO signoff message. docs/none Denotes a PR that doesn't need documentation (changes). kind/bug Categorizes issue or PR as related to a bug. lgtm Indicates that a PR is ready to be merged. release-note-none Denotes a PR that doesn't merit a release note. sig/api Denotes a PR or issue as being assigned to SIG API. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Case sensitivity in user email hash leads to inconsistent permissions with multiple identity providers

4 participants