Large number of small fixes to the layout and the build system.
[import/samba-docs-svnimport.git] / Samba3-HOWTO / TOSHARG-Securing.xml
1 <?xml version="1.0" encoding="iso-8859-1"?>
2 <!DOCTYPE chapter PUBLIC "-//Samba-Team//DTD DocBook V4.2-Based Variant V1.0//EN" "http://www.samba.org/samba/DTD/samba-doc">
3 <chapter id="securing-samba">
4
5 <chapterinfo>
6         &author.tridge;
7         &author.jht;
8         <pubdate>May 26, 2003</pubdate>
9 </chapterinfo>
10
11 <title>Securing Samba</title>
12
13 <sect1>
14 <title>Introduction</title>
15 <para>
16 This note was attached to the Samba 2.2.8 release notes as it contained an
17 important security fix. The information contained here applies to Samba
18 installations in general.
19 </para>
20
21 <blockquote>
22 <para>
23 A new apprentice reported for duty to the chief engineer of a boiler house. He said, <quote>Here I am,
24 if you will show me the boiler I'll start working on it.</quote> Then engineer replied, <quote>You're leaning
25 on it!</quote>
26 </para>
27 </blockquote>
28
29 <para>
30 Security concerns are just like that. You need to know a little about the subject to appreciate
31 how obvious most of it really is. The challenge for most of us is to discover that first morsel
32 of knowledge with which we may unlock the secrets of the masters.
33 </para>
34
35 </sect1>
36
37 <sect1>
38 <title>Features and Benefits</title>
39
40 <para>
41 There are three levels at which security principals must be observed in order to render a site
42 at least moderately secure. They are the perimeter firewall, the configuration of the host
43 server that is running Samba and Samba itself.
44 </para>
45
46 <para>
47 Samba permits a most flexible approach to network security. As far as possible Samba implements
48 the latest protocols to permit more secure MS Windows file and print operations.
49 </para>
50
51 <para>
52 Samba may be secured from connections that originate from outside the local network. This may be
53 done using <emphasis>host-based protection</emphasis> (using Samba's implementation of a technology
54 known as <quote>tcpwrappers,</quote> or it may be done be using <emphasis>interface-based exclusion</emphasis>
55 so &smbd; will bind only to specifically permitted interfaces. It is also
56 possible to set specific share or resource-based exclusions, for example on the <smbconfsection name="[IPC$]"/>
57 auto-share. The <smbconfsection name="[IPC$]"/> share is used for browsing purposes as well as to establish
58 TCP/IP connections.
59 </para>
60
61 <para>
62 Another method by which Samba may be secured is by setting Access Control Entries (ACEs) in an Access 
63 Control List (ACL) on the shares themselves. This is discussed in <link linkend="AccessControls">File, Directory and Share Access Controls</link>.
64 </para>
65
66 </sect1>
67
68 <sect1>
69 <title>Technical Discussion of Protective Measures and Issues</title>
70
71 <para>
72 The key challenge of security is the fact that protective measures suffice at best
73 only to close the door on known exploits and breach techniques. Never assume that
74 because you have followed these few measures that the Samba server is now an impenetrable
75 fortress! Given the history of information systems so far, it is only a matter of time
76 before someone will find yet another vulnerability.
77 </para>
78
79         <sect2>
80         <title>Using Host-Based Protection</title>
81
82         <para>
83         In many installations of Samba, the greatest threat comes from outside
84         your immediate network. By default, Samba will accept connections from
85         any host, which means that if you run an insecure version of Samba on
86         a host that is directly connected to the Internet you can be
87         especially vulnerable.
88         </para>
89
90         <para>
91         One of the simplest fixes in this case is to use the <smbconfoption name="hosts allow"/> and
92         <smbconfoption name="hosts deny"/> options in the Samba &smb.conf; configuration file to only
93         allow access to your server from a specific range of hosts. An example might be:
94         </para>
95
96         <para><smbconfblock>
97 <smbconfoption name="hosts allow">127.0.0.1 192.168.2.0/24 192.168.3.0/24</smbconfoption>
98 <smbconfoption name="hosts deny">0.0.0.0/0</smbconfoption>
99         </smbconfblock></para>
100
101         <para>
102         The above will only allow SMB connections from <constant>localhost</constant> (your own
103         computer) and from the two private networks 192.168.2 and 192.168.3. All other
104         connections will be refused as soon as the client sends its first packet. The refusal
105         will be marked as <errorname>not listening on called name</errorname> error.
106         </para>
107
108         </sect2>
109
110         <sect2>
111         <title>User-Based Protection</title>
112
113         <para>
114         If you want to restrict access to your server to valid users only, then the following
115         method may be of use. In the &smb.conf; <smbconfsection name="[global]"/> section put:
116         </para>
117
118         <para><smbconfblock>
119 <smbconfoption name="valid users">@smbusers, jacko</smbconfoption>
120         </smbconfblock></para>
121
122         <para>
123         This restricts all server access to either the user <emphasis>jacko</emphasis>
124         or to members of the system group <emphasis>smbusers</emphasis>.
125         </para>
126
127         </sect2>
128
129         <sect2>
130
131         <title>Using Interface Protection</title>
132
133         <para>
134         By default, Samba will accept connections on any network interface that
135         it finds on your system. That means if you have a ISDN line or a PPP
136         connection to the Internet then Samba will accept connections on those
137         links. This may not be what you want.
138         </para>
139
140         <para>
141         You can change this behavior using options like this:
142         </para>
143
144         <para><smbconfblock>
145 <smbconfoption name="interfaces">eth* lo</smbconfoption>
146 <smbconfoption name="bind interfaces only">yes</smbconfoption>
147         </smbconfblock></para>
148
149         <para>
150         This tells Samba to only listen for connections on interfaces with a
151         name starting with <constant>eth</constant> such as <constant>eth0, eth1</constant> plus on the loopback
152         interface called <constant>lo</constant>. The name you will need to use depends on what
153         OS you are using. In the above, I used the common name for Ethernet
154         adapters on Linux.
155         </para>
156
157         <para>
158         If you use the above and someone tries to make an SMB connection to
159         your host over a PPP interface called <constant>ppp0,</constant> then they will get a TCP
160         connection refused reply. In that case, no Samba code is run at all as
161         the operating system has been told not to pass connections from that
162         interface to any Samba process.
163         </para>
164
165         </sect2>
166
167         <sect2>
168         <title>Using a Firewall</title>
169
170         <para>
171         Many people use a firewall to deny access to services they do not
172         want exposed outside their network. This can be a good idea,
173         although I recommend using it in conjunction with the above
174         methods so you are protected even if your firewall is not active
175         for some reason.
176         </para>
177
178         <para>
179         If you are setting up a firewall, you need to know what TCP and
180         UDP ports to allow and block. Samba uses the following:
181         </para>
182
183         <simplelist>
184                 <member>UDP/137 - used by nmbd</member>
185                 <member>UDP/138 - used by nmbd</member>
186                 <member>TCP/139 - used by smbd</member>
187                 <member>TCP/445 - used by smbd</member>
188         </simplelist>
189
190         <para>
191         The last one is important as many older firewall setups may not be
192         aware of it, given that this port was only added to the protocol in
193         recent years. 
194         </para>
195
196         </sect2>
197
198         <sect2>
199         <title>Using IPC$ Share-Based Denials </title>
200
201         <para>
202         If the above methods are not suitable, then you could also place a
203         more specific deny on the IPC$ share that is used in the recently
204         discovered security hole. This allows you to offer access to other
205         shares while denying access to IPC$ from potentially un-trustworthy
206         hosts.
207         </para>
208
209         <para>
210         To do this you could use:
211         </para>
212
213         <para><smbconfblock>
214 <smbconfsection name="[IPC$]"/>
215 <smbconfoption name="hosts allow">192.168.115.0/24 127.0.0.1</smbconfoption>
216 <smbconfoption name="hosts deny">0.0.0.0/0</smbconfoption>
217         </smbconfblock></para>
218
219         <para>
220         This instructs Samba that IPC$ connections are not allowed from
221         anywhere except from the two listed network addresses (localhost and the 192.168.115
222         subnet). Connections to other shares are still allowed. As the
223         IPC$ share is the only share that is always accessible anonymously,
224         this provides some level of protection against attackers that do not
225         know a valid username/password for your host.
226         </para>
227
228         <para>
229         If you use this method, then clients will be given an <errorname>`access denied'</errorname>
230         reply when they try to access the IPC$ share. Those clients will not be able to
231         browse shares, and may also be unable to access some other resources.  This is not
232         recommended unless you cannot use one of the other methods listed above for some reason.
233         </para>
234
235         </sect2>
236
237         <sect2>
238         <title>NTLMv2 Security</title>
239
240         <para>
241         To configure NTLMv2 authentication, the following registry keys are worth knowing about:
242         </para>
243
244         <para>
245                 <screen>
246                 [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa]
247                 "lmcompatibilitylevel"=dword:00000003
248                 </screen>
249         </para>
250
251         <para>
252         The value 0x00000003 means send NTLMv2 response only. Clients will use NTLMv2 authentication,
253         use NTLMv2 session security if the server supports it. Domain Controllers accept LM,
254         NTLM and NTLMv2 authentication.
255         </para>
256
257         <para>
258                 <screen>
259                 [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa\MSV1_0]
260                 "NtlmMinClientSec"=dword:00080000
261                 </screen>
262         </para>
263
264         <para>
265         The value 0x00080000 means permit only NTLMv2 session security. If either NtlmMinClientSec or
266         NtlmMinServerSec is set to 0x00080000, the connection will fail if NTLMv2
267         session security is not negotiated.
268         </para>
269         </sect2>
270 </sect1>
271
272 <sect1>
273 <title>Upgrading Samba</title>
274
275 <para>
276 Please check regularly on <ulink noescape="1" url="http://www.samba.org/">http://www.samba.org/</ulink> for updates and
277 important announcements. Occasionally security releases are made and 
278 it is highly recommended to upgrade Samba when a security vulnerability
279 is discovered. Check with your OS vendor for OS specific upgrades.
280 </para>
281
282 </sect1>
283
284 <sect1>
285 <title>Common Errors</title>
286
287 <para>
288 If all of Samba and host platform configuration were really as intuitive as one might like them to be, this
289 section would not be necessary. Security issues are often vexing for a support person to resolve, not
290 because of the complexity of the problem, but for the reason that most administrators who post what turns
291 out to be a security problem request are totally convinced that the problem is with Samba.
292 </para>
293
294         <sect2>
295         <title>Smbclient Works on Localhost, but the Network Is Dead</title>
296
297         <para>
298         This is a common problem. Red Hat Linux (and others) installs a default firewall.
299         With the default firewall in place, only traffic on the loopback adapter (IP address 127.0.0.1)
300         is allowed through the firewall.
301         </para>
302
303         <para>
304         The solution is either to remove the firewall (stop it) or modify the firewall script to
305         allow SMB networking traffic through. See section above in this chapter.
306         </para>
307
308         </sect2>
309
310         <sect2>
311         <title>Why Can Users Access Home Directories of Other Users?</title>
312
313         <para>
314         <quote>
315         We are unable to keep individual users from mapping to any other user's
316         home directory once they have supplied a valid password! They only need
317         to enter their own password. I have not found any method to configure
318         Samba so that  users may map only their own home directory.
319         </quote>
320         </para>
321
322         <para><quote>
323         User xyzzy can map his home directory. Once mapped user xyzzy can also map
324         anyone else's home directory.
325         </quote></para>
326
327         <para>
328         This is not a security flaw, it is by design. Samba allows users to have
329         exactly the same access to the UNIX file system as when they were logged
330         onto the UNIX box, except that it only allows such views onto the file 
331         system as are allowed by the defined shares.
332         </para>
333
334         <para>
335         If your UNIX home directories are set up so that one user can happily <command>cd</command>
336         into another users directory and execute <command>ls</command>, the UNIX security solution is to change file
337         permissions on the user's home directories such that the <command>cd</command> and <command>ls</command> are denied.
338         </para>
339
340         <para>
341         Samba tries very hard not to second guess the UNIX administrators security policies, and
342         trusts the UNIX admin to set the policies and permissions he or she desires.
343         </para>
344
345         <para>
346         Samba allows the behavior you require. Simply put the <smbconfoption name="only user">%S</smbconfoption>
347         option in the <smbconfsection name="[homes]"/> share definition.
348         </para>
349
350         <para>
351         The <smbconfoption name="only user"></smbconfoption> works in conjunction with the <smbconfoption name="users">list</smbconfoption>,
352         so to get the behavior you require, add the line :
353         <smbconfblock>
354 <smbconfoption name="users">%S</smbconfoption>
355 </smbconfblock>
356         this is equivalent to adding
357         <smbconfblock>
358 <smbconfoption name="valid users">%S</smbconfoption>
359         </smbconfblock>
360         to the definition of the <smbconfsection name="[homes]"/> share, as recommended in
361         the &smb.conf; man page.
362         </para>
363         </sect2>
364
365 </sect1>
366 </chapter>