Skip to content

NFS mTLS Client Identities

Chuck Lever edited this page Sep 26, 2026 · 1 revision

NFS mTLS Client Identities

This page records the design behind nfstlskey and the kernel changes proposed alongside it. The userspace half is merged in ktls-utils 1.5.0. The kernel half is a proposal under review as of September 2026, and the sections below say which parts of it are settled and which are still open.

The design was first posted for discussion on linux-nfs in June 2026:

The kernel patches followed as an RFC series in September 2026:

Problem

An xprtsec=mtls NFS mount needs the client to present an x.509 certificate and prove possession of its private key. tlshd performs the handshake in userspace, and the kernel hands it the credentials by keyring serial number over the handshake genetlink upcall.

Before this work, the only way to select a certificate for a particular mount was two undocumented integer mount options:

mount -o xprtsec=mtls,cert_serial=723847,privkey_serial=723848 server:/export /mnt

The administrator loads the certificate and key into a keyring out of band, discovers the serial numbers, and pastes them onto the command line. Serial numbers are opaque, differ across boots, and are easy to transpose. Without them, every mount on the host uses the single certificate and key named in /etc/tlshd/config.

There is also no isolation. tlshd reads the keys with its own credentials, so each key has to grant user read permission, and any tlshd on the host that learns a serial number can read it. The .nfs keyring the NFS client module creates is module-global. Nothing separates one network namespace's credentials from another's.

Design

The network namespace is the isolation domain

tlshd services the handshake genetlink socket of one network namespace, and each namespace that needs kernel TLS runs its own tlshd. The network namespace is therefore the domain tlshd already lives in, and it is the one the design isolates on.

This was the main point of discussion on the RFC thread. Hannes Reinecke argued that the keyring is logically about the filesystem and belongs to the user or mount namespace, and worried that binding to the network namespace restricts future non-network users such as NVMe authentication. Sagi Grimberg agreed with network namespace isolation. The question of whether user or network namespace should own the keyring was put to the namespace maintainers and had no answer on the thread when this page was written. The v2 series keeps the network namespace binding.

The keyring is kernel-held and named by serial number

Each network namespace gets its own .nfs keyring, allocated when the namespace's NFS state is created and held in struct nfs_net. It is held rather than looked up by name because /proc/keys is not namespace scoped. The keyring is owned by the owner of the network namespace's user namespace and grants no permission to anyone else. In a container with its own user namespace, the container's root can provision the keyring and its tlshd can link it, while root on the host cannot write to it without entering that user namespace.

The keyring's serial number travels with each handshake. SUNRPC carries it in the transport's xprtsec_parms, and under the x509 policy the NFS client records its namespace keyring there. The handshake code links that keyring into tlshd's process keyring and sends the serial number in the accept message, and tlshd links it into its session keyring for the duration of the handshake. Both ends of that link already exist: the kernel side in tls_handshake_accept() and the tlshd side in its handling of the accept message.

Possession is what makes the isolation enforceable. Provisioned keys grant no user read permission at all, so a key created in namespace A is absent from B's keyring and unreadable by B's tlshd even if its serial number leaks.

What does not change

The handshake genetlink ABI is unchanged. The cert_serial= and privkey_serial= mount options are unchanged, and tlshd still selects the client certificate and private key on those two serial numbers alone, falling back to the files named in /etc/tlshd/config when neither is set. The keyring change affects only where the serial-named keys may live and who can read them.

tlshd needed one change, which shipped in ktls-utils 1.5.0: the handshake child links the .nfs keyring per handshake rather than at daemon startup. That also removes the ordering problem of starting tlshd before the NFS client module is loaded.

Userspace front end

nfstlskey manages named x.509 client identities and follows the pattern of nvme-cli and cifscreds. It lives in ktls-utils next to tlshd and has a man page, nfstlskey(8). Its final home may be nfs-utils, alongside nfsidmap and nfsconf.

nfstlskey add    <identity> --cert cert.pem --key key.pem
nfstlskey list
nfstlskey remove <identity>
nfstlskey show   <identity>
nfstlskey update <identity> --cert cert.pem --key key.pem

add reads the PEM certificate and key, converts each to DER, and creates two keys of type user on the namespace's .nfs keyring. The type is user because tlshd consumes raw DER through keyctl_read_alloc(). The descriptions are:

nfs:x509:<identity>:cert
nfs:x509:<identity>:privkey

An identity name is any non-empty string without colon, comma, space, or tab. Colons delimit the key description and commas delimit mount options.

show prints cert_serial=N,privkey_serial=M, so a mount command can be written as:

mount -o xprtsec=mtls,$(nfstlskey show <identity>) server:/export /mnt

The intended next step is a mount option that names the identity directly:

mount -o xprtsec=mtls,tls_identity=<identity> server:/export /mnt

mount.nfs would search the .nfs keyring for the two descriptions and pass the existing serial-number options to the kernel. tls_identity= is a userspace convenience only. The raw serial options remain as a documented escape hatch. That option belongs in nfs-utils and is not yet written; show stands in for it.

Open questions

How userspace names the kernel-held keyring. nfstlskey and mount.nfs need the keyring's serial number in order to add and search keys. The candidates, modeled on KEYCTL_GET_PERSISTENT, are:

  1. a new keyctl command that links the caller's namespace .nfs keyring into a destination keyring and returns its serial number;
  2. an NFS-specific request_key key type that the module instantiates to point at the namespace keyring;
  3. a per-namespace serial number exported through procfs, sysfs, or netlink.

The series prototypes option 2. The NFS module registers an nfs_keyring key type whose request_key handler runs in the caller's context rather than upcalling to /sbin/request-key. The description is the constant .nfs, and the instantiated payload is the serial number of the caller's namespace .nfs keyring. The type carries KEY_TYPE_NET_DOMAIN, so a key cached in a session keyring cannot answer for a namespace the caller has since left. Userspace needs two calls:

keyctl request2 nfs_keyring .nfs "" @s
keyctl print <returned key id>

Option 2 was chosen for the prototype because it needs no change outside fs/nfs. Option 1 is the closer match to KEYCTL_GET_PERSISTENT and would take a keyctl number. For option 3, fs/nfs/sysfs.c already carries a netns-tagged nfs_client kobject, so a read-only attribute beside its identifier attribute would be a smaller change than option 2. The difference is that sysfs binds the namespace at mount time, while request_key reads the caller's namespace at call time. nfstlskey as shipped in 1.5.0 uses option 2. On the RFC thread Sagi Grimberg suggested option 2 aligns with how NFS and SUNRPC already look up credentials; the keyrings maintainers had not weighed in when this page was written.

Quota accounting. Keys that userspace adds are quota-charged against a key_user keyed by user namespace, while the keyring lives in nfs_net. Whether that is sane when the user and network namespace boundaries do not coincide is a question for the keyrings maintainers.

One keyring or two. Sagi Grimberg asked whether .nfs and .nvme should merge into one keyring, since tlshd consumes both. Hannes Reinecke objected: NVMe uses pre-shared keys rather than x.509, his pending DH-HMAC-CHAP work uses .nvme with no link to tlshd, and the NVMe x.509 proposal has been shelved. The two keyrings remain separate.

Future work: mTLS-protected NFSROOT

NFSROOT mounts run in the kernel at boot, in the initial network namespace, before any userspace mount.nfs, nfstlskey, or possibly tlshd exists. mTLS for NFSROOT therefore cannot rely on userspace provisioning. The kernel must obtain the client certificate and key itself, most likely from a TPM, and place them on the initial namespace's .nfs keyring before the handshake, with a tlshd available early from the initramfs. The kernel-owned per-namespace keyring is a prerequisite: a userspace-created keyring could not be populated at NFSROOT time. This is out of scope for the initial work, but the design must not foreclose it. See also the NFSROOT item under Design Materials.

Alternatives considered

  • A request-key upcall keyed by server name, on the nfsidmap model. Most NFS-native and needs no mount option, but makes selection automatic rather than per-mount explicit. Worth revisiting if per-server auto-selection is ever wanted.
  • File paths in the mount options, on the strongSwan and wpa_supplicant model. Forces mount.nfs to read key files and load the keyring on every mount, and offers no reusable provisioned identity.
  • Documenting the raw serial numbers only. Does nothing for namespacing.

Clone this wiki locally