Skip to content

Drive container registry migration phase 1 with Rails FFs [RUN ALL RSPEC] [RUN AS-IF-FOSS]

João Pereira requested to merge container-registry-migration-phase1 into master

What does this MR do?

Related to #335260 (closed). Please see the description of this issue for context, technical background, functional diagrams, and a description of each FF introduced here as well as how they relate to each other.

How to test this change locally with GDK

We'll assume the existence of the gitlab-org/gitlab-test project in your GDK instance and use it for these tests. You can pick any other project, as long as the Container Registry feature is enabled for it.

We'll also assume that your GDK Rails instance is listening at gdk.test:3000 and you have a user root with a PAT foobar, with write permissions to the container registry.

We need to query the Rails API and decode a few JWT tokens during these tests. To do so you can either decode it with a JWT debugger on the web (e.g. https://jwt.io/) or use a CLI tool such as jwt-cli. We'll use the latter. We'll also use httpie to make the requests and jq to parse the token from the response, but you can do that with any other tools or manually.

Current behavior

  1. Checkout the main branch of this repository.

  2. Open up a Rails console and a terminal window/pane.

  3. On your terminal and obtain a JWT token with push permissions for gitlab-org/gitlab-test:

    http -a root:foobar http://gdk.test:3000/jwt/auth \
        client_id=="docker" \
        service=="container_registry" \
        scope=="repository:gitlab-org/gitlab-test:push" | jq -r '.token' | jwt decode -

    Output (timestamp fields will vary, the important part is access):

    Token header
    ------------
    ...
    
    Token claims
    ------------
    {
      "access": [
        {
          "actions": [
            "push"
          ],
          "name": "gitlab-org/gitlab-test",
          "type": "repository"
        }
      ],
      "aud": "container_registry",
      "exp": 1625855309,
      "iat": 1625851709,
      "iss": "gitlab-issuer",
      "jti": "51d7aa5d-5077-4d27-94fc-a250f4e7501e",
      "nbf": 1625851704,
      "sub": "root"
    }

New behavior

  1. Checkout this MR's branch.

  2. Repeat the /jwt/auth request. The output should be identical to the above (except for the timestamp fields), because all FFs are disabled by default.

  3. Enable container_registry_migration_phase1:

    Feature.enable(:container_registry_migration_phase1)
  4. Repeat the /jwt/auth request. This time we should now see a new migration_eligible field set to false (the FF change may take a bit to propagate):

    Token header
    ------------
    ...
    
    Token claims
    ------------
    {
      "access": [
        {
          "actions": [
            "push"
          ],
          "migration_eligible": false,
          "name": "gitlab-org/gitlab-test",
          "type": "repository"
        }
      ],
      "aud": "container_registry",
      "exp": 1625855625,
      "iat": 1625852025,
      "iss": "gitlab-issuer",
      "jti": "c750d758-8944-4a86-ab34-bca6082ce2ee",
      "nbf": 1625852020,
      "sub": "root"
    }
  5. Repeat the /jwt/auth request, but this time set the scope parameter to repository:gitlab-org/gitlab-test:pull instead of repository:gitlab-org/gitlab-test:push. Because we're not granting write permissions with this token, there should be no migration_eligible field in the token.

  6. Enable container_registry_migration_phase1_allow for gitlab-org/gitlab-test:

    Feature.enable(:container_registry_migration_phase1_allow, Project.find_by_full_path('gitlab-org/gitlab-test'))
  7. Repeat the /jwt/auth request. This time migration_eligible should be set to true.

  8. Enable container_registry_migration_phase1_deny for the gitlab-org top-level group/namespace:

    Feature.enable(:container_registry_migration_phase1_deny, Project.find_by_full_path('gitlab-org/gitlab-test').root_ancestor)
  9. Repeat the /jwt/auth request. This time migration_eligible should be set to false once again.

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Security

Does this MR contain changes to processing or storing of credentials or tokens, authorization and authentication methods or other items described in the security review guidelines? If not, then delete this Security section.

  • Label as security and @ mention @gitlab-com/gl-security/appsec
  • The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • Security reports checked/validated by a reviewer from the AppSec team
Edited by João Pereira

Merge request reports