{"id":223,"date":"2011-08-31T16:38:09","date_gmt":"2011-08-31T21:38:09","guid":{"rendered":"http:\/\/www.soljerome.com\/blog\/?p=223"},"modified":"2011-08-31T16:45:30","modified_gmt":"2011-08-31T21:45:30","slug":"gentoo-nfsv4-and-mit-kerberos","status":"publish","type":"post","link":"https:\/\/www.soljerome.com\/blog\/2011\/08\/31\/gentoo-nfsv4-and-mit-kerberos\/","title":{"rendered":"Gentoo NFSv4 and MIT Kerberos"},"content":{"rendered":"<p>I was unable to find any guides which accurately described setting up a NFSv4 client with Kerberos on Gentoo. There are guides for setting things up on other distros, but I have run into numerous issues which were directly related to using Gentoo. Therefore, I am going to use this guide to document some of those problems. Please note that the NFS server is running Ubuntu 10.04, so there are some parts of this guide which won&#8217;t apply to Gentoo.<\/p>\n<p>Setting up the Kerberos server is fairly straightforward, however, there is a difference in the way things are compiled on Gentoo. The <a href=\"http:\/\/en.gentoo-wiki.com\/wiki\/OpenAFS_with_MIT_Kerberos#Kerberos_Installation\" target=\"_blank\">OpenAFS<\/a> guide on the wiki is mostly correct. I&#8217;ll reiterate the correct steps here.<\/p>\n<h3>Installation<\/h3>\n<p>First, you need to install the Kerberos server.<\/p>\n<pre>emerge -av mit-krb5<\/pre>\n<p>Copy the <code>\/etc\/krb5.conf.example<\/code> file that is included over to <code>\/etc\/krb5.conf<\/code> and edit it according to your needs.<\/p>\n<pre>cp \/etc\/krb5.conf.example \/etc\/krb5.conf<\/pre>\n<p>The edited file will look similar to this<\/p>\n<pre>[libdefaults]\r\n        default_realm = EXAMPLE.COM\r\n        forwardable = true\r\n        renew_lifetime = 7days\r\n\r\n[realms]\r\n        EXAMPLE.COM = {\r\n                kdc = krb.example.com\r\n                admin_server = krb.example.com\r\n        }\r\n\r\n[domain_realm]\r\n        .example.com = EXAMPLE.COM\r\n        example.com = EXAMPLE.COM<\/pre>\n<p>You will need to replace &#8220;EXAMPLE.COM&#8221;, &#8220;example.com&#8221;, and &#8220;krb.example.com&#8221; with appropriate values for your environment. Note that realm names are always uppercase. The name of your KDC (krb.example.com in the example) is arbitrary.<\/p>\n<h3>Setting up the primary KDC<\/h3>\n<p>This is where the OpenAFS guide is confusing. The kdc.conf file should reside at <code>\/var\/lib\/krb5kdc\/kdc.conf<\/code>, not <code>\/etc\/kdc.conf<\/code>. So, go ahead and copy <code>\/var\/lib\/krb5kdc\/kdc.conf.example<\/code> and create a new file. Here are what the contents should look like.<\/p>\n<pre>[kdcdefaults]\r\n        kdc_ports = 750,88\r\n\r\n[realms]\r\n        EXAMPLE.COM = {\r\n                database_name = \/var\/lib\/krb5kdc\/principal\r\n                admin_keytab = FILE:\/var\/lib\/krb5kdc\/kadm5.keytab\r\n                acl_file = \/var\/lib\/krb5kdc\/kadm5.acl\r\n                key_stash_file = \/var\/lib\/krb5kdc\/.k5.EXAMPLE.COM\r\n                kdc_ports = 750,88\r\n                max_life = 10h 0m 0s\r\n                max_renewable_life = 7d 0h 0m 0s\r\n                default_principal_flags = +preauth\r\n        }\r\n\r\n[logging]\r\n        kdc = FILE:\/var\/log\/kerberos\/kdc.log\r\n        admin_server = FILE:\/var\/log\/kerberos\/kadmin.log<\/pre>\n<p>Replace &#8220;EXAMPLE.COM&#8221; with your own realm name. Also note that some of the options above are changed from their default values. I have added a logging section at the end and changed the directory where things reside.<\/p>\n<p>An important difference is that the <code>default_principal_flags<\/code> has been set to +preauth. The reason for this is that without it, <a href=\"http:\/\/tools.ietf.org\/html\/draft-ietf-krb-wg-preauth-framework-17#section-5.4\" target=\"_blank\">Kerberos is vulnerable to offline dictionary attacks<\/a>. If you are going to have your KDC\u00a0publicly\u00a0accessible, then you definitely want to consider enabling preauthentication. In my opinion, you probably want this even if the KDC is <strong>not<\/strong>\u00a0publicly\u00a0accessible, but that&#8217;s because I trust no one.<\/p>\n<p>After modifying <code>\/var\/lib\/krb5kdc\/kadm5.acl<\/code> to your liking, you can go ahead and create the database.<\/p>\n<pre>cd \/var\/lib\/krb5kdc\r\nkdb5_util create -r EXAMPLE.COM -s<\/pre>\n<p>As usual, make sure you use your realm name.<\/p>\n<h4>Principal Creation<\/h4>\n<p>I&#8217;ll leave this as an exercise for the reader. I generally create varying policies for services and users and those won&#8217;t be entirely useful for most. For a really good guide on creating\/using policies, see\u00a0<a href=\"http:\/\/techpubs.spinlocksolutions.com\/dklar\/kerberos.html#id2500817\">http:\/\/techpubs.spinlocksolutions.com\/dklar\/kerberos.html#id2500817<\/a>.<\/p>\n<h4>Start Kerberos Server<\/h4>\n<p>To start the kdc and kadmind servers, run the following.<\/p>\n<pre>\/etc\/init.d\/mit-krb5kadmind start\r\n\/etc\/init.d\/mit-krb5kdc start<\/pre>\n<p>Add them to the default runlevel so that they start up after a reboot<\/p>\n<pre>rc-update add mit-krb5kadmind default\r\nrc-update add mit-krb5kdc default<\/pre>\n<h3>Installing NFSv4 client<\/h3>\n<p>First install the nfs client utilities<\/p>\n<pre>emerge -av nfs-utils<\/pre>\n<p>You will want to make sure you have both the <strong>kerberos<\/strong> and the <strong>nfsv4<\/strong> USE flags enabled.<\/p>\n<h4>Configuring the kernel<\/h4>\n<p>You will need to configure the kernel with the appropriate relevant options. I won&#8217;t bother going through that entire process. Rather, I&#8217;ll point out some things that went wrong for me, but weren&#8217;t immediately obvious.<\/p>\n<p>The kernel needs to have the rpcsec_gss_krb5 option configured as a module. I spent quite a while debugging this problem. I had the option compiled directly into the kernel.\u00a0Looking in the nfs client&#8217;s syslog, I also found this obscure error message.<\/p>\n<pre>gss_create: Pseudoflavor 390003 not found!\r\nRPC: Couldn't create auth handle (flavor 390003)<\/pre>\n<p>Whatever the hell that means. Surprisingly, there are very few references to this error. One of them I found suggested recompiling the kernel with the\u00a0rpcsec_gss_krb5 module and simple loading it after boot. Surprisingly, this actually worked.<\/p>\n<h4>Adding nfs principals<\/h4>\n<p>Both the nfs server and the nfs client need nfs principals added to their krb5.keytab. Since my nfs server was running an older kernel (Ubuntu 10.04), I needed to do a couple things to get this to work.<\/p>\n<p>First, you need to add an nfs principal for both the client and the server. In my case, the server needed an encryption type which isn&#8217;t generated by default on a Gentoo Kerberos server. Therefore, I generated the principal like this.<\/p>\n<pre>addprinc -policy service -randkey -e \"des-cbc-crc:normal\" nfs\/nfsserver<\/pre>\n<p>Since I had a service policy defined, this created the nfs\/www.siriad.com principal with the &#8220;des-cbc-crc&#8221; encryption type. This is necessary for the older version of nfs that is available for Ubuntu 10.04. You then need to login to the nfs server, run kadmin, and do the following.<\/p>\n<pre>kadmin: \u00a0ktadd -e des-cbc-crc:normal nfs\/nfsserver<\/pre>\n<p>This will add the entry to your nfs server&#8217;s host keytab. Using this encryption type is extremely important. If you don&#8217;t, you will probably end up with very cryptic errors like the ones I had.<\/p>\n<pre>rpc.svcgssd: ERROR:\u00a0prepare_krb5_rfc_cfx_buffer: not implemented\r\nrpc.svcgssd: ERROR: failed serializing krb5 context for kernel\r\nrpc.svcgssd: WARNING: handle_nullreq: serialize_context_for_kernel failed<\/pre>\n<p>This indicates that the NFS server has not implemented the encryption types being used in your keytab.<\/p>\n<p>Now you just need to add an nfs principal for your client. In this case, Gentoo had support for the more recent encryption types, so I didn&#8217;t need to do anything special. I just created the principal.<\/p>\n<pre>addprinc -policy service -randkey nfs\/nfsclient<\/pre>\n<p>then added it to the client&#8217;s host keytab using kadmin on the client<\/p>\n<pre>kadmin: \u00a0ktadd nfs\/nfsclient<\/pre>\n<p>Lastly, you need to make sure you allow for weak encryption types in the <code>\/etc\/krb5.conf<\/code> file. Add the following to the <code>[libdefaults]<\/code> section.<\/p>\n<pre>allow_weak_crypto = true<\/pre>\n<h4>Setting up the NFS server<\/h4>\n<p>First, you need to allow for weak encryption types on the NFS server. You can do this by modifying the <code>\/etc\/krb5.conf<\/code> file. You will need to add the following two lines in the <code>[libdefaults]<\/code> section.<\/p>\n<pre>allow_weak_crypto = true\r\npermitted_enctypes = \"des-cbc-crc arcfour-hmac des3-cbc-sha1 aes128-cts-hmac-sha1-96 aes256-cts-hmac-sha1-96\"<\/pre>\n<p>Note that the values listed as permitted are those generated by default on my Kerberos server. Please <strong>DO NOT<\/strong>\u00a0set the default encryption type to the weak encryption. I see far too many howtos that tell you to do this and it is <strong>NOT<\/strong> a good idea. If you can use the stronger encryption for things other than NFS, there is no reason not to.<\/p>\n<p>On the NFS server, you also need to make sure that rpc.svcgssd is set to start alongside NFS. On Ubuntu, you can do this by editing your <code>\/etc\/default\/nfs-kernel-server<\/code> file and editing\/modifying the following line.<\/p>\n<pre>NEED_SVCGSSD=yes<\/pre>\n<p>You will also need to edit the following line in the <code>\/etc\/default\/nfs-common<\/code> file.<\/p>\n<pre>NEED_IDMAPD=yes<\/pre>\n<p>Edit the <code>\/etc\/idmapd.conf<\/code> file and set the Domain line to the appropriate value for your environment. Make sure you restart rpc.idmapd if necessary.<\/p>\n<p>Lastly, you need to modify \/etc\/exports with the appropriate values. My export looks something like this.<\/p>\n<pre>\/export\/dir        gss\/krb5(rw,fsid=0,insecure,no_subtree_check)<\/pre>\n<p>You can then restart the nfs-kernel-server service and your NFS server should be ready to go.<\/p>\n<h4>Setting up the NFS client<\/h4>\n<p>You need to first make sure that rpc.idmapd and rpc.gssd are set to start with nfs. Edit your <code>\/etc\/conf.d\/nfs<\/code> file and modify the following line.<\/p>\n<p>NFS_NEEDED_SERVICES=&#8221;rpc.idmapd rpc.gssd&#8221;<\/p>\n<p>You will need to edit <code>\/etc\/idmapd.conf<\/code> with the same information from the NFS server. Then you can <code>\/etc\/init.d\/nfs restart<\/code> and test your NFS mount.<\/p>\n<h4>Testing your NFS mount<\/h4>\n<p>You can now test your nfs mount with the following command<\/p>\n<pre>\u00a0mount -vvv -t nfs4 -o sec=krb5 nfsserver:\/ test\/<\/pre>\n<p>This should work successfully and you should be able to see the appropriate requests coming through in your KDC logs.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I was unable to find any guides which accurately described setting up a NFSv4 client with Kerberos on Gentoo. There are guides for setting things up on other distros, but I have run into numerous issues which were directly related to using Gentoo. Therefore, I am going to use this guide to document some of <a href='https:\/\/www.soljerome.com\/blog\/2011\/08\/31\/gentoo-nfsv4-and-mit-kerberos\/' class='excerpt-more'>[&#8230;]<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[12,17,16,3],"tags":[],"_links":{"self":[{"href":"https:\/\/www.soljerome.com\/blog\/wp-json\/wp\/v2\/posts\/223"}],"collection":[{"href":"https:\/\/www.soljerome.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.soljerome.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.soljerome.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.soljerome.com\/blog\/wp-json\/wp\/v2\/comments?post=223"}],"version-history":[{"count":14,"href":"https:\/\/www.soljerome.com\/blog\/wp-json\/wp\/v2\/posts\/223\/revisions"}],"predecessor-version":[{"id":235,"href":"https:\/\/www.soljerome.com\/blog\/wp-json\/wp\/v2\/posts\/223\/revisions\/235"}],"wp:attachment":[{"href":"https:\/\/www.soljerome.com\/blog\/wp-json\/wp\/v2\/media?parent=223"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.soljerome.com\/blog\/wp-json\/wp\/v2\/categories?post=223"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.soljerome.com\/blog\/wp-json\/wp\/v2\/tags?post=223"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}