NFS/Kerberos
Kerberos は NFS に利用可能な数少ないセキュリティメカニズムの一つです。Kerberos は強力なユーザー認証とデータ暗号化を提供し、NFSv4 を使用することでクライアントとサーバー間の UIDs/GIDs の一致が不要になります。
Kerberos には NFSv4 が推奨されます。NFSv3 で Kerberos を有効にすることは可能ですが、補助的な NFSv3 プロトコル(例えば「マウント」プロトコル)がセキュアでないため、100% のカバレッジは提供されません。また、NFSv3 には idmapping がないため、Kerberos の使用性が大幅に低下します。
前提条件
Kerberos は KDC (Key Distribution Center)サービスがどこかで動作している必要があります。MIT Kerberos (krb5)に付属する krb5-kdc.service は、Active Directory や FreeIPA のような複雑さが必要ない小規模設定に適しています。2 番目のオプションは Heimdal で、一部の BSD や Arch 上の heimdalAUR で見つかります。
Kerberos と共に NFSv4 の idmapping がとても重要になります。サーバーとクライアントはどちらも同じ idmapping ドメインを設定している必要があります:
/etc/idmapd.conf
[General] Domain = example.com
Server configuration
Each NFS server needs a Kerberos principal for nfs/server.fqdn to be created on the KDC, and its keys added to the server's /etc/krb5.keytab.
fileserv# kadmin -p frob/admin Password for frob/admin@EXAMPLE.COM: ********* kadmin: addprinc -nokey nfs/fs.example.com kadmin: ktadd nfs/fs.example.com
gssproxy.service must be enabled and started on the server.
gssproxy comes pre-configured with NFS server support (the /etc/gssproxy/24-nfs-server.conf file is part of the standard package) and does not need any tweaking, other than placing the NFS service keytab in the standard location.
Your /etc/exports should offer the Kerberos authentication flavors in the sec= option:
/home *(rw,sec=krb5p) /usr 10.147.0.0/16(rw,sec=krb5p:krb5i:krb5:sys) *(rw,sec=krb5p)
The available flavors are:
krb5pprovides 'privacy' (Kerberos-based encryption). It is sufficiently secure to be used over Internet, but might provide poor throughput over a LAN – consider usingkrb5inside RPC-with-TLS instead.krb5iprovides 'integrity' (Kerberos-based MAC) but not encryption. It might be useful for serving static data as it still protects against packet tampering.krb5provides only authentication, without data integrity or encryption. It is a good choice if you have RPC-over-TLS enabled viaxprtsec=or if Kerberos is being run over an otherwise "secure" LAN (e.g. over a WireGuard tunnel), but certainly not in the clear over public networks.sysis the traditional UID-based (non-Kerberos) NFS security mode.
Client configuration
In addition to users, each NFS client should have a machine Kerberos principal in /etc/krb5.keytab, which will be used in situations where user Kerberos tickets are not yet available – in particular, it will be needed to actually mount the filesystem at boot time before any users have logged in yet (or if mounting is done via autofs). More generally, all operations done "as root" will be authenticated as the machine principal.
Unlike in the server case, the client machine does not need an nfs/ principal specifically – it is enough to have the generic host/the.fqdn principal. (See the rpc.gssd manual page for what it looks for.)
The client must have rpc-gssd.service active (i.e. the rpc.gssd daemon).
Options used when mounting the filesystems are very similar to the options used in /etc/exports; you can specify one or more flavors using the sec= option. Although the client will automatically use the strongest mode offered, it is nevertheless recommended to explicitly require e.g. sec=krb5p to prevent downgrade attacks.
Once the filesystem has been mounted, root may already access it (using the machine's Kerberos credentials), but every non-root user needs their own Kerberos tickets to be present. This means either having the user manually run kinit for themselves, or setting up pam-krb5 to acquire tickets during login (which only works for password-based logins), or using gssproxy or k5start(1) (from kstartAUR) to acquire tickets from a keytab file.