SSH Emergency Access
smallstep.com
smallstep.com
When you're unable to access machine using your standard SSH keys usually it means that it's highly unlikely that it will be possible to login remotely via other means.
As an emergency login there are two common options:
* in case of cloud: use remote VM console provided by the hosting provider.
* in case of bare-metal: use IPMI to access machine console directly.
service network stop && sleep 10 && service network start #!/bin/bash
iptables -P INPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -P OUTPUT ACCEPT
iptables -t nat -F
iptables -t mangle -F
iptables -F
iptables -X
chmod +x resetfw.shand add it for ex to /etc/cron.hourly directory
This way you can test your iptables rules and they'll get clear at every hour. Once you check they are OK you can delete this cronjob.
(NOTE: I'm typing from memory, haven't tested this)
Or use `at` to run `iptables-restore`. Simpler than setting up a cronjob (and if youre doing it manually, cron has a bunch of gotchas that at least bite me in the ass once in a blue moon).
- Hardware in datacenters with operators who were not experts on the applications running. - All remote access was done using a short term (~1 day) ssh keys. There was an authentication service to generate these.
It was pretty easy to imagine that the authentication service would go down. In this case a selection of people who worked on the infrastructure had longer-term keys on HSMs. (With very high logging and alerting for any use). It would actually make sense for these to be CA keys so that they could access different user accounts or similar.
TL;DR you are assuming a very basic SSH auth setup. As the regular setup gets more complicated having something like this as a backup makes sense.
This is weird. Really weird.
Did that service use a more secure authentication storage than a password protected key?
A process like this allows you to ensure that people have the access they need and makes it easy to get them the privilege separation needed.
There's a few scenarios where I imagined this approach being useful:
* If you have any kind of remote dependency in your SSH auth flow (LDAP, or an online CA, or automated Ansible playbooks to push keys), any of those might fail and render the host otherwise inaccessible.
* It's becoming more common to not ever SSH into machines. So, what if emergency SSH access is the only way to access a host? Some companies even go a few steps further: When a host is SSH'd into, it is considered "tainted by humans", is quarantined and eventually shut down.
* Some hosts should never allow root access to anyone. For example, there's no reason for anyone to have root on a bastion host. So, what if the only way to get root on some hosts is with the emergency key?
While you could use the cloud VM console for emergency access in these cases, having a hardware key provides even more security and would let you turn off cloud VM access.
Of course if you broke your SSHD config, or have a network issue that prevents you from reaching the host, this won't magically fix any of that. IPMI is good for that though.
Almost! I think you meant:
Valid: from 2020-06-24T16:53:03 to 2020-06-24T17:03:03
I'm not sure it's more secure, but I suppose it depends on the provider. Your control of your account's admin key (or password) is the last bastion of security for most providers.
> Of course if you broke your SSHD config, or have a network issue that prevents you from reaching the host, this won't magically fix any of that. IPMI is good for that though.
This is why I just use the providers' emergency management (or IPMI). Easier to have one method of emergency access that always works regardless of the guest. The guest's root (or emergency) account can still have a pretty darned complex password.
This is a reality for me. At work we run a handful of distributed clusters, if anyone does an equivalent of sshing into a box and poking around (in our case, `kubectl exec`), the infrastructure team gets an alert, then follows up with whoever invoked the command. If they are doing debugging, we shift whatever resources they need into dev. If they are not debugging, they will probably get questioned by their boss. (fortunately, most of the time this chat results in, "oh wow I didn't know about the APM/Metrics/Graphs/Logs/etc setup we had, I'll check that next time)
Having an emergency method to connect is an excellent idea.
Has this approach ever been taken by server admins?
@hourly <username> ssh-import-id gh:<github username>
If I lose my keys to this host, I can simply update github.com with my new ones and go to lunch. I'll be able to login again shortly.And on all of my hosts:
@reboot <username> ssh-import-id gh:<github username>
This is REALLY helpful on devices like raspberry pi, where they may stay shutdown / offline for years. The minute they're powered up again they'll get my fresh keys and I can login to them without needing a console.http://manpages.ubuntu.com/manpages/bionic/man1/ssh-import-i...
NoodlesUK points out alerting which is a pretty important concept to incorporate.
Largely a solved concept in Electronic Medical Records & as outlined in the post.
But really good point, and i love the analogy to 'break glass'
One benefit of using certificates for emergency access is that SSHD logging can be configured to show a lot more detail about the certificate that was used. With public keys, there isn't anything to show. But with certificates you have a key ID, serial number, principals, CA fingerprint, etc. So, that log is a good hook for sounding the alarm. A more advanced version of this would allow you to record a reason for using the emergency access key when the connection is made (or when sudo is used).
There's, at minimum, client IP address, username, and the key fingerprint -- which has always been good enough for me.
There might be even more details available but I'm not sitting in front of a computer to check.
Yes - quite simple and old-fashioned, actually ...
I have this line in the SSH users' .login file:
/usr/local/sbin/sms 4153331111 4158882222 "USER LOGIN TO XXX - $DATE" >& /dev/null
... where the 'sms' command, above, is a shell script I wrote to call twilio messaging with the curl command. A very simple example of that would be: curl -X POST -d "Body=$msg" -d "From=$from" -d "To=$to" "https://api.twilio.com/2010-04-01/Accounts/$accountsid/Messages" -u "$accountsid:$authtoken"
... and this works like a charm.Alternatively, you could rick-roll your on-call sysadmin:
/usr/local/bin/curl -XPOST https://api.twilio.com/2010-04-01/Accounts/$accountsid/Calls.json --data-urlencode "To=$number" --data-urlencode "From=$callerid" --data-urlencode "Url=http://demo.twilio.com/docs/voice.xml" -u $accountsid:$authtoken
(the voice.xml demo is, in fact, Rick Astley)Edit: ooo @rsync just gave another good approach
I'd like to add that the way it's described really works.
But... Now I don't know to leave one yubikey in case I need to use it for emergency access to ssh? I have a server since 2011 and I have never problems with access through ssh, I use the same keys to this day and everything works.
I think this way with yubikey to emergency access is overkill.
It's just an interesting way to use yubikey.
What am I missing?
One difference is that the CA is on the hardware key, but the cert (and its private key) is not.
Imagine you're on a team of 50, and anyone on the team might need emergency access to a host at some point. You wouldn't want to buy 50 keys and 50 safes. Just designate a couple folks to manage emergency access. They can manually mint a cert for a colleague as needed, and send it over a secure channel. No security key needed to use the cert, and it self-destructs after a few minutes.
You could use a very long lived key, but then as soon as you have multiple people who might need production SSH access, you've got access control and revocation issues. The SSH CA is a good minimal solution, because the CA can issue only short-lived SSH keys (few hours at a time) that you use once and throw away. Also, CA trust scales better because it moves user management burden to the certificate issuing process and removes the need to modify the SSH config every time you onboard a new user.
It's a pretty standard practice. Here's a post from Facebook about it from several years ago. This post is just about how to do it using YubiKeys. https://engineering.fb.com/security/scalable-and-secure-acce...
This is actually quite useful for deploying clusters of machines that one doesn’t want normal ssh access until there is a real need. I think this was also mentioned in another comment
$ ssh-keygen -Lf the-cert.pub $ step ssh inspect the-cert.pub
Also the post already mentions that using `step` instead of `ssh-keygen` is optional, so I'm not sure why you feel the need to repeat it...You just need PKCS11 token support for SSH, which the YubiKey's smart card capability can do. YubiKey 4 and YubiKey FIPS can both do it, and so can regular old smart cards even though that form factor is a lot less popular now.
The workflow is the same: generate a key pair on the hardware token, have the CA sign it, install the signed cert onto the hardware token, and then SSH with it.
https://github.com/smallstep/certificates
One nice advantage is its support for different provisioning flows. The oauth flavor allows you to hook into an existing identity provider to authenticate certificate requests.
Simply:
$ step ssh login
and boom you've got a short-lived ssh certificate in your ssh-agent using a private key that never touched the disk. Valid: from 2020-06-24T16:53:03 to 2020-06-24T16:03:03
Um...