Commit 7731bb59 authored by Kamil Trzcinski's avatar Kamil Trzcinski

Use bearer token to access registry

parent de008127
......@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment