debian-mirror-gitlab/doc/administration/container_registry.md
2017-08-17 22:00:37 +05:30

18 KiB

GitLab Container Registry administration

Introduced in GitLab 8.8.


Notes:

  • Container Registry manifest v1 support was added in GitLab 8.9 to support Docker versions earlier than 1.10.
  • This document is about the admin guide. To learn how to use GitLab Container Registry user documentation.

With the Container Registry integrated into GitLab, every project can have its own space to store its Docker images.

You can read more about the Container Registry at https://docs.docker.com/registry/introduction/.

Enable the Container Registry

Omnibus GitLab installations

All you have to do is configure the domain name under which the Container Registry will listen to. Read #container-registry-domain-configuration and pick one of the two options that fits your case.

Note: The container registry works under HTTPS by default. Using HTTP is possible but not recommended and out of the scope of this document. Read the insecure Registry documentation if you want to implement this.


Installations from source

If you have installed GitLab from source:

  1. You will have to install Registry by yourself.
  2. After the installation is complete, you will have to configure the Registry's settings in gitlab.yml in order to enable it.
  3. Use the sample NGINX configuration file that is found under lib/support/nginx/registry-ssl and edit it to match the host, port and TLS certs paths.

The contents of gitlab.yml are:

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

where:

Parameter Description
enabled true or false. Enables the Registry in GitLab. By default this is false.
host The host URL under which the Registry will run and the users will be able to use.
port The port under which the external Registry domain will listen on.
api_url The internal API URL under which the Registry is exposed to. It defaults to http://localhost:5000.
key The private key location that is a pair of Registry's rootcertbundle. Read the token auth configuration documentation.
path This should be the same directory like specified in Registry's rootdirectory. Read the storage configuration documentation. This path needs to be readable by the GitLab user, the web-server user and the Registry user. Read more in #container-registry-storage-path.
issuer This should be the same value as configured in Registry's issuer. Read the token auth configuration documentation.

Note: A Registry init file is not shipped with GitLab if you install it from source. Hence, restarting GitLab will not restart the Registry should you modify its settings. Read the upstream documentation on how to achieve that.

At the absolute minimum, make sure your Registry configuration has container_registry as the service and https://gitlab.example.com/jwt/auth as the realm:

auth:
  token:
    realm: https://gitlab.example.com/jwt/auth
    service: container_registry
    issuer: gitlab-issuer
    rootcertbundle: /root/certs/certbundle

Container Registry domain configuration

There are two ways you can configure the Registry's external domain.

Since the container Registry requires a TLS certificate, in the end it all boils down to how easy or pricey is to get a new one.

Please take this into consideration before configuring the Container Registry for the first time.

Configure Container Registry under an existing GitLab domain

If the Registry is configured to use the existing GitLab domain, you can expose the Registry on a port so that you can reuse the existing GitLab TLS certificate.

Assuming that the GitLab domain is https://gitlab.example.com and the port the Registry is exposed to the outside world is 4567, here is what you need to set in gitlab.rb or gitlab.yml if you are using Omnibus GitLab or installed GitLab from source respectively.

Note: Be careful to choose a port different than the one that Registry listens to (5000 by default), otherwise you will run into conflicts .


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:

    registry_external_url 'https://gitlab.example.com:4567'
    

    Note how the registry_external_url is listening on HTTPS under the 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:

    registry_nginx['ssl_certificate'] = "/path/to/certificate.pem"
    registry_nginx['ssl_certificate_key'] = "/path/to/certificate.key"
    
  2. Save the file and reconfigure GitLab for the changes to take effect.


Installations from source

  1. Open /home/git/gitlab/config/gitlab.yml, find the registry entry and configure it with the following settings:

    registry:
      enabled: true
      host: gitlab.example.com
      port: 4567
    
  2. Save the file and restart GitLab for the changes to take effect.

  3. Make the relevant changes in NGINX as well (domain, port, TLS certificates path).


Users should now be able to login to the Container Registry with their GitLab credentials using:

docker login gitlab.example.com:4567

Configure Container Registry under its own domain

If the Registry is configured to use its own domain, you will need a TLS certificate for that specific domain (e.g., registry.example.com) or maybe a wildcard certificate if hosted under a subdomain of your existing GitLab domain (e.g., registry.gitlab.example.com).

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:

    chmod 600 /etc/gitlab/ssl/registry.gitlab.example.com.*
    
  2. Once the TLS certificate is in place, edit /etc/gitlab/gitlab.rb with:

    registry_external_url 'https://registry.gitlab.example.com'
    

    Note how the registry_external_url is listening on HTTPS.

  3. Save the file and reconfigure GitLab for the changes to take effect.

Note: If you have a wildcard certificate, you need to specify the path to the certificate in addition to the URL, in this case /etc/gitlab/gitlab.rb will look like:

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:

    registry:
      enabled: true
      host: registry.gitlab.example.com
    
  2. Save the file and restart GitLab for the changes to take effect.

  3. Make the relevant changes in NGINX as well (domain, port, TLS certificates path).


Users should now be able to login to the Container Registry using their GitLab credentials:

docker login registry.gitlab.example.com

Disable Container Registry site-wide

Note: Disabling the Registry in the Rails GitLab application as set by the following steps, will not remove any existing Docker images. This is handled by the Registry application itself.

Omnibus GitLab

  1. Open /etc/gitlab/gitlab.rb and set registry['enable'] to false:

    registry['enable'] = false
    
  2. Save the file and reconfigure GitLab 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:

    registry:
      enabled: false
    
  2. Save the file and restart GitLab for the changes to take effect.

Disable Container Registry for new projects site-wide

If the Container Registry is enabled, then it will be available on all new 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:

    gitlab_rails['gitlab_default_projects_features_container_registry'] = false
    
  2. Save the file and reconfigure GitLab 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:

    ## Default project features settings
    default_projects_features:
      issues: true
      merge_requests: true
      wiki: true
      snippets: false
      builds: true
      container_registry: false
    
  2. Save the file and restart GitLab for the changes to take effect.

Container Registry storage path

Note: For configuring storage in the cloud instead of the filesystem, see the storage driver configuration.

If you want to store your images on the filesystem, you can change the storage 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

Warning

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:

    gitlab_rails['registry_path'] = "/path/to/registry/storage"
    
  2. Save the file and reconfigure GitLab 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:

    registry:
      path: shared/registry
    
  2. Save the file and restart GitLab for the changes to take effect.

Container Registry storage driver

You can configure the Container Registry to use a different storage backend by configuring a different storage driver. By default the GitLab Container Registry is configured to use the filesystem driver, which makes use of storage path configuration.

The different supported drivers are:

Driver Description
filesystem Uses a path on the local filesystem
azure Microsoft Azure Blob Storage
gcs Google Cloud Storage
s3 Amazon Simple Storage Service
swift OpenStack Swift Object Storage
oss Aliyun OSS

Read more about the individual driver's config options in the Docker Registry docs.

Warning

filesystem. Remember to enable backups with your object storage provider if desired.

Important Enabling storage driver other than filesystem would mean that your Docker client needs to be able to access the storage backend directly. So you must use an address that resolves and is accessible outside GitLab server.


Omnibus GitLab installations

To configure the storage driver in Omnibus:

  1. Edit /etc/gitlab/gitlab.rb:

    registry['storage'] = {
      's3' => {
        'accesskey' => 's3-access-key',
        'secretkey' => 's3-secret-key-for-access-key',
        'bucket' => 'your-s3-bucket',
        'region' => 'your-s3-region'
      }
    }
    
  2. Save the file and reconfigure GitLab for the changes to take effect.


Installations from source

Configuring the storage driver is done in your registry config YML file created when you deployed your docker registry.

Example:

storage:
  s3:
    accesskey: 'AKIAKIAKI'
    secretkey: 'secret123'
    bucket: 'gitlab-registry-bucket-AKIAKIAKI'
    region: 'your-s3-region'
  cache:
    blobdescriptor: inmemory
  delete:
    enabled: true

Change the registry's internal port

Note: This is not to be confused with the port that GitLab itself uses to expose the Registry to the world.

The Registry server listens on localhost at port 5000 by default, which is the address for which the Registry server should accept connections. In the examples below we set the Registry's port to 5001.

Omnibus GitLab

  1. Open /etc/gitlab/gitlab.rb and set registry['registry_http_addr']:

    registry['registry_http_addr'] = "localhost:5001"
    
  2. Save the file and reconfigure GitLab for the changes to take effect.


Installations from source

  1. Open the configuration file of your Registry server and edit the http:addr value:

    http
      addr: localhost:5001
    
  2. 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 project, you can disable it from your project's settings. Read the user guide on how to achieve that.

Disable Container Registry but use GitLab as an auth endpoint

You can disable the embedded Container Registry to use an external one, but still use GitLab as an auth endpoint.

Omnibus GitLab

  1. Open /etc/gitlab/gitlab.rb and set necessary configurations:

    registry['enable'] = false
    gitlab_rails['registry_enabled'] = true
    gitlab_rails['registry_host'] = "registry.gitlab.example.com"
    gitlab_rails['registry_port'] = "5005"
    gitlab_rails['registry_api_url'] = "http://localhost:5000"
    gitlab_rails['registry_key_path'] = "/var/opt/gitlab/gitlab-rails/certificate.key"
    gitlab_rails['registry_path'] = "/var/opt/gitlab/gitlab-rails/shared/registry"
    gitlab_rails['registry_issuer'] = "omnibus-gitlab-issuer"
    
  2. Save the file and reconfigure GitLab for the changes to take effect.

Installations from source

  1. Open /home/git/gitlab/config/gitlab.yml, and edit the configuration settings under registry:

    ## Container Registry
    
    registry:
      enabled: true
      host: "registry.gitlab.example.com"
      port: "5005"
      api_url: "http://localhost:5000"
      path: /var/opt/gitlab/gitlab-rails/shared/registry
      key: /var/opt/gitlab/gitlab-rails/certificate.key
      issuer: omnibus-gitlab-issuer
    
  2. Save the file and restart GitLab for the changes to take effect.

Storage limitations

Currently, there is no storage limitation, which means a user can upload an infinite amount of Docker images with arbitrary sizes. This setting will be configurable in future releases.

Configure Container Registry notifications

You can configure the Container Registry to send webhook notifications in response to events happening within the registry.

Read more about the Container Registry notifications config options in the Docker Registry notifications documentation.

Note: Multiple endpoints can be configured for the Container Registry.

Omnibus GitLab installations

To configure a notification endpoint in Omnibus:

  1. Edit /etc/gitlab/gitlab.rb:

    registry['notifications'] = [
      {
        'name' => 'test_endpoint',
        'url' => 'https://gitlab.example.com/notify',
        'timeout' => '500ms',
        'threshold' => 5,
        'backoff' => '1s',
        'headers' => {
          "Authorization" => ["AUTHORIZATION_EXAMPLE_TOKEN"]
        }
      }
    ]
    
  2. Save the file and reconfigure GitLab for the changes to take effect.


Installations from source

Configuring the notification endpoint is done in your registry config YML file created when you deployed your docker registry.

Example:

notifications:
  endpoints:
    - name: alistener
      disabled: false
      url: https://my.listener.com/event
      headers: <http.Header>
      timeout: 500
      threshold: 5
      backoff: 1000

Changelog

GitLab 8.8 (source docs)

  • GitLab Container Registry feature was introduced.