Use bearer token to access registry

This commit is contained in:
Kamil Trzcinski
2016-05-04 16:17:08 +02:00
parent de008127eb
commit 7731bb59c8
2 changed files with 13 additions and 1 deletions
+2 -1
View File
@@ -371,7 +371,8 @@ class Project < ActiveRecord::Base
end
def image_repository
@registry ||= ImageRegistry::Registry.new(Gitlab.config.registry.api_url)
@registry_token ||= Jwt::DockerAuthenticationService.full_access_token(path_with_namespace)
@registry ||= ImageRegistry::Registry.new(Gitlab.config.registry.api_url, token: @registry_token)
@image_repository ||= ImageRegistry::Repository.new(@registry, path_with_namespace)
end
@@ -8,6 +8,17 @@ module Jwt
{ token: token.encoded }
end
def self.full_access_token(*names)
registry = Gitlab.config.registry
token = ::Jwt::RSAToken.new(registry.key)
token.issuer = registry.issuer
token.audience = 'docker'
token[:access] = names.map do |name|
{ type: 'repository', name: name, actions: %w(pull push) }
end
token.encoded
end
private
def token