debian-mirror-gitlab/doc/user/project/settings/project_access_tokens.md
2022-06-21 17:19:12 +05:30

7.5 KiB

stage group info type
Manage Authentication and Authorization To determine the technical writer assigned to the Stage/Group associated with this page, see https://about.gitlab.com/handbook/engineering/ux/technical-writing/#assignments reference, howto

Project access tokens

Project access tokens are similar to passwords, except you can limit access to resources, select a limited role, and provide an expiry date.

Use a project access token to authenticate:

  • With the GitLab API.
  • With Git, when using HTTP Basic Authentication, use:
    • Any non-blank value as a username.
    • The project access token as the password.

Project access tokens are similar to group access tokens and personal access tokens.

In self-managed instances, project access tokens are subject to the same maximum lifetime limits as personal access tokens if the limit is set.

You can use project access tokens:

  • On GitLab SaaS if you have the Premium license tier or higher. Project access tokens are not available with a trial license.
  • On self-managed instances of GitLab, with any license tier. If you have the Free tier:

You cannot use project access tokens to create other access tokens.

Project access tokens inherit the default prefix setting configured for personal access tokens.

Create a project access token

To create a project access token:

  1. On the top bar, select Menu > Projects and find your project.

  2. On the left sidebar, select Settings > Access Tokens.

  3. Enter a name. The token name is visible to any user with permissions to view the project.

  4. Optional. Enter an expiry date for the token. The token expires on that date at midnight UTC. An instance-wide maximum lifetime setting can limit the maximum allowable lifetime in self-managed instances.

  5. Select a role for the token.

  6. Select the desired scopes.

  7. Select Create project access token.

A project access token is displayed. Save the project access token somewhere safe. After you leave or refresh the page, you can't view it again.

Revoke a project access token

To revoke a project access token:

  1. On the top bar, select Menu > Projects and find your project.
  2. On the left sidebar, select Settings > Access Tokens.
  3. Next to the project access token to revoke, select Revoke.

Scopes for a project access token

The scope determines the actions you can perform when you authenticate with a project access token.

Scope Description
api Grants complete read and write access to the scoped project API, including the Package Registry.
read_api Grants read access to the scoped project API, including the Package Registry.
read_registry Allows read access (pull) to the Container Registry images if a project is private and authorization is required.
write_registry Allows write access (push) to the Container Registry.
read_repository Allows read access (pull) to the repository.
write_repository Allows read and write access (pull and push) to the repository.

Enable or disable project access token creation

Introduced in GitLab 13.11.

To enable or disable project access token creation for all projects in a top-level group:

  1. On the top bar, select Menu > Groups and find your group.
  2. On the left sidebar, select Settings > General.
  3. Expand Permissions and group features.
  4. Under Permissions, turn on or off Allow project and group access token creation.

Even when creation is disabled, you can still use and revoke existing project access tokens.

Bot users for projects

Bot users for projects are GitLab-created service accounts. Each time you create a project access token, a bot user is created and added to the project. These bot users do not count as licensed seats.

The bot users for projects have permissions that correspond with the selected role and scope of the project access token.

  • The name is set to the name of the token.
  • The username is set to project_{project_id}_bot for the first access token. For example, project_123_bot.
  • The email is set to project{project_id}_bot@noreply.{Gitlab.config.gitlab.host}. For example, project123_bot@noreply.example.com.
  • For additional access tokens in the same project, the username is set to project_{project_id}_bot{bot_count}. For example, project_123_bot1.
  • For additional access tokens in the same project, the email is set to project{project_id}_bot{bot_count}@noreply.{Gitlab.config.gitlab.host}. For example, project123_bot1@noreply.example.com.

API calls made with a project access token are associated with the corresponding bot user.

Bot users for projects:

  • Are included in a project's member list but cannot be modified.
  • Cannot be added to any other project.

When the project access token is revoked:

  • The bot user is deleted.
  • All records are moved to a system-wide user with the username Ghost User.

See also Bot users for groups.