Skip to content

Instantly share code, notes, and snippets.

@dnozay dnozay/README.md
Last active Oct 2, 2019

Embed
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: "admin@example.com")
# 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
@ghost

This comment has been minimized.

Copy link

commented Feb 6, 2018

Do you know of a way to interact with gitlab-rails console non-interactive via a script?

@Fobhep

This comment has been minimized.

Copy link

commented Feb 12, 2018

@mdebord1 try this:
echo 'user = User.find_by(username: "root");user.password="secret_pass!";user.password_confirmation="secret_pass!";user.save' | gitlab-rails console

not very nice, but functional

@danger89

This comment has been minimized.

Copy link

commented Oct 16, 2018

I can not exit this console. I tried Ctrl+C. I tried exit q I don't know anymore.
Finally: exit().

@mooreofthesame

This comment has been minimized.

Copy link

commented Sep 12, 2019

I can not exit this console. I tried Ctrl+C. I tried exit q I don't know anymore.
Finally: exit().

To exit the console, you can hit Ctrl+d (this is the same as EOF, or End Of File)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.