Commit 5fc310b4 authored by Kamil Trzcinski's avatar Kamil Trzcinski

Missing parameters of docker payload

parent 8aac802e
...@@ -113,6 +113,7 @@ module API ...@@ -113,6 +113,7 @@ module API
end end
def docker_payload def docker_payload
issued_at = Time.now
{ {
access: [ access: [
type: @type, type: @type,
...@@ -121,8 +122,14 @@ module API ...@@ -121,8 +122,14 @@ module API
], ],
iss: Gitlab.config.registry.issuer, iss: Gitlab.config.registry.issuer,
aud: "docker", aud: "docker",
sub: @user.try(:username),
aud: @service,
iat: issued_at,
nbf: issued_at - 5.seconds,
exp: issued_at + 60.minutes,
jti: SecureRandom.uuid,
exp: Time.now.to_i + 3600 exp: Time.now.to_i + 3600
} }.compact
end end
def private_key def private_key
...@@ -130,7 +137,10 @@ module API ...@@ -130,7 +137,10 @@ module API
end end
def encode(payload) def encode(payload)
JWT.encode(payload, private_key, 'RS256') headers = {
kid: kid(private_key)
}
JWT.encode(payload, private_key, 'RS256', headers)
end end
def authorize_actions!(actions) def authorize_actions!(actions)
...@@ -150,6 +160,15 @@ module API ...@@ -150,6 +160,15 @@ module API
end end
end end
def kid(private_key)
sha256 = Digest::SHA256.new
sha256.update(private_key.public_key.to_der)
payload = StringIO.new(sha256.digest).read(30)
Base32.encode(payload).split("").each_slice(4).each_with_object([]) do |slice, mem|
mem << slice.join
end.join(":")
end
class BasicRequest < Rack::Auth::AbstractRequest class BasicRequest < Rack::Auth::AbstractRequest
def basic? def basic?
"basic" == scheme "basic" == scheme
......
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