hgext/acl.py
changeset 11095 d56124931909
parent 11094 c7adea82d495
child 11114 62714143742f
equal deleted inserted replaced
11094:c7adea82d495 11095:d56124931909
     5 # This software may be used and distributed according to the terms of the
     5 # This software may be used and distributed according to the terms of the
     6 # GNU General Public License version 2 or any later version.
     6 # GNU General Public License version 2 or any later version.
     7 
     7 
     8 '''hooks for controlling repository access
     8 '''hooks for controlling repository access
     9 
     9 
    10 This hook makes it possible to allow or deny write access to given branches and
    10 This hook makes it possible to allow or deny write access to given
    11 paths of a repository when receiving incoming changesets via pretxnchangegroup
    11 branches and paths of a repository when receiving incoming changesets
    12 and pretxncommit.
    12 via pretxnchangegroup and pretxncommit.
    13 
    13 
    14 The authorization is matched based on the local user name on the
    14 The authorization is matched based on the local user name on the
    15 system where the hook runs, and not the committer of the original
    15 system where the hook runs, and not the committer of the original
    16 changeset (since the latter is merely informative).
    16 changeset (since the latter is merely informative).
    17 
    17 
    18 The acl hook is best used along with a restricted shell like hgsh,
    18 The acl hook is best used along with a restricted shell like hgsh,
    19 preventing authenticating users from doing anything other than
    19 preventing authenticating users from doing anything other than pushing
    20 pushing or pulling. The hook is not safe to use if users have
    20 or pulling. The hook is not safe to use if users have interactive
    21 interactive shell access, as they can then disable the hook.
    21 shell access, as they can then disable the hook. Nor is it safe if
    22 Nor is it safe if remote users share an account, because then there
    22 remote users share an account, because then there is no way to
    23 is no way to distinguish them.
    23 distinguish them.
    24 
    24 
    25 The order in which access checks are performed is:
    25 The order in which access checks are performed is:
    26 
    26 
    27 1) Deny  list for branches (section ``acl.deny.branches``)
    27 1) Deny  list for branches (section ``acl.deny.branches``)
    28 2) Allow list for branches (section ``acl.allow.branches``)
    28 2) Allow list for branches (section ``acl.allow.branches``)
    32 The allow and deny sections take key-value pairs.
    32 The allow and deny sections take key-value pairs.
    33 
    33 
    34 Branch-based Access Control
    34 Branch-based Access Control
    35 ---------------------------
    35 ---------------------------
    36 
    36 
    37 Use the ``acl.deny.branches`` and ``acl.allow.branches`` sections to have
    37 Use the ``acl.deny.branches`` and ``acl.allow.branches`` sections to
    38 branch-based access control.
    38 have branch-based access control. Keys in these sections can be
    39 
    39 either:
    40 Keys in these sections can be either:
    40 
    41 
    41 - a branch name, or
    42 1) a branch name
    42 - an asterisk, to match any branch;
    43 2) an asterisk, to match any branch;
       
    44 
    43 
    45 The corresponding values can be either:
    44 The corresponding values can be either:
    46 
    45 
    47 1) a comma-separated list containing users and groups.
    46 - a comma-separated list containing users and groups, or
    48 2) an asterisk, to match anyone;
    47 - an asterisk, to match anyone;
    49 
    48 
    50 Path-based Access Control
    49 Path-based Access Control
    51 -------------------------
    50 -------------------------
    52 
    51 
    53 Use the ``acl.deny`` and ``acl.allow`` sections to have path-based access control.
    52 Use the ``acl.deny`` and ``acl.allow`` sections to have path-based
    54 Keys in these sections accept a subtree pattern (with a glob syntax by default).
    53 access control. Keys in these sections accept a subtree pattern (with
    55 The corresponding values follow the same syntax as the other sections above.
    54 a glob syntax by default). The corresponding values follow the same
       
    55 syntax as the other sections above.
    56 
    56 
    57 Groups
    57 Groups
    58 ------
    58 ------
    59 
    59 
    60 Group names must be prefixed with an ``@`` symbol.
    60 Group names must be prefixed with an ``@`` symbol. Specifying a group
    61 Specifying a group name has the same effect as specifying all the users in
    61 name has the same effect as specifying all the users in that group.
    62 that group.
       
    63 The set of users for a group is taken from "grp.getgrnam"
       
    64 (see http://docs.python.org/library/grp.html#grp.getgrnam).
       
    65 
    62 
    66 Example Configuration
    63 Example Configuration
    67 ---------------------
    64 ---------------------
    68 
    65 
    69 ::
    66 ::
    71   [hooks]
    68   [hooks]
    72 
    69 
    73   # Use this if you want to check access restrictions at commit time
    70   # Use this if you want to check access restrictions at commit time
    74   pretxncommit.acl = python:hgext.acl.hook
    71   pretxncommit.acl = python:hgext.acl.hook
    75   
    72   
    76   # Use this if you want to check access restrictions for pull, push, bundle
    73   # Use this if you want to check access restrictions for pull, push,
    77   # and serve.
    74   # bundle and serve.
    78   pretxnchangegroup.acl = python:hgext.acl.hook
    75   pretxnchangegroup.acl = python:hgext.acl.hook
    79 
    76 
    80   [acl]
    77   [acl]
    81   # Check whether the source of incoming changes is in this list
    78   # Check whether the source of incoming changes is in this list where
    82   # ("serve" == ssh or http, "push", "pull", "bundle")
    79   # "serve" == ssh or http, and "push", "pull" and "bundle" are the
       
    80   # corresponding hg commands.
    83   sources = serve
    81   sources = serve
    84 
    82 
    85   [acl.deny.branches] 
    83   [acl.deny.branches] 
    86   
    84   
    87   # Everyone is denied to the frozen branch: 
    85   # Everyone is denied to the frozen branch: 
   103   
   101   
   104   # Everyone is allowed on branch-for-tests: 
   102   # Everyone is allowed on branch-for-tests: 
   105   branch-for-tests = * 
   103   branch-for-tests = * 
   106 
   104 
   107   [acl.deny]
   105   [acl.deny]
   108   # If a match is found, "acl.allow" will not be checked.
   106   # This list is checked first. If a match is found, acl.allow is not
   109   # if acl.deny is not present, no users denied by default
   107   # checked. All users are granted access if acl.deny is not present.
   110   # empty acl.deny = all users allowed
   108   # Format for both lists: glob pattern = user, ..., @group, ...
   111   # Format for both lists: glob pattern = user4, user5, @group1
       
   112 
   109 
   113   # To match everyone, use an asterisk for the user:
   110   # To match everyone, use an asterisk for the user:
   114   # my/glob/pattern = *
   111   # my/glob/pattern = *
   115 
   112 
   116   # user6 will not have write access to any file:
   113   # user6 will not have write access to any file:
   117   ** = user6
   114   ** = user6
   118 
   115 
   119   # Group "hg-denied" will not have write access to any file:
   116   # Group "hg-denied" will not have write access to any file:
   120   ** = @hg-denied
   117   ** = @hg-denied
   121 
   118 
   122   # Nobody will be able to change "DONT-TOUCH-THIS.txt", despite everyone being
   119   # Nobody will be able to change "DONT-TOUCH-THIS.txt", despite
   123   # able to change all other files. See below.
   120   # everyone being able to change all other files. See below.
   124   src/main/resources/DONT-TOUCH-THIS.txt = *
   121   src/main/resources/DONT-TOUCH-THIS.txt = *
   125 
   122 
   126   [acl.allow]
   123   [acl.allow]
   127   # if acl.allow not present, all users allowed by default
   124   # if acl.allow not present, all users allowed by default
   128   # empty acl.allow = no users allowed
   125   # empty acl.allow = no users allowed
   129 
   126 
   130   # User "doc_writer" has write access to any file under the "docs" folder:
   127   # User "doc_writer" has write access to any file under the "docs"
       
   128   # folder:
   131   docs/** = doc_writer
   129   docs/** = doc_writer
   132 
   130 
   133   # User "jack" and group "designers" have write access to any file under the
   131   # User "jack" and group "designers" have write access to any file
   134   # "images" folder:
   132   # under the "images" folder:
   135   images/** = jack, @designers
   133   images/** = jack, @designers
   136 
   134 
   137   # Everyone (except for "user6" - see "acl.deny" above) will have write access
   135   # Everyone (except for "user6" - see acl.deny above) will have write
   138   to any file under the "resources" folder (except for 1 file. See "acl.deny"):
   136   # access to any file under the "resources" folder (except for 1
       
   137   # file. See acl.deny):
   139   src/main/resources/** = *
   138   src/main/resources/** = *
   140 
   139 
   141   .hgtags = release_engineer
   140   .hgtags = release_engineer
   142 
   141 
   143 '''
   142 '''