-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes to Enable SSH for Repository hosting #4
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Default to previous behaviour of not hosting repos in phabricator | ||
# NB this setting has no effect on Ubuntu 12.04 as its version of OpenSSH | ||
# is too old to work. | ||
default['phabricator']['repo_hosting_enabled'] = false | ||
|
||
# Port that VCS SSH will listen on | ||
default['phabricator']['ssh_vcs_port'] = '617' | ||
|
||
# User for Source code hosting | ||
default['phabricator']['vcsuser'] = 'git' | ||
|
||
append_paths = [] | ||
append_paths << File.join(node['phabricator']['path'], '/phabricator/support/bin') | ||
append_paths << '/bin' | ||
append_paths << '/usr/bin' | ||
append_paths << '/usr/local/bin' | ||
append_paths << '/usr/lib/git-core' | ||
|
||
default['phabricator']['config']['environment.append-paths'] = %Q('#{append_paths}') |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,7 +65,7 @@ | |
action :create | ||
user node['phabricator']['user'] | ||
group node['phabricator']['group'] | ||
mode "0750" | ||
mode "0755" | ||
end | ||
|
||
%w{ phabricator libphutil arcanist }.each do |repo| | ||
|
@@ -83,7 +83,7 @@ | |
action :create | ||
user node['phabricator']['user'] | ||
group node['phabricator']['group'] | ||
mode "0750" | ||
mode "0755" | ||
end | ||
|
||
# Set up file storage | ||
|
@@ -187,3 +187,12 @@ | |
node.set['phabricator']['storage_upgrade_done'] = true | ||
end | ||
end | ||
|
||
# Setup ssh repo hosting if we want it! | ||
# Only applicable on 14.04 or newer, due to need for AuthorizedKeysCommand which came in | ||
# OpenSSH 6.2. | ||
if node['platform_version'] >= '14.04' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Setting Furthermore, what do you think about actually not including the |
||
if node['phabricator']['repo_hosting_enabled'] | ||
include_recipe 'phabricator::repo_hosting' | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
# | ||
# Cookbook Name:: phabricator | ||
# Recipe:: repo_hosting | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, I'd suggest not to use abbreviations unless they are really long (like VCS). |
||
# | ||
# Copyright 2014, MET Norway | ||
# | ||
# Authors: Kim Tore Jensen <[email protected]>, | ||
# Andrew Mulholland <[email protected]> | ||
# | ||
# Sets up phabricator for hosting repositories over SSH | ||
|
||
# To prevent the `vcsuser` (i.e. git ) user from being locked, a password needs to be provided with | ||
# account creation. Using OpenSSLCookbook's RandomPassword function to generate a secure password. | ||
unless node['phabricator']['vcspassword'] | ||
Chef::Recipe.send(:include, OpenSSLCookbook::RandomPassword) | ||
require 'digest/sha2' | ||
node.set['phabricator']['vcspassword'] = Digest::SHA512.hexdigest(random_password(length: 50)) | ||
end | ||
|
||
user node['phabricator']['vcsuser'] do | ||
comment 'VCS User' | ||
home File.join('/home', node['phabricator']['vcsuser']) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The home directory must definitely be configured in node attributes, instead of auto-generated. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fair, will fix |
||
shell '/bin/sh' | ||
system true | ||
# This password is never used! | ||
password node['phabricator']['vcspassword'] | ||
action [:create, :unlock] | ||
end | ||
|
||
directory File.join('/home', node['phabricator']['vcsuser']) do | ||
action :create | ||
owner node['phabricator']['vcsuser'] | ||
mode '0755' | ||
end | ||
|
||
directory '/etc/ssh-phabricator' do | ||
action :create | ||
end | ||
|
||
template '/etc/init/ssh-vcs.conf' do | ||
source 'ssh-phabricator/ssh-vcs.conf.erb' | ||
owner 'root' | ||
group 'root' | ||
mode '0755' | ||
notifies :restart, 'service[ssh-vcs]' | ||
end | ||
|
||
service 'ssh-vcs' do | ||
provider Chef::Provider::Service::Upstart | ||
supports status: true, restart: true, reload: true | ||
action [:enable, :start] | ||
end | ||
|
||
template '/etc/ssh-phabricator/sshd_config' do | ||
source 'ssh-phabricator/sshd_config.erb' | ||
owner 'root' | ||
group 'root' | ||
mode '0755' | ||
notifies :restart, 'service[ssh-vcs]' | ||
end | ||
|
||
directory '/usr/libexec' do | ||
owner 'root' | ||
group 'root' | ||
mode '0755' | ||
end | ||
|
||
template '/usr/libexec/ssh-phabricator-hook' do | ||
source 'ssh-phabricator/ssh-phabricator-hook.erb' | ||
owner 'root' | ||
group 'root' | ||
mode '0755' | ||
end | ||
|
||
# enable /etc/sudoers.d directory to enable the sudoer provider to work | ||
node.override[:authorization][:sudo][:include_sudoers_d] = true | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. eep, yes I don't know why I used symbols there. will fix. |
||
|
||
# We use template here, because right now upstream `sudo` cookbook doesn't support | ||
# setting setenv, which is needed because phab runs `sudo -E`. | ||
# Have filed https://github.com/chef-cookbooks/sudo/pull/72 for this. | ||
sudo 'vcsuser' do | ||
template 'phab_sudo.erb' | ||
variables commands: ['/usr/bin/git-upload-pack', | ||
'/usr/bin/git-receive-pack', | ||
'/usr/bin/hg', | ||
'/usr/bin/svnserve'], | ||
nopasswd: true, | ||
setenv: true, | ||
sudoer: node['phabricator']['vcsuser'], | ||
runas: node['phabricator']['user'] | ||
end | ||
|
||
sudo 'www-data' do | ||
template 'phab_sudo.erb' | ||
variables commands: ['/usr/bin/git-http-backend'], | ||
nopasswd: true, | ||
setenv: true, | ||
sudoer: 'www-data', | ||
runas: node['phabricator']['user'] | ||
end | ||
|
||
# Install Git, Mercurial, SVN | ||
%w(git subversion mercurial).each do |pkg| | ||
package pkg do | ||
action :install | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# This file is managed by Chef. | ||
# Do NOT modify this file directly. | ||
|
||
<% @commands.each do |command| -%> | ||
<%= @sudoer %> ALL=(<%= @runas %>) <%= 'NOPASSWD:' if @nopasswd %><%= 'SETENV:' if @setenv %><%= command %> | ||
<% end -%> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/bin/sh | ||
# | ||
VCSUSER="#{node['phabricator']['vcsuser']" | ||
# | ||
# Path to Phabricator directory. | ||
ROOT="#{node['phabricator']['path']" | ||
|
||
if [ "$1" != "$VCSUSER" ]; | ||
then | ||
exit 1 | ||
fi | ||
|
||
exec "$ROOT/bin/ssh-auth" $@ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/bin/sh | ||
# | ||
VCSUSER="<%= node['phabricator']['vcsuser'] %>" | ||
# | ||
# Path to Phabricator directory. | ||
ROOT="<%= File.join(node['phabricator']['path'],'phabricator') %>" | ||
|
||
if [ "$1" != "$VCSUSER" ]; | ||
then | ||
exit 1 | ||
fi | ||
|
||
exec "$ROOT/bin/ssh-auth" $@ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# ssh for VCS | ||
# | ||
# This OpenSSH server provides ssh access to VCS for Phabricator | ||
|
||
description "SSH-VCS server" | ||
|
||
start on runlevel [2345] | ||
stop on runlevel [!2345] | ||
|
||
respawn | ||
respawn limit 10 5 | ||
umask 022 | ||
|
||
env SSH_SIGSTOP=1 | ||
expect stop | ||
|
||
# 'sshd -D' leaks stderr and confuses things in conjunction with 'console log' | ||
console none | ||
|
||
pre-start script | ||
test -x /usr/sbin/sshd || { stop; exit 0; } | ||
|
||
end script | ||
|
||
# if you used to set SSHD_OPTS in /etc/default/ssh, you can change the | ||
# 'exec' line here instead | ||
exec /usr/sbin/sshd -D -f /etc/ssh-phabricator/sshd_config |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
AuthorizedKeysCommand /usr/libexec/ssh-phabricator-hook | ||
AuthorizedKeysCommandUser <%= node['phabricator']['vcsuser'] %> | ||
|
||
Port <%= node['phabricator']['ssh_vcs_port'] %> | ||
Protocol 2 | ||
PermitRootLogin no | ||
AllowAgentForwarding no | ||
AllowTcpForwarding no | ||
PrintMotd no | ||
PrintLastLog no | ||
PasswordAuthentication no | ||
AuthorizedKeysFile none |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest that the VCS functions are namespaced into e.g.
['phabricator']['vcs_hosting']
(or, preferably, something a little more elegant)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea, thanks