Proyecto

General

Perfil

TracFineGrainedPermissions » Histórico » Versión 2

Anónimo, 2009-01-21 09:53

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