Skip to contentSkip to conversation

ktls-utils client address verification and other patches

DISCUSSION Ken Milmore 2 participants 5 messages Jun 8, 2025 Handshake upcall for transport layer security

lore
Share & tools
lore
#0 lore raw

I've been evaluating the use of mtls to secure NFS mounts and have noticed there's a fairly serious limitation:
Any client which has a valid certificate can impersonate a different client, since the server does not verify client address.

This is unfortunate, as I'd like to give different clients access to different NFS shares by naming the clients in /etc/exports, and I'd like to use mtls to ensure that each client not only has a trusted certificate, but that it is only able to access the shares to which it is entitled by /etc/exports. In other words, I want to verify the client host name or address against the client certificate to avoid address spoofing.

I can understand why this is not the default behaviour: In general, a server will not be able to verify clients in this way. But for NFS on a personal or corporate LAN, it is highly desirable.

To this end, I've developed some patches which allow the tlshd server to be configured to instruct GnuTLS to perform client address verification.

Please see patch series here:

https://codeberg.org/kbm0/ktls-utils/commits/branch/verification-patchset

Because the server can only obtain the client hostname by reverse address lookup, and this has security implications, I have been careful to confirm the hostname first by performing a forward lookup in the manner of FCrDNS: We call getaddrinfo() and check that one of the resulting addresses matches the one which was obtained from the reverse lookup. Should this check fail, we reject the certificate.

I've also added an option to use a textualized IP/IPv6 address for verification against the certificate, in cases where no DNS address can be found. This works if the certificate includes the client IP address as an alternative name. It is also possible to use the IP address as the first recourse, and this may be useful in some circumstances - it is possible for client and server to verify each other entirely based on IP addresses with no reliance on DNS, if the certificates are set up correctly.

These behaviours are enabled by setting options in tlshd.conf like so:

[authenticate.server]
verify_peername=true
verify_peeraddr=true

Another issue I came across involves the fact that when a client connects to a server, the server name is passed to GnuTLS for the purposes of SNI. If the client connects with a bare IP or IPv6 address, this is not strictly allowed, as only DNS names may be used for SNI. This causes the server to reject the transaction. I've added an option to omit the SNI in cases where the client is connecting using an IP address:

[authenticate.client]
relax_sni=true

There are some other patches in the series: I wanted to textualize the peer address up front so it can be used for both logging and also for verification.

I also thought some of the processing in netlink.c looked a bit sloppy: Optimistic assumptions were being made about the contents of return buffers when functions like getnameinfo() are called. I have tried to correct these.

I am hoping for some informal review or feedback for these patches in the first instance. I didn't want to just spam the mailing list with them upfront. If there is any interest in them, I will submit them formally.

Thanks,

-Ken. :-)

#1 lore raw
Quoted 42 lines · Ken Milmore

I've been evaluating the use of mtls to secure NFS mounts and have noticed there's a fairly serious limitation:
Any client which has a valid certificate can impersonate a different client, since the server does not verify client address.

This is unfortunate, as I'd like to give different clients access to different NFS shares by naming the clients in /etc/exports, and I'd like to use mtls to ensure that each client not only has a trusted certificate, but that it is only able to access the shares to which it is entitled by /etc/exports. In other words, I want to verify the client host name or address against the client certificate to avoid address spoofing.

I can understand why this is not the default behaviour: In general, a server will not be able to verify clients in this way. But for NFS on a personal or corporate LAN, it is highly desirable.

To this end, I've developed some patches which allow the tlshd server to be configured to instruct GnuTLS to perform client address verification.

Please see patch series here:

https://codeberg.org/kbm0/ktls-utils/commits/branch/verification-patchset

Because the server can only obtain the client hostname by reverse address lookup, and this has security implications, I have been careful to confirm the hostname first by performing a forward lookup in the manner of FCrDNS: We call getaddrinfo() and check that one of the resulting addresses matches the one which was obtained from the reverse lookup. Should this check fail, we reject the certificate.

I've also added an option to use a textualized IP/IPv6 address for verification against the certificate, in cases where no DNS address can be found. This works if the certificate includes the client IP address as an alternative name. It is also possible to use the IP address as the first recourse, and this may be useful in some circumstances - it is possible for client and server to verify each other entirely based on IP addresses with no reliance on DNS, if the certificates are set up correctly.

These behaviours are enabled by setting options in tlshd.conf like so:

[authenticate.server]
verify_peername=true
verify_peeraddr=true

Another issue I came across involves the fact that when a client connects to a server, the server name is passed to GnuTLS for the purposes of SNI. If the client connects with a bare IP or IPv6 address, this is not strictly allowed, as only DNS names may be used for SNI. This causes the server to reject the transaction. I've added an option to omit the SNI in cases where the client is connecting using an IP address:

[authenticate.client]
relax_sni=true

Quoted 8 lines

There are some other patches in the series: I wanted to textualize the peer address up front so it can be used for both logging and also for verification.

I also thought some of the processing in netlink.c looked a bit sloppy: Optimistic assumptions were being made about the contents of return buffers when functions like getnameinfo() are called. I have tried to correct these.

I am hoping for some informal review or feedback for these patches in the first instance. I didn't want to just spam the mailing list with them upfront. If there is any interest in them, I will submit them formally.

Some general comments:

Essentially we don't want to make certificate validation dependent on DNS for any reason, since DNS is easily spoofed. Have you considered putting the client's IP address in it's certificate's SAN field?

Further, there will be plenty of cases where clients obtain their IP address dynamically. In those cases the server needs to perform its certificate validation based solely on what is in the certificate.

But meanwhile, you can post your patches to this mailing list (inline, not as attachments) one at a time, and we can have a look at each individual proposal.

Signature · 1 line
Chuck Lever
#2 lore raw
Quoted 46 lines · Chuck Lever
Quoted 45 lines · Ken Milmore

I've been evaluating the use of mtls to secure NFS mounts and have noticed there's a fairly serious limitation:
Any client which has a valid certificate can impersonate a different client, since the server does not verify client address.

This is unfortunate, as I'd like to give different clients access to different NFS shares by naming the clients in /etc/exports, and I'd like to use mtls to ensure that each client not only has a trusted certificate, but that it is only able to access the shares to which it is entitled by /etc/exports. In other words, I want to verify the client host name or address against the client certificate to avoid address spoofing.

I can understand why this is not the default behaviour: In general, a server will not be able to verify clients in this way. But for NFS on a personal or corporate LAN, it is highly desirable.

To this end, I've developed some patches which allow the tlshd server to be configured to instruct GnuTLS to perform client address verification.

Please see patch series here:

https://codeberg.org/kbm0/ktls-utils/commits/branch/verification-patchset

Because the server can only obtain the client hostname by reverse address lookup, and this has security implications, I have been careful to confirm the hostname first by performing a forward lookup in the manner of FCrDNS: We call getaddrinfo() and check that one of the resulting addresses matches the one which was obtained from the reverse lookup. Should this check fail, we reject the certificate.

I've also added an option to use a textualized IP/IPv6 address for verification against the certificate, in cases where no DNS address can be found. This works if the certificate includes the client IP address as an alternative name. It is also possible to use the IP address as the first recourse, and this may be useful in some circumstances - it is possible for client and server to verify each other entirely based on IP addresses with no reliance on DNS, if the certificates are set up correctly.

These behaviours are enabled by setting options in tlshd.conf like so:

[authenticate.server]
verify_peername=true
verify_peeraddr=true

Another issue I came across involves the fact that when a client connects to a server, the server name is passed to GnuTLS for the purposes of SNI. If the client connects with a bare IP or IPv6 address, this is not strictly allowed, as only DNS names may be used for SNI. This causes the server to reject the transaction. I've added an option to omit the SNI in cases where the client is connecting using an IP address:

[authenticate.client]
relax_sni=true

There are some other patches in the series: I wanted to textualize the peer address up front so it can be used for both logging and also for verification.

Quoted 8 lines
Quoted 5 lines

I also thought some of the processing in netlink.c looked a bit sloppy: Optimistic assumptions were being made about the contents of return buffers when functions like getnameinfo() are called. I have tried to correct these.

I am hoping for some informal review or feedback for these patches in the first instance. I didn't want to just spam the mailing list with them upfront. If there is any interest in them, I will submit them formally.

Some general comments:

Thanks for replying.

Quoted 4 lines

Essentially we don't want to make certificate validation dependent on DNS for any reason, since DNS is easily spoofed. Have you considered putting the client's IP address in it's certificate's SAN field?

Yes, and my "verify_peeraddr" option covers that. But the current implementation of tlshd does not check either host names or addresses at all on the server side. Therefore client A can use its own certificate to impersonate client B simply by using client B's IP address. This is because you are supplying a NULL hostname to gnutls_certificate_verify_peers3() from tlshd_server_x509_verify_function(). AFAICT this results in no checking of the certificate name at all. I've tested this on my LAN and it bears out.

Re the insecurity of DNS, yes, I agree it is insecure *in general*. But once you have forward-confirmed an address you are in essentially the same trust position as any browser connecting to a website via https. I'm not sure why you see that as no better than no verification at all? The difference, of course, is that in our case we can control the trust store, so we only trust a limited population of hosts. But what I'm pointing out here is that all trusted hosts are treated identically, which is not very useful in most setups. I want to check that the client that is connecting to my server actually matches the certificate it is presenting, otherwise we have an impersonation problem.

Additionally, in the sort of LAN situations where NFS is typically used, name lookups can be secured in a variety of ways. I'm simply using /etc/hosts, with my systems on an internal domain that has outside lookups (both forward and reverse) on that domain blocked by dnsmasq, so that is fairly secure. Obviously there is DNSSEC, LDAP and the rest to do this for enterprise setups.

Quoted 3 lines

Further, there will be plenty of cases where clients obtain their IP address dynamically. In those cases the server needs to perform its certificate validation based solely on what is in the certificate.

In a *general* client/server situation, the client may have an ephemeral IP address, or come in via NAT or a proxy or any number of ways that mean the server can't reasonably identify the client. In that case, you obviously wouldn't want to turn these options on. But as I have pointed out above you essentially end up treating all clients as equivalent. You just have to live with that I guess.

But in the specific context of NFS, very often the connection is over a LAN or VPN and the client addresses and names are meaningful, in fact they are *so* meaningful that this is how access to shares is policed within /etc/exports! So these patches cover a very natural use case for NFS. I have made everything optional so there is nothing lost (except for the additional security that you currently don't provide anyway) if you turn the name verification off.

Quoted 6 lines

But meanwhile, you can post your patches to this mailing list (inline, not as attachments) one at a time, and we can have a look at each individual proposal.

Will do. Thanks!

- Ken. :-)

#3 lore raw
Quoted 8 lines · Ken Milmore
Quoted 4 lines · Chuck Lever

Essentially we don't want to make certificate validation dependent on DNS for any reason, since DNS is easily spoofed. Have you considered putting the client's IP address in it's certificate's SAN field?

Quoted 5 lines

Yes, and my "verify_peeraddr" option covers that. But the current implementation of tlshd does not check either host names or addresses at all on the server side. Therefore client A can use its own certificate to impersonate client B simply by using client B's IP address. This is because you are supplying a NULL hostname to gnutls_certificate_verify_peers3() from tlshd_server_x509_verify_function(). AFAICT this results in no checking of the certificate name at all. I've tested this on my LAN and it bears out.

That's correct. The only checking currently done is whether the ingress certificate's trust chain is recognized.

Quoted 3 lines

Re the insecurity of DNS, yes, I agree it is insecure *in general*. But once you have forward-confirmed an address you are in essentially the same trust position as any browser connecting to a website via https. I'm not sure why you see that as no better than no verification at all?

Because NFS clients are frequently assigned ephemeral IP addresses. That is actually a common deployment scenario.

If IP checking is needed, mountd handles that as part of the usual access control, once tlshd has validated the client's certificate.

To date, we have been thinking that if a client loses control of its certificate, the cert should be revoked and the client should be issued a fresh cert. Because in order to use that certificate on another host, the client's private key will have to come with it. So both will have been stolen, quite clearly, thus revocation is probably best.

Quoted 2 lines

The difference, of course, is that in our case we can control the trust store, so we only trust a limited population of hosts.

Actually I expect that a lot of admins will simply get their certs from a third-party CA. So, it's possible to set up a small local CA just for one NFS server and its trusted clients, but I expect that will not be a common deployment scenario outside of testing environments.

Quoted 2 lines

But what I'm pointing out here is that all trusted hosts are treated identically, which is not very useful in most setups.

That is more-or-less by design. tlshd is going to be used by a bunch of systems, not just NFS. tlshd can make decisions about whether a certificate is trusted, but the consumer systems (NFS, NVMe, QUIC) need to make their own choices about authorization.

Our plan is to have tlshd tag the client's handshake result based on filters of the client's certificate fields. The trust store says the cert is good. The tags indicate what "category" of client this is (like, "Subject:O=My company") and then mountd can authorize the access based on the tags returned to the kernel with the handshake result.

I believe this can also filter based on the client's CN or DNS name, if that information is provided in the certificate's SAN field.

I'm working on it right now. See issue #21 for recent traffic, but we've also discussed here on kernel-tls-handshake@ a bit.

Quoted 6 lines

I want to check that the client that is connecting to my server actually matches the certificate it is presenting, otherwise we have an impersonation problem.
Additionally, in the sort of LAN situations where NFS is typically used, name lookups can be secured in a variety of ways. I'm simply using /etc/hosts, with my systems on an internal domain that has outside lookups (both forward and reverse) on that domain blocked by dnsmasq, so that is fairly secure. Obviously there is DNSSEC, LDAP and the rest to do this for enterprise setups.

Quoted 6 lines
Quoted 3 lines

Further, there will be plenty of cases where clients obtain their IP address dynamically. In those cases the server needs to perform its certificate validation based solely on what is in the certificate.

In a *general* client/server situation, the client may have an ephemeral IP address, or come in via NAT or a proxy or any number of ways that mean the server can't reasonably identify the client.

I think it can identify the client by the contents of its certificate.

Quoted 2 lines

In that case, you obviously wouldn't want to turn these options on.
But as I have pointed out above you essentially end up treating all clients as equivalent. You just have to live with that I guess.

The downside of setting these options in tlshd.conf is that they will then apply to /all/ exports on that server. It will also apply to any other system that is using tlshd. That does not seem terribly flexible.

Quoted 4 lines

But in the specific context of NFS, very often the connection is over a LAN or VPN and the client addresses and names are meaningful, in fact they are *so* meaningful that this is how access to shares is policed within /etc/exports! So these patches cover a very natural use case for NFS. I have made everything optional so there is nothing lost (except for the additional security that you currently don't provide anyway) if you turn the name verification off.

I believe authorizing by tags is how we want to approach this problem. tlshd filters validated certificates, and then each subsystem (eg, NFSD) will be responsible for looking at the presented tag list and granting or forbidding access to a shared domain-specific resource.

Signature · 1 line
Chuck Lever
#4 lore raw
Quoted 9 lines · Chuck Lever

If IP checking is needed, mountd handles that as part of the usual access control, once tlshd has validated the client's certificate.

To date, we have been thinking that if a client loses control of its certificate, the cert should be revoked and the client should be issued a fresh cert. Because in order to use that certificate on another host, the client's private key will have to come with it. So both will have been stolen, quite clearly, thus revocation is probably best.

AFAICT a client does not need to lose control of its certificate in order to be compromised. If more than one trusted client exists, each with its own unique certificate, then they are all able to impersonate each other. They do not need to leak their certificates for this to happen.

I don't believe mountd can prevent this, as it will take the client's address on trust. Or have I missed something completely?

Quoted 11 lines

That is more-or-less by design. tlshd is going to be used by a bunch of systems, not just NFS. tlshd can make decisions about whether a certificate is trusted, but the consumer systems (NFS, NVMe, QUIC) need to make their own choices about authorization.

Our plan is to have tlshd tag the client's handshake result based on filters of the client's certificate fields. The trust store says the cert is good. The tags indicate what "category" of client this is (like, "Subject:O=My company") and then mountd can authorize the access based on the tags returned to the kernel with the handshake result.

Quoted 5 lines

I believe this can also filter based on the client's CN or DNS name, if that information is provided in the certificate's SAN field.

I'm working on it right now. See issue #21 for recent traffic, but we've also discussed here on kernel-tls-handshake@ a bit.

That sounds great. If you can tie mount points to the certificate by any sort of identifier then that would solve the problem. Clearly I've tried to use address, as it was already there.

I realise that the approach I've taken here only works in some scenarios, although I suspect the problem I've been trying to solve is shared by a lot of sites using NFS in a non-Kerberised environment.

Having waited a long time for mtls to turn up, I realised on trying it that it doesn't (yet) offer sufficient security beyond clients being "in" or "out" of access; there is no way of securing their access to different mounts. So this seemed like a useful stopgap. Being a good open-source citizen I felt obliged to offer my solution upstream, and I've now done that. It's working well for me as an interim solution, although I'm sure I'll switch to using tags immediately once they are implemented!

Thanks,

Ken. :-)