Skip to content

Instantly share code, notes, and snippets.

@fontenele
Forked from dnozay/README.md
Last active August 29, 2015 14:21
Show Gist options
  • Save fontenele/acd633e606f3741de093 to your computer and use it in GitHub Desktop.
Save fontenele/acd633e606f3741de093 to your computer and use it in GitHub Desktop.

Reset root/admin password

Lost the root/admin password? You can reset it using the command-line. Recipe adapted from gitlab issue #308.

# start the console
sudo gitlab-rails console

Then in the ruby interpreter:

# find the user:
# user = User.find_by(email: "[email protected]")
# user = User.find_by(username: "root")
# user = User.find_by(name: "Administrator")
# user = User.find_by(admin: true)
user = User.find_by(username: "root")

# change the password
# or use the ask function from 'highline/import'
user.password = 'secret_pass'
user.password_confirmation = 'secret_pass'

# and save
user.save

Re-enable standard login

# locate application settings
# ApplicationSetting.find_each
appsettings = ApplicationSetting.find_by(signin_enabled: false)
appsettings.signin_enabled = true
appsettings.save

Pre-populate users

I have found that you can just post the info with your admin token:

import requests
headers = { 'PRIVATE-TOKEN' : 'insert-token-here' }
data = {
    'email': email,
    'extern_uid': dn,
    "provider": "ldapmain",
    "name": name,
    "username": username,
    'password': '1234567890',
    "confirm": False,
}
requests.post('https://gitlab.example.com/api/v3/users/', data, headers=headers)

I get the email, dn, name, username from ldap by using python-ldap; I use a filter to only match engineers. The password is required, but you can use a dummy value that matches the security parameters (min 8 characters ...etc)

Pre-confirm users

In case you missed to add confirm=false when creating users.

gitlab-rails console production

then

for user in User.where(confirmed_at: nil) do
    user.confirmed_at = Time.now
    user.confirmation_token = nil
    user.save!
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment