Config.pm: add more comments about setting $git_http_backend_bin
[girocco.git] / Girocco / Config.pm
blob6dcf264bd277f000b2e6f91ac2fb0c748346aa0a
1 package Girocco::Config;
3 use strict;
4 use warnings;
7 ## Basic settings
9 # Name of the service
10 our $name = "GiroccoEx";
12 # Nickname of the service (undef for initial part of $name upto first '.')
13 our $nickname = undef;
15 # Title of the service (as shown in gitweb)
16 our $title = "Example Girocco Hosting";
18 # Path to the Git binary to use (you MUST set this, even if to /usr/bin/git!)
19 our $git_bin = '/usr/bin/git';
21 # Path to the git-http-backend binary to use (undef to use /usr/lib/git-core/git-http-backend)
22 # If both $httppullurl and $httpspushurl are undef this will never be used
23 # This should usually be set to `printf %s \$($git_bin --exec-path)/git-http-backend`
24 # which is to say the git-http-backend binary located in the --exec-path directory of $git_bin.
25 our $git_http_backend_bin = undef;
27 # Path to the sendmail instance to use. It should understand the -f <from>, -i and -t
28 # options as well as accepting a list of recipient addresses in order to be used here.
29 # You MUST set this, even if to '/usr/sbin/sendmail'!
30 # Setting this to 'sendmail.pl' is special and will automatically be expanded to
31 # a full path to the ../bin/sendmail.pl executable in this Girocco installation.
32 # sendmail.pl is a sendmail-compatible script that delivers the message directly
33 # using SMTP to a mail relay host. This is the recommended configuration as it
34 # minimizes the information exposed to recipients (no sender account names or uids),
35 # can talk to an SMTP server on another host (eliminating the need for a working
36 # sendmail and/or SMTP server on this host) and avoids any unwanted address rewriting.
37 # By default it expects the mail relay to be listening on localhost port 25.
38 # See the sendmail.pl section below for more information on configuring sendmail.pl.
39 our $sendmail_bin = 'sendmail.pl';
41 # E-mail of the site admin
42 our $admin = 'admin@example.org';
44 # Sender of emails
45 # This is the SMTP 'MAIL FROM:' value
46 # It will be passed to $sendmail_bin with the -f option
47 # Some sites may not allow non-privileged users to pass the -f option to
48 # $sendmail_bin. In that case set this to undef and no -f option will be
49 # passed which means the 'MAIL FROM:' value will be the user the mail is
50 # sent as (either $cgi_user or $mirror_user depending on the activity).
51 # To avoid having bounce emails go to $admin, this may be set to something
52 # else such as 'admin-noreply@example.org' and then the 'admin-noreply' address
53 # may be redirected to /dev/null. Setting this to '' or '<>' is not
54 # recommended because that will likely cause the emails to be marked as SPAM
55 # by the receiver's SPAM filter. If $sendmail_bin is set to 'sendmail.pl' this
56 # value must be acceptable to the receiving SMTP server as a 'MAIL FROM:' value.
57 # If this is set to undef and 'sendmail.pl' is used, the 'MAIL FROM:' value will
58 # be the user the mail is sent as (either $cgi_user or $mirror_user).
59 our $sender = $admin;
61 # Copy $admin on failure/recovery messages?
62 our $admincc = 1;
64 # Girocco branch to use for html.cgi view source links (undef for HEAD)
65 our $giroccobranch = undef;
68 ## Feature knobs
70 # Enable mirroring mode if true
71 our $mirror = 1;
73 # Enable push mode if true
74 our $push = 1;
76 # Enable user management if true; this means the interface for registering
77 # user accounts and uploading SSH keys. This implies full chroot.
78 our $manage_users = 1;
80 # Minimum key length (in bits) for uploaded SSH RSA/DSA keys.
81 # If this is not set (i.e. undef) keys as small as 512 bits will be allowed.
82 # Nowadays keys less than 2048 bits in length should probably not be allowed.
83 # Note, however, that versions of OpenSSH starting with 4.3p1 will only generate
84 # DSA keys of exactly 1024 bits in length even though that length is no longer
85 # recommended. (OpenSSL can be used to generate DSA keys with lengths > 1024.)
86 # OpenSSH does not have any problem generating RSA keys longer than 1024 bits.
87 # This setting is only checked when new keys are added so setting it/increasing it
88 # will not affect existing keys. For maximum compatibility a value of 1024 may
89 # be used however 2048 is recommended. Setting it to anything other than 1024,
90 # 2048 or 3072 may have the side effect of making it very difficult to generate
91 # DSA keys that satisfy the restriction (but RSA keys should not be a problem).
92 # Note that no matter what setting is specified here keys smaller than 512 bits
93 # will never be allowed via the reguser.cgi/edituser.cgi interface.
94 our $min_key_length = 1024;
96 # Disable DSA public keys?
97 # If this is set to 1, adding DSA keys at reguser.cgi/edituser.cgi time will be
98 # prohibited. If $pushurl is undef then this is implicitly set to 1 since DSA
99 # keys are not usable with https push.
100 # OpenSSH will only generate 1024 bit DSA keys starting with version 4.3p1.
101 # Even if OpenSSL is used to generate a longer DSA key (which can then be used
102 # with OpenSSH), the SSH protocol itself still forces use of SHA-1 in the DSA
103 # signature blob which tends to defeat the purpose of going to a longer key in
104 # the first place. So it may be better from a security standpoint to simply
105 # disable DSA keys especially if $min_key_length and $rsakeylength have been set
106 # to something higher such as 3072 or 4096. This setting is only checked when
107 # new keys are added so setting it/increasing it will not affect existing keys.
108 # There is no way to disable DSA keys in the OpenSSH server config file itself.
109 our $disable_dsa = 0;
111 # Enable the special 'mob' user if set to 'mob'
112 our $mob = "mob";
114 # Let users set admin passwords; if false, all password inputs are assumed empty.
115 # This will make new projects use empty passwords and all operations on them
116 # unrestricted, but you will be able to do no operations on previously created
117 # projects you have set a password on.
118 our $project_passwords = 1;
120 # How to determine project owner; 'email' adds a form item asking for their
121 # email contact, 'source' takes realname of owner of source repository if it
122 # is a local path (and empty string otherwise). 'source' is suitable in case
123 # the site operates only as mirror of purely local-filesystem repositories.
124 our $project_owners = 'email';
126 # Which project fields to make editable, out of 'shortdesc', 'homepage',
127 # 'README', 'notifymail', 'notifyjson', 'notifycia'. (This is currently
128 # soft restriction - form fields aren't used, but manually injected values
129 # *are* used. Submit a patch if that's an issue for you.)
130 our @project_fields = qw(homepage shortdesc README notifymail notifyjson notifycia);
132 # Minimal number of seconds to pass between two updates of a project.
133 our $min_mirror_interval = 3600; # 1 hour
135 # Minimal number of seconds to pass between two garbage collections of a project.
136 our $min_gc_interval = 604800; # 1 week
139 ## Paths
141 # Path where the main chunk of Girocco files will be installed
142 # This will get COMPLETELY OVERWRITTEN by each make install!!!
143 our $basedir = '/home/repo/repomgr';
145 # Path where the automatically generated non-user certificates will be stored
146 # (The per-user certificates are always stored in $chroot/etc/sshcerts/)
147 # This is preserved by each make install and MUST NOT be under $basedir!
148 # Not used unless $httpspushurl is defined
149 our $certsdir = '/home/repo/certs';
151 # The repository collection
152 # "$reporoot-recyclebin" will also be created for use by toolbox/trash-project.pl
153 our $reporoot = "/srv/git";
155 # The repository collection's location within the chroot jail
156 # Normally $reporoot will be bind mounted onto $chroot/$jailreporoot
157 # Should NOT start with '/'
158 our $jailreporoot = "srv/git";
160 # The chroot for ssh pushing; location for project database and other run-time
161 # data even in non-chroot setups
162 our $chroot = "/home/repo/j";
164 # The gitweb files web directory (corresponds to $gitwebfiles)
165 our $webroot = "/home/repo/WWW";
167 # The CGI-enabled web directory (corresponds to $gitweburl and $webadmurl)
168 our $cgiroot = "/home/repo/WWW";
170 # A web-accessible symlink to $reporoot (corresponds to $httppullurl, can be undef)
171 our $webreporoot = "/home/repo/WWW/r";
174 ## Certificates (only used if $httpspushurl is defined)
176 # path to root certificate (undef to use automatic root cert)
177 # this certificate is made available for easy download and should be whatever
178 # the root certificate is for the https certificate being used by the web server
179 our $rootcert = undef;
181 # The certificate to sign user push client authentication certificates with (undef for auto)
182 # The automatically generated certificate should always be fine
183 our $clientcert = undef;
185 # The private key for $clientcert (undef for auto)
186 # The automatically generated key should always be fine
187 our $clientkey = undef;
189 # The client certificate chain suffix (a pemseq file to append to user client certs) (undef for auto)
190 # The automatically generated chain should always be fine
191 # This suffix will also be appended to the $mobusercert before making it available for download
192 our $clientcertsuffix = undef;
194 # The mob user certificate signed by $clientcert (undef for auto)
195 # The automatically generated certificate should always be fine
196 # Not used unless $mob is set to 'mob'
197 # The $clientcertsuffix will be appended before making $mobusercert available for download
198 our $mobusercert = undef;
200 # The private key for $mobusercert (undef for auto)
201 # The automatically generated key should always be fine
202 # Not used unless $mob is set to 'mob'
203 our $mobuserkey = undef;
205 # The key length for automatically generated RSA private keys (in bits).
206 # These keys are then used to create the automatically generated certificates.
207 # If undef or set to a value less than 2048, then 2048 will be used.
208 # Set to 3072 to generate more secure keys/certificates. Set to 4096 (or higher) for
209 # even greater security. Be warned that setting to a non-multiple of 8 and/or greater
210 # than 4096 could negatively impact compatibility with some clients.
211 # The values 2048, 3072 and 4096 are expected to be compatible with all clients.
212 # Note that OpenSSL has no problem with > 4096 or non-multiple of 8 lengths.
213 # See also the $min_key_length setting above to restrict user key sizes.
214 our $rsakeylength = undef;
216 ## URL addresses
218 # URL of the gitweb.cgi script (must be in pathinfo mode)
219 our $gitweburl = "http://repo.or.cz/w";
221 # URL of the extra gitweb files (CSS, .js files, images, ...)
222 our $gitwebfiles = "http://repo.or.cz";
224 # URL of the Girocco CGI web admin interface (Girocco cgi/ subdirectory)
225 our $webadmurl = "http://repo.or.cz";
227 # URL of the Girocco CGI html templater (Girocco cgi/html.cgi)
228 our $htmlurl = "http://repo.or.cz/h";
230 # HTTP URL of the repository collection (undef if N/A)
231 our $httppullurl = "http://repo.or.cz/r";
233 # HTTPS push URL of the repository collection (undef if N/A)
234 # If this is defined, the openssl command must be available
235 # Normally this should be set to $httppullurl with http: replaced with https:
236 our $httpspushurl = undef;
238 # Git URL of the repository collection (undef if N/A)
239 # (You need to set up git-daemon on your system, and Girocco will not
240 # do this particular thing for you.)
241 our $gitpullurl = "git://repo.or.cz";
243 # Pushy SSH URL of the repository collection (undef if N/A)
244 our $pushurl = "ssh://repo.or.cz/$jailreporoot";
246 # URL of gitweb of this Girocco instance (set to undef if you're not nice
247 # to the community)
248 our $giroccourl = "$Girocco::Config::gitweburl/girocco.git";
251 ## Some templating settings
253 # Legal warning (on reguser and regproj pages)
254 our $legalese = <<EOT;
255 <p>By submitting this form, you are confirming that you will mirror or push
256 only what we can store and show to anyone else who can visit this site without
257 breaking any law, and that you will be nice to all small furry animals.
258 <sup><a href="/h/about.html">(more details)</a></sup>
259 </p>
262 # Pre-configured mirror sources (set to undef for none)
263 # Arrayref of name - record pairs, the record has these attributes:
264 # label: The label of this source
265 # url: The template URL; %1, %2, ... will be substituted for inputs
266 # desc: Optional VERY short description
267 # link: Optional URL to make the desc point at
268 # inputs: Arrayref of hashref input records:
269 # label: Label of input record
270 # suffix: Optional suffix
271 # If the inputs arrayref is undef, single URL input is shown,
272 # pre-filled with url (probably empty string).
273 our $mirror_sources = [
275 label => 'Anywhere',
276 url => '',
277 desc => 'Any HTTP/Git/rsync pull URL - bring it on!',
278 inputs => undef
281 label => 'GitHub',
282 url => 'git://github.com/%1/%2.git',
283 desc => 'GitHub Social Code Hosting',
284 link => 'http://github.com/',
285 inputs => [ { label => 'User:' }, { label => 'Project:', suffix => '.git' } ]
288 label => 'Gitorious',
289 url => 'git://gitorious.org/%1/%2.git',
290 desc => 'Green and Orange Boxes',
291 link => 'http://gitorious.org/',
292 inputs => [ { label => 'Project:' }, { label => 'Repository:', suffix => '.git' } ]
296 # You can customize the gitweb interface widely by editing
297 # gitweb/gitweb_config.perl
300 ## Permission settings
302 # Girocco needs some way to manipulate write permissions to various parts of
303 # all repositories; this concerns three entities:
304 # - www-data: the web interface needs to be able to rewrite few files within
305 # the repository
306 # - repo: a user designated for cronjobs; handles mirroring and repacking;
307 # this one is optional if not $mirror
308 # - others: the designated users that are supposed to be able to push; they
309 # may have account either within chroot, or outside of it
311 # There are several ways how to use Girocco based on a combination of the
312 # following settings.
314 # (Non-chroot) UNIX user the CGI scripts run on; note that if some non-related
315 # untrusted CGI scripts run on this account too, that can be a big security
316 # problem and you'll probably need to set up suexec (poor you).
317 # This must always be set.
318 our $cgi_user = 'www-data';
320 # (Non-chroot) UNIX user performing mirroring jobs; this is the user who
321 # should run all the daemons and cronjobs and
322 # the user who should be running make install (if not root).
323 # This must always be set.
324 our $mirror_user = 'repo';
326 # (Non-chroot) UNIX group owning the repositories by default; it owns whole
327 # mirror repositories and at least web-writable metadata of push repositories.
328 # If you undefine this, all the data will become WORLD-WRITABLE.
329 # Both $cgi_user and $mirror_user should be members of this group!
330 our $owning_group = 'repo';
332 # Whether to use chroot jail for pushing; this must be always the same
333 # as $manage_users.
334 # TODO: Gitosis support for $manage_users and not $chrooted?
335 our $chrooted = $manage_users;
337 # How to control permissions of push-writable data in push repositories:
338 # * 'Group' for the traditional model: The $chroot/etc/group project database
339 # file is used as the UNIX group(5) file; the directories have gid appropriate
340 # for the particular repository and are group-writable. This works only if
341 # $chrooted so that users are put in the proper groups on login when using
342 # SSH push. Smart HTTPS push does not require a chroot to work -- simply
343 # run "make install" as the non-root $mirror_user user, but leave
344 # $manage_users and $chrooted enabled.
345 # * 'ACL' for a model based on POSIX ACL: The directories are coupled with ACLs
346 # listing the users with push permissions. This works for both chroot and
347 # non-chroot setups, however it requires ACL support within the filesystem.
348 # This option is BASICALLY UNTESTED, too. And UNIMPLEMENTED. :-)
349 # * 'Hooks' for a relaxed model: The directories are world-writable and push
350 # permission control is purely hook-driven. This is INSECURE and works only
351 # when you trust all your users; on the other hand, the attack vectors are
352 # mostly just DoS or fully-traceable tinkering.
353 our $permission_control = 'Group';
355 # Path to alternate screen multiuser acl file (see screen/README, undef for none)
356 our $screen_acl_file = undef;
359 ## sendmail.pl configuration
361 # Full information on available sendmail.pl settings can be found by running
362 # ../bin/sendmail.pl -v -h
364 # These settings will only used if $sendmail_bin is set to 'sendmail.pl'
366 # sendmail.pl host name
367 #$ENV{'SENDMAIL_PL_HOST'} = 'localhost'; # localhost is the default
369 # sendmail.pl port name
370 #$ENV{'SENDMAIL_PL_PORT'} = '25'; # port 25 is the default
372 # sendmail.pl nc executable
373 #$ENV{'SENDMAIL_PL_NCBIN'} = "$chroot/bin/nc.openbsd"; # default is nc found in $PATH
375 # sendmail.pl nc options
376 # multiple options may be included, e.g. '-4 -X connect -x 192.168.100.10:8080'
377 #$ENV{'SENDMAIL_PL_NCOPT'} = '-4'; # force IPv4, default is to allow IPv4 & IPv6
380 ## Sanity checks & defaults
382 # Couple of sanity checks and default settings (do not change these)
383 use Digest::MD5 qw(md5);
384 use MIME::Base64 qw(encode_base64);
385 $nickname = (split(/[.]/, $name))[0] unless $nickname;
386 our $tmpsuffix = substr(encode_base64(md5($name.':'.$nickname)),0,6);
387 $tmpsuffix =~ tr,+/,=_,;
388 ($mirror_user) or die "Girocco::Config: \$mirror_user must be set even if to current user";
389 ($basedir) or die "Girocco::Config: \$basedir must be set";
390 ($sendmail_bin) or die "Girocco::Config: \$sendmail_bin must be set";
391 $sendmail_bin = "$basedir/bin/sendmail.pl" if $sendmail_bin eq "sendmail.pl";
392 $screen_acl_file = "$basedir/screen/giroccoacl" unless $screen_acl_file;
393 $jailreporoot =~ s,^/+,,;
394 ($reporoot) or die "Girocco::Config \$reporoot must be set";
395 ($jailreporoot) or die "Girocco::Config \$jailreporoot must be set";
396 (not $mob or $mob eq 'mob') or die "Girocco::Config \$mob must be undef (or '') or 'mob'";
397 (not $min_key_length or $min_key_length =~ /^[1-9][0-9]*$/)
398 or die "Girocco::Config \$min_key_length must be undef or numeric";
399 $admincc = $admincc ? 1 : 0;
400 $rootcert = "$certsdir/girocco_root_crt.pem" if $httpspushurl && !$rootcert;
401 $clientcert = "$certsdir/girocco_client_crt.pem" if $httpspushurl && !$clientcert;
402 $clientkey = "$certsdir/girocco_client_key.pem" if $httpspushurl && !$clientkey;
403 $clientcertsuffix = "$certsdir/girocco_client_suffix.pem" if $httpspushurl && !$clientcertsuffix;
404 $mobusercert = "$certsdir/girocco_mob_user_crt.pem" if $httpspushurl && $mob && !$mobusercert;
405 $mobuserkey = "$certsdir/girocco_mob_user_key.pem" if $httpspushurl && $mob && !$mobuserkey;
406 our $mobpushurl = $pushurl;
407 $mobpushurl =~ s,^ssh://,ssh://mob@,i if $mobpushurl;
408 $disable_dsa = 1 unless $pushurl;
409 our $httpsdnsname = ($httpspushurl =~ m,https://([A-Za-z0-9.-]+),i) ? lc($1) : undef if $httpspushurl;
410 ($mirror or $push) or die "Girocco::Config: neither \$mirror nor \$push is set?!";
411 (not $push or ($pushurl or $httpspushurl or $gitpullurl or $httppullurl)) or die "Girocco::Config: no pull URL is set";
412 (not $push or ($pushurl or $httpspushurl)) or die "Girocco::Config: \$push set but \$pushurl and \$httpspushurl are undef";
413 (not $mirror or $mirror_user) or die "Girocco::Config: \$mirror set but \$mirror_user is undef";
414 ($manage_users == $chrooted) or die "Girocco::Config: \$manage_users and \$chrooted must be set to the same value";
415 (not $chrooted or $permission_control ne 'ACL') or die "Girocco::Config: resolving uids for ACL not supported when using chroot";
416 (grep { $permission_control eq $_ } qw(Group Hooks)) or die "Girocco::Config: \$permission_control must be set to Group or Hooks";
417 ($chrooted or not $mob) or die "Girocco::Config: mob user supported only in the chrooted mode";
418 (not $httpspushurl or $httpsdnsname) or die "Girocco::Config invalid \$httpspushurl does not start with https://domainname";