@matheusbsbs / matheus-bagliano / commits / b767c792fa
Fork 0

Teach update-paranoid how to store ACLs organized by groups

In some applications of this paranoid update hook the set of ACL rules that need to be applied to a user can be large, and the number of users that those rules must also be applied to can be more than a handful of individuals. Rather than repeating the same rules multiple times (once for each user) we now allow users to be members of groups, where the group supplies the list of ACL rules. For various reasons we don't depend on the underlying OS groups and instead perform our own group handling. Users can be made a member of one or more groups by setting the user.memberOf property within the "users/$who.acl" file: [user] memberOf = developer memberOf = administrator This will cause the hook to also parse the "groups/$groupname.acl" file for each value of user.memberOf, and merge any allow rules that match the current repository with the user's own private rules (if they had any). Since some rules are basically the same but may have a component differ based on the individual user, any user.* key may be inserted into a rule using the "${user.foo}" syntax. The allow rule does not match if the user does not define one (and exactly one) value for the key "foo". Signed-off-by: Shawn O. Pearce <spearce@spearce.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Shawn O. Pearce committed Aug 9, 2007 at 02:38 UTC b767c792fa202539cfb9bba36f46c62bcbf7c987
1 file changed +44 -16
contrib/hooks/update-paranoid
+44 -16
@@ -118,22 +118,29 @@ sub info ($) {
118 print STDERR "-Info- $_[0]\n" if $debug;
119 }
120
121 -sub parse_config ($$) {
122 - my ($data, $fn) = @_;
123 - info "Loading $fn";
124 - open(I,'-|','git',"--git-dir=$acl_git",'cat-file','blob',$fn);
121 +sub git_value (@) {
122 + open(T,'-|','git',@_); local $_ = <T>; chop; close T; $_;
123 +}
124 +
125 +sub parse_config ($$$$) {
126 + my $data = shift;
127 + local $ENV{GIT_DIR} = shift;
128 + my $br = shift;
129 + my $fn = shift;
130 + info "Loading $br:$fn";
131 + open(I,'-|','git','cat-file','blob',"$br:$fn");
132 my $section = '';
133 while (<I>) {
134 chomp;
135 if (/^\s*$/ || /^\s*#/) {
136 } elsif (/^\[([a-z]+)\]$/i) {
130 - $section = $1;
137 + $section = lc $1;
138 } elsif (/^\[([a-z]+)\s+"(.*)"\]$/i) {
132 - $section = "$1.$2";
139 + $section = join('.',lc $1,$2);
140 } elsif (/^\s*([a-z][a-z0-9]+)\s*=\s*(.*?)\s*$/i) {
134 - push @{$data->{"$section.$1"}}, $2;
141 + push @{$data->{join('.',$section,lc $1)}}, $2;
142 } else {
136 - deny "bad config file line $. in $fn";
143 + deny "bad config file line $. in $br:$fn";
144 }
145 }
146 close I;
@@ -202,11 +209,6 @@ sub check_committers (@) {
209 }
210 }
211
205 -sub git_value (@) {
206 - open(T,'-|','git',@_); local $_ = <T>; chop; close T;
207 - $_;
208 -}
209 -
212 deny "No GIT_DIR inherited from caller" unless $git_dir;
213 deny "Need a ref name" unless $ref;
214 deny "Refusing funny ref $ref" unless $ref =~ s,^refs/,,;
@@ -231,13 +233,39 @@ $op = 'U' if ($op eq 'R'
233 && $ref =~ m,^heads/,
234 && $old eq git_value('merge-base',$old,$new));
235
234 -# Load the user's ACL file.
236 +# Load the user's ACL file. Expand groups (user.memberof) one level.
237 {
238 my %data = ('user.committer' => []);
237 - parse_config(\%data, "$acl_branch:users/$this_user.acl");
239 + parse_config(\%data,$acl_git,$acl_branch,"external/$repository_name.acl");
240 +
241 + %data = (
242 + 'user.committer' => $data{'user.committer'},
243 + 'user.memberof' => [],
244 + );
245 + parse_config(\%data,$acl_git,$acl_branch,"users/$this_user.acl");
246 +
247 %user_committer = map {$_ => $_} @{$data{'user.committer'}};
239 - my $rules = $data{"repository.$repository_name.allow"} || [];
248 + my $rule_key = "repository.$repository_name.allow";
249 + my $rules = $data{$rule_key} || [];
250 +
251 + foreach my $group (@{$data{'user.memberof'}}) {
252 + my %g;
253 + parse_config(\%g,$acl_git,$acl_branch,"groups/$group.acl");
254 + my $group_rules = $g{$rule_key};
255 + push @$rules, @$group_rules if $group_rules;
256 + }
257 +
258 +RULE:
259 foreach (@$rules) {
260 + while (/\${user\.([a-z][a-zA-Z0-9]+)}/) {
261 + my $k = lc $1;
262 + my $v = $data{"user.$k"};
263 + next RULE unless defined $v;
264 + next RULE if @$v != 1;
265 + next RULE unless defined $v->[0];
266 + s/\${user\.$k}/$v->[0]/g;
267 + }
268 +
269 if (/^([CDRU ]+)\s+for\s+([^\s]+)$/) {
270 my $ops = $1;
271 my $ref = $2;