Add knob to require a minimum public key length
[girocco.git] / Girocco / Config.pm
blob8421dda8fea7fb015dccc55eeff93912cef5ff77
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 our $git_http_backend_bin = undef;
25 # E-mail of the site admin
26 our $admin = 'admin@example.org';
28 # Copy $admin on failure/recovery messages?
29 our $admincc = 1;
31 # Girocco branch to use for html.cgi view source links (undef for HEAD)
32 our $giroccobranch = undef;
35 ## Feature knobs
37 # Enable mirroring mode if true
38 our $mirror = 1;
40 # Enable push mode if true
41 our $push = 1;
43 # Enable user management if true; this means the interface for registering
44 # user accounts and uploading SSH keys. This implies full chroot.
45 our $manage_users = 1;
47 # Minimum key length (in bits) for uploaded SSH RSA/DSA keys.
48 # If this is not set (i.e. undef) keys as small as 512 bits will be allowed.
49 # Nowadays keys less than 2048 bits in length should probably not be allowed.
50 # Note, however, that versions of OpenSSH starting with 4.3p1 will only generate
51 # DSA keys of exactly 1024 bits in length even though that length is no longer
52 # recommended. (OpenSSL can be used to generate DSA keys with lengths > 1024.)
53 # OpenSSH does not have any problem generating RSA keys longer than 1024 bits.
54 # This setting is only checked when new keys are added so setting it/increasing it
55 # will not affect existing keys. For maximum compatibility a value of 1024 may
56 # be used however 2048 is recommended. Setting it to anything other than 1024,
57 # 2048 or 3072 may have the side effect of making it very difficult to generate
58 # DSA keys that satisfy the restriction (but RSA keys should not be a problem).
59 # Note that no matter what setting is specified here keys smaller than 512 bits
60 # will never be allowed via the reguser.cgi/edituser.cgi interface.
61 our $min_key_length = 1024;
63 # Enable the special 'mob' user if set to 'mob'
64 our $mob = "mob";
66 # Let users set admin passwords; if false, all password inputs are assumed empty.
67 # This will make new projects use empty passwords and all operations on them
68 # unrestricted, but you will be able to do no operations on previously created
69 # projects you have set a password on.
70 our $project_passwords = 1;
72 # How to determine project owner; 'email' adds a form item asking for their
73 # email contact, 'source' takes realname of owner of source repository if it
74 # is a local path (and empty string otherwise). 'source' is suitable in case
75 # the site operates only as mirror of purely local-filesystem repositories.
76 our $project_owners = 'email';
78 # Which project fields to make editable, out of 'shortdesc', 'homepage',
79 # 'README', 'notifymail', 'notifyjson', 'notifycia'. (This is currently
80 # soft restriction - form fields aren't used, but manually injected values
81 # *are* used. Submit a patch if that's an issue for you.)
82 our @project_fields = qw(homepage shortdesc README notifymail notifyjson notifycia);
84 # Minimal number of seconds to pass between two updates of a project.
85 our $min_mirror_interval = 3600; # 1 hour
87 # Minimal number of seconds to pass between two garbage collections of a project.
88 our $min_gc_interval = 604800; # 1 week
91 ## Paths
93 # Path where the main chunk of Girocco files will be installed
94 # This will get COMPLETELY OVERWRITTEN by each make install!!!
95 our $basedir = '/home/repo/repomgr';
97 # Path where the automatically generated non-user certificates will be stored
98 # (The per-user certificates are always stored in $chroot/etc/sshcerts/)
99 # This is preserved by each make install and MUST NOT be under $basedir!
100 # Not used unless $httpspushurl is defined
101 our $certsdir = '/home/repo/certs';
103 # The repository collection
104 # "$reporoot-recyclebin" will also be created for use by toolbox/trash-project.pl
105 our $reporoot = "/srv/git";
107 # The repository collection's location within the chroot jail
108 # Normally $reporoot will be bind mounted onto $chroot/$jailreporoot
109 # Should NOT start with '/'
110 our $jailreporoot = "srv/git";
112 # The chroot for ssh pushing; location for project database and other run-time
113 # data even in non-chroot setups
114 our $chroot = "/home/repo/j";
116 # The gitweb files web directory (corresponds to $gitwebfiles)
117 our $webroot = "/home/repo/WWW";
119 # The CGI-enabled web directory (corresponds to $gitweburl and $webadmurl)
120 our $cgiroot = "/home/repo/WWW";
122 # A web-accessible symlink to $reporoot (corresponds to $httppullurl, can be undef)
123 our $webreporoot = "/home/repo/WWW/r";
126 ## Certificates (only used if $httpspushurl is defined)
128 # path to root certificate (undef to use automatic root cert)
129 # this certificate is made available for easy download and should be whatever
130 # the root certificate is for the https certificate being used by the web server
131 our $rootcert = undef;
133 # The certificate to sign user push client authentication certificates with (undef for auto)
134 # The automatically generated certificate should always be fine
135 our $clientcert = undef;
137 # The private key for $clientcert (undef for auto)
138 # The automatically generated key should always be fine
139 our $clientkey = undef;
141 # The client certificate chain suffix (a pemseq file to append to user client certs) (undef for auto)
142 # The automatically generated chain should always be fine
143 # This suffix will also be appended to the $mobusercert before making it available for download
144 our $clientcertsuffix = undef;
146 # The mob user certificate signed by $clientcert (undef for auto)
147 # The automatically generated certificate should always be fine
148 # Not used unless $mob is set to 'mob'
149 # The $clientcertsuffix will be appended before making $mobusercert available for download
150 our $mobusercert = undef;
152 # The private key for $mobusercert (undef for auto)
153 # The automatically generated key should always be fine
154 # Not used unless $mob is set to 'mob'
155 our $mobuserkey = undef;
157 # The key length for automatically generated RSA private keys (in bits).
158 # These keys are then used to create the automatically generated certificates.
159 # If undef or set to a value less than 2048, then 2048 will be used.
160 # Set to 3072 to generate more secure keys/certificates. Set to 4096 (or higher) for
161 # even greater security. Be warned that setting to a non-multiple of 8 and/or greater
162 # than 4096 could negatively impact compatibility with some clients.
163 # The values 2048, 3072 and 4096 are expected to be compatible with all clients.
164 # Note that OpenSSL has no problem with > 4096 or non-multiple of 8 lengths.
165 # See also the $min_key_length setting above to restrict user key sizes.
166 our $rsakeylength = undef;
168 ## URL addresses
170 # URL of the gitweb.cgi script (must be in pathinfo mode)
171 our $gitweburl = "http://repo.or.cz/w";
173 # URL of the extra gitweb files (CSS, .js files, images, ...)
174 our $gitwebfiles = "http://repo.or.cz";
176 # URL of the Girocco CGI web admin interface (Girocco cgi/ subdirectory)
177 our $webadmurl = "http://repo.or.cz";
179 # URL of the Girocco CGI html templater (Girocco cgi/html.cgi)
180 our $htmlurl = "http://repo.or.cz/h";
182 # HTTP URL of the repository collection (undef if N/A)
183 our $httppullurl = "http://repo.or.cz/r";
185 # HTTPS push URL of the repository collection (undef if N/A)
186 # If this is defined, the openssl command must be available
187 # Normally this should be set to $httppullurl with http: replaced with https:
188 our $httpspushurl = undef;
190 # Git URL of the repository collection (undef if N/A)
191 # (You need to set up git-daemon on your system, and Girocco will not
192 # do this particular thing for you.)
193 our $gitpullurl = "git://repo.or.cz";
195 # Pushy SSH URL of the repository collection (undef if N/A)
196 our $pushurl = "ssh://repo.or.cz/$jailreporoot";
198 # URL of gitweb of this Girocco instance (set to undef if you're not nice
199 # to the community)
200 our $giroccourl = "$Girocco::Config::gitweburl/girocco.git";
203 ## Some templating settings
205 # Legal warning (on reguser and regproj pages)
206 our $legalese = <<EOT;
207 <p>By submitting this form, you are confirming that you will mirror or push
208 only what we can store and show to anyone else who can visit this site without
209 breaking any law, and that you will be nice to all small furry animals.
210 <sup><a href="/h/about.html">(more details)</a></sup>
211 </p>
214 # Pre-configured mirror sources (set to undef for none)
215 # Arrayref of name - record pairs, the record has these attributes:
216 # label: The label of this source
217 # url: The template URL; %1, %2, ... will be substituted for inputs
218 # desc: Optional VERY short description
219 # link: Optional URL to make the desc point at
220 # inputs: Arrayref of hashref input records:
221 # label: Label of input record
222 # suffix: Optional suffix
223 # If the inputs arrayref is undef, single URL input is shown,
224 # pre-filled with url (probably empty string).
225 our $mirror_sources = [
227 label => 'Anywhere',
228 url => '',
229 desc => 'Any HTTP/Git/rsync pull URL - bring it on!',
230 inputs => undef
233 label => 'GitHub',
234 url => 'git://github.com/%1/%2.git',
235 desc => 'GitHub Social Code Hosting',
236 link => 'http://github.com/',
237 inputs => [ { label => 'User:' }, { label => 'Project:', suffix => '.git' } ]
240 label => 'Gitorious',
241 url => 'git://gitorious.org/%1/%2.git',
242 desc => 'Green and Orange Boxes',
243 link => 'http://gitorious.org/',
244 inputs => [ { label => 'Project:' }, { label => 'Repository:', suffix => '.git' } ]
248 # You can customize the gitweb interface widely by editing
249 # gitweb/gitweb_config.perl
252 ## Permission settings
254 # Girocco needs some way to manipulate write permissions to various parts of
255 # all repositories; this concerns three entities:
256 # - www-data: the web interface needs to be able to rewrite few files within
257 # the repository
258 # - repo: a user designated for cronjobs; handles mirroring and repacking;
259 # this one is optional if not $mirror
260 # - others: the designated users that are supposed to be able to push; they
261 # may have account either within chroot, or outside of it
263 # There are several ways how to use Girocco based on a combination of the
264 # following settings.
266 # (Non-chroot) UNIX user the CGI scripts run on; note that if some non-related
267 # untrusted CGI scripts run on this account too, that can be a big security
268 # problem and you'll probably need to set up suexec (poor you).
269 # This must always be set.
270 our $cgi_user = 'www-data';
272 # (Non-chroot) UNIX user performing mirroring jobs; this is the user who
273 # should run all the daemons and cronjobs and
274 # the user who should be running make install (if not root).
275 # This must always be set.
276 our $mirror_user = 'repo';
278 # (Non-chroot) UNIX group owning the repositories by default; it owns whole
279 # mirror repositories and at least web-writable metadata of push repositories.
280 # If you undefine this, all the data will become WORLD-WRITABLE.
281 # Both $cgi_user and $mirror_user should be members of this group!
282 our $owning_group = 'repo';
284 # Whether to use chroot jail for pushing; this must be always the same
285 # as $manage_users.
286 # TODO: Gitosis support for $manage_users and not $chrooted?
287 our $chrooted = $manage_users;
289 # How to control permissions of push-writable data in push repositories:
290 # * 'Group' for the traditional model: The $chroot/etc/group project database
291 # file is used as the UNIX group(5) file; the directories have gid appropriate
292 # for the particular repository and are group-writable. This works only if
293 # $chrooted so that users are put in the proper groups on login when using
294 # SSH push. Smart HTTPS push does not require a chroot to work -- simply
295 # run "make install" as the non-root $mirror_user user, but leave
296 # $manage_users and $chrooted enabled.
297 # * 'ACL' for a model based on POSIX ACL: The directories are coupled with ACLs
298 # listing the users with push permissions. This works for both chroot and
299 # non-chroot setups, however it requires ACL support within the filesystem.
300 # This option is BASICALLY UNTESTED, too. And UNIMPLEMENTED. :-)
301 # * 'Hooks' for a relaxed model: The directories are world-writable and push
302 # permission control is purely hook-driven. This is INSECURE and works only
303 # when you trust all your users; on the other hand, the attack vectors are
304 # mostly just DoS or fully-traceable tinkering.
305 our $permission_control = 'Group';
307 # Path to alternate screen multiuser acl file (see screen/README, undef for none)
308 our $screen_acl_file = undef;
310 # Couple of sanity checks and default settings (do not change these)
311 use Digest::MD5 qw(md5);
312 use MIME::Base64 qw(encode_base64);
313 $nickname = (split(/[.]/, $name))[0] unless $nickname;
314 our $tmpsuffix = substr(encode_base64(md5($name.':'.$nickname)),0,6);
315 $tmpsuffix =~ tr,+/,=_,;
316 ($mirror_user) or die "Girocco::Config: \$mirror_user must be set even if to current user";
317 $screen_acl_file = "$basedir/screen/giroccoacl" unless $screen_acl_file;
318 $jailreporoot =~ s,^/+,,;
319 ($reporoot) or die "Girocco::Config \$reporoot must be set";
320 ($jailreporoot) or die "Girocco::Config \$jailreporoot must be set";
321 (not $mob or $mob eq 'mob') or die "Girocco::Config \$mob must be undef (or '') or 'mob'";
322 (not $min_key_length or $min_key_length =~ /^[1-9][0-9]*$/)
323 or die "Girocco::Config \$min_key_length must be undef or numeric";
324 $admincc = $admincc ? 1 : 0;
325 $rootcert = "$certsdir/girocco_root_crt.pem" if $httpspushurl && !$rootcert;
326 $clientcert = "$certsdir/girocco_client_crt.pem" if $httpspushurl && !$clientcert;
327 $clientkey = "$certsdir/girocco_client_key.pem" if $httpspushurl && !$clientkey;
328 $clientcertsuffix = "$certsdir/girocco_client_suffix.pem" if $httpspushurl && !$clientcertsuffix;
329 $mobusercert = "$certsdir/girocco_mob_user_crt.pem" if $httpspushurl && $mob && !$mobusercert;
330 $mobuserkey = "$certsdir/girocco_mob_user_key.pem" if $httpspushurl && $mob && !$mobuserkey;
331 our $mobpushurl = $pushurl;
332 $mobpushurl =~ s,^ssh://,ssh://mob@,i if $mobpushurl;
333 our $httpsdnsname = ($httpspushurl =~ m,https://([A-Za-z0-9.-]+),i) ? lc($1) : undef if $httpspushurl;
334 ($mirror or $push) or die "Girocco::Config: neither \$mirror nor \$push is set?!";
335 (not $push or ($pushurl or $httpspushurl or $gitpullurl or $httppullurl)) or die "Girocco::Config: no pull URL is set";
336 (not $push or ($pushurl or $httpspushurl)) or die "Girocco::Config: \$push set but \$pushurl and \$httpspushurl are undef";
337 (not $mirror or $mirror_user) or die "Girocco::Config: \$mirror set but \$mirror_user is undef";
338 ($manage_users == $chrooted) or die "Girocco::Config: \$manage_users and \$chrooted must be set to the same value";
339 (not $chrooted or $permission_control ne 'ACL') or die "Girocco::Config: resolving uids for ACL not supported when using chroot";
340 (grep { $permission_control eq $_ } qw(Group Hooks)) or die "Girocco::Config: \$permission_control must be set to Group or Hooks";
341 ($chrooted or not $mob) or die "Girocco::Config: mob user supported only in the chrooted mode";
342 (not $httpspushurl or $httpsdnsname) or die "Girocco::Config invalid \$httpspushurl does not start with https://domainname";