Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMayra Cabrera <mcabrera@gitlab.com>2018-03-30 01:56:35 +0300
committerMayra Cabrera <mcabrera@gitlab.com>2018-04-07 05:20:16 +0300
commit370fc05da7f95bf6621867a71d51493cf3899e25 (patch)
tree040f676c8c6ccf04d5ebfdbbe064a844affd63f5 /lib/gitlab/auth.rb
parentdb18993f652425b72c4b854e18a002e0ec44b196 (diff)
Implement 'read_repo' for DeployTokens
This will allow to download a repo using the token from the DeployToken
Diffstat (limited to 'lib/gitlab/auth.rb')
-rw-r--r--lib/gitlab/auth.rb16
1 files changed, 14 insertions, 2 deletions
diff --git a/lib/gitlab/auth.rb b/lib/gitlab/auth.rb
index 6af763faf10..77fef7d8cac 100644
--- a/lib/gitlab/auth.rb
+++ b/lib/gitlab/auth.rb
@@ -5,7 +5,7 @@ module Gitlab
REGISTRY_SCOPES = [:read_registry].freeze
# Scopes used for GitLab API access
- API_SCOPES = [:api, :read_user, :sudo].freeze
+ API_SCOPES = [:api, :read_user, :sudo, :read_repo].freeze
# Scopes used for OpenID Connect
OPENID_SCOPES = [:openid].freeze
@@ -26,6 +26,7 @@ module Gitlab
lfs_token_check(login, password, project) ||
oauth_access_token_check(login, password) ||
personal_access_token_check(password) ||
+ deploy_token_check(project, password) ||
user_with_password_for_git(login, password) ||
Gitlab::Auth::Result.new
@@ -163,7 +164,8 @@ module Gitlab
def abilities_for_scopes(scopes)
abilities_by_scope = {
api: full_authentication_abilities,
- read_registry: [:read_container_image]
+ read_registry: [:read_container_image],
+ read_repo: read_authentication_abilities - [:read_container_image]
}
scopes.flat_map do |scope|
@@ -171,6 +173,16 @@ module Gitlab
end.uniq
end
+ def deploy_token_check(project, password)
+ return unless project.present? && password.present?
+
+ token = DeployToken.active.find_by(project: project, token: password)
+
+ if token && valid_scoped_token?(token, available_scopes)
+ Gitlab::Auth::Result.new(token, project, :deploy_token, abilities_for_scopes(token.scopes))
+ end
+ end
+
def lfs_token_check(login, password, project)
deploy_key_matches = login.match(/\Alfs\+deploy-key-(\d+)\z/)