How to update the Primary email address of multiple users - LDAP and SAML
Task
Administrators need to update Primary email addresses for multiple users. This can happen when self-managed instances change Identity providers (e.g. LDAP, SAML, etc.) and the email domain needs to be updated.
-
Applicable offerings:
- GitLab Self-Managed
Instructions
Administators can use the following Rails console commands to bulk change user email domains. Substitute <old_domain> and <new_domain> with the old and new email domain values.
# old account primary email address
user@old_domain.com
# new account primary email address
user@new_domain.com
-
Start a rails console session
-
Perform a dry-run to confirm which emails will be updated.
User.find_each do | user | old_email = user.email new_email = old_email.gsub("<old_domain>","<new_domain>") # this will only change users with the old_domain and not update other email domains puts "#{user.name}, #{old_email}, #{new_email}" end
-
If the updates look correct, apply the changes.
User.find_each do | user | old_email = user.email new_email = old_email.gsub("<old_domain>","<new_domain>") # this will only change users with the old_domain and not update other email domains puts "#{user.name}, #{old_email}, #{new_email}" user.email = new_email user.skip_confirmation! user.save! end
Additional information
- SAML users need to unlink and link their new identities after making the changes.
- Users can manually update their primary email from the UI