Skip to content

Instantly share code, notes, and snippets.

Forked from dnozay/
Created Aug 21, 2020
What would you like to do?
Collection of useful stuff for interacting with gitlab.

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: "")
# 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

Re-enable standard login

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

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,
}'', 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


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