Some views on protocols and encryption

May 23, 2023

In the context of encryption for NFS, a good question was raised in the comments for this entry:

This makes me wonder, what is it about file-access protocols that they fundamentally "have to" go through a VPN or be tunneled through SSH, in your opinion, instead of using protocol-integrated security like everything else can? (This is in context of workstation-to-server, not server-to-server.)

That is, why we use SSH-over-Internet instead of Telnet-over-VPN, or for example IMAPS-over-Internet instead of IMAP-over-VPN, trusting their built-in encryption and authentication, but reject the same thing in NFS or SMB?

The start of my views is that encrypted NFS with Kerberos is different from IMAPS or encrypted SMTP because both of the latter are instances of '<X> over TLS', while encrypted NFS with Kerberos is its own bespoke, unique cryptographic protocol and implementation. I like '<X> over TLS' (provided that TLS identities are competently handled), because TLS is a well studied, reasonably well understood, and usually well implemented thing (if you use a common implementation, and everyone should). Bespoke cryptography is something I consider dangerous because historically it's had a rather bad track record (both in implementations and in protocols). A lot of effort from many people and hard lessons learned have gone into TLS, far more than into a niche bespoke system (which encrypted NFS with Kerberos definitely is).

(SSH has both historical and practical reasons to not use TLS, and it's often used in environments where non-mesh VPNs would be difficult to substitute for it.)

But that just pushes the question back one level, to why SMTP and IMAP were able to add TLS while NFS or SMB did not (NFS is apparently starting to support NFS over TLS). One part of my answer is 'agility'. SMTP was able to add TLS because it could add a 'STARTTLS' command to the protocol and get people to use it; IMAP was able to add TLS partly because it could also add a 'STARTTLS' command and partly because it was able to add an entire new TCP port that was 'IMAP over TLS'. As a practical matter, NFS has never had this agility; the existing NFS protocols had no easy place to add the equivalent of EHLO and STARTTLS, and the IP ports to use were either fixed or found in arcane ways that made it hard to add a new port for an all-TLS version.

(Here is a mid 2021 FreeBSD article on their NFS over TLS [PDF].)

A somewhat deeper reason is that TLS is not quite a natural match for NFS. TLS provides an encrypted stream, which works fine for IMAP and SMTP because both of those are already stream protocols. However, NFS is in theory a mostly stateless RPC protocol, although today it's transported over TCP streams. This means that a straightforward version of 'NFS over TLS' is encrypting the (TCP) transport stream, not 'NFS' as such. There are similar protocol challenges with DNS over TLS.

(I suspect that the mere existence of this mismatch helps create arguments over the 'right' way to add TLS or encryption in general to NFS and other such protocols, which of course slows down doing it.)

The deepest reason I see is that we never successfully created a generic 'random TCP streams over encryption' system that could be applied to encrypt something without the cooperation of the protocol. People sort of tried in the form of IPsec, but for various reasons IPsec has not caught on and isn't considered desirable today. Without such a system, (mesh) VPN protocols are the de facto solution if you need to encrypt traffic for a protocol that either hasn't been or can't be upgraded to be transported over TLS (or, if you must, some other commonly used encrypted transport protocol).

VPN protocols are sort of like 'encrypt arbitrary TCP streams without the upper layer caring', but they aren't implemented in a way that makes that transparent. With a VPN, you may need a whole connection establishment and monitoring system, and you need to force the upper layer you care about to go over the VPN in some way through tricks as opposed to simply specifying 'this traffic should be encrypted' (a feature that IPsec did support). Tunneling a protocol through SSH port forwarding is narrower than a full scale VPN but still requires fiddling with how the system behaves to redirect its traffic through the tunnel.

(There are programs that you can use to tunnel arbitrary things over TLS in the manner of SSH port forwarding, but they've become less popular over time. One reason for this may be that more and more things have picked up direct support for TLS; another may be that using TLS exposes you to annoying issues with configuring certificate validation and so on.)

As for why file access protocols specifically seem to have been affected by this, one obvious theory is that it's because file access servers and clients are much more likely to be deeply embedded into the kernel and the system as a whole, and seen as very critical. Deeply embedded and critical systems are hard to wrap and resistant to change (you can't just add libssl to them, and TLS in specific has a bunch of complex requirements for things like certificate validation that people don't want to do in the kernel).

PS: If you must use a non-TLS encrypted transport protocol, consider using the WireGuard protocol. There are user level implementations and in general plenty of people are studying its cryptography, so we can probably have reasonable confidence that it's sound. Or there's QUIC, although QUIC is still quite TLS like for obvious reasons, and even the SSH protocol (again, well studied and there are good server and client implementations that you can drop into your system).


Comments on this page:

From 193.219.181.219 at 2023-05-24 02:53:09:

while encrypted NFS with Kerberos is its own bespoke, unique cryptographic protocol and implementation.

I suppose that's true; although Kerberos encryption in general is also reasonably hardened over the years (with MS Active Directory being a heavy user; e.g. all AD LDAP traffic is Kerberos-encrypted instead of using TLS), but unlike TLS it indeed needs to be custom-integrated into each protocol, e.g. with SunRPC there is certainly a downside that it only encrypts the RPC call payloads but not headers.

(Though in practice for NFSv4, the only visible RPC operation is "COMPOUND", with the real ops inside the secure payload so it doesn't reveal anything really, but I'm not sure whether that's "secure by accident" or "secure by design".)

Similarly with SMBv3, the custom encryption feature does not protect authentication (it uses the auth mechanism to derive keying), so while it is fine with Kerberos, it really does not help much when used with NTLM... (And SMB-over-QUIC is apparently a thing now, but of course only for those who pay for Azure.)

One part of my answer is 'agility'. SMTP was able to add TLS because it could add a 'STARTTLS' command to the protocol and get people to use it; IMAP was able to add TLS partly because it could also add a 'STARTTLS' command and partly because it was able to add an entire new TCP port that was 'IMAP over TLS'. As a practical matter, NFS has never had this agility; the existing NFS protocols had no easy place to add the equivalent of EHLO and STARTTLS

I'm not sure that's right, exactly; for years NFS has had the "NULL" RPC function both to negotiate between existing security mechanisms (if you don't specify the correct one at mount time), and to set up a GSS context for Kerberos (as Kerberos itself is already not completely stateless if you want its integrity or encryption services).

So it appears that's exactly how they implemented RPC-TLS as well – essentially adding a "STARTTLS" pseudo-mechanism to the same NULL operation.

and the IP ports to use were either fixed or found in arcane ways that made it hard to add a new port for an all-TLS version.

For NFSv4 (which only has a single well-known port) I believe it certainly could've been done the same way as with other TLS-ified protocols, e.g. `mount -o tls` could have implied `-o port=XYZ`.

For NFSv2/3, where portmapper was a thing, I suppose it could've been achieved by defining NFS-over-TLS as a new RPC "program"?

This means that a straightforward version of 'NFS over TLS' is encrypting the (TCP) transport stream, not 'NFS' as such. There are similar protocol challenges with DNS over TLS.

This is really the same with all protocols, though. IMAPS doesn't change how IMAP works either, it only encrypts the underlying stream; on the other hand, DNS-over-TCP has always been a thing and putting it inside a TLS tunnel was possible without much change in the way it works.

The deepest reason I see is that we never successfully created a generic 'random TCP streams over encryption' system that could be applied to encrypt something without the cooperation of the protocol. People sort of tried in the form of IPsec, but for various reasons IPsec has not caught on and isn't considered desirable today.

From what I know, IPsec in the form of IKEv2 is quite alright security-wise (a bit less hassle than IKEv1 was, and many of the proprietary tweaks to IKEv1 such as Cisco-style authentication are now built-into IKEv2), though it's still annoying to set up compared to e.g. WireGuard.

Though, I believe much of its apparent complexity comes from the fact that

"as opposed to simply specifying 'this traffic should be encrypted' (a feature that IPsec did support)"

is not merely "possible" but baked hard into Linux IPsec implementations, to the point that it makes simple "VPN-like" usage annoyingly difficult. (Only recently did Linux finally add virtual "xfrmi" interfaces...) If only strongSwan could be asked to give a userspace tun interface like normal.

By cks at 2023-05-24 13:37:20:

The unencrypted IMAP and SMTP protocols are both stream focused protocols. Each starts with a stream setup phase (IMAP login, SMTP EHLO, etc) and proceeds through a series of steps where the state of the stream provides critical context. In both of them, it's clear what happens if the stream is broken for some reason; you have to start over with another stream setup and re-establish the context. NFS is not like this; the TCP stream is an implementation detail of the transport mechanism, not a core element of the protocol (and historically NFS was transported over UDP first). I believe that NFS clients typically use one TCP stream to transport all RPC for a particular server, but they aren't required to. If a NFS TCP connection breaks, re-establishment is supposed to be more or less transparent to the RPC layer, and the stream carries little or no context for the RPC operations.

It's my view that this difference matters. For example, you can argue that the correct thing to encrypt is NFS RPC operations and replies (and then continue to transport them over unencrypted TCP), whereas encrypting only the IMAP or SMTP commands and replies in an unencrypted TCP stream is relatively obviously crazy, partly because the overall integrity of the TCP stream is critical for SMTP and IMAP (since all IMAP and SMTP commands are issued in a context established by the state of the stream; if you can replay or splice in operations you can damage or destroy that state and cause valid commands from the client to go wrong, so the state must be protected).

(I'd argue that the overall integrity of the sequence of NFS RPCs and replies is also of high importance, but I'm not certain I'd win that argument and I'd expect people to try to put together clever RPC level encryption schemes to achieve it instead of encrypting the entire stream.)

Overall I have quite a different view from our blogger on these issues, to summarize:

  • There is a lot of difference between encryption for authentication (where usually encryption costs don't matter much) and for confidentiality.

  • There is no practical alternative for authentication to Kerberos.

  • Kerberos for NFS (and SMB/CIFS, AFS, and other filesystems) authentication works pretty well and has large benefits, such as the ability to enforce user/group access control at the server, plus the other advantages of Kerberos such as the ability to forward credentials.

  • Kerberos for NFS data confidentiality was a mistake, but for some people it was better-than-nothing.

  • Kerberos used to be annoying to setup for the Linux in-kernel driver, but fortunately it is quite easy to setup with the NFS Ganesha implementation, especially with NFS4.

  • IPSEC for data confidentiality works very well (and in part for host authentication), but it has come into widespread usability only with AES+GCM special instructions.

  • Before AES and AES+GCM instructions not only encryption was quite expensive and mostly usable only for authentication, it was also subject to extensive government suppression that made it risky, Therefore the prevalence of special-case encryption and in off-mainstream tools (e.g. Linux and SSH), and mostly anyhow for authentication. SSL initially was itself off-mainstream until it came to the attention of the authorities.

  • Regardless of speed and government suppression, the big problem with any encryption scheme, whether for authentication or confidentiality, is key distribution. The popularity of SSH seems to me largely based not only on its relative initial obscurity, compared to SSL too, but also on its not being associated with any kind of built-in PKI (which is also a significant risk in the hands of the sillies, but also makes it much easier to get into). That is why I think SSH (despite its terrible misdesigns) became far more popular than TELNET+SSL or TELNET+IPSEC, to the ridiculous point that IP-over-SSH is probably far more popular than IPSEC itself.

  • The best chance for IPSEC is accordingly the "strongSwan" implementation, which can use existing public and private SSH key pairs for authentication (AES+GCM with AES-NI for confidentiality) and thus is quite trivial to setup.
Written on 23 May 2023.
« What I see as good options today for encrypted NFS
Encryption for stream based protocols versus 'RPC' protocols »

Page tools: View Source, View Normal, Add Comment.
Search:
Login: Password:
Atom Syndication: Recent Comments.

Last modified: Tue May 23 22:16:46 2023
This dinky wiki is brought to you by the Insane Hackers Guild, Python sub-branch.