Commit 4bc75dc9 authored by Kamil Trzcinski's avatar Kamil Trzcinski

Add check for user being a member of group

parent e2135248
...@@ -8,7 +8,8 @@ module API ...@@ -8,7 +8,8 @@ module API
PRIVATE_TOKEN_HEADER = "HTTP_PRIVATE_TOKEN".freeze PRIVATE_TOKEN_HEADER = "HTTP_PRIVATE_TOKEN".freeze
PRIVATE_TOKEN_PARAM = :private_token PRIVATE_TOKEN_PARAM = :private_token
CI_JOB_TOKEN_PARAM = :ci_job_token CI_JOB_TOKEN_HEADER = "HTTP_JOB_TOKEN".freeze
CI_JOB_TOKEN_PARAM = :job_token
included do |base| included do |base|
# OAuth2 Resource Server Authentication # OAuth2 Resource Server Authentication
...@@ -91,11 +92,10 @@ module API ...@@ -91,11 +92,10 @@ module API
def find_user_by_ci_token def find_user_by_ci_token
return nil unless route_authentication_setting[:job_token_allowed] return nil unless route_authentication_setting[:job_token_allowed]
job_token = params[CI_JOB_TOKEN_PARAM].to_s token_string = (params[CI_JOB_TOKEN_PARAM] || env[CI_JOB_TOKEN_HEADER]).to_s
return nil unless token_string.present?
return nil unless job_token.present?
Ci::Build.find_by_token(job_token)&.user Ci::Build.find_by_token(token_string)&.user
end end
def current_user def current_user
......
...@@ -58,7 +58,9 @@ module API ...@@ -58,7 +58,9 @@ module API
def find_project!(id) def find_project!(id)
project = find_project(id) project = find_project(id)
if can?(current_user, :read_project, project) if ci_job_token && !current_user.authorized_projects.exists?(project)
not_found!('Project')
elsif can?(current_user, :read_project, project)
project project
else else
not_found!('Project') not_found!('Project')
...@@ -84,7 +86,9 @@ module API ...@@ -84,7 +86,9 @@ module API
def find_group!(id) def find_group!(id)
group = find_group(id) group = find_group(id)
if can?(current_user, :read_group, group) if ci_job_token
not_found!('Group')
elsif can?(current_user, :read_group, group)
group group
else else
not_found!('Group') not_found!('Group')
...@@ -350,6 +354,10 @@ module API ...@@ -350,6 +354,10 @@ module API
params[APIGuard::PRIVATE_TOKEN_PARAM] || env[APIGuard::PRIVATE_TOKEN_HEADER] params[APIGuard::PRIVATE_TOKEN_PARAM] || env[APIGuard::PRIVATE_TOKEN_HEADER]
end end
def ci_job_token
params[APIGuard::CI_JOB_TOKEN_PARAM] || env[APIGuard::CI_JOB_TOKEN_HEADER]
end
def warden def warden
env['warden'] env['warden']
end end
......
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