trying to get HEAD building again. If you want the code
[kai/samba.git] / docs / htmldocs / securing-samba.html
1 <html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Chapter 15. Securing Samba</title><link rel="stylesheet" href="samba.css" type="text/css"><meta name="generator" content="DocBook XSL Stylesheets V1.60.1"><link rel="home" href="index.html" title="SAMBA Project Documentation"><link rel="up" href="optional.html" title="Part III. Advanced Configuration"><link rel="previous" href="locking.html" title="Chapter 14. File and Record Locking"><link rel="next" href="InterdomainTrusts.html" title="Chapter 16. Interdomain Trust Relationships"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Chapter 15. Securing Samba</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="locking.html">Prev</a> </td><th width="60%" align="center">Part III. Advanced Configuration</th><td width="20%" align="right"> <a accesskey="n" href="InterdomainTrusts.html">Next</a></td></tr></table><hr></div><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="securing-samba"></a>Chapter 15. Securing Samba</h2></div><div><div class="author"><h3 class="author"><span class="firstname">Andrew</span> <span class="surname">Tridgell</span></h3><div class="affiliation"><span class="orgname">Samba Team<br></span><div class="address"><p><tt class="email">&lt;<a href="mailto:tridge@samba.org">tridge@samba.org</a>&gt;</tt></p></div></div></div></div><div><div class="author"><h3 class="author"><span class="firstname">John</span> <span class="othername">H.</span> <span class="surname">Terpstra</span></h3><div class="affiliation"><span class="orgname">Samba Team<br></span><div class="address"><p><tt class="email">&lt;<a href="mailto:jht@samba.org">jht@samba.org</a>&gt;</tt></p></div></div></div></div><div><p class="pubdate">May 26, 2003</p></div></div><div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><a href="securing-samba.html#id2931943">Introduction</a></dt><dt><a href="securing-samba.html#id2931976">Features and Benefits</a></dt><dt><a href="securing-samba.html#id2932050">Technical Discussion of Protective Measures and Issues</a></dt><dd><dl><dt><a href="securing-samba.html#id2932069">Using host based protection</a></dt><dt><a href="securing-samba.html#id2932140">User based protection</a></dt><dt><a href="securing-samba.html#id2932191">Using interface protection</a></dt><dt><a href="securing-samba.html#id2932244">Using a firewall</a></dt><dt><a href="securing-samba.html#id2932300">Using a IPC$ share deny</a></dt><dt><a href="securing-samba.html#id2932362">NTLMv2 Security</a></dt></dl></dd><dt><a href="securing-samba.html#id2932402">Upgrading Samba</a></dt><dt><a href="securing-samba.html#id2932426">Common Errors</a></dt><dd><dl><dt><a href="securing-samba.html#id2932444">Smbclient works on localhost, but the network is dead</a></dt><dt><a href="securing-samba.html#id2932469">Why can users access home directories of other users?</a></dt></dl></dd></dl></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2931943"></a>Introduction</h2></div></div><div></div></div><p>
2 This note was attached to the Samba 2.2.8 release notes as it contained an
3 important security fix.  The information contained here applies to Samba
4 installations in general.
5 </p><p>
6 A new apprentice reported for duty to the Chief Engineer of a boiler house. He said, &quot;Here I am,
7 if you will show me the boiler I'll start working on it.&quot; Then engineer replied, &quot;You're leaning
8 on it!&quot;
9 </p><p>
10 Security concerns are just like that: You need to know a little about the subject to appreciate
11 how obvious most of it really is. The challenge for most of us is to discover that first morsel
12 of knowledge with which we may unlock the secrets of the masters.
13 </p></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2931976"></a>Features and Benefits</h2></div></div><div></div></div><p>
14 There are three level at which security principals must be observed in order to render a site
15 at least moderately secure. These are: the perimeter firewall, the configuration of the host
16 server that is running Samba, and Samba itself.
17 </p><p>
18 Samba permits a most flexible approach to network security. As far as possible Samba implements
19 the latest protocols to permit more secure MS Windows file and print operations.
20 </p><p>
21 Samba may be secured from connections that originate from outside the local network. This may be
22 done using <span class="emphasis"><em>host based protection</em></span> (using samba's implementation of a technology
23 known as &quot;tcpwrappers&quot;, or it may be done be using <span class="emphasis"><em>interface based exclusion</em></span>
24 so that <span class="application">smbd</span> will bind only to specifically permitted interfaces. It is also
25 possible to set specific share or resource based exclusions, eg: on the <i class="parameter"><tt>IPC$</tt></i>
26 auto-share. The <i class="parameter"><tt>IPC$</tt></i> share is used for browsing purposes as well as to establish
27 TCP/IP connections.
28 </p><p>
29 Another method by which Samba may be secured is by way of setting Access Control Entries in an Access 
30 Control List on the shares themselves. This is discussed in the chapter on File, Directory and Share Access
31 Control.
32 </p></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2932050"></a>Technical Discussion of Protective Measures and Issues</h2></div></div><div></div></div><p>
33 The key challenge of security is the fact that protective measures suffice at best
34 only to close the door on known exploits and breach techniques. Never assume that
35 because you have followed these few measures that the Samba server is now an impenetrable
36 fortress! Given the history of information systems so far, it is only a matter of time
37 before someone will find yet another vulnerability.
38 </p><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2932069"></a>Using host based protection</h3></div></div><div></div></div><p>
39         In many installations of Samba the greatest threat comes for outside
40         your immediate network. By default Samba will accept connections from
41         any host, which means that if you run an insecure version of Samba on
42         a host that is directly connected to the Internet you can be
43         especially vulnerable.
44         </p><p>
45         One of the simplest fixes in this case is to use the <i class="parameter"><tt>hosts allow</tt></i> and
46         <i class="parameter"><tt>hosts deny</tt></i> options in the Samba <tt class="filename">smb.conf</tt> configuration file to only
47         allow access to your server from a specific range of hosts. An example
48         might be:
49         </p><pre class="programlisting">
50                 hosts allow = 127.0.0.1 192.168.2.0/24 192.168.3.0/24
51                 hosts deny = 0.0.0.0/0
52         </pre><p>
53         The above will only allow SMB connections from 'localhost' (your own
54         computer) and from the two private networks 192.168.2 and
55         192.168.3. All other connections will be refused as soon
56         as the client sends its first packet. The refusal will be marked as a
57         <span class="errorname">not listening on called name</span> error.
58         </p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2932140"></a>User based protection</h3></div></div><div></div></div><p>
59         If you want to restrict access to your server to valid users only then the following
60         method may be of use. In the <tt class="filename">smb.conf</tt> <i class="parameter"><tt>[globals]</tt></i> section put:
61         </p><pre class="programlisting">
62                 valid users = @smbusers, jacko
63         </pre><p>
64         What this does is, it restricts all server access to either the user <span class="emphasis"><em>jacko</em></span>
65         or to members of the system group <span class="emphasis"><em>smbusers</em></span>.
66         </p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2932191"></a>Using interface protection</h3></div></div><div></div></div><p>
67         By default Samba will accept connections on any network interface that
68         it finds on your system. That means if you have a ISDN line or a PPP
69         connection to the Internet then Samba will accept connections on those
70         links. This may not be what you want.
71         </p><p>
72         You can change this behaviour using options like the following:
73         </p><pre class="programlisting">
74                 interfaces = eth* lo
75                 bind interfaces only = yes
76         </pre><p>
77         This tells Samba to only listen for connections on interfaces with a
78         name starting with 'eth' such as eth0, eth1, plus on the loopback
79         interface called 'lo'. The name you will need to use depends on what
80         OS you are using, in the above I used the common name for Ethernet
81         adapters on Linux.
82         </p><p>
83         If you use the above and someone tries to make a SMB connection to
84         your host over a PPP interface called 'ppp0' then they will get a TCP
85         connection refused reply. In that case no Samba code is run at all as
86         the operating system has been told not to pass connections from that
87         interface to any samba process.
88         </p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2932244"></a>Using a firewall</h3></div></div><div></div></div><p>
89         Many people use a firewall to deny access to services that they don't
90         want exposed outside their network. This can be a very good idea,
91         although I would recommend using it in conjunction with the above
92         methods so that you are protected even if your firewall is not active
93         for some reason.
94         </p><p>
95         If you are setting up a firewall then you need to know what TCP and
96         UDP ports to allow and block. Samba uses the following:
97         </p><table class="simplelist" border="0" summary="Simple list"><tr><td>UDP/137 - used by nmbd</td></tr><tr><td>UDP/138 - used by nmbd</td></tr><tr><td>TCP/139 - used by smbd</td></tr><tr><td>TCP/445 - used by smbd</td></tr></table><p>
98         The last one is important as many older firewall setups may not be
99         aware of it, given that this port was only added to the protocol in
100         recent years. 
101         </p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2932300"></a>Using a IPC$ share deny</h3></div></div><div></div></div><p>
102         If the above methods are not suitable, then you could also place a
103         more specific deny on the IPC$ share that is used in the recently
104         discovered security hole. This allows you to offer access to other
105         shares while denying access to IPC$ from potentially untrustworthy
106         hosts.
107         </p><p>
108         To do that you could use:
109         </p><pre class="programlisting">
110 [ipc$]
111         hosts allow = 192.168.115.0/24 127.0.0.1
112         hosts deny = 0.0.0.0/0
113         </pre><p>
114         this would tell Samba that IPC$ connections are not allowed from
115         anywhere but the two listed places (localhost and a local
116         subnet). Connections to other shares would still be allowed. As the
117         IPC$ share is the only share that is always accessible anonymously
118         this provides some level of protection against attackers that do not
119         know a username/password for your host.
120         </p><p>
121         If you use this method then clients will be given a <span class="errorname">access denied</span>
122         reply when they try to access the IPC$ share. That means that those
123         clients will not be able to browse shares, and may also be unable to
124         access some other resources. 
125         </p><p>
126         This is not recommended unless you cannot use one of the other
127         methods listed above for some reason.
128         </p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2932362"></a>NTLMv2 Security</h3></div></div><div></div></div><p>
129         To configure NTLMv2 authentication the following registry keys are worth knowing about:
130         </p><p>
131         </p><pre class="screen">
132                 [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa]
133                 &quot;lmcompatibilitylevel&quot;=dword:00000003
134
135                 0x3 - Send NTLMv2 response only. Clients will use NTLMv2 authentication,
136                 use NTLMv2 session security if the server supports it. Domain
137                 controllers accept LM, NTLM and NTLMv2 authentication.
138
139                 [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa\MSV1_0]
140                 &quot;NtlmMinClientSec&quot;=dword:00080000
141
142                 0x80000 - NTLMv2 session security. If either NtlmMinClientSec or
143                 NtlmMinServerSec is set to 0x80000, the connection will fail if NTLMv2
144                 session security is not negotiated.
145         </pre><p>
146         </p></div></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2932402"></a>Upgrading Samba</h2></div></div><div></div></div><p>
147 Please check regularly on <a href="http://www.samba.org/" target="_top">http://www.samba.org/</a> for updates and
148 important announcements.  Occasionally security releases are made and 
149 it is highly recommended to upgrade Samba when a security vulnerability
150 is discovered.
151 </p></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2932426"></a>Common Errors</h2></div></div><div></div></div><p>
152 If all of samba and host platform configuration were really as intuitive as one might like then this
153 section would not be necessary. Security issues are often vexing for a support person to resolve, not
154 because of the complexity of the problem, but for reason that most administrators who post what turns
155 out to be a security problem request are totally convinced that the problem is with Samba.
156 </p><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2932444"></a>Smbclient works on localhost, but the network is dead</h3></div></div><div></div></div><p>
157         This is a very common problem. Red Hat Linux (as do others) will install a default firewall.
158         With the default firewall in place only traffic on the loopback adapter (IP address 127.0.0.1)
159         will be allowed through the firewall.
160         </p><p>
161         The solution is either to remove the firewall (stop it) or to modify the firewall script to
162         allow SMB networking traffic through. See section above in this chapter.
163         </p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2932469"></a>Why can users access home directories of other users?</h3></div></div><div></div></div><p>
164         &#8220;<span class="quote">
165         We are unable to keep individual users from mapping to any other user's
166         home directory once they have supplied a valid password! They only need
167         to enter their own password. I have not found *any* method that I can
168         use to configure samba to enforce that only a user may map their own
169         home directory.
170         </span>&#8221;
171         </p><p>&#8220;<span class="quote">
172         User xyzzy can map his home directory. Once mapped user xyzzy can also map
173         *anyone* else's home directory!
174         </span>&#8221;</p><p>
175         This is not a security flaw, it is by design. Samba allows
176         users to have *exactly* the same access to the UNIX filesystem
177         as they would if they were logged onto the UNIX box, except
178         that it only allows such views onto the file system as are
179         allowed by the defined shares.
180         </p><p>
181         This means that if your UNIX home directories are set up
182         such that one user can happily cd into another users
183         directory and do an ls, the UNIX security solution is to
184         change the UNIX file permissions on the users home directories
185         such that the cd and ls would be denied.
186         </p><p>
187         Samba tries very hard not to second guess the UNIX administrators
188         security policies, and trusts the UNIX admin to set
189         the policies and permissions he or she desires.
190         </p><p>
191         Samba does allow the setup you require when you have set the
192         <i class="parameter"><tt>only user = yes</tt></i> option on the share, is that you have not set the
193         valid users list for the share.
194         </p><p>
195         Note that only user works in conjunction with the users= list,
196         so to get the behavior you require, add the line :
197         </p><pre class="programlisting">
198         users = %S
199         </pre><p>
200         this is equivalent to:
201         </p><pre class="programlisting">
202         valid users = %S
203         </pre><p>
204         to the definition of the <i class="parameter"><tt>[homes]</tt></i> share, as recommended in
205         the <tt class="filename">smb.conf</tt> man page.
206         </p></div></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="locking.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="optional.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="InterdomainTrusts.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter 14. File and Record Locking </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> Chapter 16. Interdomain Trust Relationships</td></tr></table></div></body></html>