Add registry migration eligibility flag to tokens for internal use
What does this MR do?
Please read #338605 (closed) for context and a description of the problem we are solving (and how) here. I also provide some fine-grain details/justification in the diff with comments on relevant places.
Related to #335260 (closed).
How to setup and validate locally (strongly suggested)
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.
Current behavior
Checkout the master
branch and open a Rails console:
# All FFs turned off
[1] pry(main)> Feature.enabled? 'container_registry_migration_phase1'
=> false
[2] pry(main)> token = Auth::ContainerRegistryAuthenticationService.full_access_token('gitlab-org/gitlab-test')
[3] pry(main)> JWT.decode(token, nil, false)
# Note that there is no `migration_eligible` flag within `access`, as expected
=> [{"access"=>[{"type"=>"repository", "name"=>"gitlab-org/gitlab-test", "actions"=>["*"]}], "jti"=>"1675db8e-b4d0-47bf-b2b5-bf258a9ffd7b", "aud"=>"container_registry", "iss"=>"gitlab-issuer", "iat"=>1629214655, "nbf"=>1629214650, "exp"=>1629214955},
{"alg"=>"RS256", "kid"=>"2IDF:LJVN:25IP:5QWZ:IX6N:LEZG:HAXI:HTP6:SH6N:25DY:2ZI7:MCGD", "typ"=>"JWT"}]
# Let's turn on the FFs and make our gitlab-org/gitlab-test project eligible
[4] pry(main)> Feature.enable 'container_registry_migration_phase1'
=> true
[5] pry(main)> Feature.enable(:container_registry_migration_phase1_allow, Project.find_by_full_path('gitlab-org/gitlab-test'))
=> true
# Now let's obtain a new token
[6] pry(main)> token = Auth::ContainerRegistryAuthenticationService.full_access_token('gitlab-org/gitlab-test')
[7] pry(main)> JWT.decode(token, nil, false)
# Note that there is still no `migration_eligible` flag within `access`, but it should!
=> [{"access"=>[{"type"=>"repository", "name"=>"gitlab-org/gitlab-test", "actions"=>["*"]}], "jti"=>"0f7e9072-bf86-4b91-b896-3f92e977f680", "aud"=>"container_registry", "iss"=>"gitlab-issuer", "iat"=>1629214840, "nbf"=>1629214835, "exp"=>1629215140},
{"alg"=>"RS256", "kid"=>"2IDF:LJVN:25IP:5QWZ:IX6N:LEZG:HAXI:HTP6:SH6N:25DY:2ZI7:MCGD", "typ"=>"JWT"}]
New behavior
Checkout the 338605
branch and open a Rails console:
# All FFs turned off
[1] pry(main)> Feature.disable 'container_registry_migration_phase1'
=> true
[2] pry(main)> token = Auth::ContainerRegistryAuthenticationService.full_access_token('gitlab-org/gitlab-test')
[3] pry(main)> JWT.decode(token, nil, false)
# There is no `migration_eligible` flag within `access`, as expected, because the FFs are disabled
=> [{"access"=>[{"type"=>"repository", "name"=>"gitlab-org/gitlab-test", "actions"=>["*"]}], "jti"=>"372dfefa-ea10-445e-b67c-b5d3866c86ab", "aud"=>"container_registry", "iss"=>"gitlab-issuer", "iat"=>1629215018, "nbf"=>1629215013, "exp"=>1629215318},
{"alg"=>"RS256", "kid"=>"2IDF:LJVN:25IP:5QWZ:IX6N:LEZG:HAXI:HTP6:SH6N:25DY:2ZI7:MCGD", "typ"=>"JWT"}]
# Let's turn on the FFs and make our gitlab-org/gitlab-test project eligible
[4] pry(main)> Feature.enable 'container_registry_migration_phase1'
=> true
[5] pry(main)> Feature.enable(:container_registry_migration_phase1_allow, Project.find_by_full_path('gitlab-org/gitlab-test'))
=> true
# Now let's obtain a new token
[6] pry(main)> token = Auth::ContainerRegistryAuthenticationService.full_access_token('gitlab-org/gitlab-test')
[7] pry(main)> JWT.decode(token, nil, false)
# Now we can see the `migration_eligible` flag within `access`, as expected
=> [{"access"=>[{"type"=>"repository", "name"=>"gitlab-org/gitlab-test", "actions"=>["*"], "migration_eligible"=>true}], "jti"=>"3ed32db6-9bf7-4b72-bcba-b85199056a6d", "aud"=>"container_registry", "iss"=>"gitlab-issuer", "iat"=>1629215076, "nbf"=>1629215071, "exp"=>1629215376},
{"alg"=>"RS256", "kid"=>"2IDF:LJVN:25IP:5QWZ:IX6N:LEZG:HAXI:HTP6:SH6N:25DY:2ZI7:MCGD", "typ"=>"JWT"}]
Does this MR meet the acceptance criteria?
Conformity
-
I have included changelog trailers, or none are needed. (Does this MR need a changelog?) -
I have added/updated documentation, or it's not needed. (Is documentation required?) -
I have properly separated EE content from FOSS, or this MR is FOSS only. (Where should EE code go?) -
I have added information for database reviewers in the MR description, or it's not needed. (Does this MR have database related changes?) -
I have self-reviewed this MR per code review guidelines. -
This MR does not harm performance, or I have asked a reviewer to help assess the performance impact. (Merge request performance guidelines) -
I have followed the style guides. -
This change is backwards compatible across updates, or this does not apply.
Availability and Testing
-
I have added/updated tests following the Testing Guide, or it's not needed. (Consider all test levels. See the Test Planning Process.) -
I have tested this MR in all supported browsers, or it's not needed. -
I have informed the Infrastructure department of a default or new setting change per definition of done, or it's not needed.
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