Sync expected URL between Rails and Container Registry for import notifications

Context

As part of the container registry migration phase 2, we want to notify GitLab Rails when a pre-import or an import operation has completed.

The features have been implemented on both sides with container-registry#529 (closed) and #349742 (closed).

However, there are a few details that are not clear yet and we need to sync between both sides.

Current Status

  • The container registry has a new section that can be configurable with the import notification endpoint - container-registry!854 (merged)

    migration:
      enabled: true
      rootdirectory: online
        importnotification:
          enabled: true
          url: 'http://registry.test:3000/api/v4/internal/registry/repositories/{path}/migration/status'
          timeout: 10s
          secret: 'registry-secret'
  • GitLab now exposes an internal API that expects the import notification - !79200 (merged)

Problems

While testing the integration for container-registry#529 (closed) I found the following issues:

  • The container registry needs to make sure that the configured URL can be built including the repository path to match the endpoint Rails is expecting: 'https://gitlab.com/api/v4/internal/registry/repositories/:path/migration/status'. Currently the registry will just use the configured URL without any parsing logic.

  • The container registry API has a strict slash policy, meaning that the routes need to include the forward slash / at the end of the URL. In my testing I found out that Rails sends the PUT request without the slash /, see the log below for uri="/gitlab/v1/import/root/hello?pre=true"

    INFO[0838] access                                        content_type= correlation_id=01FTZ5YSTHQG45V1TAGA394K1X duration_ms=0 host="gdk.test:5000" method=PUT proto=HTTP/1.1 referrer= remote_addr="172.16.123.1:53803" remote_ip=172.16.123.1 status=301 system=http ttfb_ms=0 uri="/gitlab/v1/import/root/hello?pre=true" user_agent=GitLab/14.8.0-pre written_bytes=0
    • The registry will indicate a redirect with a 301

Proposal

Here is a possible solution

Container registry:

  • Allow passing a {path} in the URL that the import notifier can parse and replace with the repository path.
  • Another solution is always attaching the /migration/status subpath at the end of the request.

GitLab Rails:

  • Ensure the forward slash / is included in the request, or
  • Follow the redirect.

Regardless of each choice we need to make changes on both sides.