2018-04-06 04:57:33 -04:00
# Deploy Tokens
2018-03-31 20:11:28 -04:00
> [Introduced][ce-17894] in GitLab 10.7.
Deploy tokens allow to download (through `git clone` ), or read the container registry images of a project without the need of having a user and a password.
Please note, that the expiration of deploy tokens happens on the date you define,
2018-05-25 02:18:42 -04:00
at midnight UTC and that they can be only managed by [maintainers ](https://docs.gitlab.com/ee/user/permissions.html ).
2018-03-31 20:11:28 -04:00
2018-04-05 21:04:11 -04:00
## Creating a Deploy Token
2018-03-31 20:11:28 -04:00
2018-09-05 06:57:43 -04:00
You can create as many deploy tokens as you like from the settings of your project:
2018-03-31 20:11:28 -04:00
1. Log in to your GitLab account.
1. Go to the project you want to create Deploy Tokens for.
2018-11-12 19:39:21 -05:00
1. Go to **Settings** > **Repository** .
1. Click on "Expand" on **Deploy Tokens** section.
2018-03-31 20:11:28 -04:00
1. Choose a name and optionally an expiry date for the token.
1. Choose the [desired scopes ](#limiting-scopes-of-a-deploy-token ).
1. Click on **Create deploy token** .
1. Save the deploy token somewhere safe. Once you leave or refresh
the page, **you won't be able to access it again** .
![Personal access tokens page ](img/deploy_tokens.png )
2018-04-23 00:15:10 -04:00
## Revoking a deploy token
2018-03-31 20:11:28 -04:00
At any time, you can revoke any deploy token by just clicking the
respective **Revoke** button under the 'Active deploy tokens' area.
## Limiting scopes of a deploy token
Deploy tokens can be created with two different scopes that allow various
actions that a given token can perform. The available scopes are depicted in
the following table.
| Scope | Description |
| ----- | ----------- |
2018-04-05 21:04:11 -04:00
| `read_repository` | Allows read-access to the repository through `git clone` |
2018-04-02 10:45:37 -04:00
| `read_registry` | Allows read-access to [container registry] images if a project is private and authorization is required. |
2018-03-31 20:11:28 -04:00
## Usage
### Git clone a repository
To download a repository using a Deploy Token, you just need to:
2018-04-04 19:43:41 -04:00
1. Create a Deploy Token with `read_repository` as a scope.
2018-11-12 19:39:21 -05:00
1. Take note of your `username` and `token` .
1. `git clone` the project using the Deploy Token:
2018-03-31 20:11:28 -04:00
2018-09-05 06:57:43 -04:00
```sh
git clone http://< username > :< deploy_token > @gitlab.example.com/tanuki/awesome_project.git
```
2018-03-31 20:11:28 -04:00
2018-09-05 06:57:43 -04:00
Replace `<username>` and `<deploy_token>` with the proper values.
2018-03-31 20:11:28 -04:00
2018-09-05 06:57:43 -04:00
### Read Container Registry images
2018-03-31 20:11:28 -04:00
To read the container registry images, you'll need to:
1. Create a Deploy Token with `read_registry` as a scope.
2018-11-12 19:39:21 -05:00
1. Take note of your `username` and `token` .
1. Log in to GitLab’ s Container Registry using the deploy token:
2018-03-31 20:11:28 -04:00
2018-09-05 06:57:43 -04:00
```sh
2018-03-31 20:11:28 -04:00
docker login registry.example.com -u < username > -p < deploy_token >
```
2018-04-05 23:02:13 -04:00
2018-09-05 06:57:43 -04:00
Just replace `<username>` and `<deploy_token>` with the proper values. Then you can simply
2018-04-05 23:02:13 -04:00
pull images from your Container Registry.
2018-03-31 20:11:28 -04:00
2018-04-16 17:18:43 -04:00
### GitLab Deploy Token
> [Introduced][ce-18414] in GitLab 10.8.
2018-09-05 06:57:43 -04:00
There's a special case when it comes to Deploy Tokens. If a user creates one
named `gitlab-deploy-token` , the username and token of the Deploy Token will be
automatically exposed to the CI/CD jobs as environment variables: `CI_DEPLOY_USER` and
`CI_DEPLOY_PASSWORD` , respectively. With the GitLab Deploy Token, the
`read_registry` scope is implied.
After you create the token, you can login to the Container Registry using
those variables:
```sh
docker login -u $CI_DEPLOY_USER -p $CI_DEPLOY_PASSWORD $CI_REGISTRY
```
2018-04-16 17:18:43 -04:00
2018-03-31 20:11:28 -04:00
[ce-17894]: https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/17894
[ce-11845]: https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/11845
2018-04-16 17:18:43 -04:00
[ce-18414]: https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/18414
2018-04-02 10:45:37 -04:00
[container registry]: ../container_registry.md