Skip to content

Commit

Permalink
Allow only authorized users to make push and clone
Browse files Browse the repository at this point in the history
Check if user is owner of the project when git sends push request or
clone request for private projects.
  • Loading branch information
sonalkr132 committed Jun 13, 2015
1 parent 3a8e680 commit 1d6f498
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 28 deletions.
9 changes: 9 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,13 @@ def git_author_params
time: Time.now
}
end

# checks if the user if the owner of the passed project
def owner?(project)
if id == project.user.id
true
else
false
end
end
end
24 changes: 0 additions & 24 deletions config.ru
Original file line number Diff line number Diff line change
@@ -1,29 +1,5 @@

# This file is used by Rack-based servers to start the application.

# require './lib/rack/git_http'

require ::File.expand_path('../config/environment', __FILE__)
run Glitter::Application

# map '/health' do
# health = proc do |env|
# [200, { "Content-Type" => "text/html" }, ["1"]]
# end
# run health
# end


# map '/git' do
# use Rack::ShowExceptions

# config = {
# :project_root => "#{ENV["OPENSHIFT_DATA_DIR"]}/repos",
# :git_path => '/usr/bin/git',
# :upload_pack => true,
# :receive_pack => true,
# }

# run GitHttp::App.new(config)

# end
8 changes: 4 additions & 4 deletions lib/rack/grack_auth.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,17 @@ def project_by_path(path)
def authorized_request?
case git_cmd
when *%w{ git-upload-pack git-upload-archive }
unless project.private
if user
user.owner?(project)
elsif !project.private
# Allow clone/fetch for public projects
true
else
false
end
when *%w{ git-receive-pack }
if user
# Skip user authorization on upload request.
# It will be done by the pre-receive hook in the repository.
true
user.owner?(project)
else
false
end
Expand Down

0 comments on commit 1d6f498

Please sign in to comment.