Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f6b0835

Browse files
authored
fix: avoid processing updates to usernames (#3571)
- With the support of OIDC we began processing updates to a user's email and username to stay in sync with the upstream provider. This can cause issues in templates that use the user's username as a stable identifier, potentially causing the deletion of user's home volumes. - Fix some faulty error wrapping.
1 parent 04c5f92 commit f6b0835

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

coderd/userauth.go

+8-7
Original file line numberDiff line numberDiff line change
@@ -229,13 +229,13 @@ func (api *API) userOAuth2Github(rw http.ResponseWriter, r *http.Request) {
229229
if link.LinkedID == "" {
230230
link, err = api.Database.UpdateUserLinkedID(ctx, database.UpdateUserLinkedIDParams{
231231
UserID: user.ID,
232-
LinkedID: githubLinkedID(ghUser),
233232
LoginType: database.LoginTypeGithub,
233+
LinkedID: githubLinkedID(ghUser),
234234
})
235235
if err != nil {
236236
httpapi.Write(rw, http.StatusInternalServerError, codersdk.Response{
237237
Message: "A database error occurred.",
238-
Detail: xerrors.Errorf("update user link: %w", err.Error).Error(),
238+
Detail: fmt.Sprintf("update user link: %s", err.Error()),
239239
})
240240
return
241241
}
@@ -437,13 +437,13 @@ func (api *API) userOIDC(rw http.ResponseWriter, r *http.Request) {
437437
if link.LinkedID == "" {
438438
link, err = api.Database.UpdateUserLinkedID(ctx, database.UpdateUserLinkedIDParams{
439439
UserID: user.ID,
440+
LoginType: database.LoginTypeOIDC,
440441
LinkedID: oidcLinkedID(idToken),
441-
LoginType: database.LoginTypeGithub,
442442
})
443443
if err != nil {
444444
httpapi.Write(rw, http.StatusInternalServerError, codersdk.Response{
445445
Message: "A database error occurred.",
446-
Detail: xerrors.Errorf("update user link: %w", err.Error).Error(),
446+
Detail: fmt.Sprintf("update user link: %s", err.Error()),
447447
})
448448
return
449449
}
@@ -477,9 +477,10 @@ func (api *API) userOIDC(rw http.ResponseWriter, r *http.Request) {
477477
// longer sign in until an administrator finds the offending built-in
478478
// user and changes their username.
479479
user, err = api.Database.UpdateUserProfile(ctx, database.UpdateUserProfileParams{
480-
ID: user.ID,
481-
Email: claims.Email,
482-
Username: claims.Username,
480+
ID: user.ID,
481+
Email: claims.Email,
482+
// TODO: This should run in a transaction.
483+
Username: user.Username,
483484
UpdatedAt: database.Now(),
484485
})
485486
if err != nil {

0 commit comments

Comments
 (0)