| 1 |
<?xml version="1.0" encoding="utf-8"?> |
| 2 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
| 3 |
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> |
| 4 |
<head> |
| 5 |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
| 6 |
<meta name="generator" content="Docutils 0.21.2: https://docutils.sourceforge.io/" /> |
| 7 |
<title>acl</title> |
| 8 |
<link rel="stylesheet" href="../style.css" type="text/css" /> |
| 9 |
</head> |
| 10 |
<body> |
| 11 |
<div class="document" id="acl"> |
| 12 |
<span id="ext-acl"></span> |
| 13 |
<h1 class="title">acl</h1> |
| 14 |
|
| 15 |
<div class="contents htmlonly topic" id="contents"> |
| 16 |
<p class="topic-title"><a class="reference internal" href="#top">Contents</a></p> |
| 17 |
<ul class="simple"> |
| 18 |
<li><a class="reference internal" href="#description" id="toc-entry-1">Description</a><ul> |
| 19 |
<li><a class="reference internal" href="#branch-based-access-control" id="toc-entry-2">Branch-based Access Control</a></li> |
| 20 |
<li><a class="reference internal" href="#path-based-access-control" id="toc-entry-3">Path-based Access Control</a></li> |
| 21 |
<li><a class="reference internal" href="#bookmark-based-access-control" id="toc-entry-4">Bookmark-based Access Control</a></li> |
| 22 |
<li><a class="reference internal" href="#groups" id="toc-entry-5">Groups</a></li> |
| 23 |
<li><a class="reference internal" href="#example-configuration" id="toc-entry-6">Example Configuration</a></li> |
| 24 |
</ul> |
| 25 |
</li> |
| 26 |
</ul> |
| 27 |
</div> |
| 28 |
<p>hooks for controlling repository access</p> |
| 29 |
<div class="section" id="description"> |
| 30 |
<h1><a class="toc-backref" href="#contents">Description</a></h1> |
| 31 |
<p>This hook makes it possible to allow or deny write access to given |
| 32 |
branches and paths of a repository when receiving incoming changesets |
| 33 |
via pretxnchangegroup and pretxncommit.</p> |
| 34 |
<p>The authorization is matched based on the local user name on the |
| 35 |
system where the hook runs, and not the committer of the original |
| 36 |
changeset (since the latter is merely informative).</p> |
| 37 |
<p>The acl hook is best used along with a restricted shell like hgsh, |
| 38 |
preventing authenticating users from doing anything other than pushing |
| 39 |
or pulling. The hook is not safe to use if users have interactive |
| 40 |
shell access, as they can then disable the hook. Nor is it safe if |
| 41 |
remote users share an account, because then there is no way to |
| 42 |
distinguish them.</p> |
| 43 |
<p>The order in which access checks are performed is:</p> |
| 44 |
<ol class="arabic simple"> |
| 45 |
<li>Deny list for branches (section <tt class="docutils literal">acl.deny.branches</tt>)</li> |
| 46 |
<li>Allow list for branches (section <tt class="docutils literal">acl.allow.branches</tt>)</li> |
| 47 |
<li>Deny list for paths (section <tt class="docutils literal">acl.deny</tt>)</li> |
| 48 |
<li>Allow list for paths (section <tt class="docutils literal">acl.allow</tt>)</li> |
| 49 |
</ol> |
| 50 |
<p>The allow and deny sections take key-value pairs.</p> |
| 51 |
<div class="section" id="branch-based-access-control"> |
| 52 |
<h2><a class="toc-backref" href="#contents">Branch-based Access Control</a></h2> |
| 53 |
<p>Use the <tt class="docutils literal">acl.deny.branches</tt> and <tt class="docutils literal">acl.allow.branches</tt> sections to |
| 54 |
have branch-based access control. Keys in these sections can be |
| 55 |
either:</p> |
| 56 |
<ul class="simple"> |
| 57 |
<li>a branch name, or</li> |
| 58 |
<li>an asterisk, to match any branch;</li> |
| 59 |
</ul> |
| 60 |
<p>The corresponding values can be either:</p> |
| 61 |
<ul class="simple"> |
| 62 |
<li>a comma-separated list containing users and groups, or</li> |
| 63 |
<li>an asterisk, to match anyone;</li> |
| 64 |
</ul> |
| 65 |
<p>You can add the "!" prefix to a user or group name to invert the sense |
| 66 |
of the match.</p> |
| 67 |
</div> |
| 68 |
<div class="section" id="path-based-access-control"> |
| 69 |
<h2><a class="toc-backref" href="#contents">Path-based Access Control</a></h2> |
| 70 |
<p>Use the <tt class="docutils literal">acl.deny</tt> and <tt class="docutils literal">acl.allow</tt> sections to have path-based |
| 71 |
access control. Keys in these sections accept a subtree pattern (with |
| 72 |
a glob syntax by default). The corresponding values follow the same |
| 73 |
syntax as the other sections above.</p> |
| 74 |
</div> |
| 75 |
<div class="section" id="bookmark-based-access-control"> |
| 76 |
<h2><a class="toc-backref" href="#contents">Bookmark-based Access Control</a></h2> |
| 77 |
<p>Use the <tt class="docutils literal">acl.deny.bookmarks</tt> and <tt class="docutils literal">acl.allow.bookmarks</tt> sections to |
| 78 |
have bookmark-based access control. Keys in these sections can be |
| 79 |
either:</p> |
| 80 |
<ul class="simple"> |
| 81 |
<li>a bookmark name, or</li> |
| 82 |
<li>an asterisk, to match any bookmark;</li> |
| 83 |
</ul> |
| 84 |
<p>The corresponding values can be either:</p> |
| 85 |
<ul class="simple"> |
| 86 |
<li>a comma-separated list containing users and groups, or</li> |
| 87 |
<li>an asterisk, to match anyone;</li> |
| 88 |
</ul> |
| 89 |
<p>You can add the "!" prefix to a user or group name to invert the sense |
| 90 |
of the match.</p> |
| 91 |
<p>Note: for interactions between clients and servers using Mercurial 3.6+ |
| 92 |
a rejection will generally reject the entire push, for interactions |
| 93 |
involving older clients, the commit transactions will already be accepted, |
| 94 |
and only the bookmark movement will be rejected.</p> |
| 95 |
</div> |
| 96 |
<div class="section" id="groups"> |
| 97 |
<h2><a class="toc-backref" href="#contents">Groups</a></h2> |
| 98 |
<p>Group names must be prefixed with an <tt class="docutils literal">@</tt> symbol. Specifying a group |
| 99 |
name has the same effect as specifying all the users in that group.</p> |
| 100 |
<p>You can define group members in the <tt class="docutils literal">acl.groups</tt> section. |
| 101 |
If a group name is not defined there, and Mercurial is running under |
| 102 |
a Unix-like system, the list of users will be taken from the OS. |
| 103 |
Otherwise, an exception will be raised.</p> |
| 104 |
</div> |
| 105 |
<div class="section" id="example-configuration"> |
| 106 |
<h2><a class="toc-backref" href="#contents">Example Configuration</a></h2> |
| 107 |
<pre class="literal-block"> |
| 108 |
[hooks] |
| 109 |
|
| 110 |
# Use this if you want to check access restrictions at commit time |
| 111 |
pretxncommit.acl = python:hgext.acl.hook |
| 112 |
|
| 113 |
# Use this if you want to check access restrictions for pull, push, |
| 114 |
# bundle and serve. |
| 115 |
pretxnchangegroup.acl = python:hgext.acl.hook |
| 116 |
|
| 117 |
[acl] |
| 118 |
# Allow or deny access for incoming changes only if their source is |
| 119 |
# listed here, let them pass otherwise. Source is "serve" for all |
| 120 |
# remote access (http or ssh), "push", "pull" or "bundle" when the |
| 121 |
# related commands are run locally. |
| 122 |
# Default: serve |
| 123 |
sources = serve |
| 124 |
|
| 125 |
[acl.deny.branches] |
| 126 |
|
| 127 |
# Everyone is denied to the frozen branch: |
| 128 |
frozen-branch = * |
| 129 |
|
| 130 |
# A bad user is denied on all branches: |
| 131 |
* = bad-user |
| 132 |
|
| 133 |
[acl.allow.branches] |
| 134 |
|
| 135 |
# A few users are allowed on branch-a: |
| 136 |
branch-a = user-1, user-2, user-3 |
| 137 |
|
| 138 |
# Only one user is allowed on branch-b: |
| 139 |
branch-b = user-1 |
| 140 |
|
| 141 |
# The super user is allowed on any branch: |
| 142 |
* = super-user |
| 143 |
|
| 144 |
# Everyone is allowed on branch-for-tests: |
| 145 |
branch-for-tests = * |
| 146 |
|
| 147 |
[acl.deny] |
| 148 |
# This list is checked first. If a match is found, acl.allow is not |
| 149 |
# checked. All users are granted access if acl.deny is not present. |
| 150 |
# Format for both lists: glob pattern = user, ..., @group, ... |
| 151 |
|
| 152 |
# To match everyone, use an asterisk for the user: |
| 153 |
# my/glob/pattern = * |
| 154 |
|
| 155 |
# user6 will not have write access to any file: |
| 156 |
** = user6 |
| 157 |
|
| 158 |
# Group "hg-denied" will not have write access to any file: |
| 159 |
** = @hg-denied |
| 160 |
|
| 161 |
# Nobody will be able to change "DONT-TOUCH-THIS.txt", despite |
| 162 |
# everyone being able to change all other files. See below. |
| 163 |
src/main/resources/DONT-TOUCH-THIS.txt = * |
| 164 |
|
| 165 |
[acl.allow] |
| 166 |
# if acl.allow is not present, all users are allowed by default |
| 167 |
# empty acl.allow = no users allowed |
| 168 |
|
| 169 |
# User "doc_writer" has write access to any file under the "docs" |
| 170 |
# folder: |
| 171 |
docs/** = doc_writer |
| 172 |
|
| 173 |
# User "jack" and group "designers" have write access to any file |
| 174 |
# under the "images" folder: |
| 175 |
images/** = jack, @designers |
| 176 |
|
| 177 |
# Everyone (except for "user6" and "@hg-denied" - see acl.deny above) |
| 178 |
# will have write access to any file under the "resources" folder |
| 179 |
# (except for 1 file. See acl.deny): |
| 180 |
src/main/resources/** = * |
| 181 |
|
| 182 |
.hgtags = release_engineer |
| 183 |
</pre> |
| 184 |
<div class="section" id="examples-using-the-prefix"> |
| 185 |
<h3>Examples using the "!" prefix</h3> |
| 186 |
<p>Suppose there's a branch that only a given user (or group) should be able to |
| 187 |
push to, and you don't want to restrict access to any other branch that may |
| 188 |
be created.</p> |
| 189 |
<p>The "!" prefix allows you to prevent anyone except a given user or group to |
| 190 |
push changesets in a given branch or path.</p> |
| 191 |
<p>In the examples below, we will: |
| 192 |
1) Deny access to branch "ring" to anyone but user "gollum" |
| 193 |
2) Deny access to branch "lake" to anyone but members of the group "hobbit" |
| 194 |
3) Deny access to a file to anyone but user "gollum"</p> |
| 195 |
<pre class="literal-block"> |
| 196 |
[acl.allow.branches] |
| 197 |
# Empty |
| 198 |
|
| 199 |
[acl.deny.branches] |
| 200 |
|
| 201 |
# 1) only 'gollum' can commit to branch 'ring'; |
| 202 |
# 'gollum' and anyone else can still commit to any other branch. |
| 203 |
ring = !gollum |
| 204 |
|
| 205 |
# 2) only members of the group 'hobbit' can commit to branch 'lake'; |
| 206 |
# 'hobbit' members and anyone else can still commit to any other branch. |
| 207 |
lake = !@hobbit |
| 208 |
|
| 209 |
# You can also deny access based on file paths: |
| 210 |
|
| 211 |
[acl.allow] |
| 212 |
# Empty |
| 213 |
|
| 214 |
[acl.deny] |
| 215 |
# 3) only 'gollum' can change the file below; |
| 216 |
# 'gollum' and anyone else can still change any other file. |
| 217 |
/misty/mountains/cave/ring = !gollum |
| 218 |
</pre> |
| 219 |
</div> |
| 220 |
</div> |
| 221 |
</div> |
| 222 |
</div> |
| 223 |
</body> |
| 224 |
</html> |