A service account is a user account intended for use in automated scripts. These accounts are typically used in CI/CD pipelines and integrations. A service account cannot be used to authenticate via the web interface or to perform actions through impersonation.
Creating a service account
Rails console
A service account is created from the Rails console. Open the console for the installation type in use:
- Linux package
- Omnibus Docker
- Helm Chart
- Deckhouse Kubernetes Platform module
sudo gitlab-rails consoledocker exec -it code gitlab-rails consolecode is the container name from the docker run command in Quick start.
d8 k -n code exec -it deploy/code-toolbox -- gitlab-rails consoleThe console is part of the Toolbox utility set:
d8 k -n d8-code exec -it -c toolbox deploy/toolbox -- gitlab-rails console -e productionCreating an account
-
In the Rails console, prepare the parameters defining the account to be created. Fill in the
name,username,email, andadminfields, and define the rest of the parameters as shown in the example below:user_args = { name: 'kaiten_sa', username: 'kaiten_sa', email: 'kaiten_sa@flant.com', admin: false, user_type: :service_account, organization_id: Organizations::Organization.default_organization.id, password_automatically_set: true, force_random_password: true, skip_confirmation: true } -
Select the user on whose behalf the service account will be created and execute the account creation:
user = User.find_by_username('root') Users::CreateService.new(user, user_args).execute
Generating an access token
To generate an access token, use GitLab’s Personal access tokens API.