528c87c52c3a0786c6ce67838c72f33db82ee9fa
[ira/wip.git] / docs / docbook / projdoc / security_level.xml
1 <chapter id="securitylevels">
2 <chapterinfo>
3         &author.tridge;
4         &author.jelmer;
5 </chapterinfo>
6 <title>Samba as Stand-Alone Server</title>
7
8 <para>
9 In this section the function and purpose of Samba's <emphasis>security</emphasis>
10 modes are described.
11 </para>
12
13 <sect1>
14 <title>User and Share security level</title>
15
16 <para>
17 A SMB server tells the client at startup what "security level" it is
18 running. There are two options "share level" and "user level". Which
19 of these two the client receives affects the way the client then tries
20 to authenticate itself. It does not directly affect (to any great
21 extent) the way the Samba server does security. I know this is
22 strange, but it fits in with the client/server approach of SMB. In SMB
23 everything is initiated and controlled by the client, and the server
24 can only tell the client what is available and whether an action is
25 allowed. 
26 </para>
27
28 <sect2>
29 <title>User Level Security</title>
30
31 <para>
32 I'll describe user level security first, as its simpler. In user level
33 security the client will send a "session setup" command directly after
34 the protocol negotiation. This contains a username and password. The
35 server can either accept or reject that username/password
36 combination. Note that at this stage the server has no idea what
37 share the client will eventually try to connect to, so it can't base
38 the "accept/reject" on anything other than:
39 </para>
40
41 <orderedlist>
42 <listitem><para>the username/password</para></listitem>
43 <listitem><para>the machine that the client is coming from</para></listitem>
44 </orderedlist>
45
46 <para>
47 If the server accepts the username/password then the client expects to
48 be able to mount any share (using a "tree connection") without
49 specifying a password. It expects that all access rights will be as
50 the username/password specified in the "session setup". 
51 </para>
52
53 <para>
54 It is also possible for a client to send multiple "session setup"
55 requests. When the server responds it gives the client a "uid" to use
56 as an authentication tag for that username/password. The client can
57 maintain multiple authentication contexts in this way (WinDD is an
58 example of an application that does this)
59 </para>
60
61 </sect2>
62
63 <sect2>
64 <title>Share Level Security</title>
65
66 <para>
67 Ok, now for share level security. In share level security the client
68 authenticates itself separately for each share. It will send a
69 password along with each "tree connection" (share mount). It does not
70 explicitly send a username with this operation. The client is
71 expecting a password to be associated with each share, independent of
72 the user. This means that samba has to work out what username the
73 client probably wants to use. It is never explicitly sent the
74 username. Some commercial SMB servers such as NT actually associate
75 passwords directly with shares in share level security, but samba
76 always uses the unix authentication scheme where it is a
77 username/password that is authenticated, not a "share/password".
78 </para>
79
80 <para>
81 Many clients send a "session setup" even if the server is in share
82 level security. They normally send a valid username but no
83 password. Samba records this username in a list of "possible
84 usernames". When the client then does a "tree connection" it also adds
85 to this list the name of the share they try to connect to (useful for
86 home directories) and any users listed in the <command>user =</command> &smb.conf;
87 line. The password is then checked in turn against these "possible
88 usernames". If a match is found then the client is authenticated as
89 that user.
90 </para>
91
92 </sect2>
93
94 <sect2>
95 <title>Server Level Security</title>
96
97 <para>
98 Finally "server level" security. In server level security the samba
99 server reports to the client that it is in user level security. The
100 client then does a "session setup" as described earlier. The samba
101 server takes the username/password that the client sends and attempts
102 to login to the "password server" by sending exactly the same
103 username/password that it got from the client. If that server is in
104 user level security and accepts the password then samba accepts the
105 clients connection. This allows the samba server to use another SMB
106 server as the "password server". 
107 </para>
108
109 <para>
110 You should also note that at the very start of all this, where the
111 server tells the client what security level it is in, it also tells
112 the client if it supports encryption. If it does then it supplies the
113 client with a random "cryptkey". The client will then send all
114 passwords in encrypted form. You have to compile samba with encryption
115 enabled to support this feature, and you have to maintain a separate
116 smbpasswd file with SMB style encrypted passwords. It is
117 cryptographically impossible to translate from unix style encryption
118 to SMB style encryption, although there are some fairly simple management
119 schemes by which the two could be kept in sync.
120 </para>
121
122 <para>
123 "security = server" means that Samba reports to clients that
124 it is running in "user mode" but actually passes off all authentication
125 requests to another "user mode" server. This requires an additional
126 parameter "password server =" that points to the real authentication server.
127 That real authentication server can be another Samba server or can be a
128 Windows NT server, the later natively capable of encrypted password support.
129 </para>
130
131 <note><para>
132 <emphasis>Server</emphasis> level security is incompatible with what is known 
133 as <emphasis>schannel</emphasis> or "sign and seal" protocols. This means that
134 if you want to use <emphasis>server</emphasis> level security you must disable
135 the use of "sign and seal" on all machines on your network.
136 </para></note>
137
138 <sect3>
139 <title>Configuring Samba for Seemless Windows Network Integration</title>
140
141 <para>
142 MS Windows clients may use encrypted passwords as part of a challenege/response
143 authentication model (a.k.a. NTLMv1) or alone, or clear text strings for simple
144 password based authentication. It should be realized that with the SMB protocol
145 the password is passed over the network either in plain text or encrypted, but
146 not both in the same authentication request.
147 </para>
148
149 <para>
150 When encrypted passwords are used a password that has been entered by the user
151 is encrypted in two ways:
152 </para>
153
154 <itemizedlist>
155         <listitem><para>An MD4 hash of the UNICODE of the password
156         string.  This is known as the NT hash.
157         </para></listitem>
158
159         <listitem><para>The password is converted to upper case,
160         and then padded or trucated to 14 bytes.  This string is 
161         then appended with 5 bytes of NULL characters and split to
162         form two 56 bit DES keys to encrypt a "magic" 8 byte value.
163         The resulting 16 bytes for the LanMan hash.
164         </para></listitem>      
165 </itemizedlist>
166
167 <para>
168 MS Windows 95 pre-service pack 1, MS Windows NT versions 3.x and version 4.0
169 pre-service pack 3 will use either mode of password authentication. All
170 versions of MS Windows that follow these versions no longer support plain
171 text passwords by default.
172 </para>
173
174 <para>
175 MS Windows clients have a habit of dropping network mappings that have been idle
176 for 10 minutes or longer. When the user attempts to use the mapped drive
177 connection that has been dropped, the client re-establishes the connection using
178 a cached copy of the password.
179 </para>
180
181 <para>
182 When Microsoft changed the default password mode, support was dropped for caching
183 of the plain text password. This means that when the registry parameter is changed
184 to re-enable use of plain text passwords it appears to work, but when a dropped
185 service connection mapping attempts to revalidate it will fail if the remote
186 authentication server does not support encrypted passwords.  This means that it
187 is definitely not a good idea to re-enable plain text password support in such clients.
188 </para>
189
190 <para>
191 The following parameters can be used to work around the issue of Windows 9x client
192 upper casing usernames and password before transmitting them to the SMB server
193 when using clear text authentication.
194 </para>
195
196 <para><programlisting>
197         <ulink url="smb.conf.5.html#PASSWORDLEVEL">passsword level</ulink> = <replaceable>integer</replaceable>
198         <ulink url="smb.conf.5.html#USERNAMELEVEL">username level</ulink> = <replaceable>integer</replaceable>
199 </programlisting></para>
200
201 <para>
202 By default Samba will lower case the username before attempting to lookup the user
203 in the database of local system accounts.  Because UNIX usernames conventionally
204 only contain lower case character, the <parameter>username level</parameter> parameter
205 is rarely needed.
206 </para>
207
208 <para>
209 However, passwords on UNIX systems often make use of mixed case characters. 
210 This means that in order for a user on a Windows 9x client to connect to a Samba
211 server using clear text authentication, the <parameter>password level</parameter>
212 must be set to the maximum number of upper case letter which <emphasis>could</emphasis>
213 appear is a password.  Note that the server OS uses the traditional DES version
214 of crypt(), a <parameter>password level</parameter> of 8 will result in case
215 insensitive passwords as seen from Windows users.  This will also result in longer
216 login times as Samba has to compute the permutations of the password string and 
217 try them one by one until a match is located (or all combinations fail).
218 </para>
219
220 <para>
221 The best option to adopt is to enable support for encrypted passwords 
222 where ever Samba is used. There are three configuration possibilities 
223 for support of encrypted passwords:
224 </para>
225
226 </sect3>
227 <sect3>
228 <title>Use MS Windows NT as an authentication server</title>
229
230 <para>
231 This method involves the additions of the following parameters in the &smb.conf; file:
232 </para>
233
234 <para><programlisting>
235         encrypt passwords = Yes
236         security = server
237         password server = "NetBIOS_name_of_PDC"
238 </programlisting></para>
239
240
241 <para>
242 There are two ways of identifying whether or not a username and 
243 password pair was valid or not. One uses the reply information provided 
244 as part of the authentication messaging process, the other uses 
245 just an error code.
246 </para>
247
248 <para>
249 The down-side of this mode of configuration is the fact that 
250 for security reasons Samba will send the password server a bogus 
251 username and a bogus password and if the remote server fails to 
252 reject the username and password pair then an alternative mode 
253 of identification of validation is used. Where a site uses password 
254 lock out after a certain number of failed authentication attempts 
255 this will result in user lockouts.
256 </para>
257
258 <para>
259 Use of this mode of authentication does require there to be 
260 a standard Unix account for the user, this account can be blocked 
261 to prevent logons by other than MS Windows clients.
262 </para>
263
264 </sect3>
265 </sect2>
266
267 <sect2>
268 <title>Domain Level Security</title>
269
270 <para>
271 When samba is operating in <emphasis>security = domain</emphasis> mode this means that
272 the Samba server has a domain security trust account (a machine account) and will cause
273 all authentication requests to be passed through to the domain controllers.
274 </para>
275
276 <sect3>
277 <title>Samba as a member of an MS Windows NT security domain</title>
278
279 <para>
280 This method involves addition of the following parameters in the &smb.conf; file:
281 </para>
282
283 <para><programlisting>
284         encrypt passwords = Yes
285         security = domain
286         workgroup = "name of NT domain"
287         password server = *
288 </programlisting></para>
289
290 <para>
291 The use of the "*" argument to <command>password server</command> will cause samba to locate the
292 domain controller in a way analogous to the way this is done within MS Windows NT.
293 This is the default behaviour.
294 </para>
295
296 <para>
297 In order for this method to work the Samba server needs to join the 
298 MS Windows NT security domain. This is done as follows:
299 </para>
300
301 <itemizedlist>
302         <listitem><para>On the MS Windows NT domain controller using 
303         the Server Manager add a machine account for the Samba server.
304         </para></listitem>
305         
306         <listitem><para>Next, on the Linux system execute: 
307         <command>smbpasswd -r PDC_NAME -j DOMAIN_NAME</command> (samba 2.x)
308
309         <command>net join -U administrator%password</command>   (samba-3)
310         </para></listitem>
311 </itemizedlist>
312
313 <para>
314 Use of this mode of authentication does require there to be a standard Unix account
315 for the user in order to assign a uid once the account has been authenticated by
316 the remote Windows DC.  This account can be blocked to prevent logons by clients other than
317 MS Windows through things such as setting an invalid shell in the
318 <filename>/etc/passwd</filename> entry. 
319 </para>
320
321 <para>
322 An alternative to assigning UIDs to Windows users on a Samba member server is
323 presented in the <link linkend="winbind">Winbind Overview</link> chapter
324 in this HOWTO collection.
325 </para>
326
327 </sect3>
328 </sect2>
329
330 <sect2>
331 <title>ADS Level Security</title>
332
333 <para>
334 For information about the configuration option please refer to the entire section entitled
335 <emphasis>Samba as an ADS Domain Member.</emphasis>
336 </para>
337
338 </sect2>
339 </sect1>
340 </chapter>