Changes between Version 61 and Version 62 of TracFineGrainedPermissions
- Timestamp:
- Jan 3, 2015, 1:13:46 PM (9 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
TracFineGrainedPermissions
v61 v62 3 3 [[TracGuideToc]] 4 4 5 There's a general mechanism in place that allows custom **permission policy plugins** to grant or deny any action on any kind of Trac resources, even at the level of specific versions of such resources. 6 7 That mechanism is `authz_policy`, which is an optional module (in `tracopt.perm.authz_policy.*`), so it's installed by default and can simply be activated via the //Plugins// panel in the Trac administration module. 8 5 There is a general mechanism in place that allows custom **permission policy plugins** to grant or deny any action on any kind of Trac resource, even at the level of specific versions of such resources. 6 7 That mechanism is `authz_policy`, which is an optional module in `tracopt.perm.authz_policy.*`, so it is installed by default. It can be activated via the //Plugins// panel in the Trac administration module. 9 8 10 9 == Permission Policies == 11 10 12 A great diversity of permission policies can be implemented ,and Trac comes with a few examples.11 A great diversity of permission policies can be implemented and Trac comes with a few examples. 13 12 14 13 Which policies are currently active is determined by a configuration setting in TracIni: 15 e.g. 14 16 15 {{{#!ini 17 16 [trac] … … 20 19 This lists the [#AuthzSourcePolicy] described below as the first policy, followed by the !DefaultPermissionPolicy which checks for the traditional coarse grained style permissions described in TracPermissions, and the !LegacyAttachmentPolicy which knows how to use the coarse grained permissions for checking the permissions available on attachments. 21 20 22 Among the possibleoptional choices, there is [#AuthzPolicy], a very generic permission policy, based on an Authz-style system. See21 Among the optional choices, there is [#AuthzPolicy], a very generic permission policy, based on an Authz-style system. See 23 22 [trac:source:branches/1.0-stable/tracopt/perm/authz_policy.py authz_policy.py] for details. 24 23 … … 26 25 27 26 See also [trac:source:branches/1.0-stable/sample-plugins/permissions sample-plugins/permissions] for more examples. 28 29 27 30 28 === !AuthzPolicy === … … 33 31 * Put a [http://swapoff.org/files/authzpolicy.conf authzpolicy.conf] file somewhere, preferably on a secured location on the server, not readable for others than the webuser. If the file contains non-ASCII characters, the UTF-8 encoding should be used. 34 32 * Update your `trac.ini`: 35 1. modify the [TracIni#trac-section permission_policies] entry in the `[trac]` section 33 1. modify the [TracIni#trac-section permission_policies] entry in the `[trac]` section: 36 34 {{{#!ini 37 35 [trac] … … 39 37 permission_policies = AuthzPolicy, DefaultPermissionPolicy, LegacyAttachmentPolicy 40 38 }}} 41 1. add a new `[authz_policy]` section 39 1. add a new `[authz_policy]` section: 42 40 {{{#!ini 43 41 [authz_policy] 44 42 authz_file = /some/trac/env/conf/authzpolicy.conf 45 43 }}} 46 1. enable the plugin through [/admin/general/plugin WebAdmin] or by editing the `[components]` section 44 1. enable the plugin through [/admin/general/plugin WebAdmin] or by editing the `[components]` section: 47 45 {{{#!ini 48 46 [components] … … 50 48 }}} 51 49 52 53 50 ==== Usage Notes ==== 54 Note that the order in which permission policies are specified is quite critical, 55 as policies will be examined in the sequence provided.51 52 Note the order in which permission policies are specified: policies are implemented in the sequence provided and therefore may override earlier policy specifications. 56 53 57 54 A policy will return either `True`, `False` or `None` for a given permission check. `True` is returned if the policy explicitly grants the permission. `False` is returned if the policy explicitly denies the permission. `None` is returned if the policy is unable to either grant or deny the permission. 58 55 59 NOTE: Only if the return value is `None` will the ''next'' permission policy be consulted. 60 If none of the policies explicitly grants the permission, the final result will be `False` 61 (i.e. permission denied). 56 NOTE: Only if the return value is `None` will the ''next'' permission policy be consulted. If none of the policies explicitly grants the permission, the final result will be `False`, i.e. permission denied. 62 57 63 58 The `authzpolicy.conf` file is a `.ini` style configuration file: … … 68 63 * = 69 64 }}} 70 * Each section of the config is a glob pattern used to match against a Trac resource 71 descriptor. These descriptors are in the form: 65 * Each section of the config is a glob pattern used to match against a Trac resource descriptor. These descriptors are in the form: 72 66 {{{ 73 67 <realm>:<id>@<version>[/<realm>:<id>@<version> ...] 74 68 }}} 75 Resources are ordered left to right, from parent to child. If any 76 component is inapplicable, `*` is substituted. If the version pattern is 77 not specified explicitely, all versions (`@*`) is added implicitly 78 79 Example: Match the WikiStart page 69 70 Resources are ordered left to right, from parent to child. If any component is inapplicable, `*` is substituted. If the version pattern is not specified explicitly, all versions (`@*`) is added implicitly. Example: Match the WikiStart page: 80 71 {{{#!ini 81 72 [wiki:*] … … 85 76 }}} 86 77 87 Example: Match the attachment `wiki:WikiStart@117/attachment:FOO.JPG@*` 88 on WikiStart 78 Example: Match the attachment `wiki:WikiStart@117/attachment:FOO.JPG@*` on WikiStart: 89 79 {{{#!ini 90 80 [wiki:*] … … 95 85 }}} 96 86 97 * Sections are checked against the current Trac resource descriptor '''IN ORDER''' of 98 appearance in the configuration file. '''ORDER IS CRITICAL'''. 99 100 * Once a section matches, the current username is matched against the keys 101 (usernames) of the section, '''IN ORDER'''. 87 * Sections are checked against the current Trac resource descriptor '''IN ORDER''' of appearance in the configuration file. '''ORDER IS CRITICAL'''. 88 89 * Once a section matches, the current username is matched against the keys (usernames) of the section, '''IN ORDER'''. 102 90 * If a key (username) is prefixed with a `@`, it is treated as a group. 103 * If a value (permission) is prefixed with a `!`, the permission is 104 denied rather than granted. 105 106 The username will match any of 'anonymous', 'authenticated', <username> or '*', using normal Trac permission rules. || '''Note:''' Other groups which are created by user (e.g. by 'adding subjects to groups' on web interface page //Admin / Permissions//) cannot be used. See [trac:ticket:5648 #5648] for details about this missing feature || 91 * If a value (permission) is prefixed with a `!`, the permission is denied rather than granted. 92 93 The username will match any of 'anonymous', 'authenticated', <username> or '*', using normal Trac permission rules. || '''Note:''' Other groups which are created by user (e.g. by 'adding subjects to groups' on web interface page //Admin / Permissions//) cannot be used. See [trac:ticket:5648 #5648] for details about this missing feature. || 107 94 108 95 For example, if the `authz_file` contains: … … 123 110 124 111 Then: 125 * All versions of WikiStart will be viewable by everybody (including anonymous)112 * All versions of WikiStart will be viewable by everybody, including anonymous 126 113 * !PrivatePage will be viewable only by john 127 114 * other pages will be viewable only by john and jack … … 166 153 }}} 167 154 168 Very fine grainrepository access:155 Very granular repository access: 169 156 {{{#!ini 170 157 # John has BROWSER_VIEW and FILE_VIEW access to trunk/src/some/location/ only … … 172 159 john = BROWSER_VIEW, FILE_VIEW 173 160 174 175 161 # John has BROWSER_VIEW and FILE_VIEW access to only revision 1 of all files at trunk/src/some/location only 176 162 [repository:test_repo@*/source:trunk/src/some/location/*@1] 177 163 john = BROWSER_VIEW, FILE_VIEW 178 164 179 180 165 # John has BROWSER_VIEW and FILE_VIEW access to all revisions of 'somefile' at trunk/src/some/location only 181 166 [repository:test_repo@*/source:trunk/src/some/location/somefile@*] 182 167 john = BROWSER_VIEW, FILE_VIEW 183 168 184 185 169 # John has BROWSER_VIEW and FILE_VIEW access to only revision 1 of 'somefile' at trunk/src/some/location only 186 170 [repository:test_repo@*/source:trunk/src/some/location/somefile@1] … … 190 174 Note: In order for Timeline to work/visible for John, we must add CHANGESET_VIEW to the above permission list. 191 175 192 193 176 ==== Missing Features ==== 194 Although possible with the !DefaultPermissionPolicy handling (see Admin panel), fine-grained permissions still miss those grouping features (see [trac:ticket:9573 #9573], [trac:ticket:5648 #5648]). Patches are partially available, see forgotten authz_policy.2.patch part of [trac:ticket:6680 #6680]).177 Although possible with the !DefaultPermissionPolicy handling (see Admin panel), fine-grained permissions still miss those grouping features (see [trac:ticket:9573 #9573], [trac:ticket:5648 #5648]). Patches are partially available, see authz_policy.2.patch, part of [trac:ticket:6680 #6680]. 195 178 196 179 You cannot do the following: … … 203 186 }}} 204 187 205 Permission groups are not supported either . You cannot do the following:188 Permission groups are not supported either, so you cannot do the following: 206 189 {{{#!ini 207 190 [groups] … … 216 199 === !AuthzSourcePolicy (mod_authz_svn-like permission policy) === #AuthzSourcePolicy 217 200 218 At the time of this writing, the old fine grained permissions system from Trac 0.11 and before used for restricting access to the repository has been converted to a permission policy component, but from the user point of view, this makes little if nodifference.219 220 That kind of fine-grainedpermission control needs a definition file, which is the one used by Subversion's mod_authz_svn.221 More information about this file format and about its usage in Subversion is available in the 201 At the time of this writing, the old granular permissions system from Trac 0.11 and before used for restricting access to the repository has been converted to a permission policy component. But from the user's point of view, this makes little if any difference. 202 203 That kind of granular permission control needs a definition file, which is the one used by Subversion's mod_authz_svn. 204 More information about this file format and about its usage in Subversion is available in the [http://svnbook.red-bean.com/en/1.5/svn.serverconfig.pathbasedauthz.html Path-Based Authorization] section in the Server Configuration chapter of the svn book. 222 205 223 206 Example: … … 240 223 ==== Trac Configuration ==== 241 224 242 To activate fine grained permissions you __must__ specify the {{{authz_file}}} option in the {{{[trac]}}} section of trac.ini. If this option is set to null or not specifiedthe permissions will not be used.225 To activate granular permissions you __must__ specify the {{{authz_file}}} option in the {{{[trac]}}} section of trac.ini. If this option is set to null or not specified, the permissions will not be used. 243 226 244 227 {{{#!ini … … 247 230 }}} 248 231 249 If you want to support the use of the `[`''modulename''`:/`''some''`/`''path''`]` syntax within the `authz_file`, add 232 If you want to support the use of the `[`''modulename''`:/`''some''`/`''path''`]` syntax within the `authz_file`, add: 250 233 251 234 {{{#!ini … … 253 236 }}} 254 237 255 where ''modulename'' refers to the same repository indicated by the `repository_dir` entry in the `[trac]` section. As an example, if the `repository_dir` entry in the `[trac]` section is {{{/srv/active/svn/ blahblah}}}, that would yield the following:238 where ''modulename'' refers to the same repository indicated by the `repository_dir` entry in the `[trac]` section. As an example, if the `repository_dir` entry in the `[trac]` section is {{{/srv/active/svn/somemodule}}}, that would yield the following: 256 239 257 240 {{{ #!ini 258 241 [trac] 259 242 authz_file = /path/to/svnaccessfile 260 authz_module_name = blahblah243 authz_module_name = somemodule 261 244 ... 262 repository_dir = /srv/active/svn/ blahblah263 }}} 264 265 where the svn access file, {{{/path/to/svnaccessfile}}}, contains entries such as {{{[ blahblah:/some/path]}}}.245 repository_dir = /srv/active/svn/somemodule 246 }}} 247 248 where the svn access file, {{{/path/to/svnaccessfile}}}, contains entries such as {{{[somemodule:/some/path]}}}. 266 249 267 250 '''Note:''' Usernames inside the Authz file __must__ be the same as those used inside trac. … … 287 270 }}} 288 271 289 For information about how to restrict access to entire projects in a multiple project environment see [trac:wiki:TracMultipleProjectsSVNAccess] 272 For information about how to restrict access to entire projects in a multiple project environment see [trac:wiki:TracMultipleProjectsSVNAccess]. 290 273 291 274 == Debugging permissions … … 298 281 }}} 299 282 300 And watch:283 Display the trac.log to understand what checks are being performed: 301 284 {{{#!sh 302 285 tail -n 0 -f log/trac.log | egrep '\[perm\]|\[authz_policy\]' 303 286 }}} 304 287 305 to understand what checks are being performed. See the sourced documentation of the plugin for more info. 306 288 See the sourced documentation of the plugin for more info. 307 289 308 290 ----