TracFineGrainedPermissions

Version 1 (Anonymous, 03/15/2008 04:41 PM)

1 1
= Fine grained permissions =
2 1
3 1
Before Trac 0.11, it was only possible to define fine-grained permissions checks on the repository browser sub-system.
4 1
5 1
Since 0.11, 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 1
7 1
== Permission Policies ==
8 1
9 1
=== !AuthzPolicy ===
10 1
11 1
An example policy based on an Authz-style system has been added. See
12 1
[source:trunk/sample-plugins/permissions/authz_policy.py] for details. (See also [source:trunk/sample-plugins/permissions] for more samples.)
13 1
14 1
 - Install [http://www.voidspace.org.uk/python/configobj.html ConfigObj] (required).
15 1
 - Copy this file in your plugins directory
16 1
 - Plonk a [http://swapoff.org/files/authzpolicy.conf authzpolicy.conf] file somewhere. FIXME: what does ''plonk'' mean? ;-)
17 1
 - Update your `trac.ini`:
18 1
{{{
19 1
[trac]
20 1
...
21 1
permission_policies = AuthzPolicy, DefaultPermissionPolicy
22 1
23 1
[authz_policy]
24 1
authz_file = /some/trac/env/conf/authzpolicy.conf
25 1
26 1
[components]
27 1
...
28 1
authz_policy = enabled
29 1
}}}
30 1
31 1
Note that the order in which permission policies are specified is quite critical, 
32 1
as policies will be examined in the sequence provided.
33 1
34 1
A policy will return either `True`, `False` or `None` for a given permission check.
35 1
Only if the return value is `None` will the ''next'' permission policy be consulted.
36 1
If no policy explicitly grants the permission, the final result will be `False` 
37 1
(i.e. no permission).
38 1
39 1
For example, if the `authz_file` contains:
40 1
{{{
41 1
[wiki:WikiStart@*]
42 1
* = VIEW
43 1
44 1
[wiki:PrivatePage@*]
45 1
john = VIEW
46 1
* =
47 1
}}}
48 1
and the default permissions are set like this:
49 1
{{{
50 1
john           WIKI_VIEW
51 1
jack           WIKI_VIEW
52 1
# anonymous has no WIKI_VIEW
53 1
}}}
54 1
55 1
Then: 
56 1
 - All versions of WikiStart will be viewable by everybody (including anonymous)
57 1
 - !PrivatePage will be viewable only by john
58 1
 - other pages will be viewable only by john and jack
59 1
60 1
61 1
=== mod_authz_svn-like permission policy ===
62 1
63 1
At the time of this writing, the old fine grained permissions system from Trac 0.10 and before used for restricting access to the repository has not yet been converted to a permission policy component, but from the user point of view, this makes little if no differences.
64 1
65 1
That kind of fine-grained permission control needs a definition file, which is the one used by Subversion's mod_authz_svn. 
66 1
More information about this file format and about its usage in Subversion is available in the [http://svnbook.red-bean.com/svnbook/book.html#svn-ch-6-sect-4.4.2 Subversion Book (Per-Directory Access Control)].
67 1
68 1
Example:
69 1
{{{
70 1
[/]
71 1
* = r
72 1
73 1
[/branches/calc/bug-142]
74 1
harry = rw
75 1
sally = r
76 1
77 1
[/branches/calc/bug-142/secret]
78 1
harry =
79 1
}}}
80 1
81 1
 * '''/''' = ''Everyone has read access by default''
82 1
 * '''/branches/calc/bug-142''' = ''harry has read/write access, sally read only''
83 1
 * '''/branches/calc/bug-142/secret''' = ''harry has no access, sally has read access (inherited as a sub folder permission)''
84 1
85 1
==== Trac Configuration ====
86 1
87 1
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 specified the permissions will not be used.
88 1
89 1
{{{
90 1
[trac]
91 1
authz_file = /path/to/svnaccessfile
92 1
}}}
93 1
94 1
if you want to support the use of the `[`''modulename''`:/`''some''`/`''path''`]` syntax within the `authz_file`, add 
95 1
96 1
{{{
97 1
authz_module_name = modulename
98 1
}}}
99 1
100 1
where ''modulename'' refers to the same repository indicated by the `repository_dir` entry in the `[trac]` section.
101 1
102 1
'''Note:''' Usernames inside the Authz file __must__ be the same as those used inside trac. 
103 1
104 1
==== Subversion Configuration ====
105 1
106 1
The same access file is typically applied to the corresponding Subversion repository using an Apache directive like this:
107 1
{{{
108 1
<Location /repos>
109 1
  DAV svn
110 1
  SVNParentPath /usr/local/svn
111 1
112 1
  # our access control policy
113 1
  AuthzSVNAccessFile /path/to/svnaccessfile
114 1
</Location>
115 1
}}}
116 1
117 1
For information about how to restrict access to entire projects in a multiple project environment see [trac:wiki:TracMultipleProjectsSVNAccess]
118 1
119 1
----
120 1
See also: TracPermissions
Redmine Appliance - Powered by TurnKey Linux