add security warning to 'config' command
[gitolite.git] / src / commands / config
blob7851c1188a409d7f68d394aed1293c5e0091fb00
1 #!/usr/bin/perl
2 use 5.10.0;
4 # ---- WARNING ----
6 # If your site makes a distinction between "right to push the admin repo" and
7 # "right to run arbitrary commands on the server" (i.e., if not all of your
8 # "admins" have shell access to the server), this is a security risk. If that
9 # is the case, DO NOT ENABLE THIS COMMAND.
11 # ----------------------------------------------------------------------
12 # gitolite command to allow "git config" on repos (with some restrictions)
14 # (Not to be confused with the 'git-config' command, which is used only in
15 # server-side scripts, not remotely.)
17 # setup:
18 # 1. Enable the command by adding it to the COMMANDS section in the ENABLE
19 # list in the rc file. (Have you read the warning above?)
21 # 2. Specify configs allowed to be changed by the user. This is a space
22 # separated regex list. For example:
24 # repo ...
25 # ... (various rules) ...
26 # option user-configs = hook\..* foo.bar[0-9].*
28 use strict;
29 use warnings;
31 use lib $ENV{GL_LIBDIR};
32 use Gitolite::Easy;
33 use Gitolite::Common;
35 # ----------------------------------------------------------------------
36 # usage
38 =for usage
39 Usage: ssh git@host config <repo> [git config options]
41 Runs "git config" in the repo. Only the following 3 syntaxes are supported
42 (see 'man git-config'):
44 --add name value
45 --get-all name
46 --unset-all name
47 --list
49 Your administrator should tell you what keys are allowed for the "name".
50 =cut
52 # ----------------------------------------------------------------------
53 # arg checks
55 my %nargs = qw(
56 --add 3
57 --get-all 2
58 --unset-all 2
59 --list 1
62 usage() if not @ARGV or $ARGV[0] eq '-h';
64 my $repo = shift;
66 my ($op, $key, $val) = @ARGV;
67 usage() unless $op and exists $nargs{$op} and @ARGV == $nargs{$op};
69 # ----------------------------------------------------------------------
70 # authorisation checks
72 die "sorry, you are not authorised\n" unless
73 owns($repo)
75 ( ( $op eq '--get-all' or $op eq '--list' )
76 ? can_read($repo)
77 : ( can_write($repo) and option( $repo, 'writer-is-owner' ) )
80 # ----------------------------------------------------------------------
81 # key validity checks
83 unless ($op eq '--list') {
84 my $user_configs = option( $repo, 'user-configs' );
85 # this is a space separated list of allowed config keys
86 my @validkeys = split( ' ', ( $user_configs || '' ) );
87 my @matched = grep { $key =~ /^$_$/i } @validkeys;
88 _die "config '$key' not allowed\n" if ( @matched < 1 );
91 # ----------------------------------------------------------------------
92 # go!
94 _chdir("$rc{GL_REPO_BASE}/$repo.git");
95 _system( "git", "config", @ARGV );