debian-mirror-gitlab/doc/administration/packages/container_registry.md

1844 lines
74 KiB
Markdown
Raw Normal View History

2020-06-23 00:09:42 +05:30
---
stage: Package
2023-01-13 00:05:48 +05:30
group: Container Registry
2022-11-25 23:54:43 +05:30
info: To determine the technical writer assigned to the Stage/Group associated with this page, see https://about.gitlab.com/handbook/product/ux/technical-writing/#assignments
2020-06-23 00:09:42 +05:30
---
2021-04-29 21:17:54 +05:30
# GitLab Container Registry administration **(FREE SELF)**
2019-12-04 20:38:33 +05:30
2021-01-03 14:25:43 +05:30
With the GitLab Container Registry, every project can have its
own space to store Docker images.
2019-12-04 20:38:33 +05:30
2021-01-03 14:25:43 +05:30
Read more about the Docker Registry in [the Docker documentation](https://docs.docker.com/registry/introduction/).
2019-12-04 20:38:33 +05:30
2021-01-03 14:25:43 +05:30
This document is the administrator's guide. To learn how to use the GitLab Container
Registry, see the [user documentation](../../user/packages/container_registry/index.md).
2019-12-04 20:38:33 +05:30
## Enable the Container Registry
**Omnibus GitLab installations**
2020-05-24 23:13:21 +05:30
If you installed GitLab by using the Omnibus installation package, the Container Registry
may or may not be available by default.
2019-12-26 22:10:19 +05:30
2023-07-09 08:55:56 +05:30
The Container Registry is automatically enabled and available on your GitLab domain, port 5050 if
you're using the built-in [Let's Encrypt integration](https://docs.gitlab.com/omnibus/settings/ssl/index.html#enable-the-lets-encrypt-integration).
2020-05-24 23:13:21 +05:30
Otherwise, the Container Registry is not enabled. To enable it:
- You can configure it for your [GitLab domain](#configure-container-registry-under-an-existing-gitlab-domain), or
- You can configure it for [a different domain](#configure-container-registry-under-its-own-domain).
2019-12-04 20:38:33 +05:30
2020-05-24 23:13:21 +05:30
The Container Registry works under HTTPS by default. You can use HTTP
2021-01-03 14:25:43 +05:30
but it's not recommended and is beyond the scope of this document.
2019-12-04 20:38:33 +05:30
Read the [insecure Registry documentation](https://docs.docker.com/registry/insecure/)
if you want to implement this.
**Installations from source**
If you have installed GitLab from source:
2022-11-25 23:54:43 +05:30
1. You must [deploy a registry](https://docs.docker.com/registry/deploying/) using the image corresponding to the
version of GitLab you are installing
(for example: `registry.gitlab.com/gitlab-org/build/cng/gitlab-container-registry:v3.15.0-gitlab`)
2021-01-03 14:25:43 +05:30
1. After the installation is complete, to enable it, you must configure the Registry's
settings in `gitlab.yml`.
1. Use the sample NGINX configuration file from under
2021-09-04 01:27:46 +05:30
[`lib/support/nginx/registry-ssl`](https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/support/nginx/registry-ssl) and edit it to match the
2021-01-03 14:25:43 +05:30
`host`, `port`, and TLS certificate paths.
2019-12-04 20:38:33 +05:30
The contents of `gitlab.yml` are:
```yaml
registry:
enabled: true
host: registry.gitlab.example.com
port: 5005
api_url: http://localhost:5000/
key: config/registry.key
path: shared/registry
issuer: gitlab-issuer
```
2021-01-03 14:25:43 +05:30
Where:
2019-12-04 20:38:33 +05:30
| Parameter | Description |
| --------- | ----------- |
| `enabled` | `true` or `false`. Enables the Registry in GitLab. By default this is `false`. |
2021-01-03 14:25:43 +05:30
| `host` | The host URL under which the Registry runs and users can use. |
| `port` | The port the external Registry domain listens on. |
2021-04-17 20:07:23 +05:30
| `api_url` | The internal API URL under which the Registry is exposed. It defaults to `http://localhost:5000`. Do not change this unless you are setting up an [external Docker registry](#use-an-external-container-registry-with-gitlab-as-an-auth-endpoint). |
2019-12-04 20:38:33 +05:30
| `key` | The private key location that is a pair of Registry's `rootcertbundle`. Read the [token auth configuration documentation](https://docs.docker.com/registry/configuration/#token). |
2020-07-28 23:09:34 +05:30
| `path` | This should be the same directory like specified in Registry's `rootdirectory`. Read the [storage configuration documentation](https://docs.docker.com/registry/configuration/#storage). This path needs to be readable by the GitLab user, the web-server user and the Registry user. Read more in [#configure-storage-for-the-container-registry](#configure-storage-for-the-container-registry). |
2019-12-04 20:38:33 +05:30
| `issuer` | This should be the same value as configured in Registry's `issuer`. Read the [token auth configuration documentation](https://docs.docker.com/registry/configuration/#token). |
A Registry init file is not shipped with GitLab if you install it from source.
2021-01-03 14:25:43 +05:30
Hence, [restarting GitLab](../restart_gitlab.md#installations-from-source) does not restart the Registry should
2019-12-04 20:38:33 +05:30
you modify its settings. Read the upstream documentation on how to achieve that.
At the **absolute** minimum, make sure your [Registry configuration](https://docs.docker.com/registry/configuration/#auth)
has `container_registry` as the service and `https://gitlab.example.com/jwt/auth`
as the realm:
```yaml
auth:
token:
realm: https://gitlab.example.com/jwt/auth
service: container_registry
issuer: gitlab-issuer
rootcertbundle: /root/certs/certbundle
```
2021-02-22 17:27:13 +05:30
WARNING:
2021-01-03 14:25:43 +05:30
If `auth` is not set up, users can pull Docker images without authentication.
2019-12-04 20:38:33 +05:30
## Container Registry domain configuration
2023-07-09 08:55:56 +05:30
You can configure the Registry's external domain in either of these ways:
2019-12-04 20:38:33 +05:30
2021-01-03 14:25:43 +05:30
- [Use the existing GitLab domain](#configure-container-registry-under-an-existing-gitlab-domain).
2021-02-22 17:27:13 +05:30
The Registry listens on a port and reuses the TLS certificate from GitLab.
2019-12-04 20:38:33 +05:30
- [Use a completely separate domain](#configure-container-registry-under-its-own-domain) with a new TLS certificate
for that domain.
2021-01-03 14:25:43 +05:30
Because the Container Registry requires a TLS certificate, cost may be a factor.
2019-12-04 20:38:33 +05:30
2021-01-03 14:25:43 +05:30
Take this into consideration before configuring the Container Registry
2019-12-04 20:38:33 +05:30
for the first time.
### Configure Container Registry under an existing GitLab domain
2023-07-09 08:55:56 +05:30
If the Container Registry is configured to use the existing GitLab domain, you can
expose the Container Registry on a port. This way you can reuse the existing GitLab TLS
2019-12-04 20:38:33 +05:30
certificate.
2023-07-09 08:55:56 +05:30
If the GitLab domain is `https://gitlab.example.com` and the port to the outside world is `5050`,
to configure the Container Registry:
- Edit `gitlab.rb` if you are using Omnibus GitLab.
- Edit `gitlab.yml` if you installed GitLab from source.
2019-12-04 20:38:33 +05:30
2021-01-03 14:25:43 +05:30
Ensure you choose a port different than the one that Registry listens to (`5000` by default),
otherwise conflicts occur.
2019-12-04 20:38:33 +05:30
2021-11-18 22:05:49 +05:30
NOTE:
Host and container firewall rules must be configured to allow traffic in through the port listed
under the `registry_external_url` line, rather than the port listed under
`gitlab_rails['registry_port']` (default `5000`).
2019-12-04 20:38:33 +05:30
**Omnibus GitLab installations**
1. Your `/etc/gitlab/gitlab.rb` should contain the Registry URL as well as the
path to the existing TLS certificate and key used by GitLab:
```ruby
2020-06-23 00:09:42 +05:30
registry_external_url 'https://gitlab.example.com:5050'
2019-12-04 20:38:33 +05:30
```
2021-01-03 14:25:43 +05:30
The `registry_external_url` is listening on HTTPS under the
2019-12-04 20:38:33 +05:30
existing GitLab URL, but on a different port.
If your TLS certificate is not in `/etc/gitlab/ssl/gitlab.example.com.crt`
and key not in `/etc/gitlab/ssl/gitlab.example.com.key` uncomment the lines
below:
```ruby
registry_nginx['ssl_certificate'] = "/path/to/certificate.pem"
registry_nginx['ssl_certificate_key'] = "/path/to/certificate.key"
```
1. Save the file and [reconfigure GitLab](../restart_gitlab.md#omnibus-gitlab-reconfigure)
for the changes to take effect.
1. Validate using:
2020-03-13 15:44:24 +05:30
```shell
2020-06-23 00:09:42 +05:30
openssl s_client -showcerts -servername gitlab.example.com -connect gitlab.example.com:5050 > cacert.pem
2019-12-04 20:38:33 +05:30
```
If your certificate provider provides the CA Bundle certificates, append them to the TLS certificate file.
2021-11-18 22:05:49 +05:30
An administrator may want the container registry listening on an arbitrary port such as `5678`.
However, the registry and application server are behind an AWS application load balancer that only
2022-11-25 23:54:43 +05:30
listens on ports `80` and `443`. The administrator may remove the port number for
2021-11-18 22:05:49 +05:30
`registry_external_url`, so HTTP or HTTPS is assumed. Then, the rules apply that map the load
balancer to the registry from ports `80` or `443` to the arbitrary port. This is important if users
rely on the `docker login` example in the container registry. Here's an example:
```ruby
registry_external_url 'https://registry-gitlab.example.com'
registry_nginx['redirect_http_to_https'] = true
registry_nginx['listen_port'] = 5678
```
2019-12-04 20:38:33 +05:30
**Installations from source**
1. Open `/home/git/gitlab/config/gitlab.yml`, find the `registry` entry and
configure it with the following settings:
2020-03-13 15:44:24 +05:30
```yaml
2019-12-04 20:38:33 +05:30
registry:
enabled: true
host: gitlab.example.com
2020-06-23 00:09:42 +05:30
port: 5050
2019-12-04 20:38:33 +05:30
```
1. Save the file and [restart GitLab](../restart_gitlab.md#installations-from-source) for the changes to take effect.
1. Make the relevant changes in NGINX as well (domain, port, TLS certificates path).
2021-01-29 00:20:46 +05:30
Users should now be able to sign in to the Container Registry with their GitLab
2019-12-04 20:38:33 +05:30
credentials using:
2020-03-13 15:44:24 +05:30
```shell
2020-06-23 00:09:42 +05:30
docker login gitlab.example.com:5050
2019-12-04 20:38:33 +05:30
```
### Configure Container Registry under its own domain
2021-01-03 14:25:43 +05:30
When the Registry is configured to use its own domain, you need a TLS
certificate for that specific domain (for example, `registry.example.com`). You might need
2019-12-04 20:38:33 +05:30
a wildcard certificate if hosted under a subdomain of your existing GitLab
2023-01-13 00:05:48 +05:30
domain. For example, `*.gitlab.example.com`, is a wildcard that matches `registry.gitlab.example.com`,
and is distinct from `*.example.com`.
2019-12-04 20:38:33 +05:30
As well as manually generated SSL certificates (explained here), certificates automatically
2023-07-09 08:55:56 +05:30
generated by Let's Encrypt are also [supported in Omnibus installs](https://docs.gitlab.com/omnibus/settings/ssl/index.html).
2019-12-04 20:38:33 +05:30
Let's assume that you want the container Registry to be accessible at
`https://registry.gitlab.example.com`.
**Omnibus GitLab installations**
1. Place your TLS certificate and key in
`/etc/gitlab/ssl/registry.gitlab.example.com.crt` and
`/etc/gitlab/ssl/registry.gitlab.example.com.key` and make sure they have
correct permissions:
2020-03-13 15:44:24 +05:30
```shell
2019-12-04 20:38:33 +05:30
chmod 600 /etc/gitlab/ssl/registry.gitlab.example.com.*
```
2021-01-03 14:25:43 +05:30
1. After the TLS certificate is in place, edit `/etc/gitlab/gitlab.rb` with:
2019-12-04 20:38:33 +05:30
```ruby
registry_external_url 'https://registry.gitlab.example.com'
```
2021-01-03 14:25:43 +05:30
The `registry_external_url` is listening on HTTPS.
2019-12-04 20:38:33 +05:30
1. Save the file and [reconfigure GitLab](../restart_gitlab.md#omnibus-gitlab-reconfigure) for the changes to take effect.
2021-01-03 14:25:43 +05:30
If you have a [wildcard certificate](https://en.wikipedia.org/wiki/Wildcard_certificate), you must specify the path to the
certificate in addition to the URL, in this case `/etc/gitlab/gitlab.rb`
looks like:
2019-12-04 20:38:33 +05:30
```ruby
registry_nginx['ssl_certificate'] = "/etc/gitlab/ssl/certificate.pem"
registry_nginx['ssl_certificate_key'] = "/etc/gitlab/ssl/certificate.key"
```
**Installations from source**
1. Open `/home/git/gitlab/config/gitlab.yml`, find the `registry` entry and
configure it with the following settings:
```yaml
registry:
enabled: true
host: registry.gitlab.example.com
```
1. Save the file and [restart GitLab](../restart_gitlab.md#installations-from-source) for the changes to take effect.
1. Make the relevant changes in NGINX as well (domain, port, TLS certificates path).
2021-01-29 00:20:46 +05:30
Users should now be able to sign in to the Container Registry using their GitLab
2019-12-04 20:38:33 +05:30
credentials:
2020-03-13 15:44:24 +05:30
```shell
2019-12-04 20:38:33 +05:30
docker login registry.gitlab.example.com
```
## Disable Container Registry site-wide
2021-01-03 14:25:43 +05:30
When you disable the Registry by following these steps, you do not
2023-07-09 08:55:56 +05:30
remove any existing Docker images. Docker image removal is handled by the
2019-12-04 20:38:33 +05:30
Registry application itself.
**Omnibus GitLab**
1. Open `/etc/gitlab/gitlab.rb` and set `registry['enable']` to `false`:
```ruby
registry['enable'] = false
```
1. Save the file and [reconfigure GitLab](../restart_gitlab.md#omnibus-gitlab-reconfigure) for the changes to take effect.
**Installations from source**
1. Open `/home/git/gitlab/config/gitlab.yml`, find the `registry` entry and
set `enabled` to `false`:
```yaml
registry:
enabled: false
```
1. Save the file and [restart GitLab](../restart_gitlab.md#installations-from-source) for the changes to take effect.
## Disable Container Registry for new projects site-wide
2021-01-03 14:25:43 +05:30
If the Container Registry is enabled, then it should be available on all new
2019-12-04 20:38:33 +05:30
projects. To disable this function and let the owners of a project to enable
the Container Registry by themselves, follow the steps below.
**Omnibus GitLab installations**
1. Edit `/etc/gitlab/gitlab.rb` and add the following line:
```ruby
gitlab_rails['gitlab_default_projects_features_container_registry'] = false
```
1. Save the file and [reconfigure GitLab](../restart_gitlab.md#omnibus-gitlab-reconfigure) for the changes to take effect.
**Installations from source**
1. Open `/home/git/gitlab/config/gitlab.yml`, find the `default_projects_features`
entry and configure it so that `container_registry` is set to `false`:
```yaml
## Default project features settings
default_projects_features:
issues: true
merge_requests: true
wiki: true
snippets: false
builds: true
container_registry: false
```
1. Save the file and [restart GitLab](../restart_gitlab.md#installations-from-source) for the changes to take effect.
2022-07-23 23:45:48 +05:30
### Increase token duration
In GitLab, tokens for the Container Registry expire every five minutes.
To increase the token duration:
2022-10-11 01:57:18 +05:30
1. On the top bar, select **Main menu > Admin**.
2022-07-23 23:45:48 +05:30
1. On the left sidebar, select **Settings > CI/CD**.
1. Expand **Container Registry**.
1. For the **Authorization token duration (minutes)**, update the value.
1. Select **Save changes**.
2020-07-28 23:09:34 +05:30
## Configure storage for the Container Registry
2019-12-04 20:38:33 +05:30
2021-06-08 01:23:25 +05:30
NOTE:
For storage backends that support it, you can use object versioning to preserve, retrieve, and
restore the non-current versions of every object stored in your buckets. However, this may result in
higher storage usage and costs. Due to how the registry operates, image uploads are first stored in
a temporary path and then transferred to a final location. For object storage backends, including S3
and GCS, this transfer is achieved with a copy followed by a delete. With object versioning enabled,
these deleted temporary upload artifacts are kept as non-current versions, therefore increasing the
storage bucket size. To ensure that non-current versions are deleted after a given amount of time,
you should configure an object lifecycle policy with your storage provider.
2023-03-04 22:38:38 +05:30
WARNING:
Do not directly modify the files or objects stored by the container registry. Anything other than the registry writing or deleting these entries can lead to instance-wide data consistency and instability issues from which recovery may not be possible.
2020-07-28 23:09:34 +05:30
You can configure the Container Registry to use various storage backends by
configuring a storage driver. By default the GitLab Container Registry
2021-01-03 14:25:43 +05:30
is configured to use the [file system driver](#use-file-system)
2020-07-28 23:09:34 +05:30
configuration.
The different supported drivers are:
2021-03-11 19:13:27 +05:30
| Driver | Description |
|--------------|--------------------------------------|
| `filesystem` | Uses a path on the local file system |
2021-11-11 11:23:49 +05:30
| `azure` | Microsoft Azure Blob Storage |
2021-03-11 19:13:27 +05:30
| `gcs` | Google Cloud Storage |
| `s3` | Amazon Simple Storage Service. Be sure to configure your storage bucket with the correct [S3 Permission Scopes](https://docs.docker.com/registry/storage-drivers/s3/#s3-permission-scopes). |
| `swift` | OpenStack Swift Object Storage |
| `oss` | Aliyun OSS |
2020-07-28 23:09:34 +05:30
2021-01-03 14:25:43 +05:30
Although most S3 compatible services (like [MinIO](https://min.io/)) should work with the Container Registry, we only guarantee support for AWS S3. Because we cannot assert the correctness of third-party S3 implementations, we can debug issues, but we cannot patch the registry unless an issue is reproducible against an AWS S3 bucket.
2020-10-24 23:57:45 +05:30
2020-07-28 23:09:34 +05:30
Read more about the individual driver's configuration options in the
[Docker Registry docs](https://docs.docker.com/registry/configuration/#storage).
2021-01-03 14:25:43 +05:30
### Use file system
2019-12-04 20:38:33 +05:30
2021-01-03 14:25:43 +05:30
If you want to store your images on the file system, you can change the storage
2019-12-04 20:38:33 +05:30
path for the Container Registry, follow the steps below.
This path is accessible to:
- The user running the Container Registry daemon.
- The user running GitLab.
2021-01-03 14:25:43 +05:30
All GitLab, Registry, and web server users must
2019-12-04 20:38:33 +05:30
have access to this directory.
**Omnibus GitLab installations**
The default location where images are stored in Omnibus, is
`/var/opt/gitlab/gitlab-rails/shared/registry`. To change it:
1. Edit `/etc/gitlab/gitlab.rb`:
```ruby
gitlab_rails['registry_path'] = "/path/to/registry/storage"
```
1. Save the file and [reconfigure GitLab](../restart_gitlab.md#omnibus-gitlab-reconfigure) for the changes to take effect.
**Installations from source**
The default location where images are stored in source installations, is
`/home/git/gitlab/shared/registry`. To change it:
1. Open `/home/git/gitlab/config/gitlab.yml`, find the `registry` entry and
change the `path` setting:
```yaml
registry:
path: shared/registry
```
1. Save the file and [restart GitLab](../restart_gitlab.md#installations-from-source) for the changes to take effect.
2020-07-28 23:09:34 +05:30
### Use object storage
2019-12-04 20:38:33 +05:30
2020-07-28 23:09:34 +05:30
If you want to store your images on object storage, you can change the storage
driver for the Container Registry.
2019-12-04 20:38:33 +05:30
2020-04-22 19:07:51 +05:30
[Read more about using object storage with GitLab](../object_storage.md).
2021-02-22 17:27:13 +05:30
WARNING:
2021-01-03 14:25:43 +05:30
GitLab does not back up Docker images that are not stored on the
file system. Enable backups with your object storage provider if
2019-12-04 20:38:33 +05:30
desired.
**Omnibus GitLab installations**
To configure the `s3` storage driver in Omnibus:
1. Edit `/etc/gitlab/gitlab.rb`:
```ruby
registry['storage'] = {
's3' => {
'accesskey' => 's3-access-key',
'secretkey' => 's3-secret-key-for-access-key',
'bucket' => 'your-s3-bucket',
'region' => 'your-s3-region',
'regionendpoint' => 'your-s3-regionendpoint'
}
}
```
2021-01-29 00:20:46 +05:30
To avoid using static credentials, use an
[IAM role](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html)
and omit `accesskey` and `secretkey`. Make sure that your IAM profile follows
[the permissions documented by Docker](https://docs.docker.com/registry/storage-drivers/s3/#s3-permission-scopes).
```ruby
registry['storage'] = {
's3' => {
'bucket' => 'your-s3-bucket',
'region' => 'your-s3-region'
}
}
```
2021-09-04 01:27:46 +05:30
If using with an [AWS S3 VPC endpoint](https://docs.aws.amazon.com/vpc/latest/privatelink/vpc-endpoints-s3.html),
2022-01-26 12:08:38 +05:30
then set `regionendpoint` to your VPC endpoint address and set `pathstyle` to false:
2021-09-04 01:27:46 +05:30
```ruby
registry['storage'] = {
's3' => {
'accesskey' => 's3-access-key',
'secretkey' => 's3-secret-key-for-access-key',
'bucket' => 'your-s3-bucket',
'region' => 'your-s3-region',
'regionendpoint' => 'your-s3-vpc-endpoint',
2022-01-26 12:08:38 +05:30
'pathstyle' => false
2021-09-04 01:27:46 +05:30
}
}
```
- `regionendpoint` is only required when configuring an S3 compatible service such as MinIO, or
when using an AWS S3 VPC Endpoint.
2021-01-03 14:25:43 +05:30
- `your-s3-bucket` should be the name of a bucket that exists, and can't include subdirectories.
2022-01-26 12:08:38 +05:30
- `pathstyle` should be set to true to use `host/bucket_name/object` style paths instead of
2021-09-04 01:27:46 +05:30
`bucket_name.host/object`. [Set to false for AWS S3](https://aws.amazon.com/blogs/aws/amazon-s3-path-deprecation-plan-the-rest-of-the-story/).
2019-12-04 20:38:33 +05:30
2022-05-07 20:08:51 +05:30
You can set a rate limit on connections to S3 to avoid 503 errors from the S3 API. To do this,
2023-04-23 21:23:45 +05:30
set `maxrequestspersecond` to a number within the [S3 request rate threshold](https://repost.aws/knowledge-center/s3-503-within-request-rate-prefix):
2022-05-07 20:08:51 +05:30
```ruby
registry['storage'] = {
's3' => {
'accesskey' => 's3-access-key',
'secretkey' => 's3-secret-key-for-access-key',
'bucket' => 'your-s3-bucket',
'region' => 'your-s3-region',
'regionendpoint' => 'your-s3-regionendpoint',
'maxrequestspersecond' => 100
}
}
```
2021-01-03 14:25:43 +05:30
1. Save the file and [reconfigure GitLab](../restart_gitlab.md#omnibus-gitlab-reconfigure) for the changes to take effect.
2020-03-13 15:44:24 +05:30
2019-12-04 20:38:33 +05:30
**Installations from source**
2022-07-23 23:45:48 +05:30
Configuring the storage driver is done in the registry configuration YAML file created
2020-06-23 00:09:42 +05:30
when you [deployed your Docker registry](https://docs.docker.com/registry/deploying/).
2019-12-04 20:38:33 +05:30
`s3` storage driver example:
2020-03-13 15:44:24 +05:30
```yaml
2019-12-04 20:38:33 +05:30
storage:
s3:
2021-01-29 00:20:46 +05:30
accesskey: 's3-access-key' # Not needed if IAM role used
secretkey: 's3-secret-key-for-access-key' # Not needed if IAM role used
2020-03-13 15:44:24 +05:30
bucket: 'your-s3-bucket'
2019-12-04 20:38:33 +05:30
region: 'your-s3-region'
regionendpoint: 'your-s3-regionendpoint'
cache:
blobdescriptor: inmemory
delete:
enabled: true
```
2021-01-03 14:25:43 +05:30
`your-s3-bucket` should be the name of a bucket that exists, and can't include subdirectories.
2020-03-13 15:44:24 +05:30
2020-07-28 23:09:34 +05:30
#### Migrate to object storage without downtime
2022-01-26 12:08:38 +05:30
WARNING:
Using [AWS DataSync](https://aws.amazon.com/datasync/)
to copy the registry data to or between S3 buckets creates invalid metadata objects in the bucket.
For additional details, see [Tags with an empty name](#tags-with-an-empty-name).
To move data to and between S3 buckets, the AWS CLI `sync` operation is recommended.
2020-07-28 23:09:34 +05:30
To migrate storage without stopping the Container Registry, set the Container Registry
to read-only mode. On large instances, this may require the Container Registry
to be in read-only mode for a while. During this time,
you can pull from the Container Registry, but you cannot push.
1. Optional: To reduce the amount of data to be migrated, run the [garbage collection tool without downtime](#performing-garbage-collection-without-downtime).
2020-10-24 23:57:45 +05:30
1. This example uses the `aws` CLI. If you haven't configured the
CLI before, you have to configure your credentials by running `sudo aws configure`.
2021-01-03 14:25:43 +05:30
Because a non-administrator user likely can't access the Container Registry folder,
2020-10-24 23:57:45 +05:30
ensure you use `sudo`. To check your credential configuration, run
[`ls`](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/s3/ls.html) to list
all buckets.
```shell
sudo aws --endpoint-url https://your-object-storage-backend.com s3 ls
```
If you are using AWS as your back end, you do not need the [`--endpoint-url`](https://docs.aws.amazon.com/cli/latest/reference/#options).
1. Copy initial data to your S3 bucket, for example with the `aws` CLI
[`cp`](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/s3/cp.html)
2020-07-28 23:09:34 +05:30
or [`sync`](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/s3/sync.html)
command. Make sure to keep the `docker` folder as the top-level folder inside the bucket.
```shell
2020-10-24 23:57:45 +05:30
sudo aws --endpoint-url https://your-object-storage-backend.com s3 sync registry s3://mybucket
2020-07-28 23:09:34 +05:30
```
2021-02-22 17:27:13 +05:30
NOTE:
2020-10-24 23:57:45 +05:30
If you have a lot of data, you may be able to improve performance by
2023-04-23 21:23:45 +05:30
[running parallel sync operations](https://repost.aws/knowledge-center/s3-improve-transfer-sync-command).
2020-10-24 23:57:45 +05:30
2020-07-28 23:09:34 +05:30
1. To perform the final data sync,
[put the Container Registry in `read-only` mode](#performing-garbage-collection-without-downtime) and
[reconfigure GitLab](../restart_gitlab.md#omnibus-gitlab-reconfigure).
2023-07-09 08:55:56 +05:30
1. Sync any changes dating from after the initial data load to your S3 bucket, and delete files that exist in the destination bucket but not in the source:
2020-07-28 23:09:34 +05:30
```shell
2020-10-24 23:57:45 +05:30
sudo aws --endpoint-url https://your-object-storage-backend.com s3 sync registry s3://mybucket --delete --dryrun
2020-07-28 23:09:34 +05:30
```
2020-06-23 00:09:42 +05:30
2021-01-03 14:25:43 +05:30
After verifying the command performs as expected, remove the
2020-10-24 23:57:45 +05:30
[`--dryrun`](https://docs.aws.amazon.com/cli/latest/reference/s3/sync.html)
flag and run the command.
2021-02-22 17:27:13 +05:30
WARNING:
2020-10-24 23:57:45 +05:30
The [`--delete`](https://docs.aws.amazon.com/cli/latest/reference/s3/sync.html)
2021-01-03 14:25:43 +05:30
flag deletes files that exist in the destination but not in the source.
If you swap the source and destination, all data in the Registry is deleted.
2020-06-23 00:09:42 +05:30
2020-10-24 23:57:45 +05:30
1. Verify all Container Registry files have been uploaded to object storage
by looking at the file count returned by these two commands:
```shell
sudo find registry -type f | wc -l
```
```shell
sudo aws --endpoint-url https://your-object-storage-backend.com s3 ls s3://mybucket --recursive | wc -l
```
The output of these commands should match, except for the content in the
`_uploads` directories and sub-directories.
2020-07-28 23:09:34 +05:30
1. Configure your registry to [use the S3 bucket for storage](#use-object-storage).
1. For the changes to take effect, set the Registry back to `read-write` mode and [reconfigure GitLab](../restart_gitlab.md#omnibus-gitlab-reconfigure).
2020-06-23 00:09:42 +05:30
2023-03-04 22:38:38 +05:30
#### Moving to Azure Object Storage
2023-07-09 08:55:56 +05:30
> The default configuration for the storage driver is scheduled to be [changed](https://gitlab.com/gitlab-org/container-registry/-/issues/854) in GitLab 16.0.
2023-03-17 16:20:25 +05:30
<!--- start_remove The following content will be removed on remove_date: '2023-10-22' -->
WARNING:
2023-07-09 08:55:56 +05:30
The default configuration for the storage driver is scheduled to be [changed](https://gitlab.com/gitlab-org/container-registry/-/issues/854) in GitLab 16.0. The storage driver will use `/` as the default root directory. You can add `trimlegacyrootprefix: false` to your current configuration now to avoid any disruptions. For more information, see the [Container Registry configuration](https://gitlab.com/gitlab-org/container-registry/-/tree/master/docs-gitlab#azure-storage-driver) documentation.
2023-03-17 16:20:25 +05:30
<!--- end_remove -->
2023-03-04 22:38:38 +05:30
When moving from an existing file system or another object storage provider to Azure Object Storage, you must configure the registry to use the standard root directory.
2023-07-09 08:55:56 +05:30
Configure it by setting [`trimlegacyrootprefix: true]`](https://gitlab.com/gitlab-org/container-registry/-/blob/a3f64464c3ec1c5a599c0a2daa99ebcbc0100b9a/docs-gitlab/README.md#azure-storage-driver) in the Azure storage driver section of the registry configuration.
2023-03-04 22:38:38 +05:30
Without this configuration, the Azure storage driver uses `//` instead of `/` as the first section of the root path, rendering the migrated images inaccessible.
**Omnibus GitLab installations**
```ruby
registry['storage'] = {
'azure' => {
'accountname' => 'accountname',
2023-05-27 22:25:52 +05:30
'accountkey' => 'base64encodedaccountkey',
2023-03-04 22:38:38 +05:30
'container' => 'containername',
'rootdirectory' => '/azure/virtual/container',
2023-05-27 22:25:52 +05:30
'trimlegacyrootprefix' => true
2023-03-04 22:38:38 +05:30
}
}
```
**Installations from source**
```yaml
storage:
azure:
accountname: accountname
accountkey: base64encodedaccountkey
container: containername
rootdirectory: /azure/virtual/container
trimlegacyrootprefix: true
```
2023-05-27 22:25:52 +05:30
By default, Azure Storage Driver uses the `core.windows.net` realm. You can set another value for `realm` in the `azure` section (for example, `core.usgovcloudapi.net` for Azure Government Cloud). For more information, see the [Docker documentation](https://docs.docker.com/registry/storage-drivers/azure/).
2020-04-22 19:07:51 +05:30
### Disable redirect for storage driver
By default, users accessing a registry configured with a remote backend are redirected to the default backend for the storage driver. For example, registries can be configured using the `s3` storage driver, which redirects requests to a remote S3 bucket to alleviate load on the GitLab server.
2020-07-28 23:09:34 +05:30
However, this behavior is undesirable for registries used by internal hosts that usually can't access public servers. To disable redirects and [proxy download](../object_storage.md#proxy-download), set the `disable` flag to true as follows. This makes all traffic always go through the Registry service. This results in improved security (less surface attack as the storage backend is not publicly accessible), but worse performance (all traffic is redirected via the service).
2020-04-22 19:07:51 +05:30
**Omnibus GitLab installations**
1. Edit `/etc/gitlab/gitlab.rb`:
2023-05-27 22:25:52 +05:30
```ruby
registry['storage'] = {
's3' => {
'accesskey' => 's3-access-key',
'secretkey' => 's3-secret-key-for-access-key',
'bucket' => 'your-s3-bucket',
'region' => 'your-s3-region',
'regionendpoint' => 'your-s3-regionendpoint'
},
'redirect' => {
'disable' => true
}
}
```
2020-04-22 19:07:51 +05:30
1. Save the file and [reconfigure GitLab](../restart_gitlab.md#omnibus-gitlab-reconfigure) for the changes to take effect.
**Installations from source**
2022-07-23 23:45:48 +05:30
1. Add the `redirect` flag to your registry configuration YAML file:
2020-04-22 19:07:51 +05:30
2023-05-27 22:25:52 +05:30
```yaml
storage:
s3:
accesskey: 'AKIAKIAKI'
secretkey: 'secret123'
bucket: 'gitlab-registry-bucket-AKIAKIAKI'
region: 'your-s3-region'
regionendpoint: 'your-s3-regionendpoint'
redirect:
disable: true
cache:
blobdescriptor: inmemory
delete:
enabled: true
```
2020-04-22 19:07:51 +05:30
1. Save the file and [restart GitLab](../restart_gitlab.md#installations-from-source) for the changes to take effect.
2021-10-27 15:23:28 +05:30
#### Encrypted S3 buckets
You can use server-side encryption with AWS KMS for S3 buckets that have
[SSE-S3 or SSE-KMS encryption enabled by default](https://docs.aws.amazon.com/kms/latest/developerguide/services-s3.html).
2023-07-09 08:55:56 +05:30
Customer master keys (CMKs) and SSE-C encryption aren't supported because this requires sending the
2021-10-27 15:23:28 +05:30
encryption keys in every request.
For SSE-S3, you must enable the `encrypt` option in the registry settings. How you do this depends
on how you installed GitLab. Follow the instructions here that match your installation method.
For Omnibus GitLab installations:
1. Edit `/etc/gitlab/gitlab.rb`:
2023-05-27 22:25:52 +05:30
```ruby
registry['storage'] = {
's3' => {
'accesskey' => 's3-access-key',
'secretkey' => 's3-secret-key-for-access-key',
'bucket' => 'your-s3-bucket',
'region' => 'your-s3-region',
'regionendpoint' => 'your-s3-regionendpoint',
'encrypt' => true
}
}
```
2021-10-27 15:23:28 +05:30
1. Save the file and [reconfigure GitLab](../restart_gitlab.md#omnibus-gitlab-reconfigure)
for the changes to take effect.
For installations from source:
2022-07-23 23:45:48 +05:30
1. Edit your registry configuration YAML file:
2021-10-27 15:23:28 +05:30
2023-05-27 22:25:52 +05:30
```yaml
storage:
s3:
accesskey: 'AKIAKIAKI'
secretkey: 'secret123'
bucket: 'gitlab-registry-bucket-AKIAKIAKI'
region: 'your-s3-region'
regionendpoint: 'your-s3-regionendpoint'
encrypt: true
```
2021-10-27 15:23:28 +05:30
1. Save the file and [restart GitLab](../restart_gitlab.md#installations-from-source)
for the changes to take effect.
2020-03-13 15:44:24 +05:30
### Storage limitations
2023-07-09 08:55:56 +05:30
There is no storage limitation, which means a user can upload an
2021-01-03 14:25:43 +05:30
infinite amount of Docker images with arbitrary sizes. This setting should be
2020-03-13 15:44:24 +05:30
configurable in future releases.
2019-12-04 20:38:33 +05:30
## Change the registry's internal port
The Registry server listens on localhost at port `5000` by default,
which is the address for which the Registry server should accept connections.
2022-04-04 11:22:00 +05:30
In the examples below we set the Registry's port to `5010`.
2019-12-04 20:38:33 +05:30
**Omnibus GitLab**
1. Open `/etc/gitlab/gitlab.rb` and set `registry['registry_http_addr']`:
```ruby
2022-04-04 11:22:00 +05:30
registry['registry_http_addr'] = "localhost:5010"
2019-12-04 20:38:33 +05:30
```
1. Save the file and [reconfigure GitLab](../restart_gitlab.md#omnibus-gitlab-reconfigure) for the changes to take effect.
**Installations from source**
1. Open the configuration file of your Registry server and edit the
[`http:addr`](https://docs.docker.com/registry/configuration/#http) value:
```yaml
2021-01-03 14:25:43 +05:30
http:
2022-04-04 11:22:00 +05:30
addr: localhost:5010
2019-12-04 20:38:33 +05:30
```
1. Save the file and restart the Registry server.
## Disable Container Registry per project
If Registry is enabled in your GitLab instance, but you don't need it for your
2022-07-23 23:45:48 +05:30
project, you can [disable it from your project's settings](../../user/project/settings/index.md#configure-project-visibility-features-and-permissions).
2019-12-04 20:38:33 +05:30
2020-01-01 13:55:28 +05:30
## Use an external container registry with GitLab as an auth endpoint
2019-12-04 20:38:33 +05:30
2023-07-09 08:55:56 +05:30
WARNING:
Using external container registries in GitLab is [deprecated](https://gitlab.com/gitlab-org/gitlab/-/issues/376217)
in GitLab 15.8 and the end of support is scheduled for GitLab 16.0.
If you need to use external container registries instead of the GitLab Container Registry,
tell us about your use cases in [feedback issue 958](https://gitlab.com/gitlab-org/container-registry/-/issues/958).
2023-03-17 16:20:25 +05:30
2021-01-03 14:25:43 +05:30
If you use an external container registry, some features associated with the
2022-03-02 08:16:31 +05:30
container registry may be unavailable or have [inherent risks](../../user/packages/container_registry/reduce_container_registry_storage.md#use-with-external-container-registries).
2020-04-22 19:07:51 +05:30
2021-03-08 18:12:59 +05:30
For the integration to work, the external registry must be configured to
use a JSON Web Token to authenticate with GitLab. The
[external registry's runtime configuration](https://docs.docker.com/registry/configuration/#token)
**must** have the following entries:
```yaml
auth:
token:
realm: https://gitlab.example.com/jwt/auth
service: container_registry
issuer: gitlab-issuer
rootcertbundle: /root/certs/certbundle
```
Without these entries, the registry logins cannot authenticate with GitLab.
GitLab also remains unaware of
2023-03-17 16:20:25 +05:30
[nested image names](../../user/packages/container_registry/index.md#naming-convention-for-your-container-images)
2021-03-08 18:12:59 +05:30
under the project hierarchy, like
`registry.example.com/group/project/image-name:tag` or
`registry.example.com/group/project/my/image-name:tag`, and only recognizes
`registry.example.com/group/project:tag`.
2019-12-04 20:38:33 +05:30
**Omnibus GitLab**
2020-01-01 13:55:28 +05:30
You can use GitLab as an auth endpoint with an external container registry.
2019-12-04 20:38:33 +05:30
1. Open `/etc/gitlab/gitlab.rb` and set necessary configurations:
```ruby
gitlab_rails['registry_enabled'] = true
2021-04-17 20:07:23 +05:30
gitlab_rails['registry_api_url'] = "https://<external_registry_host>:5000"
2021-03-08 18:12:59 +05:30
gitlab_rails['registry_issuer'] = "gitlab-issuer"
2019-12-04 20:38:33 +05:30
```
2021-04-17 20:07:23 +05:30
- `gitlab_rails['registry_enabled'] = true` is needed to enable GitLab
Container Registry features and authentication endpoint. The GitLab bundled
Container Registry service does not start, even with this enabled.
- `gitlab_rails['registry_api_url'] = "http://<external_registry_host>:5000"`
must be changed to match the host where Registry is installed.
It must also specify `https` if the external registry is
configured to use TLS. Read more on the
[Docker registry documentation](https://docs.docker.com/registry/deploying/).
2021-03-08 18:12:59 +05:30
2020-01-01 13:55:28 +05:30
1. A certificate-key pair is required for GitLab and the external container
2021-01-03 14:25:43 +05:30
registry to communicate securely. You need to create a certificate-key
2020-01-01 13:55:28 +05:30
pair, configuring the external container registry with the public
2021-03-08 18:12:59 +05:30
certificate (`rootcertbundle`) and configuring GitLab with the private key.
To do that, add the following to `/etc/gitlab/gitlab.rb`:
2019-12-04 20:38:33 +05:30
```ruby
# registry['internal_key'] should contain the contents of the custom key
# file. Line breaks in the key file should be marked using `\n` character
# Example:
registry['internal_key'] = "---BEGIN RSA PRIVATE KEY---\nMIIEpQIBAA\n"
2020-01-01 13:55:28 +05:30
# Optionally define a custom file for Omnibus GitLab to write the contents
# of registry['internal_key'] to.
gitlab_rails['registry_key_path'] = "/custom/path/to/registry-key.key"
2019-12-04 20:38:33 +05:30
```
2021-01-03 14:25:43 +05:30
Each time reconfigure is executed, the file specified at `registry_key_path`
gets populated with the content specified by `internal_key`. If
no file is specified, Omnibus GitLab defaults it to
`/var/opt/gitlab/gitlab-rails/etc/gitlab-registry.key` and populates
2019-12-04 20:38:33 +05:30
it.
2020-01-01 13:55:28 +05:30
1. To change the container registry URL displayed in the GitLab Container
Registry pages, set the following configurations:
```ruby
gitlab_rails['registry_host'] = "registry.gitlab.example.com"
gitlab_rails['registry_port'] = "5005"
```
1. Save the file and [reconfigure GitLab](../restart_gitlab.md#omnibus-gitlab-reconfigure)
for the changes to take effect.
2019-12-04 20:38:33 +05:30
**Installations from source**
1. Open `/home/git/gitlab/config/gitlab.yml`, and edit the configuration settings under `registry`:
```yaml
## Container Registry
registry:
enabled: true
host: "registry.gitlab.example.com"
port: "5005"
2021-04-17 20:07:23 +05:30
api_url: "https://<external_registry_host>:5000"
path: /var/lib/registry
key: /path/to/keyfile
2021-03-08 18:12:59 +05:30
issuer: gitlab-issuer
2019-12-04 20:38:33 +05:30
```
2021-04-17 20:07:23 +05:30
[Read more](#enable-the-container-registry) about what these parameters mean.
2019-12-04 20:38:33 +05:30
1. Save the file and [restart GitLab](../restart_gitlab.md#installations-from-source) for the changes to take effect.
## Configure Container Registry notifications
You can configure the Container Registry to send webhook notifications in
2023-07-09 08:55:56 +05:30
response to events happening in the registry.
2019-12-04 20:38:33 +05:30
2020-06-23 00:09:42 +05:30
Read more about the Container Registry notifications configuration options in the
2019-12-04 20:38:33 +05:30
[Docker Registry notifications documentation](https://docs.docker.com/registry/notifications/).
2021-01-03 14:25:43 +05:30
You can configure multiple endpoints for the Container Registry.
2019-12-04 20:38:33 +05:30
**Omnibus GitLab installations**
To configure a notification endpoint in Omnibus:
1. Edit `/etc/gitlab/gitlab.rb`:
```ruby
registry['notifications'] = [
{
'name' => 'test_endpoint',
'url' => 'https://gitlab.example.com/notify',
'timeout' => '500ms',
'threshold' => 5,
'backoff' => '1s',
'headers' => {
"Authorization" => ["AUTHORIZATION_EXAMPLE_TOKEN"]
}
}
]
```
1. Save the file and [reconfigure GitLab](../restart_gitlab.md#omnibus-gitlab-reconfigure) for the changes to take effect.
**Installations from source**
2022-07-23 23:45:48 +05:30
Configuring the notification endpoint is done in your registry configuration YAML file created
2020-06-23 00:09:42 +05:30
when you [deployed your Docker registry](https://docs.docker.com/registry/deploying/).
2019-12-04 20:38:33 +05:30
Example:
```yaml
notifications:
endpoints:
- name: alistener
disabled: false
url: https://my.listener.com/event
headers: <http.Header>
timeout: 500
threshold: 5
backoff: 1000
```
2020-10-24 23:57:45 +05:30
## Run the Cleanup policy now
2021-10-27 15:23:28 +05:30
WARNING:
If you're using a distributed architecture and Sidekiq is running on a different node, the cleanup
2023-07-09 08:55:56 +05:30
policies don't work. To fix this:
1. Configure the `gitlab.rb` file on the Sidekiq nodes to
point to the correct registry URL.
1. Copy the `registry.key` file to each Sidekiq node.
For more information, see the [Sidekiq configuration](../sidekiq/index.md)
2021-10-27 15:23:28 +05:30
page.
2022-11-25 23:54:43 +05:30
To reduce the amount of [Container Registry disk space used by a given project](#registry-disk-space-usage-by-project),
2023-06-20 00:43:36 +05:30
administrators can setup cleanup policies
2020-10-24 23:57:45 +05:30
and [run garbage collection](#container-registry-garbage-collection).
2022-11-25 23:54:43 +05:30
### Registry Disk Space Usage by Project
To find the disk space used by each project, run the following in the
[GitLab Rails console](../operations/rails_console.md#starting-a-rails-console-session):
```ruby
projects_and_size = [["project_id", "creator_id", "registry_size_bytes", "project path"]]
# You need to specify the projects that you want to look through. You can get these in any manner.
projects = Project.last(100)
projects.each do |p|
project_total_size = 0
container_repositories = p.container_repositories
container_repositories.each do |c|
c.tags.each do |t|
project_total_size = project_total_size + t.total_size unless t.total_size.nil?
end
end
if project_total_size > 0
projects_and_size << [p.project_id, p.creator.id, project_total_size, p.full_path]
end
end
# print it as comma separated output
projects_and_size.each do |ps|
puts "%s,%s,%s,%s" % ps
end
```
2020-10-24 23:57:45 +05:30
To remove image tags by running the cleanup policy, run the following commands in the
2022-08-13 15:12:31 +05:30
[GitLab Rails console](../operations/rails_console.md):
2020-10-24 23:57:45 +05:30
```ruby
# Numeric ID of the project whose container registry should be cleaned up
P = <project_id>
2022-01-26 12:08:38 +05:30
# Numeric ID of a user with Developer, Maintainer, or Owner role for the project
2020-10-24 23:57:45 +05:30
U = <user_id>
# Get required details / objects
user = User.find_by_id(U)
project = Project.find_by_id(P)
policy = ContainerExpirationPolicy.find_by(project_id: P)
2020-11-24 15:15:51 +05:30
# Loop through each container repository
project.container_repositories.find_each do |repo|
puts repo.attributes
# Start the tag cleanup
2022-10-11 01:57:18 +05:30
puts Projects::ContainerRepository::CleanupTagsService.new(container_repository: repo, current_user: user, params: policy.attributes.except("created_at", "updated_at")).execute
2020-11-24 15:15:51 +05:30
end
2020-10-24 23:57:45 +05:30
```
2022-03-02 08:16:31 +05:30
You can also [run cleanup on a schedule](../../user/packages/container_registry/reduce_container_registry_storage.md#cleanup-policy).
2020-10-24 23:57:45 +05:30
2020-03-13 15:44:24 +05:30
## Container Registry garbage collection
2022-06-21 17:19:12 +05:30
NOTE:
2023-07-09 08:55:56 +05:30
Retention policies in your object storage provider, such as Amazon S3 Lifecycle, may prevent
2022-06-21 17:19:12 +05:30
objects from being properly deleted.
2020-03-13 15:44:24 +05:30
Container Registry can use considerable amounts of disk space. To clear up
some unused layers, the registry includes a garbage collect command.
GitLab offers a set of APIs to manipulate the Container Registry and aid the process
of removing unused tags. Currently, this is exposed using the API, but in the future,
2021-01-03 14:25:43 +05:30
these controls should migrate to the GitLab interface.
2020-03-13 15:44:24 +05:30
2022-01-26 12:08:38 +05:30
Users who have the [Maintainer role](../../user/permissions.md) for the project can
2020-03-13 15:44:24 +05:30
[delete Container Registry tags in bulk](../../api/container_registry.md#delete-registry-repository-tags-in-bulk)
2022-08-13 15:12:31 +05:30
periodically based on their own criteria. However, deleting the tags alone does not recycle data,
2020-03-13 15:44:24 +05:30
it only unlinks tags from manifests and image blobs. To recycle the Container
2022-08-13 15:12:31 +05:30
Registry data in the whole GitLab instance, you can use the built-in garbage collection command
2020-03-13 15:44:24 +05:30
provided by `gitlab-ctl`.
2021-01-03 14:25:43 +05:30
Prerequisites:
- You must have installed GitLab by using an Omnibus package or the
2022-11-25 23:54:43 +05:30
[GitLab Helm chart](https://docs.gitlab.com/charts/charts/registry/#garbage-collection).
2021-01-03 14:25:43 +05:30
- You must set the Registry to [read-only mode](#performing-garbage-collection-without-downtime).
Running garbage collection causes downtime for the Container Registry. When you run this command
2022-08-13 15:12:31 +05:30
on an instance in an environment where another instance is still writing to the Registry storage,
2021-01-03 14:25:43 +05:30
referenced manifests are removed.
2020-03-13 15:44:24 +05:30
### Understanding the content-addressable layers
Consider the following example, where you first build the image:
2020-04-08 14:13:33 +05:30
```shell
2020-03-13 15:44:24 +05:30
# This builds a image with content of sha256:111111
docker build -t my.registry.com/my.group/my.project:latest .
docker push my.registry.com/my.group/my.project:latest
```
Now, you do overwrite `:latest` with a new version:
2020-04-08 14:13:33 +05:30
```shell
2020-03-13 15:44:24 +05:30
# This builds a image with content of sha256:222222
docker build -t my.registry.com/my.group/my.project:latest .
docker push my.registry.com/my.group/my.project:latest
```
2023-07-09 08:55:56 +05:30
Now, the `:latest` tag points to manifest of `sha256:222222`.
Due to the architecture of registry, this data is still accessible when pulling the
image `my.registry.com/my.group/my.project@sha256:111111`, though it is
2020-03-13 15:44:24 +05:30
no longer directly accessible via the `:latest` tag.
### Recycling unused tags
2021-01-03 14:25:43 +05:30
Before you run the built-in command, note the following:
2020-03-13 15:44:24 +05:30
2021-01-03 14:25:43 +05:30
- The built-in command stops the registry before it starts the garbage collection.
2020-03-13 15:44:24 +05:30
- The garbage collect command takes some time to complete, depending on the
amount of data that exists.
2021-01-03 14:25:43 +05:30
- If you changed the location of registry configuration file, you must
2020-03-13 15:44:24 +05:30
specify its path.
2021-01-03 14:25:43 +05:30
- After the garbage collection is done, the registry should start automatically.
2020-03-13 15:44:24 +05:30
If you did not change the default location of the configuration file, run:
2020-05-24 23:13:21 +05:30
```shell
2020-03-13 15:44:24 +05:30
sudo gitlab-ctl registry-garbage-collect
```
2021-02-22 17:27:13 +05:30
This command takes some time to complete, depending on the amount of
2020-03-13 15:44:24 +05:30
layers you have stored.
If you changed the location of the Container Registry `config.yml`:
2020-05-24 23:13:21 +05:30
```shell
2020-03-13 15:44:24 +05:30
sudo gitlab-ctl registry-garbage-collect /path/to/config.yml
```
2021-01-29 00:20:46 +05:30
You may also [remove all untagged manifests and unreferenced layers](#removing-untagged-manifests-and-unreferenced-layers),
2020-03-13 15:44:24 +05:30
although this is a way more destructive operation, and you should first
understand the implications.
2021-01-29 00:20:46 +05:30
### Removing untagged manifests and unreferenced layers
2020-03-13 15:44:24 +05:30
2021-02-22 17:27:13 +05:30
WARNING:
2020-03-13 15:44:24 +05:30
This is a destructive operation.
The GitLab Container Registry follows the same default workflow as Docker Distribution:
2021-01-29 00:20:46 +05:30
retain untagged manifests and all layers, even ones that are not referenced directly. All content
can be accessed by using context addressable identifiers.
2020-03-13 15:44:24 +05:30
2021-01-29 00:20:46 +05:30
However, in most workflows, you don't care about untagged manifests and old layers if they are not directly
referenced by a tagged manifest. The `registry-garbage-collect` command supports the
2020-03-13 15:44:24 +05:30
`-m` switch to allow you to remove all unreferenced manifests and layers that are
not directly accessible via `tag`:
2020-05-24 23:13:21 +05:30
```shell
2020-03-13 15:44:24 +05:30
sudo gitlab-ctl registry-garbage-collect -m
```
Since this is a way more destructive operation, this behavior is disabled by default.
You are likely expecting this way of operation, but before doing that, ensure
that you have backed up all registry data.
2021-04-17 20:07:23 +05:30
When the command is used without the `-m` flag, the Container Registry only removes layers that are not referenced by any manifest, tagged or not.
2020-03-13 15:44:24 +05:30
### Performing garbage collection without downtime
2020-07-28 23:09:34 +05:30
You can perform garbage collection without stopping the Container Registry by putting
it in read-only mode and by not using the built-in command. On large instances
this could require Container Registry to be in read-only mode for a while.
During this time,
2021-02-22 17:27:13 +05:30
you are able to pull from the Container Registry, but you are not able to
2020-03-13 15:44:24 +05:30
push.
2020-07-28 23:09:34 +05:30
By default, the [registry storage path](#configure-storage-for-the-container-registry)
2020-03-13 15:44:24 +05:30
is `/var/opt/gitlab/gitlab-rails/shared/registry`.
To enable the read-only mode:
1. In `/etc/gitlab/gitlab.rb`, specify the read-only mode:
```ruby
registry['storage'] = {
'filesystem' => {
'rootdirectory' => "<your_registry_storage_path>"
},
'maintenance' => {
'readonly' => {
'enabled' => true
}
}
}
```
1. Save and reconfigure GitLab:
2020-05-24 23:13:21 +05:30
```shell
2020-03-13 15:44:24 +05:30
sudo gitlab-ctl reconfigure
```
2021-06-08 01:23:25 +05:30
This command sets the Container Registry into the read-only mode.
2020-03-13 15:44:24 +05:30
2020-04-08 14:13:33 +05:30
1. Next, trigger one of the garbage collect commands:
2020-03-13 15:44:24 +05:30
2023-03-04 22:38:38 +05:30
WARNING:
2023-04-23 21:23:45 +05:30
You must use `/opt/gitlab/embedded/bin/registry` to recycle unused tags. If you use `gitlab-ctl registry-garbage-collect`, **the container registry goes down**.
2023-03-04 22:38:38 +05:30
2020-05-24 23:13:21 +05:30
```shell
2020-04-08 14:13:33 +05:30
# Recycling unused tags
2020-03-13 15:44:24 +05:30
sudo /opt/gitlab/embedded/bin/registry garbage-collect /var/opt/gitlab/registry/config.yml
2020-04-08 14:13:33 +05:30
# Removing unused layers not referenced by manifests
sudo /opt/gitlab/embedded/bin/registry garbage-collect -m /var/opt/gitlab/registry/config.yml
2020-03-13 15:44:24 +05:30
```
2021-02-22 17:27:13 +05:30
This command starts the garbage collection, which might take some time to complete.
2020-03-13 15:44:24 +05:30
1. Once done, in `/etc/gitlab/gitlab.rb` change it back to read-write mode:
```ruby
registry['storage'] = {
'filesystem' => {
'rootdirectory' => "<your_registry_storage_path>"
},
'maintenance' => {
'readonly' => {
'enabled' => false
}
}
}
```
1. Save and reconfigure GitLab:
2020-05-24 23:13:21 +05:30
```shell
2020-03-13 15:44:24 +05:30
sudo gitlab-ctl reconfigure
```
### Running the garbage collection on schedule
Ideally, you want to run the garbage collection of the registry regularly on a
weekly basis at a time when the registry is not being in-use.
2021-02-22 17:27:13 +05:30
The simplest way is to add a new crontab job that it runs periodically
2020-03-13 15:44:24 +05:30
once a week.
Create a file under `/etc/cron.d/registry-garbage-collect`:
2020-04-08 14:13:33 +05:30
```shell
2020-03-13 15:44:24 +05:30
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
# Run every Sunday at 04:05am
5 4 * * 0 root gitlab-ctl registry-garbage-collect
```
2021-01-29 00:20:46 +05:30
You may want to add the `-m` flag to [remove untagged manifests and unreferenced layers](#removing-untagged-manifests-and-unreferenced-layers).
2022-01-26 12:08:38 +05:30
### Stop garbage collection
If you anticipate stopping garbage collection, you should manually run garbage collection as
described in [Performing garbage collection without downtime](#performing-garbage-collection-without-downtime).
You can then stop garbage collection by pressing <kbd>Control</kbd>+<kbd>C</kbd>.
Otherwise, interrupting `gitlab-ctl` could leave your registry service in a down state. In this
case, you must find the [garbage collection process](https://gitlab.com/gitlab-org/omnibus-gitlab/-/blob/master/files/gitlab-ctl-commands/registry_garbage_collect.rb#L26-35)
itself on the system so that the `gitlab-ctl` command can bring the registry service back up again.
Also, there's no way to save progress or results during the mark phase of the process. Only once
blobs start being deleted is anything permanent done.
2021-11-11 11:23:49 +05:30
## Configuring GitLab and Registry to run on separate nodes (Omnibus GitLab)
By default, package assumes that both services are running on the same node.
2023-01-13 00:05:48 +05:30
To get GitLab and Registry to run on a separate nodes, separate configuration
2021-11-11 11:23:49 +05:30
is necessary for Registry and GitLab.
### Configuring Registry
2022-01-26 12:08:38 +05:30
Below you can find configuration options you should set in `/etc/gitlab/gitlab.rb`,
2021-11-11 11:23:49 +05:30
for Registry to run separately from GitLab:
- `registry['registry_http_addr']`, default [set programmatically](https://gitlab.com/gitlab-org/omnibus-gitlab/blob/10-3-stable/files/gitlab-cookbooks/gitlab/libraries/registry.rb#L50). Needs to be reachable by web server (or LB).
- `registry['token_realm']`, default [set programmatically](https://gitlab.com/gitlab-org/omnibus-gitlab/blob/10-3-stable/files/gitlab-cookbooks/gitlab/libraries/registry.rb#L53). Specifies the endpoint to use to perform authentication, usually the GitLab URL.
This endpoint needs to be reachable by user.
- `registry['http_secret']`, [random string](https://gitlab.com/gitlab-org/omnibus-gitlab/blob/10-3-stable/files/gitlab-cookbooks/gitlab/libraries/registry.rb#L32). A random piece of data used to sign state that may be stored with the client to protect against tampering.
2022-01-26 12:08:38 +05:30
- `registry['internal_key']`, default [automatically generated](https://gitlab.com/gitlab-org/omnibus-gitlab/blob/10-3-stable/files/gitlab-cookbooks/gitlab/recipes/gitlab-rails.rb#L113-119). Contents of the key that GitLab uses to sign the tokens. They key gets created on the Registry server, but it is not used there.
- `gitlab_rails['registry_key_path']`, default [set programmatically](https://gitlab.com/gitlab-org/omnibus-gitlab/blob/10-3-stable/files/gitlab-cookbooks/gitlab/recipes/gitlab-rails.rb#L35). This is the path where `internal_key` contents are written to disk.
2021-11-11 11:23:49 +05:30
- `registry['internal_certificate']`, default [automatically generated](https://gitlab.com/gitlab-org/omnibus-gitlab/blob/10-3-stable/files/gitlab-cookbooks/registry/recipes/enable.rb#L60-66). Contents of the certificate that GitLab uses to sign the tokens.
- `registry['rootcertbundle']`, default [set programmatically](https://gitlab.com/gitlab-org/omnibus-gitlab/blob/10-3-stable/files/gitlab-cookbooks/registry/recipes/enable.rb#L60). Path to certificate. This is the path where `internal_certificate`
2022-01-26 12:08:38 +05:30
contents are written to disk.
2021-11-11 11:23:49 +05:30
- `registry['health_storagedriver_enabled']`, default [set programmatically](https://gitlab.com/gitlab-org/omnibus-gitlab/blob/10-7-stable/files/gitlab-cookbooks/gitlab/libraries/registry.rb#L88). Configure whether health checks on the configured storage driver are enabled.
- `gitlab_rails['registry_issuer']`, [default value](https://gitlab.com/gitlab-org/omnibus-gitlab/blob/10-3-stable/files/gitlab-cookbooks/gitlab/attributes/default.rb#L153). This setting needs to be set the same between Registry and GitLab.
### Configuring GitLab
2022-01-26 12:08:38 +05:30
Below you can find configuration options you should set in `/etc/gitlab/gitlab.rb`,
2021-11-11 11:23:49 +05:30
for GitLab to run separately from Registry:
2022-01-26 12:08:38 +05:30
- `gitlab_rails['registry_enabled']`, must be set to `true`. This setting
signals to GitLab that it should allow Registry API requests.
2021-11-11 11:23:49 +05:30
- `gitlab_rails['registry_api_url']`, default [set programmatically](https://gitlab.com/gitlab-org/omnibus-gitlab/blob/10-3-stable/files/gitlab-cookbooks/gitlab/libraries/registry.rb#L52). This is the Registry URL used internally that users do not need to interact with, `registry['registry_http_addr']` with scheme.
2022-07-23 23:45:48 +05:30
- `gitlab_rails['registry_host']`, for example, `registry.gitlab.example`. Registry endpoint without the scheme, the address that gets shown to the end user.
2021-11-11 11:23:49 +05:30
- `gitlab_rails['registry_port']`. Registry endpoint port, visible to the end user.
- `gitlab_rails['registry_issuer']` must match the issuer in the Registry configuration.
- `gitlab_rails['registry_key_path']`, path to the key that matches the certificate on the
Registry side.
- `gitlab_rails['internal_key']`, contents of the key that GitLab uses to sign the tokens.
## Architecture of GitLab Container Registry
The GitLab registry is what users use to store their own Docker images.
Because of that the Registry is client facing, meaning that we expose it directly
on the web server (or load balancers, LB for short).
![GitLab Registry diagram](img/gitlab-registry-architecture.png)
The flow described by the diagram above:
1. A user runs `docker login registry.gitlab.example` on their client. This reaches the web server (or LB) on port 443.
1. Web server connects to the Registry backend pool (by default, using port 5000). Since the user
2022-07-23 23:45:48 +05:30
didn't provide a valid token, the Registry returns a 401 HTTP code and the URL (`token_realm` from
2021-11-11 11:23:49 +05:30
Registry configuration) where to get one. This points to the GitLab API.
1. The Docker client then connects to the GitLab API and obtains a token.
1. The API signs the token with the registry key and hands it to the Docker client
1. The Docker client now logs in again with the token received from the API. It can now push and pull Docker images.
Reference: <https://docs.docker.com/registry/spec/auth/token/>
### Communication between GitLab and Registry
2022-07-23 23:45:48 +05:30
Registry doesn't have a way to authenticate users internally so it relies on
2021-11-11 11:23:49 +05:30
GitLab to validate credentials. The connection between Registry and GitLab is
TLS encrypted. The key is used by GitLab to sign the tokens while the certificate
is used by Registry to validate the signature. By default, a self-signed certificate key pair is generated
for all installations. This can be overridden as needed.
GitLab interacts with the Registry using the Registry private key. When a Registry
request goes out, a new short-living (10 minutes) namespace limited token is generated
and signed with the private key.
The Registry then verifies that the signature matches the registry certificate
specified in its configuration and allows the operation.
GitLab background jobs processing (through Sidekiq) also interacts with Registry.
2022-11-25 23:54:43 +05:30
These jobs talk directly to Registry to handle image deletion.
2021-11-11 11:23:49 +05:30
2019-12-04 20:38:33 +05:30
## Troubleshooting
Before diving in to the following sections, here's some basic troubleshooting:
1. Check to make sure that the system clock on your Docker client and GitLab server have
2021-09-30 23:02:18 +05:30
been synchronized (for example, via NTP).
2019-12-04 20:38:33 +05:30
1. If you are using an S3-backed Registry, double check that the IAM
2022-10-11 01:57:18 +05:30
permissions and the S3 credentials (including region) are correct. See
2022-08-27 11:52:29 +05:30
[the sample IAM policy](https://docs.docker.com/registry/storage-drivers/s3/)
2019-12-04 20:38:33 +05:30
for more details.
2021-09-30 23:02:18 +05:30
1. Check the Registry logs (for example `/var/log/gitlab/registry/current`) and the GitLab production logs
for errors (for example `/var/log/gitlab/gitlab-rails/production.log`). You may be able to find clues
2019-12-04 20:38:33 +05:30
there.
### Using self-signed certificates with Container Registry
If you're using a self-signed certificate with your Container Registry, you
might encounter issues during the CI jobs like the following:
2020-03-13 15:44:24 +05:30
```plaintext
2019-12-04 20:38:33 +05:30
Error response from daemon: Get registry.example.com/v1/users/: x509: certificate signed by unknown authority
```
The Docker daemon running the command expects a cert signed by a recognized CA,
thus the error above.
While GitLab doesn't support using self-signed certificates with Container
Registry out of the box, it is possible to make it work by
2020-06-23 00:09:42 +05:30
[instructing the Docker daemon to trust the self-signed certificates](https://docs.docker.com/registry/insecure/#use-self-signed-certificates),
2020-11-24 15:15:51 +05:30
mounting the Docker daemon and setting `privileged = false` in the GitLab Runner
`config.toml` file. Setting `privileged = true` takes precedence over the Docker daemon:
2019-12-04 20:38:33 +05:30
```toml
[runners.docker]
2020-03-13 15:44:24 +05:30
image = "ruby:2.6"
2019-12-04 20:38:33 +05:30
privileged = false
volumes = ["/var/run/docker.sock:/var/run/docker.sock", "/cache"]
```
2020-06-23 00:09:42 +05:30
Additional information about this: [issue 18239](https://gitlab.com/gitlab-org/gitlab-foss/-/issues/18239).
2019-12-04 20:38:33 +05:30
2021-04-17 20:07:23 +05:30
### Docker login attempt fails with: 'token signed by untrusted key'
2021-11-11 11:23:49 +05:30
[Registry relies on GitLab to validate credentials](#architecture-of-gitlab-container-registry)
2021-04-17 20:07:23 +05:30
If the registry fails to authenticate valid login attempts, you get the following error message:
```shell
# docker login gitlab.company.com:4567
Username: user
2021-06-08 01:23:25 +05:30
Password:
2021-04-17 20:07:23 +05:30
Error response from daemon: login attempt to https://gitlab.company.com:4567/v2/ failed with status: 401 Unauthorized
```
And more specifically, this appears in the `/var/log/gitlab/registry/current` log file:
```plaintext
2021-06-08 01:23:25 +05:30
level=info msg="token signed by untrusted key with ID: "TOKE:NL6Q:7PW6:EXAM:PLET:OKEN:BG27:RCIB:D2S3:EXAM:PLET:OKEN""
level=warning msg="error authorizing context: invalid token" go.version=go1.12.7 http.request.host="gitlab.company.com:4567" http.request.id=74613829-2655-4f96-8991-1c9fe33869b8 http.request.method=GET http.request.remoteaddr=10.72.11.20 http.request.uri="/v2/" http.request.useragent="docker/19.03.2 go/go1.12.8 git-commit/6a30dfc kernel/3.10.0-693.2.2.el7.x86_64 os/linux arch/amd64 UpstreamClient(Docker-Client/19.03.2 \(linux\))"
2021-04-17 20:07:23 +05:30
```
GitLab uses the contents of the certificate key pair's two sides to encrypt the authentication token
for the Registry. This message means that those contents do not align.
Check which files are in use:
- `grep -A6 'auth:' /var/opt/gitlab/registry/config.yml`
```yaml
## Container Registry Certificate
auth:
token:
realm: https://gitlab.my.net/jwt/auth
service: container_registry
issuer: omnibus-gitlab-issuer
--> rootcertbundle: /var/opt/gitlab/registry/gitlab-registry.crt
autoredirect: false
```
- `grep -A9 'Container Registry' /var/opt/gitlab/gitlab-rails/etc/gitlab.yml`
```yaml
## Container Registry Key
registry:
enabled: true
host: gitlab.company.com
port: 4567
2022-01-26 12:08:38 +05:30
api_url: http://127.0.0.1:5000 # internal address to the registry, is used by GitLab to directly communicate with API
2021-04-17 20:07:23 +05:30
path: /var/opt/gitlab/gitlab-rails/shared/registry
--> key: /var/opt/gitlab/gitlab-rails/etc/gitlab-registry.key
issuer: omnibus-gitlab-issuer
notification_secret:
```
The output of these `openssl` commands should match, proving that the cert-key pair is a match:
```shell
2022-11-25 23:54:43 +05:30
/opt/gitlab/embedded/bin/openssl x509 -noout -modulus -in /var/opt/gitlab/registry/gitlab-registry.crt | /opt/gitlab/embedded/bin/openssl sha256
/opt/gitlab/embedded/bin/openssl rsa -noout -modulus -in /var/opt/gitlab/gitlab-rails/etc/gitlab-registry.key | /opt/gitlab/embedded/bin/openssl sha256
2021-04-17 20:07:23 +05:30
```
If the two pieces of the certificate do not align, remove the files and run `gitlab-ctl reconfigure`
2022-07-23 23:45:48 +05:30
to regenerate the pair. The pair is recreated using the existing values in `/etc/gitlab/gitlab-secrets.json` if they exist. To generate a new pair,
delete the `registry` section in your `/etc/gitlab/gitlab-secrets.json` before running `gitlab-ctl reconfigure`.
If you have overridden the automatically generated self-signed pair with
2021-04-17 20:07:23 +05:30
your own certificates and have made sure that their contents align, you can delete the 'registry'
section in your `/etc/gitlab/gitlab-secrets.json` and run `gitlab-ctl reconfigure`.
2019-12-04 20:38:33 +05:30
### AWS S3 with the GitLab registry error when pushing large images
When using AWS S3 with the GitLab registry, an error may occur when pushing
large images. Look in the Registry log for the following error:
2020-03-13 15:44:24 +05:30
```plaintext
2019-12-04 20:38:33 +05:30
level=error msg="response completed with error" err.code=unknown err.detail="unexpected EOF" err.message="unknown error"
```
To resolve the error specify a `chunksize` value in the Registry configuration.
2023-03-04 22:38:38 +05:30
Start with a value between `25000000` (25 MB) and `50000000` (50 MB).
2019-12-04 20:38:33 +05:30
**For Omnibus installations**
1. Edit `/etc/gitlab/gitlab.rb`:
```ruby
registry['storage'] = {
's3' => {
'accesskey' => 'AKIAKIAKI',
'secretkey' => 'secret123',
'bucket' => 'gitlab-registry-bucket-AKIAKIAKI',
'chunksize' => 25000000
}
}
```
1. Save the file and [reconfigure GitLab](../restart_gitlab.md#omnibus-gitlab-reconfigure) for the changes to take effect.
**For installations from source**
1. Edit `config/gitlab.yml`:
```yaml
storage:
s3:
accesskey: 'AKIAKIAKI'
secretkey: 'secret123'
2021-01-03 14:25:43 +05:30
bucket: 'gitlab-registry-bucket-AKIAKIAKI'
2019-12-04 20:38:33 +05:30
chunksize: 25000000
```
1. Save the file and [restart GitLab](../restart_gitlab.md#installations-from-source) for the changes to take effect.
### Supporting older Docker clients
2022-03-02 08:16:31 +05:30
The Docker container registry shipped with GitLab disables the schema1 manifest
by default. If you are still using older Docker clients (1.9 or older), you may
experience an error pushing images. See
[omnibus-4145](https://gitlab.com/gitlab-org/omnibus-gitlab/-/issues/4145) for more details.
2019-12-04 20:38:33 +05:30
You can add a configuration option for backwards compatibility.
**For Omnibus installations**
1. Edit `/etc/gitlab/gitlab.rb`:
```ruby
registry['compatibility_schema1_enabled'] = true
```
1. Save the file and [reconfigure GitLab](../restart_gitlab.md#omnibus-gitlab-reconfigure) for the changes to take effect.
**For installations from source**
2022-07-23 23:45:48 +05:30
1. Edit the YAML configuration file you created when you [deployed the registry](https://docs.docker.com/registry/deploying/). Add the following snippet:
2019-12-04 20:38:33 +05:30
```yaml
compatibility:
schema1:
enabled: true
```
1. Restart the registry for the changes to take affect.
### Docker connection error
A Docker connection error can occur when there are special characters in either the group,
project or branch name. Special characters can include:
- Leading underscore
- Trailing hyphen/dash
- Double hyphen/dash
2022-08-27 11:52:29 +05:30
To get around this, you can [change the group path](../../user/group/manage.md#change-a-groups-path),
2022-08-13 15:12:31 +05:30
[change the project path](../../user/project/settings/index.md#rename-a-repository) or change the
2022-04-04 11:22:00 +05:30
branch name. Another option is to create a [push rule](../../user/project/repository/push_rules.md) to prevent
2019-12-04 20:38:33 +05:30
this at the instance level.
### Image push errors
When getting errors or "retrying" loops in an attempt to push an image but `docker login` works fine,
there is likely an issue with the headers forwarded to the registry by NGINX. The default recommended
NGINX configurations should handle this, but it might occur in custom setups where the SSL is
offloaded to a third party reverse proxy.
2020-06-23 00:09:42 +05:30
This problem was discussed in a [Docker project issue](https://github.com/docker/distribution/issues/970)
2019-12-04 20:38:33 +05:30
and a simple solution would be to enable relative URLs in the Registry.
**For Omnibus installations**
1. Edit `/etc/gitlab/gitlab.rb`:
```ruby
registry['env'] = {
"REGISTRY_HTTP_RELATIVEURLS" => true
}
```
1. Save the file and [reconfigure GitLab](../restart_gitlab.md#omnibus-gitlab-reconfigure) for the changes to take effect.
**For installations from source**
2022-07-23 23:45:48 +05:30
1. Edit the YAML configuration file you created when you [deployed the registry](https://docs.docker.com/registry/deploying/). Add the following snippet:
2019-12-04 20:38:33 +05:30
```yaml
http:
relativeurls: true
```
1. Save the file and [restart GitLab](../restart_gitlab.md#installations-from-source) for the changes to take effect.
### Enable the Registry debug server
2021-02-22 17:27:13 +05:30
You can use the Container Registry debug server to diagnose problems. The debug endpoint can monitor metrics and health, as well as do profiling.
WARNING:
Sensitive information may be available from the debug endpoint.
Access to the debug endpoint must be locked down in a production environment.
2019-12-04 20:38:33 +05:30
The optional debug server can be enabled by setting the registry debug address
in your `gitlab.rb` configuration.
```ruby
registry['debug_addr'] = "localhost:5001"
```
After adding the setting, [reconfigure GitLab](../restart_gitlab.md#omnibus-gitlab-reconfigure) to apply the change.
Use curl to request debug output from the debug server:
2020-03-13 15:44:24 +05:30
```shell
2021-02-22 17:27:13 +05:30
curl "localhost:5001/debug/health"
curl "localhost:5001/debug/vars"
2019-12-04 20:38:33 +05:30
```
2021-09-04 01:27:46 +05:30
### Access old schema v1 Docker images
2022-08-13 15:12:31 +05:30
Support for the Docker registry API V1,
2021-09-04 01:27:46 +05:30
including [schema V1 image manifests](https://docs.docker.com/registry/spec/manifest-v2-1/),
was:
- [Deprecated in GitLab 13.7](https://about.gitlab.com/releases/2020/12/22/gitlab-13-7-released/#deprecate-pulls-that-use-v1-of-the-docker-registry-api)
- [Removed in GitLab 13.9](https://about.gitlab.com/releases/2021/02/22/gitlab-13-9-released/#deprecate-pulls-that-use-v1-of-the-docker-registry-api)
It's no longer possible to push or pull v1 images from the GitLab Container Registry.
If you had v1 images in the GitLab Container Registry, but you did not upgrade them (following the
[steps Docker recommends](https://docs.docker.com/registry/spec/deprecated-schema-v1/))
ahead of the GitLab 13.9 upgrade, these images are no longer accessible. If you try to pull them,
this error appears:
- `Error response from daemon: manifest invalid: Schema 1 manifest not supported`
For Self-Managed GitLab instances, you can regain access to these images by temporarily downgrading
the GitLab Container Registry to a version lower than `v3.0.0-gitlab`. Follow these steps to regain
access to these images:
1. Downgrade the Container Registry to [`v2.13.1-gitlab`](https://gitlab.com/gitlab-org/container-registry/-/releases/v2.13.1-gitlab).
1. Upgrade any v1 images.
1. Revert the Container Registry downgrade.
There's no need to put the registry in read-only mode during the image upgrade process. Ensure that
you are not relying on any new feature introduced since `v3.0.0-gitlab`. Such features are
unavailable during the upgrade process. See the [complete registry changelog](https://gitlab.com/gitlab-org/container-registry/-/blob/master/CHANGELOG.md)
for more information.
The following sections provide additional details about each installation method.
#### Helm chart installations
For Helm chart installations:
1. Override the [`image.tag`](https://docs.gitlab.com/charts/charts/registry/#configuration)
configuration parameter with `v2.13.1-gitlab`.
1. Restart.
1. Performing the [images upgrade](#images-upgrade)) steps.
1. Revert the `image.tag` parameter to the previous value.
No other registry configuration changes are required.
#### Omnibus installations
For Omnibus installations:
1. Temporarily replace the registry binary that ships with GitLab 13.9+ for one prior to
`v3.0.0-gitlab`. To do so, pull a previous version of the Docker image for the GitLab Container
Registry, such as `v2.13.1-gitlab`. You can then grab the `registry` binary from within this
image, located at `/bin/registry`:
```shell
id=$(docker create registry.gitlab.com/gitlab-org/build/cng/gitlab-container-registry:v2.13.1-gitlab)
docker cp $id:/bin/registry registry-2.13.1-gitlab
docker rm $id
```
1. Replace the binary embedded in the Omnibus install, located at
`/opt/gitlab/embedded/bin/registry`, with `registry-2.13.1-gitlab`. Make sure to start by backing
up the original binary embedded in Omnibus, and restore it after performing the
[image upgrade](#images-upgrade)) steps. You should [stop](https://docs.gitlab.com/omnibus/maintenance/#starting-and-stopping)
the registry service before replacing its binary and start it right after. No registry
configuration changes are required.
2021-09-30 23:02:18 +05:30
2021-09-04 01:27:46 +05:30
#### Source installations
For source installations, locate your `registry` binary and temporarily replace it with the one
obtained from `v3.0.0-gitlab`, as explained for [Omnibus installations](#omnibus-installations).
Make sure to start by backing up the original registry binary, and restore it after performing the
[images upgrade](#images-upgrade))
steps.
#### Images upgrade
Follow the [steps that Docker recommends to upgrade v1 images](https://docs.docker.com/registry/spec/deprecated-schema-v1/).
The most straightforward option is to pull those images and push them once again to the registry,
using a Docker client version above v1.12. Docker converts images automatically before pushing them
to the registry. Once done, all your v1 images should now be available as v2 images.
2022-01-26 12:08:38 +05:30
### Tags with an empty name
If using [AWS DataSync](https://aws.amazon.com/datasync/)
to copy the registry data to or between S3 buckets, an empty metadata object is created in the root
path of each container repository in the destination bucket. This causes the registry to interpret
such files as a tag that appears with no name in the GitLab UI and API. For more information, see
[this issue](https://gitlab.com/gitlab-org/container-registry/-/issues/341).
To fix this you can do one of two things:
- Use the AWS CLI [`rm`](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/s3/rm.html)
command to remove the empty objects from the root of **each** affected repository. Pay special
attention to the trailing `/` and make sure **not** to use the `--recursive` option:
```shell
aws s3 rm s3://<bucket>/docker/registry/v2/repositories/<path to repository>/
```
- Use the AWS CLI [`sync`](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/s3/sync.html)
command to copy the registry data to a new bucket and configure the registry to use it. This
leaves the empty objects behind.
2019-12-04 20:38:33 +05:30
### Advanced Troubleshooting
2021-02-22 17:27:13 +05:30
We use a concrete example to illustrate how to
2019-12-04 20:38:33 +05:30
diagnose a problem with the S3 setup.
2022-04-04 11:22:00 +05:30
#### Investigate a cleanup policy
If you're unsure why your cleanup policy did or didn't delete a tag, execute the policy line by line
by running the below script from the [Rails console](../../administration/operations/rails_console.md).
This can help diagnose problems with the policy.
```ruby
repo = ContainerRepository.find(<project_id>)
policy = repo.project.container_expiration_policy
tags = repo.tags
tags.map(&:name)
tags.reject!(&:latest?)
tags.map(&:name)
regex_delete = ::Gitlab::UntrustedRegexp.new("\\A#{policy.name_regex}\\z")
regex_retain = ::Gitlab::UntrustedRegexp.new("\\A#{policy.name_regex_keep}\\z")
tags.select! { |tag| regex_delete.match?(tag.name) && !regex_retain.match?(tag.name) }
tags.map(&:name)
now = DateTime.current
tags.sort_by! { |tag| tag.created_at || now }.reverse! # Lengthy operation
tags = tags.drop(policy.keep_n)
tags.map(&:name)
older_than_timestamp = ChronicDuration.parse(policy.older_than).seconds.ago
tags.select! { |tag| tag.created_at && tag.created_at < older_than_timestamp }
tags.map(&:name)
```
- The script builds the list of tags to delete (`tags`).
- `tags.map(&:name)` prints a list of tags to remove. This may be a lengthy operation.
- After each filter, check the list of `tags` to see if it contains the intended tags to destroy.
2019-12-04 20:38:33 +05:30
#### Unexpected 403 error during push
A user attempted to enable an S3-backed Registry. The `docker login` step went
fine. However, when pushing an image, the output showed:
2020-03-13 15:44:24 +05:30
```plaintext
2020-06-23 00:09:42 +05:30
The push refers to a repository [s3-testing.myregistry.com:5050/root/docker-test/docker-image]
2019-12-04 20:38:33 +05:30
dc5e59c14160: Pushing [==================================================>] 14.85 kB
03c20c1a019a: Pushing [==================================================>] 2.048 kB
a08f14ef632e: Pushing [==================================================>] 2.048 kB
228950524c88: Pushing 2.048 kB
6a8ecde4cc03: Pushing [==> ] 9.901 MB/205.7 MB
5f70bf18a086: Pushing 1.024 kB
737f40e80b7f: Waiting
82b57dbc5385: Waiting
19429b698a22: Waiting
9436069b92a3: Waiting
error parsing HTTP 403 response body: unexpected end of JSON input: ""
```
This error is ambiguous, as it's not clear whether the 403 is coming from the
GitLab Rails application, the Docker Registry, or something else. In this
case, since we know that since the login succeeded, we probably need to look
at the communication between the client and the Registry.
2021-06-08 01:23:25 +05:30
The REST API between the Docker client and Registry is described
2023-04-23 21:23:45 +05:30
[in the Docker documentation](https://docs.docker.com/registry/spec/api/). Usually, one would just
2019-12-04 20:38:33 +05:30
use Wireshark or tcpdump to capture the traffic and see where things went
wrong. However, since all communications between Docker clients and servers
are done over HTTPS, it's a bit difficult to decrypt the traffic quickly even
if you know the private key. What can we do instead?
2022-10-11 01:57:18 +05:30
One way would be to disable HTTPS by setting up an
2022-08-27 11:52:29 +05:30
[insecure Registry](https://docs.docker.com/registry/insecure/). This could introduce a
2019-12-04 20:38:33 +05:30
security hole and is only recommended for local testing. If you have a
production system and can't or don't want to do this, there is another way:
use mitmproxy, which stands for Man-in-the-Middle Proxy.
#### mitmproxy
[mitmproxy](https://mitmproxy.org/) allows you to place a proxy between your
client and server to inspect all traffic. One wrinkle is that your system
needs to trust the mitmproxy SSL certificates for this to work.
The following installation instructions assume you are running Ubuntu:
1. [Install mitmproxy](https://docs.mitmproxy.org/stable/overview-installation/).
1. Run `mitmproxy --port 9000` to generate its certificates.
Enter <kbd>CTRL</kbd>-<kbd>C</kbd> to quit.
1. Install the certificate from `~/.mitmproxy` to your system:
2020-03-13 15:44:24 +05:30
```shell
2019-12-04 20:38:33 +05:30
sudo cp ~/.mitmproxy/mitmproxy-ca-cert.pem /usr/local/share/ca-certificates/mitmproxy-ca-cert.crt
sudo update-ca-certificates
```
If successful, the output should indicate that a certificate was added:
2020-03-13 15:44:24 +05:30
```shell
2019-12-04 20:38:33 +05:30
Updating certificates in /etc/ssl/certs... 1 added, 0 removed; done.
Running hooks in /etc/ca-certificates/update.d....done.
```
To verify that the certificates are properly installed, run:
2020-03-13 15:44:24 +05:30
```shell
2019-12-04 20:38:33 +05:30
mitmproxy --port 9000
```
2021-02-22 17:27:13 +05:30
This command runs mitmproxy on port `9000`. In another window, run:
2019-12-04 20:38:33 +05:30
2020-03-13 15:44:24 +05:30
```shell
2021-02-22 17:27:13 +05:30
curl --proxy "http://localhost:9000" "https://httpbin.org/status/200"
2019-12-04 20:38:33 +05:30
```
2021-02-22 17:27:13 +05:30
If everything is set up correctly, information is displayed on the mitmproxy window and
no errors are generated by the curl commands.
2019-12-04 20:38:33 +05:30
#### Running the Docker daemon with a proxy
For Docker to connect through a proxy, you must start the Docker daemon with the
2021-09-30 23:02:18 +05:30
proper environment variables. The easiest way is to shutdown Docker (for example `sudo initctl stop docker`)
2019-12-04 20:38:33 +05:30
and then run Docker by hand. As root, run:
2020-03-13 15:44:24 +05:30
```shell
2019-12-04 20:38:33 +05:30
export HTTP_PROXY="http://localhost:9000"
export HTTPS_PROXY="https://localhost:9000"
docker daemon --debug
```
2021-02-22 17:27:13 +05:30
This command launches the Docker daemon and proxies all connections through mitmproxy.
2019-12-04 20:38:33 +05:30
#### Running the Docker client
2021-01-29 00:20:46 +05:30
Now that we have mitmproxy and Docker running, we can attempt to sign in and
push a container image. You may need to run as root to do this. For example:
2019-12-04 20:38:33 +05:30
2020-03-13 15:44:24 +05:30
```shell
2020-06-23 00:09:42 +05:30
docker login s3-testing.myregistry.com:5050
docker push s3-testing.myregistry.com:5050/root/docker-test/docker-image
2019-12-04 20:38:33 +05:30
```
In the example above, we see the following trace on the mitmproxy window:
![mitmproxy output from Docker](img/mitmproxy-docker.png)
The above image shows:
- The initial PUT requests went through fine with a 201 status code.
- The 201 redirected the client to the S3 bucket.
- The HEAD request to the AWS bucket reported a 403 Unauthorized.
What does this mean? This strongly suggests that the S3 user does not have the right
2019-12-26 22:10:19 +05:30
[permissions to perform a HEAD request](https://docs.aws.amazon.com/AmazonS3/latest/API/API_HeadObject.html).
2019-12-04 20:38:33 +05:30
The solution: check the [IAM permissions again](https://docs.docker.com/registry/storage-drivers/s3/).
2021-02-22 17:27:13 +05:30
Once the right permissions were set, the error goes away.
2022-05-07 20:08:51 +05:30
### Missing `gitlab-registry.key` prevents container repository deletion
If you disable your GitLab instance's Container Registry and try to remove a project that has
container repositories, the following error occurs:
```plaintext
Errno::ENOENT: No such file or directory @ rb_sysopen - /var/opt/gitlab/gitlab-rails/etc/gitlab-registry.key
```
In this case, follow these steps:
1. Temporarily enable the instance-wide setting for the Container Registry in your `gitlab.rb`:
```ruby
gitlab_rails['registry_enabled'] = true
```
2022-07-23 23:45:48 +05:30
2022-05-07 20:08:51 +05:30
1. Save the file and [reconfigure GitLab](../restart_gitlab.md#omnibus-gitlab-reconfigure)
for the changes to take effect.
1. Try the removal again.
If you still can't remove the repository using the common methods, you can use the
2022-08-13 15:12:31 +05:30
[GitLab Rails console](../operations/rails_console.md)
2022-05-07 20:08:51 +05:30
to remove the project by force:
```ruby
# Path to the project you'd like to remove
prj = Project.find_by_full_path(<project_path>)
# The following will delete the project's container registry, so be sure to double-check the path beforehand!
if prj.has_container_registry_tags?
prj.container_repositories.each { |p| p.destroy }
end
```