diff options
author | Kamil Trzcinski <ayufan@ayufan.eu> | 2016-09-13 15:27:05 +0200 |
---|---|---|
committer | Kamil Trzcinski <ayufan@ayufan.eu> | 2016-09-13 15:27:05 +0200 |
commit | 571226f166f638f821ce84b90bce9cec1e5d5d06 (patch) | |
tree | 27cefbdc529510f757df251f125e344c7deeaf7c /app | |
parent | 505dc808b3c0dc98413506446d368b91b56ff682 (diff) | |
download | gitlab-ce-571226f166f638f821ce84b90bce9cec1e5d5d06.tar.gz |
Make result to return project and capabilities granted
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/jwt_controller.rb | 30 | ||||
-rw-r--r-- | app/controllers/projects/git_http_client_controller.rb | 12 | ||||
-rw-r--r-- | app/controllers/projects/git_http_controller.rb | 2 | ||||
-rw-r--r-- | app/helpers/lfs_helper.rb | 6 | ||||
-rw-r--r-- | app/services/auth/container_registry_authentication_service.rb | 23 |
5 files changed, 27 insertions, 46 deletions
diff --git a/app/controllers/jwt_controller.rb b/app/controllers/jwt_controller.rb index ca02df28b91..1b075cc5e2d 100644 --- a/app/controllers/jwt_controller.rb +++ b/app/controllers/jwt_controller.rb @@ -11,7 +11,7 @@ class JwtController < ApplicationController service = SERVICES[params[:service]] return head :not_found unless service - result = service.new(@project, @user, auth_params).execute(access_type: @access_type) + result = service.new(@project, @user, auth_params).execute(capabilities: @capabilities) render json: result, status: result[:http_status] end @@ -20,12 +20,16 @@ class JwtController < ApplicationController def authenticate_project_or_user authenticate_with_http_basic do |login, password| - # if it's possible we first try to authenticate project with login and password - @project, @user, @access_type = authenticate_build(login, password) - return if @project + @auth_result = Gitlab::Auth.find_for_git_client(login, password, ip: request.ip) - @user, @access_type = authenticate_user(login, password) - return if @user + @user = auth_result.user + @project = auth_result.project + @type = auth_result.type + @capabilities = auth_result.capabilities || [] + + if @user || @project + return # Allow access + end render_403 end @@ -34,18 +38,4 @@ class JwtController < ApplicationController def auth_params params.permit(:service, :scope, :account, :client_id) end - - def authenticate_build(login, password) - return unless login == 'gitlab-ci-token' - return unless password - - build = Ci::Build.running.find_by(token: password) - return build.project, build.user, :restricted if build - end - - def authenticate_user(login, password) - user = Gitlab::Auth.find_with_user_password(login, password) - Gitlab::Auth.rate_limit!(request.ip, success: user.present?, login: login) - return user, :full - end end diff --git a/app/controllers/projects/git_http_client_controller.rb b/app/controllers/projects/git_http_client_controller.rb index 0f72dc8437c..6870102c296 100644 --- a/app/controllers/projects/git_http_client_controller.rb +++ b/app/controllers/projects/git_http_client_controller.rb @@ -4,7 +4,7 @@ class Projects::GitHttpClientController < Projects::ApplicationController include ActionController::HttpAuthentication::Basic include KerberosSpnegoHelper - attr_reader :user, :access_type + attr_reader :user, :capabilities # Git clients will not know what authenticity token to send along skip_before_action :verify_authenticity_token @@ -34,7 +34,7 @@ class Projects::GitHttpClientController < Projects::ApplicationController @user = auth_result.user end - @access_type = auth_result.access_type + @capabilities = auth_result.capabilities || [] if ci? || user return # Allow access @@ -120,12 +120,8 @@ class Projects::GitHttpClientController < Projects::ApplicationController @ci.present? end - def full? - @access_type == :full - end - - def restricted? - @access_type == :restricted + def has_capability?(capability) + @capabilities.include?(capability) end def verify_workhorse_api! diff --git a/app/controllers/projects/git_http_controller.rb b/app/controllers/projects/git_http_controller.rb index d59a47417f4..89afaaed510 100644 --- a/app/controllers/projects/git_http_controller.rb +++ b/app/controllers/projects/git_http_controller.rb @@ -86,7 +86,7 @@ class Projects::GitHttpController < Projects::GitHttpClientController end def access - @access ||= Gitlab::GitAccess.new(user, project, 'http', access_type: access_type) + @access ||= Gitlab::GitAccess.new(user, project, 'http', capabilities: capabilities) end def access_check diff --git a/app/helpers/lfs_helper.rb b/app/helpers/lfs_helper.rb index 625dfddcf8d..bee03ffb446 100644 --- a/app/helpers/lfs_helper.rb +++ b/app/helpers/lfs_helper.rb @@ -29,11 +29,11 @@ module LfsHelper end def privileged_user_can_download_code? - full? && user && user.can?(:download_code, project) + has_capability?(:download_code) && user && user.can?(:download_code, project) end def restricted_user_can_download_code? - restricted? && user && user.can?(:restricted_download_code, project) + has_capability?(:restricted_download_code) && user && user.can?(:restricted_download_code, project) end def lfs_upload_access? @@ -43,7 +43,7 @@ module LfsHelper end def privileged_user_can_push_code? - full? && user && user.can?(:push_code, project) + has_capability?(:push_code) && user && user.can?(:push_code, project) end def render_lfs_forbidden diff --git a/app/services/auth/container_registry_authentication_service.rb b/app/services/auth/container_registry_authentication_service.rb index 270d5a11d9e..cba0e2297a8 100644 --- a/app/services/auth/container_registry_authentication_service.rb +++ b/app/services/auth/container_registry_authentication_service.rb @@ -4,8 +4,8 @@ module Auth AUDIENCE = 'container_registry' - def execute(access_type: access_type) - @access_type = access_type + def execute(capabilities: capabilities) + @capabilities = capabilities return error('not found', 404) unless registry.enabled @@ -91,33 +91,28 @@ module Auth private def restricted_user_can_pull?(requested_project) - return false unless restricted? - # Restricted can: # 1. pull from it's own project (for ex. a build) # 2. read images from dependent projects if he is a team member - requested_project == project || can?(current_user, :restricted_read_container_image, requested_project) + requested_project == project || + has_ability?(:restricted_read_container_image, requested_project) end def privileged_user_can_pull?(requested_project) - full? && can?(current_user, :read_container_image, requested_project) + has_ability?(:read_container_image, requested_project) end def restricted_user_can_push?(requested_project) # Restricted can push only to project to from which he originates - restricted? && requested_project == project + requested_project == project end def privileged_user_can_push?(requested_project) - full? && can?(current_user, :create_container_image, requested_project) - end - - def full? - @access_type == :full + has_ability?(:create_container_image, requested_project) end - def restricted? - @access_type == :restricted + def has_ability?(ability, requested_project) + @capabilities.include?(ability) && can?(current_user, ability, requested_project) end end end |