summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/api/internal.rb39
-rw-r--r--lib/gitlab/backend/grack_auth.rb52
-rw-r--r--lib/gitlab/push_data_builder.rb2
-rw-r--r--lib/gitlab/url_builder.rb17
-rw-r--r--lib/support/nginx/gitlab10
-rw-r--r--lib/support/nginx/gitlab-ssl10
6 files changed, 63 insertions, 67 deletions
diff --git a/lib/api/internal.rb b/lib/api/internal.rb
index ba3fe619b92..753d0fcbd98 100644
--- a/lib/api/internal.rb
+++ b/lib/api/internal.rb
@@ -16,6 +16,17 @@ module API
#
post "/allowed" do
status 200
+
+ actor = if params[:key_id]
+ Key.find_by(id: params[:key_id])
+ elsif params[:user_id]
+ User.find_by(id: params[:user_id])
+ end
+
+ unless actor
+ return Gitlab::GitAccessStatus.new(false, 'No such user or key')
+ end
+
project_path = params[:project]
# Check for *.wiki repositories.
@@ -32,26 +43,20 @@ module API
project = Project.find_with_namespace(project_path)
- unless project
- return Gitlab::GitAccessStatus.new(false, 'No such project')
+ if project
+ status = access.check(
+ actor,
+ params[:action],
+ project,
+ params[:changes]
+ )
end
- actor = if params[:key_id]
- Key.find_by(id: params[:key_id])
- elsif params[:user_id]
- User.find_by(id: params[:user_id])
- end
-
- unless actor
- return Gitlab::GitAccessStatus.new(false, 'No such user or key')
+ if project && status && status.allowed?
+ status
+ else
+ Gitlab::GitAccessStatus.new(false, 'No such project')
end
-
- access.check(
- actor,
- params[:action],
- project,
- params[:changes]
- )
end
#
diff --git a/lib/gitlab/backend/grack_auth.rb b/lib/gitlab/backend/grack_auth.rb
index dc4b945f9d4..ee877e099b1 100644
--- a/lib/gitlab/backend/grack_auth.rb
+++ b/lib/gitlab/backend/grack_auth.rb
@@ -10,8 +10,9 @@ module Grack
@request = Rack::Request.new(env)
@auth = Request.new(env)
- # Need this patch due to the rails mount
+ @gitlab_ci = false
+ # Need this patch due to the rails mount
# Need this if under RELATIVE_URL_ROOT
unless Gitlab.config.gitlab.relative_url_root.empty?
# If website is mounted using relative_url_root need to remove it first
@@ -22,8 +23,12 @@ module Grack
@env['SCRIPT_NAME'] = ""
- if project
- auth!
+ auth!
+
+ if project && authorized_request?
+ @app.call(env)
+ elsif @user.nil? && !@gitlab_ci
+ unauthorized
else
render_not_found
end
@@ -32,35 +37,30 @@ module Grack
private
def auth!
- if @auth.provided?
- return bad_request unless @auth.basic?
-
- # Authentication with username and password
- login, password = @auth.credentials
+ return unless @auth.provided?
- # Allow authentication for GitLab CI service
- # if valid token passed
- if gitlab_ci_request?(login, password)
- return @app.call(env)
- end
+ return bad_request unless @auth.basic?
- @user = authenticate_user(login, password)
+ # Authentication with username and password
+ login, password = @auth.credentials
- if @user
- Gitlab::ShellEnv.set_env(@user)
- @env['REMOTE_USER'] = @auth.username
- end
+ # Allow authentication for GitLab CI service
+ # if valid token passed
+ if gitlab_ci_request?(login, password)
+ @gitlab_ci = true
+ return
end
- if authorized_request?
- @app.call(env)
- else
- unauthorized
+ @user = authenticate_user(login, password)
+
+ if @user
+ Gitlab::ShellEnv.set_env(@user)
+ @env['REMOTE_USER'] = @auth.username
end
end
def gitlab_ci_request?(login, password)
- if login == "gitlab-ci-token" && project.gitlab_ci?
+ if login == "gitlab-ci-token" && project && project.gitlab_ci?
token = project.gitlab_ci_service.token
if token.present? && token == password && git_cmd == 'git-upload-pack'
@@ -107,6 +107,8 @@ module Grack
end
def authorized_request?
+ return true if @gitlab_ci
+
case git_cmd
when *Gitlab::GitAccess::DOWNLOAD_COMMANDS
if user
@@ -141,7 +143,9 @@ module Grack
end
def project
- @project ||= project_by_path(@request.path_info)
+ return @project if defined?(@project)
+
+ @project = project_by_path(@request.path_info)
end
def project_by_path(path)
diff --git a/lib/gitlab/push_data_builder.rb b/lib/gitlab/push_data_builder.rb
index 9d8d3ea3d22..5cefa67d3ab 100644
--- a/lib/gitlab/push_data_builder.rb
+++ b/lib/gitlab/push_data_builder.rb
@@ -9,6 +9,7 @@ module Gitlab
# ref: String,
# user_id: String,
# user_name: String,
+ # user_email: String
# project_id: String,
# repository: {
# name: String,
@@ -36,6 +37,7 @@ module Gitlab
checkout_sha: checkout_sha(project.repository, newrev, ref),
user_id: user.id,
user_name: user.name,
+ user_email: user.email,
project_id: project.id,
repository: {
name: project.name,
diff --git a/lib/gitlab/url_builder.rb b/lib/gitlab/url_builder.rb
index e7153cc3225..ab7c8ad89f3 100644
--- a/lib/gitlab/url_builder.rb
+++ b/lib/gitlab/url_builder.rb
@@ -1,6 +1,7 @@
module Gitlab
class UrlBuilder
include Rails.application.routes.url_helpers
+ include GitlabRoutingHelper
def initialize(type)
@type = type
@@ -9,18 +10,22 @@ module Gitlab
def build(id)
case @type
when :issue
- issue_url(id)
+ build_issue_url(id)
+ when :merge_request
+ build_merge_request_url(id)
end
end
private
- def issue_url(id)
+ def build_issue_url(id)
issue = Issue.find(id)
- namespace_project_issue_url(namespace_id: issue.project.namespace,
- id: issue.iid,
- project_id: issue.project,
- host: Gitlab.config.gitlab['url'])
+ issue_url(issue, host: Gitlab.config.gitlab['url'])
+ end
+
+ def build_merge_request_url(id)
+ merge_request = MergeRequest.find(id)
+ merge_request_url(merge_request, host: Gitlab.config.gitlab['url'])
end
end
end
diff --git a/lib/support/nginx/gitlab b/lib/support/nginx/gitlab
index fd5b2664786..62a4276536c 100644
--- a/lib/support/nginx/gitlab
+++ b/lib/support/nginx/gitlab
@@ -77,16 +77,6 @@ server {
proxy_pass http://gitlab;
}
- ## If ``go get`` detected, return go-import meta tag.
- ## This works for public and for private repositories.
- ## See also http://golang.org/cmd/go/#hdr-Remote_import_paths
- if ($http_user_agent ~* "Go") {
- return 200 "
- <!DOCTYPE html>
- <head><meta content='$host$uri git $scheme://$host$uri.git' name='go-import'></head>
- </html>";
- }
-
## If a file, which is not found in the root folder is requested,
## then the proxy passes the request to the upsteam (gitlab unicorn).
location @gitlab {
diff --git a/lib/support/nginx/gitlab-ssl b/lib/support/nginx/gitlab-ssl
index a9699bac611..2aefc944698 100644
--- a/lib/support/nginx/gitlab-ssl
+++ b/lib/support/nginx/gitlab-ssl
@@ -123,16 +123,6 @@ server {
proxy_pass http://gitlab;
}
- ## If ``go get`` detected, return go-import meta tag.
- ## This works for public and for private repositories.
- ## See also http://golang.org/cmd/go/#hdr-Remote_import_paths
- if ($http_user_agent ~* "Go") {
- return 200 "
- <!DOCTYPE html>
- <head><meta content='$host$uri git $scheme://$host$uri.git' name='go-import'></head>
- </html>";
- }
-
## If a file, which is not found in the root folder is requested,
## then the proxy passes the request to the upsteam (gitlab unicorn).
location @gitlab {