The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

check-acls.pl - Git::Hooks plugin for branch/tag access control.

DESCRIPTION

This Git::Hooks plugin can act as any of the below hooks to guarantee that only allowed users can push commits and tags to specific branches.

update

This hook is invoked multiple times in the remote repository during git push, once per branch being updated, checking if the user performing the push can update the branch in question.

pre-receive

This hook is invoked once in the remote repository during git push, checking if the user performing the push can update every affected branch.

To enable it you should define the appropriate Git configuration option:

    git config --add githooks.update      check-acls.pl
    git config --add githooks.pre-receive check-acls.pl

CONFIGURATION

The plugin is configured by the following git options.

check-acls.userenv STRING

This variable is deprecated. Please, use the githooks.userenv variable, which is defined in the Git::Hooks module. Please, see its documentation to understand it.

check-acls.admin USERSPEC

This variable is deprecated. Please, use the githooks.admin variable, which is defined in the Git::Hooks module. Please, see its documentation to understand it.

check-acls.acl ACL

The authorization specification for a repository is defined by the set of ACLs defined by this option. Each ACL specify 'who' has 'what' kind of access to which refs, by means of a string with three components separated by spaces:

    who what refs

By default, nobody has access to anything, except the above-specified admins. During an update, all the ACLs are processed in the order defined by the git config --list command. The first ACL matching the authenticated username and the affected reference name (usually a branch) defines what operations are allowed. If no ACL matches username and reference name, then the operation is denied.

The 'who' component specifies to which users this ACL gives access. It can be specified in the same three ways as was explained to the check-acls.admin option above.

The 'what' component specifies what kind of access to allow. It's specified as a string of one or more of the following opcodes:

C

Create a new ref.

R

Rewind/Rebase an existing ref. (With commit loss.)

U

Update an existing ref. (A fast-forward with no commit loss.)

D

Delete an existing ref.

You may specify that the user has no access whatsoever to the references by using a single hifen (-) as the what component.

The 'refs' component specifies which refs this ACL applies to. It can be specified in one of these formats:

^REGEXP

A regular expression anchored at the beginning of the reference name. For example, "^refs/heads", meaning every branch.

!REGEXP

A negated regular expression. For example, "!^refs/heads/master", meaning everything but the master branch.

STRING

The complete name of a reference. For example, "refs/heads/master".

The ACL specification can embed strings in the format {VAR}. These strings are substituted by the corresponding environment's variable VAR value. This interpolation ocurrs before the components are split and processed.

This is useful, for instance, if you want developers to be restricted in what they can do to oficial branches but to have complete control with their own branch namespace.

    git config check-acls.acl '^. CRUD ^refs/heads/{USER}/'
    git config check-acls.acl '^. U    ^refs/heads'

In this example, every user (^.) has complete control (CRUD) to the branches below "refs/heads/{USER}". Supposing the environment variable USER contains the user's login name during a "pre-receive" hook. For all other branches (^refs/heads) the users have only update (U) rights.

REFERENCES

This script is heavily inspired (and, in some places, derived) from the update-paranoid example hook which comes with the Git distribution (https://github.com/gitster/git/blob/b12905140a8239ac687450ad43f18b5f0bcfb62e/contrib/hooks/update-paranoid).