Skip to content
Snippets Groups Projects
Unverified Commit 7be745d2 authored by João Pereira's avatar João Pereira
Browse files

Add registry migration eligibility flag to tokens for internal use

Previously this was only being added to tokens for external use
obtained through the /jwt/auth API endpoint.
parent 064e9079
No related branches found
No related tags found
1 merge request!68357Add registry migration eligibility flag to tokens for internal use
Pipeline #354642659 passed
......@@ -45,7 +45,12 @@ def self.access_token(actions, names)
token.expire_time = token_expire_at
token[:access] = names.map do |name|
{ type: 'repository', name: name, actions: actions }
{
type: 'repository',
name: name,
actions: actions,
migration_eligible: migration_eligible(repository_path: name)
}.compact
end
token.encoded
......@@ -119,13 +124,20 @@ def process_repository_access(type, path, actions)
type: type,
name: path.to_s,
actions: authorized_actions,
migration_eligible: migration_eligible(requested_project, authorized_actions)
migration_eligible: self.class.migration_eligible(project: requested_project)
}.compact
end
def migration_eligible(project, actions)
def self.migration_eligible(project: nil, repository_path: nil)
return unless Feature.enabled?(:container_registry_migration_phase1)
# project has precedence over repository_path. If only the latter is provided, we find the corresponding Project.
unless project
return unless repository_path
project = ContainerRegistry::Path.new(repository_path).repository_project
end
# The migration process will start by allowing only specific test and gitlab-org projects using the
# `container_registry_migration_phase1_allow` FF. We'll then move on to a percentage rollout using this same FF.
# To remove the risk of impacting enterprise customers that rely heavily on the registry during the percentage
......
......@@ -84,5 +84,36 @@
it_behaves_like 'a modified token'
end
describe '#access_token' do
let(:token) { described_class.access_token(%w[push], [project.full_path]) }
subject { { token: token } }
it_behaves_like 'a modified token'
end
end
context 'when not in migration mode' do
include_context 'container registry auth service context'
let_it_be(:project) { create(:project) }
before do
stub_feature_flags(container_registry_migration_phase1: false)
end
shared_examples 'an unmodified token' do
it_behaves_like 'a valid token'
it { expect(payload['access']).not_to include(have_key('migration_eligible')) }
end
describe '#access_token' do
let(:token) { described_class.access_token(%w[push], [project.full_path]) }
subject { { token: token } }
it_behaves_like 'an unmodified token'
end
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment