27

I've just setup gitlab, but I'm completely lost with regards to admin user. The wiki seems silent about this topic, and google hasn't been of help either.

So, how do I setup admin users with gitlab on LDAP authentication?

Daniel C. Sobral
  • 295,120
  • 86
  • 501
  • 681
  • What version of GitLab is this for? Is this still applicable? – Paul Verest May 07 '13 at 02:23
  • 1
    @PaulVerest I've since left the job of that gitlab installation, so I can answer what version it was (beyond just looking at the tag dates to see what was around at the time I asked the question). Nor do I use gitlab on my present job, so I can't answer whether it's still applicable. – Daniel C. Sobral May 07 '13 at 22:40

6 Answers6

28

You can also set admin permissions to a user by doing something like this in the rails console:

User.find_by_email("user@example.org") do |i|
    i.admin = true
    i.save
end
morgents
  • 505
  • 5
  • 11
  • How do I start/enter the gitlab rails console? Thanks/newbie – MrJ May 06 '13 at 18:39
  • @user973956 try something like "cd /home/git/gitlab && RAILS_ENV=production rails console" – morgents May 07 '13 at 11:33
  • 5
    Does not work for me. After I enter that, I get a long output of the User object, but it still contains `admin: false`. – flyx Oct 24 '14 at 09:22
  • (from /home/git/gitlab) `sudo su git` then `bundle exec rails c production` – Duke Nov 17 '14 at 07:33
  • 1
    I just launched it with sudo gitlab-rails console production As described here: https://docs.gitlab.com/ee/security/reset_root_password.html – jorfus Oct 19 '17 at 22:15
27

Mine is a variant of the accepted answer but it's based on an example from the official documentation

From the command line of your gitlab server:

Open the gitlab rails console (I'm assuming here that you aren't logged in as root):

sudo gitlab-rails console production

Then type the following commands:

 user = User.find_by(username: 'my_username')
 user.admin = true
 user.save!

Close the console:

exit

Update your gitlab server:

sudo gitlab-ctl reconfigure
David Fofana
  • 371
  • 3
  • 3
24

This is what I did to make a LDAP (or Windows AD) user vikas as admin.

First login on GitLab portal and logout, then run the below commands.

gitlab-rails console production
u = User.where(id: 1).first
u.admin = true
u.save!
exit

After running the above commands, login again and now your will have admin privileges for vikas AD user.

vikas027
  • 5,282
  • 4
  • 39
  • 51
  • 2
    I tested the above commands in Rails version 4.2.6 ( gitlab-rails --version ) and it works also without logging out of the gitlab. One can simply refresh the browser and the admin button ( Tools ) would appear. One just needs to be careful about the id number you pass in the command. In my case it was 3 ..... u = User.where(id: 3).first – infoclogged Aug 08 '16 at 16:53
6

The file db/fixtures/production/001_admin.rb contains a user and password setup for administration, but you have to disable LDAP to login with it. Afterwards, if you have created a user by login in with LDAP, you can set it up to be an administrator and re-enable LDAP.

Hopefully, a more rational way exists...

Daniel C. Sobral
  • 295,120
  • 86
  • 501
  • 681
3

There is a check box on web interface, if your GitLab username has admin access.

Login to GitLab, and in the context of Admin Area > Users > the.other.user > edit > Access > Access level, check "Admin".

I didn't try the Linux commands, because web GUI is more reliable. The official GitLab document about permission didn't include this setting, maybe it feels like intuitive.

James
  • 1,373
  • 3
  • 13
  • 27
1

Login to gitlab database and run:

update users set admin = 't' where email like 'xxxxx@xxxxx';