none
[openafs-wiki.git] / TWiki / TWikiAccessControl.mdwn
1 # <a name="TWiki Access Control"></a> TWiki Access Control
2
3 _Restricting read and write access to topics and webs, by Users and groups_
4
5 TWiki Access Control allows you restrict access to single topics and entire webs, by individual user and by user Groups. Access control, combined with [[TWikiUserAuthentication]], lets you easily create and manage an extremely flexible, fine-grained privilege system.
6
7 **_%T% Tip:_** TWiki:TWiki.TWikiAccessControlSupplement on TWiki.org has additional documentation on access control.
8
9 <div>
10   <ul>
11     <li><a href="#TWiki Access Control"> TWiki Access Control</a><ul>
12         <li><a href="#An Important Control Considerati"> An Important Control Consideration</a></li>
13         <li><a href="#Permissions settings of the webs"> Permissions settings of the webs on this TWiki site</a></li>
14         <li><a href="#Authentication vs. Access Contro"> Authentication vs. Access Control</a></li>
15         <li><a href="#Users and Groups"> Users and Groups</a><ul>
16             <li><a href="#Managing Users"> Managing Users</a></li>
17             <li><a href="#Managing Groups"> Managing Groups</a></li>
18             <li><a href="#The Super Admin Group"> The Super Admin Group</a></li>
19           </ul>
20         </li>
21         <li><a href="#Restricting Access"> Restricting Access</a><ul>
22             <li><a href="#Controlling access to a Web"> Controlling access to a Web</a></li>
23             <li><a href="#Controlling access to a Topic"> Controlling access to a Topic</a></li>
24             <li><a href="#Controlling access to Attachment"> Controlling access to Attachments</a></li>
25             <li><a href="#Controlling who can manage top-l"> Controlling who can manage top-level webs</a></li>
26             <li><a href="#How TWiki evaluates ALLOW/DENY s"> How TWiki evaluates ALLOW/DENY settings</a></li>
27           </ul>
28         </li>
29         <li><a href="#Access control and INCLUDE"> Access control and INCLUDE</a></li>
30         <li><a href="#Access Control quick recipes"> Access Control quick recipes</a><ul>
31             <li><a href="#Obfuscating Webs"> Obfuscating Webs</a></li>
32             <li><a href="#Restrict Access to Whole TWiki S"> Restrict Access to Whole TWiki Site</a></li>
33             <li><a href="#Authenticate all Webs and Restri"> Authenticate all Webs and Restrict Selected Webs</a></li>
34             <li><a href="#Authenticate and Restrict Select"> Authenticate and Restrict Selected Webs Only</a></li>
35             <li><a href="#Hide Control Settings"> Hide Control Settings</a></li>
36           </ul>
37         </li>
38       </ul>
39     </li>
40   </ul>
41 </div>
42
43 <a name="ImportantConsideration"></a>
44
45 ## <a name="An Important Control Considerati"></a> An Important Control Consideration
46
47 Open, freeform editing is the essence of [[WikiCulture]] - what makes TWiki different and often more effective than other collaboration tools. For that reason, it is strongly recommended that decisions to restrict read or write access to a web or a topic are made with great care - the more restrictions, the less Wiki in the mix. Experience shows that _unrestricted write access_ works very well because:
48
49 - **Peer influence** is enough to ensure that only relevant content is posted.
50 - **Peer editing** - the ability for anyone to rearrange all content on a page - keeps topics focused.
51 - In TWiki, content is transparently preserved under **revision control**:
52   - Edits can be undone by the administrator (per default a member of %USERSWEB%.TWikiAdminGroup; see [[#ManagingGroups|Main/WebHome#ManagingGroups]]).
53   - Users are encouraged to edit and refactor (condense a long topic), since there's a safety net.
54
55 As a **collaboration guideline**:
56
57 - Create broad-based Groups (for more and varied input), and...
58 - Avoid creating view-only Users (if you can read it, you should be able to contribute to it).
59
60 ## <a name="Permissions settings of the webs"></a> Permissions settings of the webs on this TWiki site
61
62 **_Note:_** Above table comes from [[SitePermissions]]
63
64 ## <a name="Authentication vs. Access Contro"></a> Authentication vs. Access Control
65
66 **Authentication:** Identifies who a user is based on a login procedure. See [[TWikiUserAuthentication]].
67
68 **Access control:** Restrict access to content based on users and groups once a user is identified.
69
70 <a name="UsersAndGroups"></a>
71
72 ## <a name="Users and Groups"></a> Users and Groups
73
74 Access control is based on the familiar concept of Users and Groups. Users are defined by their [[WikiNames]]. They can then be organized in unlimited combinations by inclusion in one or more user Groups. For convenience, Groups can also be included in other Groups.
75
76 <a name="ManagingUsers"></a>
77
78 ### <a name="Managing Users"></a> Managing Users
79
80 A user can create an account in [[TWikiRegistration]]. The following actions are performed:
81
82 - [[WikiName]] and encrypted password are recorded using the password manager if authentication is enabled.
83 - A confirmation e-mail is sent to the user.
84 - A user home page with the [[WikiName]] of the user is created in the %USERSWEB% web.
85 - The user is added to the %USERSWEB%.TWikiUsers topic.
86
87 The default visitor name is %USERSWEB%.TWikiGuest. This is the non-authenticated user.
88
89 <a name="ManagingGroups"></a>
90
91 ### <a name="Managing Groups"></a> Managing Groups
92
93 The following describes the standard TWiki support for groups. Your local TWiki may have an alternate group mapping manager installed. Check with your TWiki administrator if you are in doubt.
94
95 Groups are defined by group topics located in the <code>**%USERSWEB%**</code> web. To create a new group, visit %USERSWEB%.TWikiGroups and enter the name of the new group ending in <code>**Group**</code> into the "new group" form field. This will create a new group topic with two important settings:
96
97 - <code>**Set GROUP = &lt; list of Users and/or Groups &gt;**</code>
98 - <code>**Set ALLOWTOPICCHANGE = &lt; list of Users and/or Groups &gt;**</code>
99
100 The GROUP setting is a comma-separated list of users and/or other groups. Example:
101
102 - <code>**Set GROUP = %USERSWEB%.SomeUser, %USERSWEB%.OtherUser, %USERSWEB%.SomeGroup**</code>
103
104 The ALLOWTOPICCHANGE setting defines who is allowed to change the group topic; it is a comma delimited list of users and groups. You typically want to restrict that to the members of the group itself, so it should contain the name of the topic. This prevents users not in the group from editing the topic to give themselves or others access. For example, for the KasabianGroup topic write:
105
106 - <code>**Set ALLOWTOPICCHANGE = %USERSWEB%.KasabianGroup**</code>
107
108 **_%X% Note:_** TWiki has strict formatting rules. Make sure you have three spaces, an asterisk, and an extra space in front of any access control rule.
109
110 <a name="SuperAdminGroup"></a>
111
112 ### <a name="The Super Admin Group"></a> The Super Admin Group
113
114 A number of TWiki functions (for example, renaming webs) are only available to administrators. Administrators are simply users who belong to the **SuperAdminGroup**. This is a standard user group, the name of which is defined by \{SuperAdminGroup\} setting in [configure](http://www.dementia.org/twiki/configure). The default name of this group is the `TWikiAdminGroup`. The system administrator may have chosen a different name for this group if your local TWiki uses an alternate group mapping manager but for simplicity we will use the default name TWikiAdminGroup in the rest of this topic.
115
116 You can create new administrators simply by adding them to the %USERSWEB%.TWikiAdminGroup topic. For example,
117
118 - <code>**Set GROUP = %USERSWEB%.ElizabethWindsor, %USERSWEB%.TonyBlair**</code>
119
120 A member of the Super Admin Group has unrestricted access throughout the TWiki, so only trusted staff should be added to this group.
121
122 <a name="RestrictingAccess"></a>
123
124 ## <a name="Restricting Access"></a> Restricting Access
125
126 You can define who is allowed to read or write to a web or a topic. Note that some plugins may not respect access permissions.
127
128 - Restricting VIEW blocks viewing and searching of content. When you restric VIEW to a topic or web, this also restricts [[INCLUDE|Main/VarINCLUDE]] and [[Formatted SEARCH|Main/FormattedSearch]] from showing the content of the topics.
129 - Restricting CHANGE blocks creating new topics, changing topics or attaching files.
130 - Restricting RENAME prevents renaming of topics within a web.
131
132 Note that there is an important distinction between CHANGE access and RENAME access. A user can CHANGE a topic, but thanks to version control their changes cannot be lost (the history of the topic before the change is recorded). However if a topic or web is renamed, that history may be lost. Typically a site will only give RENAME access to administrators and content owners.
133
134 <a name="ControllingWeb"></a>
135
136 ### <a name="Controlling access to a Web"></a> Controlling access to a Web
137
138 You can define restrictions on who is allowed to view a %WIKITOOLNAME% web. You can restrict access to certain webs to selected Users and Groups, by:
139
140 - **authenticating all webs and restricting selected webs:** Topic access in all webs is authenticated, and selected webs have restricted access.
141 - **authenticating and restricting selected webs only:** Provide unrestricted viewing access to open webs, with authentication and restriction only on selected webs.
142
143 - You can define these settings in the [[WebPreferences]] topic, preferable towards the end of the topic:
144   - <code>**Set DENYWEBVIEW = &lt; comma-delimited list of Users and Groups &gt;**</code>
145   - <code>**Set ALLOWWEBVIEW = &lt; comma-delimited list of Users and Groups &gt;**</code>
146   - <code>**Set DENYWEBCHANGE = &lt; comma-delimited list of Users and Groups &gt;**</code>
147   - <code>**Set ALLOWWEBCHANGE = &lt; comma-delimited list of Users and Groups &gt;**</code>
148   - <code>**Set DENYWEBRENAME = &lt; comma-delimited list of Users and Groups &gt;**</code>
149   - <code>**Set ALLOWWEBRENAME = &lt; comma-delimited list of Users and Groups &gt;**</code>
150
151 If your site allows hierarchical webs, then access to sub-webs is determined from the access controls of the parent web, plus the access controls in the sub-web. So, if the parent web has <code>**ALLOWWEBVIEW**</code> set, this will also apply to the subweb. Also note that you will need to ensure that the parent web's <code>**FINALPREFERENCES**</code> does not include the access control settings listed above. Otherwise you will not be able override the parent web's access control settings in sub-webs.
152
153 Creation and renaming of sub-webs is controlled by the WEBCHANGE setting on the parent web (or ROOTCHANGE for [[root webs|Main/WebHome#RootWebs]]). Renaming is additionally restricted by the setting of WEBRENAME in the web itself.
154
155 **_Note:_** If you restrict access to the %USERSWEB%, make sure to add the `TWikiRegistrationAgent` so that users can register. Example:
156
157 - - <code>**Set ALLOWWEBCHANGE = TWikiAdminGroup, TWikiRegistrationAgent**</code>
158
159 **_Note:_** For Web level access rights Setting any of these settings to an empty value has the same effect as not setting them at all. Please note that the documentation of TWiki 4.0 and earlier versions of TWiki 4.1 did not reflect the actual implementation, e.g. an empty ALLOWWEBVIEW does _not_ prevent anyone from viewing the web, and an an empty DENYWEBVIEW does _not_ allow all to view the web.
160
161 <a name="ControllingTopic"></a>
162
163 ### <a name="Controlling access to a Topic"></a> Controlling access to a Topic
164
165 - You can define these settings in any topic, preferable towards the end of the topic:
166   - <code>**Set DENYTOPICVIEW = &lt; comma-delimited list of Users and Groups &gt;**</code>
167   - <code>**Set ALLOWTOPICVIEW = &lt; comma-delimited list of Users and Groups &gt;**</code>
168   - <code>**Set DENYTOPICCHANGE = &lt; comma-delimited list of Users and Groups &gt;**</code>
169   - <code>**Set ALLOWTOPICCHANGE = &lt; comma-delimited list of Users and Groups &gt;**</code>
170   - <code>**Set DENYTOPICRENAME = &lt; comma-delimited list of Users and Groups &gt;**</code>
171   - <code>**Set ALLOWTOPICRENAME = &lt; comma-delimited list of Users and Groups &gt;**</code>
172
173 Remember when opening up access to specific topics within a restricted web that other topics in the web - for example, the [[WebLeftBar]] - may also be accessed when viewing the topics. The message you get when you are denied access should tell you what topic you were not permitted to access.
174
175 **Be careful** with empty values for any of these.
176
177 - <code>**Set ALLOWTOPICVIEW = **</code><br />This means the same as not setting it at all. (This was documented wrong in versions 4.0.X, 4.1.0 and 4.1.1)
178
179 - <code>**Set DENYTOPICVIEW = **</code><br />Since TWiki 4.0 this means _do not deny anyone the right to view this topic_. If DENYTOPICVIEW is set to an empty value anyone has access even if ALLOWTOPICVIEW or ALLOWWEBVIEW is defined. This allows to have very restrictive default access rights to an entire web and still allow individual topics to have more open access.
180
181 The same rules apply to ALLOWTOPICCHANGE/DENYTOPICCHANGE and APPLYTOPICRENAME/DENYTOPICRENAME. Setting ALLOWTOPICCHANGE or ALLOWTOPICRENAME to en empty value means the same as not defining it. Setting DENYTOPICCHANGE or DENYTOPICRENAME to an empty value means that anyone can edit or rename the topic.
182
183 %X% If the same setting is defined multiple times the last one overrides the previous. They are not OR'ed together.
184
185 %X% _The setting to an empty has caused confusion and great debate and it has been decided that the empty setting syntax will be replaced by something which is easier to understand in a later version of TWiki. A method to upgrade will be provided. Please read the release notes carefully when you upgrade._
186
187 See "How TWiki evaluates ALLOW/DENY settings" below for more on how ALLOW and DENY interacts.
188
189 <a name="ControllingAttachments"></a>
190
191 ### <a name="Controlling access to Attachment"></a> Controlling access to Attachments
192
193 Attachments are referred to directly, and are not normally indirected via TWiki scripts. This means that the above instructions for access control will _not_ apply to attachments. It is possible that someone may inadvertently publicise a URL that they expected to be access-controlled.
194
195 The easiest way to apply the same access control rules for attachments as apply to topics is to use the Apache `mod_rewrite` module, and configure your webserver to redirect accesses to attachments to the TWiki `viewfile` script. For example,
196
197         ScriptAlias /twiki/bin/ /filesystem/path/to/twiki/bin/
198         Alias /twiki/pub/       /filesystem/path/to/twiki/pub/
199
200         RewriteEngine on
201         RewriteCond %{REQUEST_URI} !^/+twiki/+pub/+TWiki/+.+
202         RewriteRule ^/+twiki/+pub/+([^/]+)/+((([^/]+)/+)+)(.+) /twiki/bin/viewfile/$1/$4?filename=$5 [L,PT]
203
204 That way all the controls that apply to the topic also apply to attachments to the topic. Other types of webserver have similar support.
205
206 **_Note:_** Images embedded in topics will load much slower since each image will be delivered by the `viewfile` script.
207
208 <a name="RootWebs"></a>
209
210 ### <a name="Controlling who can manage top-l"></a> Controlling who can manage top-level webs
211
212 Top level webs are a special case, because they don't have a parent web with a [[WebPreferences]]. So there has to be a special control just for the root level.
213
214 - You can define these settings in the %USERSWEB%.%TWIKIPREFSTOPIC% topic, preferable towards the end of the topic:
215   - <code>**Set DENYROOTCHANGE = &lt; comma-delimited list of Users and Groups &gt;**</code>
216   - <code>**Set ALLOWROOTCHANGE = &lt; comma-delimited list of Users and Groups &gt;**</code>
217
218 Note that you do **not** require `ROOTCHANGE` access to rename an existing top-level web. You just need `WEBCHANGE` in the web itself.
219
220 <a name="EvaluatingAllowDeny"></a>
221
222 ### <a name="How TWiki evaluates ALLOW/DENY s"></a> How TWiki evaluates ALLOW/DENY settings
223
224 When deciding whether to grant access, TWiki evaluates the following rules in order (read from the top of the list; if the logic arrives at **PERMITTED** or **DENIED** that applies immediately and no more rules are applied). You need to read the rules bearing in mind that VIEW, CHANGE and RENAME access may be granted/denied separately.
225
226 1. If the user is an [[administrator|Main/WebHome#SuperAdminGroup]]
227   - access is **PERMITTED**.
228 2. If DENYTOPIC is set to a list of wikinames
229   - people in the list will be **DENIED**.
230 3. If DENYTOPIC is set to _empty_ ( i.e. `Set DENYTOPIC =` )
231   - access is **PERMITTED** _i.e_ no-one is denied access to this topic.%BR% %X% **_Attention:_** Use this with caution. This is **_deprecated_** and will likely change in the next release.
232 4. If ALLOWTOPIC is set
233   1. people in the list are **PERMITTED**
234   2. everyone else is **DENIED**
235 5. If DENYWEB is set to a list of wikinames
236   - people in the list are **DENIED** access
237 6. If ALLOWWEB is set to a list of wikinames
238   - people in the list will be **PERMITTED**
239   - everyone else will be **DENIED**
240 7. If you got this far, access is **PERMITTED**
241
242 ## <a name="Access control and INCLUDE"></a> Access control and INCLUDE
243
244 ALLOWTOPICVIEW and ALLOWTOPICCHANGE only applies to the topic in which the settings are defined. If a topic A includes another topic B, topic A does not inherit the access rights of the included topic B.
245
246 Examples: Topic A includes topic B
247
248 - If the included topic B has ALLOWTOPICCHANGE set to block editing for a user, it does not prevent editing the including topic A.
249 - If the included topic B has ALLOWTOPICVIEW set to block view for a user, the user can still view topic A but he cannot see the included topic B. He will see a message _No permission to view B_
250
251 <a name="QuickRecipes"></a>
252
253 ## <a name="Access Control quick recipes"></a> Access Control quick recipes
254
255 ### <a name="Obfuscating Webs"></a> Obfuscating Webs
256
257 Another way of hiding webs is to keep them hidden by not publishing the URL and by preventing the <code>**all webs**</code> search option from accessing obfuscated webs. Do so by enabling the <code>**NOSEARCHALL**</code> variable in [[WebPreferences]]:
258
259 - <code>**Set NOSEARCHALL = on**</code>
260
261 This setup can be useful to hide a new web until content its ready for deployment, or to hide view access restricted webs.
262
263 **_%X% Note:_** Obfuscating a web without view access control is **very** insecure, as anyone who knows the URL can access the web.
264
265 ### <a name="Restrict Access to Whole TWiki S"></a> Restrict Access to Whole TWiki Site
266
267 For a firewalled TWiki, e.g. an intranet wiki or extranet wiki, you want to allow only invited people to access your TWiki. In this case, enable [[user authentication with ApacheLogin|Main/TWikiUserAuthentication#ApacheLogin]] and lock down access to the whole `twiki/bin` and `twiki/pub` directories to all but valid users. In the Apache `.htaccess` file or the appropriate `.conf` file, replace the `<FilesMatch "(attach|edit|...` section with this:
268
269     <FilesMatch ".*">
270            require valid-user
271     </FilesMatch>
272
273 If needed, you can further restrict access to selected webs with ALLOWWEBVIEW and other access control settings.
274
275 **_Note:_** With this configuration, someone with access to the site needs to register new users.
276
277 ### <a name="Authenticate all Webs and Restri"></a> Authenticate all Webs and Restrict Selected Webs
278
279 Use the following setup to authenticate users for topic viewing in all webs and to restrict access to selected webs. Requires [[TWikiUserAuthentication]] to be enabled.
280
281 1. Set `require valid-user` on your `view` script in .htaccess or the appropriate Apache .conf file. As of 4.x, this looks like: `FilesMatch "(attach|edit|manage|rename|save|view|upload|mail|logon|.*auth).*"` (normally `view` is not in that list).
282 2. **Restrict** view access to selected Users and Groups. Set one or both of these variables in its [[WebPreferences]] topic:
283   - <code>**Set DENYWEBVIEW = &lt; list of Users and Groups &gt;**</code>
284   - <code>**Set ALLOWWEBVIEW = &lt; list of Users and Groups &gt;**</code>
285   - **_Note:_** `DENYWEBVIEW` is evaluated before `ALLOWWEBVIEW`. Access is denied if the authenticated person is in the `DENYWEBVIEW` list, or not in the `ALLOWWEBVIEW` list. Access is granted if `DENYWEBVIEW` and `ALLOWWEBVIEW` are not defined.
286 3. If you still want public users to be able to register automatically follow TWiki:TWiki.RegisterOnViewRestrictedSite.
287
288 ### <a name="Authenticate and Restrict Select"></a> Authenticate and Restrict Selected Webs Only
289
290 Use the following setup to provide unrestricted viewing access to open webs, with authentication only on selected webs. Requires [[TWikiUserAuthentication]] to be enabled.
291
292 1. **Restrict** view access to selected Users and Groups. Set one or both of these variables in its [[WebPreferences]] topic:
293   - <code>**Set DENYWEBVIEW = &lt; list of Users and Groups &gt;**</code>
294   - <code>**Set ALLOWWEBVIEW = &lt; list of Users and Groups &gt;**</code>
295   - **_Note:_** `DENYWEBVIEW` is evaluated before `ALLOWWEBVIEW`. Access is denied if the authenticated person is in the `DENYWEBVIEW` list, or not in the `ALLOWWEBVIEW` list. Access is granted if `DENYWEBVIEW` and `ALLOWWEBVIEW` are not defined.
296
297 ### <a name="Hide Control Settings"></a> Hide Control Settings
298
299 **_%T% Tip:_** To hide access control settings from normal browser viewing, you can put them into the _topic preference settings_ by clicking the link `Edit topic preference settings` under `More topic actions` menu. Preferences set in this manner are not visible in the topic text, but take effect nevertheless. Access control settings added as topic preference settings are stored in the topic meta data and they override settings defined in the topic text.
300
301 Alternatively, place them in HTML comment markers, but this exposes the access setting during ordinary editing.
302
303 > <code>**&lt;!--**</code>
304 >
305 > <br />
306 >
307 > <code>**   \* Set DENYTOPICCHANGE = %USERSWEB%.SomeGroup**</code>
308 >
309 > <br />
310 >
311 > <code>**--&gt;**</code>
312
313 **_Related Topics:_** [[AdminDocumentationCategory]], [[TWikiUserAuthentication]], TWiki:TWiki.TWikiAccessControlSupplement
314
315 -- **_Contributors:_** TWiki:Main.PeterThoeny, TWiki:Main.MikeMannix, TWiki:Main.CrawfordCurrie