|
|
Log in / Subscribe / Register

Using certificates for SSH authentication

November 8, 2022

This article was contributed by Lars Wirzenius

SSH is a well-known mechanism for accessing remote computers in a secure way; thanks to its use of cryptography, nobody can alter or eavesdrop on the communication. Unfortunately, SSH is somewhat cumbersome when connecting to a host for the first time; it's also tricky for a server administrator to provide time-limited access to the server. SSH certificates can solve these problems.

Verification

The OpenSSH project maintains what is, in practice, the reference implementation of the SSH protocol. In the default configuration, its SSH client asks the user to verify the server's identity (its "host key") when first connecting to it, by examining a key fingerprint, which is a secure checksum for the server's public key:

    The authenticity of host 'stamina (10.2.2.176)' can't be established.
    ED25519 key fingerprint is SHA256:cawPF9UX0DwRb5F1kr55JkQ9xNNXZEeqG8MtuV82dRU.
    Are you sure you want to continue connecting (yes/no/[fingerprint])?

The user is asked to verify the host key by comparing long strings of hexadecimal. In the example, the fingerprint is the letters and numbers after SHA256:. This manual check is tedious and error-prone.

There are alternatives to checking the fingerprint manually. The server administrator can publish a list of host keys for their servers, in a format that the client can use in its "known hosts" file. The file could even be updated by a centralized IT department on the user's machine. If there is no centralized IT, the user could update the list themselves. There's also a way to publish the host keys over DNSSEC, to avoid having to update known-host lists on user machines.

But what usually happens is that the user answers "yes" by reflex.

Authentication

The user then needs to authenticate themselves to the server. Traditionally this has been done using passwords, but passwords are a security weakness. Humans just aren't good at remembering secure passwords. SSH allows key-based authentication, which can be much more secure. By default, this works by the user maintaining a file with authorized public keys in their home directory on the server.

At login time, if the user's client can prove to the server that the user has a private key corresponding to one of the keys listed, the user can log in without a password. Overall, this is a big win for security, except for the first time a user accesses the server. How can they add their public key to the list of authorized keys before they can log in?

For this, too, there are alternatives. An organization might centrally collect the public keys of their users. The server administrator could use this to maintain the list of authorized keys for each user. This solves the first-login situation. However, all of these alternative mechanisms need to be added on top of SSH; they also need to be developed and maintained.

In principle, a host's key never changes. Sometimes, it does, however. For example, a server might be replaced, reinstalled, or its domain name changed to refer to a new one. This happens often with virtual machines and in the cloud environment. The server might also be a board used for embedded-system development, where the operating system gets replaced from time to time.

Likewise, a user may need to get a new key for various reasons. They might accidentally post their private key on social media, or just lose the file and not have backups. If nothing else, attacks on cryptography only get stronger and, over time, a strong key will become weaker, resulting in a need to generate a new key, with newer, stronger cryptography.

Certificates

OpenSSH supports an "SSH certificate", which includes an SSH public key along with some metadata related to the key, all cryptographically signed by a trusted party. The certificate is used instead of the SSH public key when connecting, though the corresponding private key is still needed in order to complete the connection; the included signature allows the key to be trusted without manual checking. The trusted party is typically the server system administrator, who controls access to their servers. They create an SSH key dedicated for use as a certificate authority (or CA), and use that key to create host and user certificates. A CA key is just a plain SSH key, created with ssh-keygen, like any other SSH key. The CA key is used to sign (ssh-keygen -s) host and user keys, creating certificates.

The system administrator configures their servers to provide host certificates and to trust user certificates made by the CA, while users configure their clients to trust host certificates signed by the CA. This allows a user to trust a host's identity without having to manually verify the host key. It also allows a server to authenticate a user without passwords, or without the user's public key being in a list of trusted keys for that user. Almost.

There is still one step where some trust needs to be established in a way that isn't automated. How does a CA get a user's public key and how does the user get the CA's public key in a secure way? There's no generic, scalable solution for this, but the problem is somewhat simplified because it only needs to be done rarely.

A solution for this initial exchange of public keys will build on existing trust relationships. Perhaps the parties have OpenPGP keys and can use the Web of Trust for this? Maybe they can access the same intranet of the organization? It might even be enough to rely on TLS and get public keys over HTTPS.

Note that the SSH CA mechanism does not require or support a network of globally trusted certificate authorities the way that TLS does. This means it can be used without paying, or at least involving, a third party, but also means that obtaining the CA key is a manual process. An SSH client does not come with a list of implicitly trusted SSH certificate authorities.

The SSH certificate doesn't work on its own, just like a public key doesn't: the party presenting a certificate must prove (using cryptography) that they have the corresponding private key. The metadata in a certificate makes certificates more useful than plain public keys, however. An SSH public key does not specify which host or user it belongs to, for example, whereas a certificate has a list of "principals" that it vouches for. A principal is a host or user name. The metadata in a certificate can be examined with ssh-keygen -L.

    Type: ssh-ed25519-cert-v01@openssh.com host certificate
    Public key: ED25519-CERT SHA256:V/jJ9f+0sxWuK4Kmjr9x26OUmrQV+pPE8PmnKnFL650
    Signing CA: ED25519 SHA256:6qIHXzaIX8CJ0jO/Iv0rvhZIlwaWxmOVItuD+973HUI (using ssh-ed25519)
    Key ID: "certificate for host stamina"
    Serial: 0
    Valid: from 2022-11-03T10:02:00 to 2023-02-01T10:03:26
    Principals: 
	    stamina
    Critical Options: (none)
    Extensions: (none)

Certificates can have a validity period, which allows them to automatically expire without having to be explicitly revoked. OpenSSH does support revocations, but revocation information can be difficult to communicate to all parties in a fast, reliable way. A common way to sidestep the need for revocation lists is to use short-lived certificates (this is what Let's Encrypt does for TLS certificates). For example, a continuous-integration (CI) worker process might be given a certificate for deployment that only lives for 60 seconds. A student at a university might get one that is only valid for a semester, while an employee might get one that is only valid during working hours of that specific day.

Short-lived certificates are only useful, of course, if a user can get a new one when they need it. For example, a company might store the public keys of all its employees in a secure database and then automatically issue a new one-day certificate to employees every morning. The employees can even retrieve it from an unauthenticated web server. Certificates don't contain any secrets, and they only work with specific private keys, so the transport doesn't necessarily need to be protected strongly.

User certificates can also be tied to specific IP addresses or restrict the commands that the user can invoke. This further limits the damage an attacker can cause if they can steal someone's private key.

Certificate management

Managing the SSH CA infrastructure can be done using only the tools provided by OpenSSH, particularly ssh-keygen. The man page (and the certificates section in particular) has all of the necessary information, though in quite a dense form. There are various HOWTO documents around the Internet to explain things in more accessible ways; I maintain a HOWTO for SSH CA and the OpenSSH Cookbook has a section on SSH CA too.

The SSH CA mechanism first appeared in OpenSSH version 5.4 in 2010, so it has been around for quite some time at this point.

An organization (or even just a solitary system administrator) with many hosts or many users may want to create automation around ssh-keygen. This will allow securely managing a collection of host and user public keys, as well as CA private keys, in order to conveniently and quickly issue certificates on demand. SSH certificates can then be integrated into configuration management with ease. I am in the process of developing such tooling, creatively called sshca, and would appreciate feedback.

Conclusion

SSH certificates are a way to make the use of SSH more convenient and more secure at the same time. The technology is widely available, and implementing it for an organization is straightforward, at least from an SSH point of view. For anyone who is struggling with the key-management aspects of SSH, it is a mechanism that is worth investigating.


Index entries for this article
GuestArticlesWirzenius, Lars


to post comments

Using certificates for SSH authentication

Posted Nov 8, 2022 17:58 UTC (Tue) by scientes (guest, #83068) [Link] (4 responses)

I would really like to see a communication system that transfers keys by NFC.

Using certificates for SSH authentication

Posted Nov 8, 2022 18:14 UTC (Tue) by bferrell (subscriber, #624) [Link] (1 responses)

How does the work across the internet?

Using certificates for SSH authentication

Posted Nov 9, 2022 1:40 UTC (Wed) by mathstuf (subscriber, #69389) [Link]

Once we get that "punch other users across the internet" feature ("Network Face Connection"?) that was so wanted back in the Usenet days, you can just hold your phone in your hand and stop an inch or so in front of whatever you need to scan.

Using certificates for SSH authentication

Posted Nov 9, 2022 10:46 UTC (Wed) by mkj (subscriber, #85885) [Link] (1 responses)

What kind of devices would you use it with? Configuring routers always seems like a bit of a chicken-and-egg problem, NFC could be an interesting option. The hardware mightn't be cheap enough though to get it added.

Using certificates for SSH authentication

Posted Apr 21, 2023 9:48 UTC (Fri) by sammythesnake (guest, #17693) [Link]

I don't think hardware cost is much of an issue, even at single unit prices they're less than a tall flat white and presumably somewhat less in bulk (https://www.google.com/search?q=nfc+reader&tbm=shop). Most mobile phones have NFC already, so adding it to a laptop or an access terminal isn't much of an ask. There are keyboards with integrated ID card readers which are basically the same thing.

On the other hand, Bluetooth, WiFi, USB (for key dongles) and QR codes are all somewhat more commonly available and could do the job (perhaps combined with "enter this code to confirm"). Android phones use QR codes to share WiFi connection details, for example, and WhatsApp uses them to connect to the web client, which is a pretty similar authentication pattern...

Using certificates for SSH authentication

Posted Nov 8, 2022 18:19 UTC (Tue) by Cyberax (✭ supporter ✭, #52523) [Link] (7 responses)

One thing that is really interesting is that you can use very short-lived certificates produced by your organization's single-sign-on system. This way you can avoid any static credentials on developers' machines.

Using certificates for SSH authentication

Posted Nov 8, 2022 19:25 UTC (Tue) by joib (subscriber, #8541) [Link] (2 responses)

There are a couple of commercial/open core projects that do this, teleport and smallstep come to mind. I think hashicorp vault also has something related to ssh cert management.

Using certificates for SSH authentication

Posted Nov 8, 2022 20:37 UTC (Tue) by Cyberax (✭ supporter ✭, #52523) [Link]

Uber has open-sourced its version: https://medium.com/uber-security-privacy/introducing-the-...

We have our own version that I hope to push to open source, but it's typically very tied to the company's infrastructure.

Using certificates for SSH authentication

Posted Nov 11, 2022 21:35 UTC (Fri) by dbnichol (subscriber, #39622) [Link]

Indeed Vault does - https://developer.hashicorp.com/vault/docs/secrets/ssh/si.... I've never used that engine, but we use it for lots of other things. Since it also has a wide variety of authentication methods, you can configure it in a way that fits your organization.

Using certificates for SSH authentication

Posted Nov 9, 2022 9:55 UTC (Wed) by grawity (subscriber, #80596) [Link] (3 responses)

I've always thought that such systems just reinvent Kerberos (which SSH has supported for quite a while now). Is there a specific advantage in using SSH certificates instead?

Using certificates for SSH authentication

Posted Nov 9, 2022 10:10 UTC (Wed) by anselm (subscriber, #2796) [Link]

You can do without the inconvenience and expense of setting up and maintaining a Kerberos infrastructure.

Using certificates for SSH authentication

Posted Nov 9, 2022 15:58 UTC (Wed) by Cyberax (✭ supporter ✭, #52523) [Link] (1 responses)

Anything that uses a trusted third party to produce and validate authentication tokens looks like Kerberos.

Kerberos is something that JustDoesn'tWork(tm). Quite simply. It can go wrong in many, many different ways that are impossible to debug. For example, I once spent a week debugging Putty only to find out that it linked with Heimdall Kerberos libraries instead of MIT Kerberos.

And Kerberos is also very hard to set up. And there's also very little support for 2FA in common tools like kinit. Etc.

Additionally, Kerberos requires constant connection to the KDC, while SSH CAs just need to be able to put the CA root certificate on machines once (it can even be baked-in during the image creation). You don't need to enroll instances individually (although it might be a good idea, for machine certs).

Using certificates for SSH authentication

Posted Nov 9, 2022 22:19 UTC (Wed) by AdamW (subscriber, #48457) [Link]

There's always FreeIPA, which handles most of the kerberos messiness for you and provides a lot of handy stuff around it.

Using certificates for SSH authentication

Posted Nov 8, 2022 18:25 UTC (Tue) by riking (subscriber, #95706) [Link]

> For example, a company might store the public keys of all its employees in a secure database and then automatically issue a new one-day certificate to employees every morning. The employees can even retrieve it from an unauthenticated web server.

Or, throw in security keys and online signing and you get: Resident certificate on security key support + password challenge-response + password challenge transcript must be signed by the key + effective screen locks => 2FA assurance for SSH

Using certificates for SSH authentication

Posted Nov 8, 2022 21:02 UTC (Tue) by jonesmz (subscriber, #130234) [Link] (9 responses)

There is a patch series to make OpenSSH support x509 certificates, which is available easily on distros like Gentoo.

I think a brief discussion of that in the main text would be worth having.

Using certificates for SSH authentication

Posted Nov 8, 2022 21:13 UTC (Tue) by mjg59 (subscriber, #23239) [Link] (4 responses)

OpenSSH upstream has been pretty clear about not wanting to support that for understandable reasons (asn.1 parsing is extremely hard to get right). Thankfully it's possible to do this without having to patch OpenSSH - https://github.com/mjg59/ssh_pki (I do not recommend doing this)

Using certificates for SSH authentication

Posted Nov 8, 2022 23:47 UTC (Tue) by mss (subscriber, #138799) [Link] (2 responses)

asn.1 parsing is extremely hard to get right
I guess you mean BER here, since that's how X.509 certificates are usually encoded.

One is supposed to use a well-established library for doing such parsing (no new hand-crafted parsers in C please), so the main issue here is whether the project could take an additional external dependency.

Using certificates for SSH authentication

Posted Nov 9, 2022 5:43 UTC (Wed) by buck (subscriber, #55985) [Link]

> I guess you mean BER here, since that's how X.509 certificates are usually encoded.

Wouldn't it be DER, so there's no choice of whether to use indefinite-length encoding and other such things that lead to a multitude of possibilities for finding hash collisions? Or maybe it's just whatever the PKCS or IETF specs say, more to the point.

At any rate, trusting the X.509 public CA ecosystem, while convenient, has its downsides. This recent article (paywalled, after free monthly article limit exceeded, i believe) offers a particularly compelling case study:

Mysterious company with government ties plays key internet role

https://www.washingtonpost.com/technology/2022/11/08/trus...

Using certificates for SSH authentication

Posted Nov 9, 2022 8:33 UTC (Wed) by mjg59 (subscriber, #23239) [Link]

DER is just the serialisation of the asn.1 data, and even well-established parsers have had bugs. That's why my approach (which, again, I do not recommend people use) has that done out of process in a language that's rather less vulnerable to the standard parsing fuckups.

Using certificates for SSH authentication

Posted Nov 9, 2022 20:25 UTC (Wed) by edeloget (subscriber, #88392) [Link]

For those interested, there is a whole ssh clone out there which already allows the use of X.509 certificates. It's based upon openssh and has been maintained for years (and, hopefully, will continue to be maintained).

https://roumenpetrov.info/secsh/

Using certificates for SSH authentication

Posted Nov 8, 2022 22:41 UTC (Tue) by ras (subscriber, #33059) [Link] (3 responses)

> There is a patch series to make OpenSSH support x509 certificates, which is available easily on distros like Gentoo.

I'm curious, what is the motivation?

I've struggled for literally days to create x509 certificates that some application (like OpenVPN, or IPSec) will accept. Maybe parsing asn.1 is hard as mjg59 says, but I've had to do it ISO 7816 card and, well, at the end of the day it's just a binary format. It never caused me a real world issue when using x509.

It was the complexity of x509 itself and it myriad of options that cause the issues. You have mind read useless error messages, and go on whumpus hunts for OID's that no one has every heard of to set options or flags some programmer apparently decided was necessary. Yet as far as I could tell, I could tell those options had no effect whatsoever on security. For example flags like "may be used to sign other certificates" may be useful for x509 PKI, but are of no use whatsoever outside of it - yet applications will insist on them being set one way or the other. Trying to get two ends of a IPSec connection to agree on what was a valid x509 cert sometimes seemed like it would be impossible.

After dealing with that, the simplicity of "just give me a raw key pair please" that ssh and wireguard employ is a breath of fresh air. The only reason I could think of for using x509 is you wanted to plug into the existing CA / PKI system.

Using certificates for SSH authentication

Posted Nov 8, 2022 23:37 UTC (Tue) by Cyberax (✭ supporter ✭, #52523) [Link]

X.509 allows multiple signers and some control of the subject name matching.

Using certificates for SSH authentication

Posted Nov 10, 2022 14:27 UTC (Thu) by esemwy (guest, #83963) [Link] (1 responses)

It’s more that the complexity of ASN.1 makes it prone to exploitable bugs in individual implementations. Even mature libraries are regularly patched for common vulnerabilities.

Using certificates for SSH authentication

Posted Nov 10, 2022 21:28 UTC (Thu) by ras (subscriber, #33059) [Link]

There have been vulnerabilities. But I struggle with the "complex" bit. Its just a TLV encoding, which man + dog uses everywhere. There is a some bit twiddling involved. I guess that's because it harks from an era when bits were a precious commodity. But the twiddling is no worse than UTF-8.

The one criticism you can make of it is all that bit twiddling makes decoding slow for a binary format. It's still far faster than JSON.

My problems with ASN.1 have never been due to the format itself. It's simple enough, yet can describe complex data structures with ease. The issue has always been that ISO in particular seems has never been a "less is more" style of place. Their idea of compromise seems to be to accept and every idea into the standard, provided the ideas sponsor throws enough money and man power at them. The problem with ASN.1 is it allows them to get away with that. Which I guess is why they use ASN.1 a lot. Which in turn means as soon as I see something is using ASN.1 I shudder. But not because of ASN.1 itself. It's because the thing it encodes will be a behemoth, with a million different knobs, all of which have to be in exactly the right place for it to work. The icing on the cake is ISO will want to charge you for the document that documents those knobs.

Using certificates for SSH authentication

Posted Nov 9, 2022 0:16 UTC (Wed) by developer122 (guest, #152928) [Link] (1 responses)

>sshca
Missed opportunity to call it cassh ($) I guess. :P

Using certificates for SSH authentication

Posted Nov 10, 2022 13:51 UTC (Thu) by smitty_one_each (subscriber, #28989) [Link]

"Rockin' the casshba / Rock the casshba"

Using certificates for SSH authentication

Posted Nov 9, 2022 0:16 UTC (Wed) by gerdesj (subscriber, #5446) [Link] (1 responses)

"Humans just aren't good at remembering secure passwords."

If only there was a password manager database system that enabled you to have unique passwords per thingie!

(Nearly) All of my managed devices have unique and very long passwords. I could not possibly remember those passwords but they are all "secure". I have a few qualis in this space.

As always - evaluate your risks and fix up any flaws found in a responsible way. If you don't have some skills in house, then buy them in (carefully).

Using certificates for SSH authentication

Posted Nov 9, 2022 10:26 UTC (Wed) by farnz (subscriber, #17727) [Link]

Secure passwords have two problems when compared to certificates:

  1. They're symmetric keys, not asymmetric. If I can intercept enough of your authentication exchange in the clear to grab your password, that's it - the password is compromised. Certificates are asymmetric keys; the actual authentication exchange is based on using the key to encrypt a random chunk of data, thus demonstrating that you hold the other half of the key, so even if I can intercept the authentication exchange, I can't authenticate as you in future.
  2. A good password manager password will use the Base 64 alphabet or similar, for 6 bits per character. That means you need 19 characters of password to match a 2048 bit RSA key or a 224 bit elliptic curve key. To match a 384 bit elliptic curve key (current NSA recommendation for key length until we get post-quantum cryptography), you need a 64 character password. This ends up being a lot larger than most people put in their password manager databases.

The second is easy enough to overcome if you're paying attention - you just ask for very long passwords. The first is not possible to solve - it's inherent in using a shared secret - and means that if you ever send the per-thingie password to the wrong thingie, you have to not only change the password immediately, but also audit the thingie that the password belongs to for attacker behaviour (in case your luck ran out and the attacker was able to read the authentication exchange). With a certificate, this doesn't matter - the authentication exchange isn't enough to pretend to be you.

There's a reason that the big targets (Apple, Google, Facebook etc) are trying to move people to FIDO2 passwordless authentication - this is also a process based on asymmetric encryption, and hence your secret cannot be intercepted.

Using certificates for SSH authentication

Posted Nov 9, 2022 2:51 UTC (Wed) by motk (subscriber, #51120) [Link]

I read this and felt my soul drain away. Not more certificate nonsense, please. Just let me login and work,

Using certificates for SSH authentication

Posted Nov 9, 2022 10:04 UTC (Wed) by Karellen (subscriber, #67644) [Link] (8 responses)

I am wondering why there isn't an option to publish a hosts SSH public key under, e.g. https://<hostname>/.well-known/ssh.pub, and have SSH either check that automatically by default for new hosts, or have a command-line option to check it.

Obviously it won't cover all uses cases, but it ought to be useful for enough of them to be worth considering.

https://en.wikipedia.org/wiki/Well-known_URI

Using certificates for SSH authentication

Posted Nov 9, 2022 18:20 UTC (Wed) by zdzichu (subscriber, #17118) [Link] (6 responses)

There's a DNS record for that https://en.wikipedia.org/wiki/SSHFP_record

Using certificates for SSH authentication

Posted Nov 9, 2022 22:26 UTC (Wed) by Karellen (subscriber, #67644) [Link] (5 responses)

SSHFP requires DNSSEC, which is not as widely deployed as HTTPS. Also, someone who is in a position to configure a server with SSH is very likely to be in a position to configure a static web page on that server to serve the SSH public key. I estimate that they are somewhat less likely to be in a position to configure DNS records for the server, on average.

And I don't see why both couldn't be an option.

Using certificates for SSH authentication

Posted Nov 10, 2022 8:33 UTC (Thu) by matthias (subscriber, #94967) [Link] (4 responses)

> Also, someone who is in a position to configure a server with SSH is very likely to be in a position to configure a static web page on that server to serve the SSH public key.

That is the problem. Someone who is able to deploy a fake ssh server is likely also in a position to configure a static web page on the same server. So now instead of needing a secure way to transfer the ssh key, you need a secure channel to transfer the public key of the https server. DNSSEC is an option, but if you configure this, you can directly use SSHFP. Or you can deploy a CA to manage the https keys. But then, why don't you directly use the CA to sign ssh keys?

And no, the browsers default of trusting every CA on the planet to sign any website on the planet is not really a secure way.

Using certificates for SSH authentication

Posted Nov 10, 2022 9:26 UTC (Thu) by tialaramex (subscriber, #21167) [Link] (3 responses)

> And no, the browsers default of trusting every CA on the planet to sign any website on the planet is not really a secure way.

Theory: The browsers just trust every CA on the planet with no oversight, my team will run our private CA very well.

Practice: m.d.s.policy does provide meaningful oversight and most browsers either tacitly or not do roughly what m.d.s.policy decided

Meanwhile, who is running your private CA? Huh, I thought it was Bob but he left in May. Maybe Sarah has Bob's old laptop? Oh, the CA is just a Perl script on old-web-test-04.example.com. No chance bad guys will find it on there right?

In principle running a CA ought to be fine, in practice it's exactly the sort of thing people are bad at, and so it will usually be done badly.

Using certificates for SSH authentication

Posted Nov 10, 2022 10:44 UTC (Thu) by zdzichu (subscriber, #17118) [Link] (1 responses)

FreeIPA, already mentioned somewhere here, contains a CA. It's easy to build replicated, HA setup, has a web UI, nicely integrates with automation (certmonger, ACME).

Using certificates for SSH authentication

Posted Nov 10, 2022 23:03 UTC (Thu) by tialaramex (subscriber, #21167) [Link]

The documentation at least for the ACME integration talks about this as if it just lets any applicant trigger issuance, which seems like exactly not what you want for a Private CA ?

Using certificates for SSH authentication

Posted Nov 11, 2022 0:36 UTC (Fri) by pabs (subscriber, #43278) [Link]

Uh, trust in browser vendor CA processes might be a little misplaced:

https://lwn.net/Articles/914267/

Using certificates for SSH authentication

Posted Nov 9, 2022 18:20 UTC (Wed) by dankamongmen (subscriber, #35141) [Link]

the SSHFP DNS record seems a superior solution for this?

Using certificates for SSH authentication

Posted Nov 9, 2022 12:39 UTC (Wed) by dtucker (subscriber, #6575) [Link]

> But what usually happens is that the user answers "yes" by reflex.

Instead of "yes", in OpenSSH versions 8.0 or later, you can also paste the expected key fingerprint. If they match it's equivalent to "yes", if not it's equivalent to "no".

It's not as good as a cert verification, but it's better than manually comparing fingerprint bytes.

Using certificates for SSH authentication

Posted Nov 9, 2022 12:46 UTC (Wed) by cortana (subscriber, #24596) [Link] (3 responses)

It'd be interesting to compare a setup using SSH certificates with that other network authentication protocol: Kerberos.

With Kerberos (as configured by FreeIPA, with which I'm most familiar) we have:

* Initial authentication on a user workstation with password, password + OTP or smart card
* Initial authentication can also be linked to an external OpenID Connect identity provider (although you can't yet use this from the GDM login screen, it's more usable when with kinit or SSH with keyboard-interactive authentication, in which case the user can click the URL in their terminal, log in to the IdP in their browser, and then hit enter to receive their TGT & finish logging in
* With a short TGT expiry time & longer renewable lifetime, sssd (running on user workstation) can automatically renew TGTs when they expire - this gives you the ability to lock users out in the middle of the day (say, if the new CEO capriciously decides to fire half the workforce...)
* Kerberos works with lots of other stuff than just SSH so you get SSO for all sorts of protocols (HTTP, NFS, SMB, LDAP, IMAP, SMTP, at home I even use Kerberos to authenticate virsh on my workstation to libvirtd running on servers)
* The amazing pam_sss_gss module can be used in service's auth stacks; for instance, to implement passwordless sudo
* Pretty good integration with Windows which is important for acceptance in enterprises where IdM is likely to be built around Active Directory

Disadvantages:

* Kerberos itself doesn't provide perfect forward security, so if your session keys are stolen they can be used to decrypt network traffic later on
* The GSSAPI path for OpenSSH is not approved by upstream. I don't know all the details of why but I think part of it is that the Kerberos authentication runs as the part of sshd that still runs as root. But it's patched in by Debian and Red Hat & so for most people this isn't a huge concern as long as they install security updates
* It initially seems complex & mysterious to maintain, which is why I rely on FreeIPA to do it for me. Is it harder than running a CA properly, probably not...
* Fragmentation in the Kerberos ecosystem means that you can run into annoying compatibility issues (e.g., on Debian, Samba is built against Heimdal Kerberos, which can't use KEYRING/KCM credentials caches; anything running on the JVM is generally a nightmare to configure, can't use the system-wide credentials cache, can't obtain a TGT using modern authentication so you're stuck with password authentication for obtaining the TGT & imposes obsolete crypto)

Using certificates for SSH authentication

Posted Nov 9, 2022 18:31 UTC (Wed) by iabervon (subscriber, #722) [Link]

I think it's easier than running an X.509 CA properly, but harder than running an SSH CA properly. The difficulty of running a trusted third party is based on the complexity of what it has to judge (plus implementation awkwardness), and SSH is at least as simple on that as Kerberos, while X.509 is really complicated. The fixed structure of a SSH certificate makes it pretty much equivalent in semantic complexity to a Kerberos ticket, and far simpler than most things called "certificates".

Using certificates for SSH authentication

Posted Nov 17, 2022 12:58 UTC (Thu) by zwol (guest, #126152) [Link] (1 responses)

* There is no way (AFAICT) to use an SSH key as the credential with which to request a TGT. You're stuck using a passphrase for the initial authentication process. This is a UX friction point for anyone who has to work with remote hosts managed via Kerberos *and* remote hosts managed via .ssh/authorized_keys -- your ssh-agent does you no good for the former and your local Kerberos tickets do you no good for the latter. And since all the big cloud code hosters are in the latter category for "git push", this in turn means *any Kerberized organization* is probably caught in this irritating catch-22.

Using certificates for SSH authentication

Posted Nov 19, 2022 2:23 UTC (Sat) by rra (subscriber, #99804) [Link]

> There is no way (AFAICT) to use an SSH key as the credential with which to request a TGT.

Not out of the box but it's not particularly difficult to write. I did so at my previous job. Conceptually, it's just a simple ssh forced-command wrapper around kinit against the KDC as the backing store and then returning the resulting TGT for storage in a ticket cache. Maybe a week or two of work.

The hard part in all of these systems isn't the protocols, it's your chain of trust for how you get keys to users, manage them, and revoke them when necessary.

Using certificates for SSH authentication

Posted Nov 9, 2022 21:27 UTC (Wed) by amarao (guest, #87073) [Link] (6 responses)

We use them, but the next thing with certificate, is desire to create user on first login with signed key. Unfortunately, it's not possible now, which is a big bummer. You need to enroll each user on each sever, or use one user for all users.

Using certificates for SSH authentication

Posted Nov 9, 2022 21:49 UTC (Wed) by mjg59 (subscriber, #23239) [Link] (2 responses)

You can use AuthorizedPrincipalsCommand for this, with a bootstrap user - when a user tries to log in as the bootstrap user, extract the user principal from the certificate, create the user, and then exit. The user can now log in. It's a little cumbersome, but it works.

Using certificates for SSH authentication

Posted Nov 9, 2022 21:58 UTC (Wed) by amarao (guest, #87073) [Link] (1 responses)

We've tried. It doesn't work. Ssh consults pam for user existence at key validation time. No user, no auth.

Using certificates for SSH authentication

Posted Nov 9, 2022 22:33 UTC (Wed) by mjg59 (subscriber, #23239) [Link]

Right. You need a separate bootstrap user (which actually exists) to trigger user creation. It's a somewhat clumsy solution, but it avoids needing to pre-create every user everywhere.

Using certificates for SSH authentication

Posted Nov 9, 2022 22:07 UTC (Wed) by unBrice (subscriber, #72229) [Link] (2 responses)

I think you should be able to provision them dynamically with a custom AuthorizedPrincipalsCommand, no? Google (Disclaimer: my employer) uses a custom AuthorizedPrincipalsCommand to allow limiting the scope of a user key without needing to provision a certificate for each machine. This is a slightly different problem but a related one. Code is on GitHub

Using certificates for SSH authentication

Posted Nov 9, 2022 22:13 UTC (Wed) by amarao (guest, #87073) [Link] (1 responses)

Yes, it was my expectations too. The problem is that without existing user it's not possible to authorize it, therefore there is no AuthorizedPrincipalCommand run.

There is a pam module to autocreate user on check, but it's creating random users under Chinese bot scans.

Using certificates for SSH authentication

Posted Nov 10, 2022 12:22 UTC (Thu) by bof (subscriber, #110741) [Link]

Who forces you to allow chinese bots to scan your machines in the first place?

... and now we come to the point of how to distribute ipsets with known-good source IPs securely around the places we care about :-)

Using certificates for SSH authentication

Posted Nov 10, 2022 10:17 UTC (Thu) by abbe (subscriber, #137089) [Link]

We use host certificates for our 1000s of servers signed at the time of deployment. In our known_hosts, there is only one entry:

@cert-authority * ecdsa-sha2-nistp256 XXXXXXXXXXXXXXXXXXXXXX CA

And we never get prompted for host key verification. The only reason we get prompted is if we made a typo, or something is really wrong.

Using certificates for SSH authentication

Posted Nov 11, 2022 11:00 UTC (Fri) by paulj (subscriber, #341) [Link]

Niall Sheridan wrote and maintains an SSH CA, with production use, "cashier": https://github.com/nsheridan/cashier

Using certificates for SSH authentication

Posted Nov 15, 2022 7:06 UTC (Tue) by tilt12345678 (subscriber, #126336) [Link] (3 responses)

“How does a CA get a user's public key and how does the user get the CA's public key in a secure way? There's no generic, scalable solution for this, but the problem is somewhat simplified because it only needs to be done rarely.”

“OpenSSH does support revocations, but revocation information can be difficult to communicate to all parties in a fast, reliable way.”

To me this reads "we propose you manage SSH access in a PKI fashion, only that there is no PKI."

“An SSH public key does not specify which host or user it belongs to, for example, whereas a certificate has a list of "principals" that it vouches for. A principal is a host or user name.”

I fail to find this disclosure desirable.

Using certificates for SSH authentication

Posted Nov 15, 2022 9:55 UTC (Tue) by anselm (subscriber, #2796) [Link]

I fail to find this disclosure desirable.

Tying a public key to a principal is basically what certificates are for. X.509 certificates also contain subject information.

Using certificates for SSH authentication

Posted Nov 15, 2022 16:46 UTC (Tue) by anton (subscriber, #25547) [Link] (1 responses)

“An SSH public key does not specify which host or user it belongs to, for example, whereas a certificate has a list of "principals" that it vouches for. A principal is a host or user name.”

I fail to find this disclosure desirable.

Apparently neither do the OpenSSH maintainers. I have old user public keys that contain username@hostname (which is helpful when weeding out authorized_keys files), and old entries in known_hosts files that contain the FQDN and IP of the host. That's gone or (for known_hosts) encrypted in newer public keys and known_hosts entries.

Makes me wonder if the reasons why they were eliminated also hold for certificates. I guess that in the presence of certificate servers one would need to encrypt the public keys in the files, otherwise one could recreate the information that were intentionally left away from these files by looking the public keys up in a certificate server.

Using certificates for SSH authentication

Posted Nov 19, 2022 2:27 UTC (Sat) by rra (subscriber, #99804) [Link]

Hostnames in known_hosts files were hashed because they were widely used by attackers to build target lists of places where the credentials they just stole were likely to work. I would argue that it's security via obscurity, not a real security control, but it does tend to slow them down.

If you prefer the format without the hashing, you can turn it off in your config (HashKnownHosts).

Using certificates for SSH authentication

Posted Nov 15, 2022 16:50 UTC (Tue) by anton (subscriber, #25547) [Link]

In principle, a host's key never changes. Sometimes, it does, however. For example, a server might be replaced, reinstalled
When we do that, we always install the old host keys on the new server.

Using certificates for SSH authentication

Posted Nov 17, 2022 8:34 UTC (Thu) by eduperez (guest, #11232) [Link]

> But what usually happens is that the user answers "yes" by reflex.

In many of the environments where I have worked, the sysadmins would stare at me with a confused look, when asked them to confirm a fingerprint...


Copyright © 2022, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds