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