Stage 1 of PHPTR Edits.
[Samba/gebeck_regimport.git] / docs / Samba3-HOWTO / TOSHARG-Securing.xml
bloba35c48e807c0e00f2ccbec8ff11c457176cd397a
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">
5 <chapterinfo>
6         &author.tridge;
7         &author.jht;
8         <pubdate>May 26, 2003</pubdate>
9 </chapterinfo>
11 <title>Securing Samba</title>
13 <sect1>
14 <title>Introduction</title>
15 <para>
16 This note was attached to the Samba 2.2.8 release notes because it contains an
17 important security fix. The information contained here applies to Samba
18 installations in general.
19 </para>
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>
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>
35 </sect1>
37 <sect1>
38 <title>Features and Benefits</title>
40 <para>
41 There are three levels at which security principles 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>
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>
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 autoshare. The <smbconfsection name="[IPC$]"/> share is used for browsing purposes as well as to establish
58 TCP/IP connections.
59 </para>
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
64 <link linkend="AccessControls">File, Directory, and Share Access Controls</link>.
65 </para>
67 </sect1>
69 <sect1>
70 <title>Technical Discussion of Protective Measures and Issues</title>
72 <para>
73 The key challenge of security is that protective measures suffice at best
74 only to close the door on known exploits and breach techniques. Never assume that
75 because you have followed these few measures, the Samba server is now an impenetrable
76 fortress! Given the history of information systems so far, it is only a matter of time
77 before someone will find yet another vulnerability.
78 </para>
80         <sect2>
81         <title>Using Host-Based Protection</title>
83         <para>
84         In many installations of Samba, the greatest threat comes from outside
85         your immediate network. By default, Samba accepts connections from
86         any host, which means that if you run an insecure version of Samba on
87         a host that is directly connected to the Internet, you can be
88         especially vulnerable.
89         </para>
91         <para>
92         One of the simplest fixes in this case is to use the <smbconfoption name="hosts allow"/> and
93         <smbconfoption name="hosts deny"/> options in the Samba &smb.conf; configuration file to
94         allow access to your server only from a specific range of hosts. An example might be:
95         </para>
97         <para><smbconfblock>
98 <smbconfoption name="hosts allow">127.0.0.1 192.168.2.0/24 192.168.3.0/24</smbconfoption>
99 <smbconfoption name="hosts deny">0.0.0.0/0</smbconfoption>
100         </smbconfblock></para>
102         <para>
103         The above will allow SMB connections only from <constant>localhost</constant> (your own
104         computer) and from the two private networks 192.168.2 and 192.168.3. All other
105         connections will be refused as soon as the client sends its first packet. The refusal
106         will be marked as <errorname>not listening on called name</errorname> error.
107         </para>
109         </sect2>
111         <sect2>
112         <title>User-Based Protection</title>
114         <para>
115         If you want to restrict access to your server to valid users only, then the following
116         method may be of use. In the &smb.conf; <smbconfsection name="[global]"/> section put:
117         </para>
119         <para><smbconfblock>
120 <smbconfoption name="valid users">@smbusers, jacko</smbconfoption>
121         </smbconfblock></para>
123         <para>
124         This restricts all server access either to the user <emphasis>jacko</emphasis>
125         or to members of the system group <emphasis>smbusers</emphasis>.
126         </para>
128         </sect2>
130         <sect2>
132         <title>Using Interface Protection</title>
134         <para>
135         By default, Samba accepts connections on any network interface that
136         it finds on your system. That means if you have an ISDN line or a PPP
137         connection to the Internet then Samba will accept connections on those
138         links. This may not be what you want.
139         </para>
141         <para>
142         You can change this behavior using options like this:
143         </para>
145         <para><smbconfblock>
146 <smbconfoption name="interfaces">eth* lo</smbconfoption>
147 <smbconfoption name="bind interfaces only">yes</smbconfoption>
148         </smbconfblock></para>
150         <para>
151         This tells Samba to only listen for connections on interfaces with a
152         name starting with <constant>eth</constant> such as <constant>eth0 or eth1</constant>, plus on the loopback
153         interface called <constant>lo</constant>. The name you will need to use depends on what
154         OS you are using. In the above, I used the common name for Ethernet
155         adapters on Linux.
156         </para>
158         <para>
159         If you use the above and someone tries to make an SMB connection to
160         your host over a PPP interface called <constant>ppp0,</constant> then he or she will get a TCP
161         connection refused reply. In that case, no Samba code is run at all because
162         the operating system has been told not to pass connections from that
163         interface to any Samba process.
164         </para>
166         </sect2>
168         <sect2 id="firewallports">
169         <title>Using a Firewall</title>
171         <para>
172         Many people use a firewall to deny access to services they do not
173         want exposed outside their network. This can be a good idea,
174         although I recommend using it in conjunction with the above
175         methods so you are protected even if your firewall is not active
176         for some reason.
177         </para>
179         <para>
180         If you are setting up a firewall, you need to know what TCP and
181         UDP ports to allow and block. Samba uses the following:
182         </para>
184         <simplelist>
185                 <member>UDP/137 - used by nmbd</member>
186                 <member>UDP/138 - used by nmbd</member>
187                 <member>TCP/139 - used by smbd</member>
188                 <member>TCP/445 - used by smbd</member>
189         </simplelist>
191         <para>
192         The last one is important because many older firewall setups may not be
193         aware of it, given that this port was only added to the protocol in
194         recent years. 
195         </para>
197         <para>
198         When configuring a firewall, the high order ports (1024-65535) are often
199         used for outgoing connections and therefore should be permitted through the
200         firewall. It is prudent to block incoming packets on the high order ports
201         except for established connections.
202         </para>
204         </sect2>
206         <sect2>
207         <title>Using IPC$ Share-Based Denials </title>
209         <para>
210         If the above methods are not suitable, then you could also place a
211         more specific deny on the IPC$ share that is used in the recently
212         discovered security hole. This allows you to offer access to other
213         shares while denying access to IPC$ from potentially untrustworthy
214         hosts.
215         </para>
217         <para>
218         To do this you could use:
219         </para>
221         <para><smbconfblock>
222 <smbconfsection name="[IPC$]"/>
223 <smbconfoption name="hosts allow">192.168.115.0/24 127.0.0.1</smbconfoption>
224 <smbconfoption name="hosts deny">0.0.0.0/0</smbconfoption>
225         </smbconfblock></para>
227         <para>
228         This instructs Samba that IPC$ connections are not allowed from
229         anywhere except the two listed network addresses (localhost and the 192.168.115
230         subnet). Connections to other shares are still allowed. Because the
231         IPC$ share is the only share that is always accessible anonymously,
232         this provides some level of protection against attackers who do not
233         know a valid username/password for your host.
234         </para>
236         <para>
237         If you use this method, then clients will be given an <errorname>`access denied'</errorname>
238         reply when they try to access the IPC$ share. Those clients will not be able to
239         browse shares and may also be unable to access some other resources.  This is not
240         recommended unless for some reason you cannot use one of the other methods just discussed.
241         </para>
243         </sect2>
245         <sect2>
246         <title>NTLMv2 Security</title>
248         <para>
249         To configure NTLMv2 authentication, the following registry keys are worth knowing about:
250         </para>
252         <para>
253                 <screen>
254                 [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa]
255                 "lmcompatibilitylevel"=dword:00000003
256                 </screen>
257         </para>
259         <para>
260         The value 0x00000003 means to send NTLMv2 response only. Clients will use NTLMv2 authentication;
261         use NTLMv2 session security if the server supports it. Domain controllers accept LM,
262         NTLM, and NTLMv2 authentication.
263         </para>
265         <para>
266                 <screen>
267                 [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa\MSV1_0]
268                 "NtlmMinClientSec"=dword:00080000
269                 </screen>
270         </para>
272         <para>
273         The value 0x00080000 means permit only NTLMv2 session security. If either NtlmMinClientSec or
274         NtlmMinServerSec is set to 0x00080000, the connection will fail if NTLMv2
275         session security is negotiated.
276         </para>
277         </sect2>
278 </sect1>
280 <sect1>
281 <title>Upgrading Samba</title>
283 <para>
284 Please check regularly on <ulink noescape="1" url="http://www.samba.org/">http://www.samba.org/</ulink> for updates and
285 important announcements. Occasionally security releases are made, and 
286 it is highly recommended to upgrade Samba when a security vulnerability
287 is discovered. Check with your OS vendor for OS-specific upgrades.
288 </para>
290 </sect1>
292 <sect1>
293 <title>Common Errors</title>
295 <para>
296 If all of Samba and host platform configurations were really as intuitive as one might like them to be, this
297 section would not be necessary. Security issues are often vexing for a support person to resolve, not
298 because of the complexity of the problem, but because most administrators who post what turns
299 out to be a security problem request are totally convinced that the problem is with Samba.
300 </para>
302         <sect2>
303         <title>Smbclient Works on Localhost, but the Network Is Dead</title>
305         <para>
306         This is a common problem. Red Hat Linux (and others) installs a default firewall.
307         With the default firewall in place, only traffic on the loopback adapter (IP address 127.0.0.1)
308         is allowed through the firewall.
309         </para>
311         <para>
312         The solution is either to remove the firewall (stop it) or modify the firewall script to
313         allow SMB networking traffic through. See <link linkend="firewallports">the Using a 
314         firewall</link> section.
315         </para>
317         </sect2>
319         <sect2>
320         <title>Why Can Users Access Home Directories of Other Users?</title>
322         <para>
323         <quote>
324         We are unable to keep individual users from mapping to any other user's
325         home directory once they have supplied a valid password! They only need
326         to enter their own password. I have not found any method to configure
327         Samba so that  users may map only their own home directory.
328         </quote>
329         </para>
331         <para><quote>
332         User xyzzy can map his home directory. Once mapped, user xyzzy can also map
333         anyone else's home directory.
334         </quote></para>
336         <para>
337         This is not a security flaw, it is by design. Samba allows users to have
338         exactly the same access to the UNIX file system as when they were logged
339         onto the UNIX box, except that it only allows such views onto the file 
340         system as are allowed by the defined shares.
341         </para>
343         <para>
344         If your UNIX home directories are set up so that one user can happily <command>cd</command>
345         into another user's directory and execute <command>ls</command>, the UNIX security solution is to change file
346         permissions on the user's home directories so that the <command>cd</command> and <command>ls</command> are denied.
347         </para>
349         <para>
350         Samba tries very hard not to second guess the UNIX administrator's security policies and
351         trusts the UNIX admin to set the policies and permissions he or she desires.
352         </para>
354         <para>
355         Samba allows the behavior you require. Simply put the <smbconfoption name="only user">%S</smbconfoption>
356         option in the <smbconfsection name="[homes]"/> share definition.
357         </para>
359         <para>
360         The <smbconfoption name="only user"></smbconfoption> works in conjunction with the <smbconfoption name="users">list</smbconfoption>,
361         so to get the behavior you require, add the line:
362         <smbconfblock>
363 <smbconfoption name="users">%S</smbconfoption>
364 </smbconfblock>
365         This is equivalent to adding
366         <smbconfblock>
367 <smbconfoption name="valid users">%S</smbconfoption>
368         </smbconfblock>
369         to the definition of the <smbconfsection name="[homes]"/> share, as recommended in
370         the &smb.conf; man page.
371         </para>
372         </sect2>
374 </sect1>
375 </chapter>