<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <title>Edd Dumbill's Weblog: 'debian' articles</title>
  <link href="http://times.usefulinc.com/tagdebianatom" rel="self"/>
  <link href="http://times.usefulinc.com/tagdebian" rel="alternate"/>
  <id>http://times.usefulinc.com/</id>
  <updated>2006-09-29T13:08:15Z</updated>
  <author>
    <name>Edd Dumbill</name>
    <email>edd-web@usefulinc.com</email>
  </author>
  <entry>
    <title>Locking down portmap on Debian</title>
    <link href="http://times.usefulinc.com/2006/09/29-portmap-security" rel="alternate"/>
    <id>http://times.usefulinc.com/public/read/867</id>
    <updated>2006-09-29T13:08:15Z</updated>
    <published>2006-09-29T12:53:10Z</published>
    <summary>Sharing the benefit of my recent system administration adventures.</summary>
    <category term="linux"/>
    <category term="ubuntu"/>
    <category term="debian"/>
    <content type="html">
&lt;p&gt;Most sensible people are very wary of NFS and its potential for security holes. If you can at all help it, it's a good idea not to run NFS and portmap on a network interface with direct internet connectivity. However, this isn't always convenient.
&lt;/p&gt;
&lt;p&gt;
As I needed to have NFS sharing on a host exposed to the internet, I set about finding the various places I needed to firewall. The tools I typically use to verify I've done the right things are &lt;code&gt;netstat -nap&lt;/code&gt; on the machine concerned, to check for listening processes, and &lt;code&gt;nmap&lt;/code&gt; from remote hosts to sniff for open ports.
&lt;/p&gt;
&lt;p&gt;

Portmap and its associated programs mostly use 'tcpwrappers' for controlling access. The first step you ought to take in securing portmap is to ensure that your &lt;em&gt;hosts.allow&lt;/em&gt; and &lt;em&gt;hosts.deny&lt;/em&gt; files are set up to control access properly.
&lt;/p&gt;
&lt;p&gt;

In &lt;em&gt;/etc/hosts.deny&lt;/em&gt;, deny access to allcomers:
&lt;/p&gt;
&lt;pre&gt;
mountd: ALL
statd: ALL
portmap: ALL
rquotad: ALL
&lt;/pre&gt;
&lt;p&gt;
Then in &lt;em&gt;/etc/hosts.allow&lt;/em&gt;, let the good guys through (adjust for your network):
&lt;/p&gt;
&lt;pre&gt;
mountd: 192.168.0.
statd: 192.168.0.
portmap: 192.168.0.
rquotad: 192.168.0.
&lt;/pre&gt;
&lt;p&gt;
On top of this, however, you should firewall off the ports that these programs use. As I found out, this is not as easy as it sounds. Portmap assigns random ports for some of the services it starts.
&lt;/p&gt;
&lt;p&gt;
You can run &lt;code&gt;rpcinfo -p&lt;/code&gt; to see the ports in use. An example run on one of my machines looks like this:
&lt;/p&gt;
&lt;pre&gt;
program vers proto   port
 100000    2   tcp    111  portmapper
 100000    2   udp    111  portmapper
 100003    2   udp   2049  nfs
 100003    3   udp   2049  nfs
 100003    4   udp   2049  nfs
 100003    2   tcp   2049  nfs
 100003    3   tcp   2049  nfs
 100003    4   tcp   2049  nfs
 100021    1   udp  32770  nlockmgr
 100021    3   udp  32770  nlockmgr
 100021    4   udp  32770  nlockmgr
 100021    1   tcp  32788  nlockmgr
 100021    3   tcp  32788  nlockmgr
 100021    4   tcp  32788  nlockmgr
 100005    1   udp   1005  mountd
 100005    1   tcp   1008  mountd
 100005    2   udp   1005  mountd
 100005    2   tcp   1008  mountd
 100005    3   udp   1005  mountd
 100005    3   tcp   1008  mountd
 100024    1   udp    863  status
 100024    1   tcp    866  status
&lt;/pre&gt;
&lt;p&gt;
Of these, &lt;em&gt;nfs&lt;/em&gt; and &lt;em&gt;portmapper&lt;/em&gt; always use the same ports, 2049 and 111, so ensure you block off these.
&lt;/p&gt;
&lt;p&gt;
What about the rest? Happily, there's a way to configure them to use constant ports so we can reliably firewall them. Life would be too easy if all this configuration was in the one place, so here's how to find the different places you need to change.
&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;b&gt;nlockmgr&lt;/b&gt;: you're probably using the kernel NFS server, which means the port needs passing at module load time for the lockd module.  Add this line into a new file, &lt;em&gt;/etc/modutils/local-lockd&lt;/em&gt; &lt;/p&gt;

&lt;pre&gt;options lockd nlm_udpport=32768 nlm_tcpport=32768&lt;/pre&gt;

&lt;p&gt;Then run &lt;code&gt;update-modules&lt;/code&gt; to recreate your &lt;em&gt;/etc/modules.conf&lt;/em&gt;. The next time you boot these ports will be used for &lt;em&gt;nlockmgr&lt;/em&gt;. If you've got the &lt;em&gt;lockd&lt;/em&gt; statically compiled into your kernel, you'll need to pass these options as &lt;code&gt;lockd.mnlm_udpport&lt;/code&gt; and &lt;code&gt;lockd.nlm_tcpport&lt;/code&gt; to the kernel on boot.
&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;b&gt;status&lt;/b&gt;: this is the port used by &lt;em&gt;statd&lt;/em&gt;. There's also an outgoing port, on which &lt;em&gt;statd&lt;/em&gt; sends outgoing status requests. You can configure them by altering &lt;code&gt;STATDOPTS&lt;/code&gt; in &lt;em&gt;/etc/default/nfs-common&lt;/em&gt;, e.g.&lt;/p&gt;

&lt;pre&gt;STATDOPTS="--port 699 --outgoing-port 700"&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;b&gt;mountd&lt;/b&gt;: you can control the port used for &lt;em&gt;mountd&lt;/em&gt; by editing &lt;em&gt;/etc/default/nfs-kernel-server&lt;/em&gt; and altering &lt;code&gt;RPCMOUNDOPTS&lt;/code&gt;, e.g.&lt;/p&gt;

&lt;pre&gt;RPCMOUNTDOPTS="--port 962"&lt;/pre&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Finally, if you're running quotas, be sure to do something similar with &lt;code&gt;RPCRQUOTADOPTS&lt;/code&gt; in &lt;em&gt;/etc/default/quota&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;See also:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="http://wiki.debian.org/SecuringNFS"&gt;SecuringNFS&lt;/a&gt; on the Debian Wiki&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.tldp.org/HOWTO/NFS-HOWTO/security.html"&gt;Linux NFS HOWTO&lt;/a&gt; security chapter&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Finally, I ought to note that I've written this up in case it helps anybody else.  As with everything I write here, I make no warranty about its accuracy.  Security is hard and obscure (but that's no reason not make our best efforts!)&lt;/p&gt;&lt;p&gt;&lt;a href="http://times.usefulinc.com/2006/09/29-portmap-security#disqus_thread"&gt;Join the conversation about this post&lt;/a&gt;&lt;/p&gt;    </content>
  </entry>
  <entry>
    <title>Rails deployment tip for Debian systems and Apache</title>
    <link href="http://times.usefulinc.com/2006/09/15-rails-debian-apache" rel="alternate"/>
    <id>http://times.usefulinc.com/public/read/863</id>
    <updated>2006-09-30T15:59:25Z</updated>
    <published>2006-09-15T22:26:07Z</published>
    <summary>A little Capistrano rule that helps keep all your configuration in one place when using Rails with Apache and Ubuntu or Debian.</summary>
    <category term="rails"/>
    <category term="ubuntu"/>
    <category term="debian"/>
    <content type="html">
&lt;p&gt;I deploy my Rails applications with Capistrano to an Ubuntu machine, which uses the excellent Debian style layout of Apache 2 configuration files.&lt;/p&gt;
&lt;p&gt;To keep things tidy, I like to place the Apache configuration file inside the &lt;i&gt;config&lt;/i&gt; directory of the Rails project, along with the rest of the configuration for the Rails application and Mongrel.&lt;/p&gt;
&lt;p&gt;With the help of a couple of Capistrano rules I can then ensure that, on deployment, the latest Apache configuration file is also sent to the server:&lt;/p&gt;

&lt;pre&gt;
# after setup, do a one-time link in
task :after_setup do
  sudo "ln -nfs #{current_path}/config/#{application}        
     /etc/apache2/sites-available/"
end

# cause apache2 to re-read. you probably have this rule anyway
task :restart do
  # if you're running mongrel_cluster, uncomment the following line
  # restart_mongrel_cluster
  sudo "/usr/sbin/apache2ctl graceful"
end
&lt;/pre&gt;

&lt;p&gt;The first time round you'll probably want to do &lt;tt&gt;a2ensite &lt;i&gt;yourapp&lt;/i&gt;&lt;/tt&gt; manually, but this could easily be added into the &lt;tt&gt;after_setup&lt;/tt&gt; rule.&lt;/p&gt;

&lt;p&gt;Not rocket science, but a pleasing bit of configuration that keeps things tidy.&lt;/p&gt;&lt;p&gt;&lt;a href="http://times.usefulinc.com/2006/09/15-rails-debian-apache#disqus_thread"&gt;Join the conversation about this post&lt;/a&gt;&lt;/p&gt;    </content>
  </entry>
</feed>
