Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
34ec29b9
Commit
34ec29b9
authored
Jul 13, 2018
by
Kamil Trzciński
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support multiple scopes when using authing container registry scopes
parent
3d2dad44
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
155 additions
and
39 deletions
+155
-39
app/controllers/jwt_controller.rb
app/controllers/jwt_controller.rb
+17
-1
app/services/auth/container_registry_authentication_service.rb
...ervices/auth/container_registry_authentication_service.rb
+7
-5
changelogs/unreleased/fix-multiple-scopes.yml
changelogs/unreleased/fix-multiple-scopes.yml
+5
-0
spec/requests/jwt_controller_spec.rb
spec/requests/jwt_controller_spec.rb
+19
-0
spec/services/auth/container_registry_authentication_service_spec.rb
...es/auth/container_registry_authentication_service_spec.rb
+107
-33
No files found.
app/controllers/jwt_controller.rb
View file @
34ec29b9
...
@@ -54,6 +54,22 @@ class JwtController < ApplicationController
...
@@ -54,6 +54,22 @@ class JwtController < ApplicationController
end
end
def
auth_params
def
auth_params
params
.
permit
(
:service
,
:scope
,
:account
,
:client_id
)
params
.
permit
(
:service
,
:account
,
:client_id
)
.
merge
(
additional_params
)
end
def
additional_params
{
scopes:
scopes_param
}.
compact
end
# We have to parse scope here, because Docker Client does not send an array of scopes,
# but rather a flat list and we loose second scope when being processed by Rails:
# scope=scopeA&scope=scopeB
#
# This method makes to always return an array of scopes
def
scopes_param
return
unless
params
[
:scope
].
present?
Array
(
Rack
::
Utils
.
parse_query
(
request
.
query_string
)[
'scope'
])
end
end
end
end
app/services/auth/container_registry_authentication_service.rb
View file @
34ec29b9
...
@@ -9,11 +9,11 @@ module Auth
...
@@ -9,11 +9,11 @@ module Auth
return
error
(
'UNAVAILABLE'
,
status:
404
,
message:
'registry not enabled'
)
unless
registry
.
enabled
return
error
(
'UNAVAILABLE'
,
status:
404
,
message:
'registry not enabled'
)
unless
registry
.
enabled
unless
scope
||
current_user
||
project
unless
scope
s
.
any?
||
current_user
||
project
return
error
(
'DENIED'
,
status:
403
,
message:
'access forbidden'
)
return
error
(
'DENIED'
,
status:
403
,
message:
'access forbidden'
)
end
end
{
token:
authorized_token
(
scope
).
encoded
}
{
token:
authorized_token
(
*
scopes
).
encoded
}
end
end
def
self
.
full_access_token
(
*
names
)
def
self
.
full_access_token
(
*
names
)
...
@@ -47,10 +47,12 @@ module Auth
...
@@ -47,10 +47,12 @@ module Auth
end
end
end
end
def
scope
def
scope
s
return
unless
params
[
:scope
]
return
[]
unless
params
[
:scopes
]
@scope
||=
process_scope
(
params
[
:scope
])
@scopes
||=
params
[
:scopes
].
map
do
|
scope
|
process_scope
(
scope
)
end
.
compact
end
end
def
process_scope
(
scope
)
def
process_scope
(
scope
)
...
...
changelogs/unreleased/fix-multiple-scopes.yml
0 → 100644
View file @
34ec29b9
---
title
:
Support multiple scopes when authing container registry scopes
merge_request
:
20617
author
:
type
:
fixed
spec/requests/jwt_controller_spec.rb
View file @
34ec29b9
...
@@ -70,6 +70,25 @@ describe JwtController do
...
@@ -70,6 +70,25 @@ describe JwtController do
it
{
expect
(
service_class
).
to
have_received
(
:new
).
with
(
nil
,
user
,
parameters
)
}
it
{
expect
(
service_class
).
to
have_received
(
:new
).
with
(
nil
,
user
,
parameters
)
}
context
'when passing a flat array of scopes'
do
# We use this trick to make rails to generate a query_string:
# scope=scope1&scope=scope2
# It works because :scope and 'scope' are the same as string, but different objects
let
(
:parameters
)
do
{
:service
=>
service_name
,
:scope
=>
'scope1'
,
'scope'
=>
'scope2'
}
end
let
(
:service_parameters
)
do
{
service:
service_name
,
scopes:
%w(scope1 scope2)
}
end
it
{
expect
(
service_class
).
to
have_received
(
:new
).
with
(
nil
,
user
,
service_parameters
)
}
end
context
'when user has 2FA enabled'
do
context
'when user has 2FA enabled'
do
let
(
:user
)
{
create
(
:user
,
:two_factor
)
}
let
(
:user
)
{
create
(
:user
,
:two_factor
)
}
...
...
spec/services/auth/container_registry_authentication_service_spec.rb
View file @
34ec29b9
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment