Securing NFS

Securing NFS


NFS is a network protocol with which many UNIX-administrators have a love/hate relationship. On the one hand, it’s the ideal protocol if you need to export a filesystem from a UNIX-like system. On the other, it has a bit of a reputation of being insecure. Since a rogue system can just tell an NFS server that “hey, I’m representing a user with UID 1000, please remove all the files in my home directory”, this reputation may not be totally undeserved.

Or is it?

Well, yes and no. It’s true that, by default, NFS works in the above described way. There are ways to mitigate most security issues (for example, only allow trusted systems to connect to the server, and do not enable the root_squash option unless you really need it), but they’re all workarounds. But on the other hand, recent modifications to the NFS protocols have allowed GSSAPI—i.e., Kerberos—authentication to be used for NFS exports. Which is totally cool.

For this to be possible, obviously you need to set up a Kerberos realm. That’s not too hard; I wrote about that very subject last week. Let’s recap: I explained that in any Kerberos authentication dialogue, there are three parties: the Kerberos-enabled server; the Kerberos-enabled client; and the Kerberos daemon itself—also known as Kerberos Distribution Center, or KDC. Each of these three parties must have a principal.

  • The user’s principal is password-protected, and gets unlocked when the user logs on. After that, it’s stored in the user’s ticket cache, so that applications can use it. When a client application wants to authenticate itself against a server, it will ask the KDC for a ticket for the server’s principal, which will then also be stored in the ticket cache. User tickets are valid for only a limited time; 10 hours by default. After that, the user will have to re-enter his or her password to be able to use any kerberos-enabled services again.
  • The server’s principal is protected by a random password that’s stored on the server’s hard disk in what is called a “keytab”. Since any malicious user or application can use this principal to pose as the server in question, it is obviously imperative that this keytab is well protected. Usually the keytab is stored as /etc/krb5.keytab, but most server applications allow you to vary the file name (useful in case you’re not running a server as root; /etc/krb5.keytab must only be readable to root).
  • The KDC can obviously access its principal without a password; it only needs to read its database to get it.

So we can conclude that in general, and as I explained last week, to set up a server so that it uses Kerberos, you need to:

  1. create a kerberos principal
  2. store the principal so that the server can access it
  3. set up the server to use Kerberos as authentication
  4. set up the client to do the same

However, NFS is a bit of a special case here. Usually, NFS shares get mounted by initscripts at boot time, well before any user has had the chance to enter a password. As a result, you can not use their principal to authenticate to the NFS server, since we don’t have access to it yet. So how can we authenticate ourselves to the server at that time, to be allowed to mount anything in the first place?

The answer is simple: we just create a server principal for the client, too. After all, server principals are no different than user principals; they only have a different name. It’s perfectly valid to authenticate to a server principal by use of another server principal—that is, unless you’ve configured a particular server not to accept that. Which is a good thing to do, except obviously for NFS.

So, we’ll create a server principal; but first, we’ll need to make sure that the server will find our KDC. This is very simply done with a configuration file; in my case, with GREP.BE as my realm, I have created a file /etc/krb5.conf with the following contents:

[libdefaults]
  default_realm = GREP.BE
  kdc_timesync = 1
  forwardable = true
  proxiable = true
[realms]
  GREP.BE = {
    kdc = kdc.grep.be
    kdc = kdc-1.grep.be
    admin_server = kdc.grep.be
  }
[login]
  krb4_convert = false
  krb4_get_tickets = false

Whoa, that’s quite a bit. Let’s go over it one by one, shall we?

The [libdefaults] section obviously sets a few defaults for my Kerberos setup: I want to use GREP.BE as my realm by default, I want forwardable and proxiable tickets (both allow a server to authenticate itself on my behalf; this is useful in certain situations). The kdc_timesync option will make a client adjust the timings in kerberos communications if it finds that its clock is off by too much; this can help if NTP doesn’t work (but you should still try to use it).

The [realms] section simply explains where to find your KDCs. The admin_server option specifies where your master kdc is. It’s legal to have multiple KDCs, but you may have only one master KDC (setting up slave KDCs is outside the scope of this article).

The final section disables use of Kerberos V4. This is an older version of the protocol that has been proven to have security issues; you should not use it.

With that, we can just use kadmin to create the server principal. If we run kadmin as root, we’ll be able to do step 2 in one go:

nfs-server# kadmin
Authenticating as principal root/admin@GREP.BE with password.
Password for root/admin@GREP.BE:
kadmin: addprinc -randkey nfs/host.grep.be@GREP.BE
WARNING: no policy specified for nfs/techno.grep.be@GREP.BE; defaulting to no policy
Principal "nfs/techno.grep.be@GREP.BE" created.
kadmin: xst nfs/techno.grep.be@GREP.BE
Entry for principal nfs/techno.grep.be@GREP.BE with (...)
(...)
kadmin: quit

That was the principal. Notice how this time we created a principal based on a general scheme of < service name > / < hostname > @REALM for the name. It’s imperative that the hostname part of the ticket is what the client will find when it does a reverse name lookup on the IP address; otherwise the client won’t find the ticket. It is also imperative that you write nfs exactly as specified above; i.e., not in upper case.

As explained above, you now need to do the same thing on the client. Go ahead, create a principal there, and store it in its own keytab. I’ll wat.

Now that we’ve created the principals, it’s time to start configuring NFS exports to allow for Kerberos authentication. But before we take that step, let’s verify you have software which will actually understand such authentication. You need the NFS support utilities version 1.0.7 or above; and you need a fairly recent kernel to support it properly (in fact, Linux 2.6.17 had a few crucial bugs, so Linux 2.6.18 is what you really want). If you have those, you’re all set to enable kerberos authentication:

  • On the server, edit /etc/exports, and add a share like this: /export gss/krb5i(sync,subtree_check,rw)
  • On the client, edit /etc/fstab, and add a share like this: server:/export /mnt/server nfs rw,sec=krb5i,nfsvers=3 0 0

You must also make sure that the rpc.gssd utility is running on the client, and that the rpc.svcgssd utility does on the server. The nfs-common and nfs-kernel-server initscripts should do this automatically if you’ve edited the two files as above; but do verify that they’re doing so.

And that’s it. Now either reboot the client or manually mount the share with the same options, and you’re all set. When a user wants to write to a Kerberos NFS share, then the system will use this user’s principal to authenticate. And you, the system administrator, will be happy with the knowledge that it’s indeed that user, not some imposter, who’s writing a file. Isn’t that nice?

Category: 

Comments

Anonymous visitor's picture
Submitted by Anonymous visitor (not verified) on

hi,

thanks for article, very useful. i thought it would be difficult until reading this.

i think you made a typo, the
kadmin: addprinc -randkey nfs/host.grep.be@GREP.BE
should be
kadmin: addprinc -randkey nfs/techno.blah

(i think)

matt

Author information

Wouter Verhelst's picture

Biography

Wouter is an independent contractor specializing on Free Software. In his free time, he contributes to the Debian Project as a Debian Developer.

Most forwarded

Interview with Dave Mohyla, of DTIDATA

Dave Mohyla is the president and founder of dtidata.com, a hard drive recovery facility based in Tampa, Florida.

TM: Where are you based? What does your company do?
DTI Data recovery is based in South Pasadena, Florida which is a suburb of Tampa. We have been here for over 10 years. We operate a bio-metrically secured class 100 clean room where we perform hard drive recovery on all types of hard disks, from laptop hard drives to multi drive RAID systems.

Anybody up to writing good directory software?

Since the very beginning, directories (of any kind) have had a very central role in the internet. (I have recently grown fond of Free Web Directory. Even Slashdot can be considered a directory: a collection of great news and invaluable user-generated comments. As far as software is concerned, doing a quick search on Google about software directories will return the free (as in freedom) software directories like Savannah, SourceForge, Freshmeat and so on, followed by shareware and freeware sites such as FileBuzz, PCWin Download Center and All Freeware (great if you're looking for shareware and freeware, but definitely less comprehensive than their free-as-in-freedom counterparts).

Interview with Mark Shuttleworth

Mark Shuttleworth is the founder of Thawte, the first Certification Authority to sell public SSL certificates. After selling Thawte to Verisign, Mark moved on to training as an astronaut in Russia and visiting space. Once he got back he founded Ubuntu, the leading GNU/Linux distribution. He agreed on releasing a quick interview to Free Software Magazine.

Is better education the key to finding better software?

I read David Jonathon's article Anybody Up To Writing Good Directory Software? the other day, which got me thinking about software directories in general. As David mentioned, many of the software directories one finds when doing a quick google search are free as in beer, not as in freedom. But what interests me is the software directories that already exist, providing a combination of both free as in beer software, and open source software. Sites such as Freeware Downloads and Shareware Download don't advertise themselves as providing free as in liberty software, but each of them have a good selection of open source software available... if you know where to look.

Most emailed

Free Open Document label templates

If you’ve ever spent hours at work doing mailings, cursed your printer for printing outside the lines on your labels, or moaned “There has got to be a better way to do this,” here’s the solution you’ve been looking for. Working smarter, not harder! Worldlabel.com, a manufacture of labels offers Open Office / Libre Office labels templates for downloading in ODF format which will save you time, effort, and (if you want) make really cool-looking labels

Creating a user-centric site in Drupal

A little while ago, while talking in the #drupal mailing list, I showed my latest creation to one of the core developers there. His reaction was "Wow, I am always surprised what people use Drupal for". His surprise is somehow justified: I did create a site for a bunch of entertainers in Perth, a company set to use Drupal to take over the world with Entertainers.Biz.

Update: since writing this article, I have updated the system so that the whole booking process happens online. I will update the article accordingly!

So, why, why do people and companies develop free software?

More and more people are discovering free software. Many people only do so after weeks, or even months, of using it. I wonder, for example, how many Firefox users actually know how free Firefox really is—many of them realise that you can get it for free, but find it hard to believe that anybody can modify it and even redistribute it legally.

When the discovery is made, the first instinct is to ask: why do they do it? Programming is hard work. Even though most (if not all) programmers are driven by their higher-than-normal IQs and their amazing passion for solving problems, it’s still hard to understand why so many of them would donate so much of their time to creating something that they can’t really show off to anybody but their colleagues or geek friends.

Sure, anybody can buy laptops, and just program. No need to get a full-on lab or spend thousands of dollars in equipment. But... is that the full story?

Fun articles

Santa Claus - the most successful open source project

It dawned on me the other day, as I was shopping for the dozens of gifts it seems I have to buy every December, that Santa Claus is the most successful open source project in history. (Bridget @ Illiterarty would agree with that). Santa Claus is essentially a marketing development that is embodied by everyone who stuffs a sock, gives a gift, hosts a dinner or wishes Merry Christmas over the holiday season.

Most emailed

Editorial

When I first started thinking about Free Software Magazine, I was feeling enthusiastic about the dream. I had Dave, Gianluca, and Alan willing to help me, I had established members of the free software community willing to help me out, I had writers volunteering their time and energy for free, and I had a generous offer from OpenHosting for servers, all before I'd proved myself. There was a sense of excitement in the air, and I thought maybe, just maybe, I could make this work.

Free Software Magazine uses Apollo project management software and CRM for its everyday activities!