Use TouchID to Authenticate Sudo on macOS
it.digitaino.com
it.digitaino.com
https://github.com/maxgoedjen/secretive
I've been looking for something like this for 3-4 years but only found it six months ago (in an HN thread). I use separate keys for every use case, and now know every time a key is used for any purpose, whether it's connecting to source control or my text editor is connecting to a remote VM.
Only thing I haven't figured out is how to do git signatures with these sorts of keys, but I haven't debugged it at all.
I just wish there were something as clean as Secretive for using generic PC TPMs or YubiKeys in place of a Secure Enclave under Windows and Linux. Currently have a Linux laptop halfway through setting that up and it's messy in comparison.
0: https://github.com/tavrez/openssh-sk-winhello
0.footnote: "Windows Hello also supports other types of authenticators like internal TPM device(if they support generating ECDSA or Ed25519 keys, they can be used instead of FIDO/U2F security keys)."
1: https://github.com/tavrez/openssh-sk-winhello/issues
2: https://github.com/PowerShell/Win32-OpenSSH/issues/1804#issu...
- Init Your TPM
- Create a key+cert on your TPM using certutil.exe
- Grab your public key
- Use WinCryptSSH (https://github.com/buptczq/WinCryptSSHAgent) as your SSH agent and away you go
These are very simplified steps, but there are howtos floating around (eg https://blog.habets.se/2016/10/Windows-SSH-client-with-TPM.h...)
`ssh-keygen -t ed25516-sk` or `ecdsa-sk` and then you touch your yubikey when unlocking the key, the same time as you would type a password.
Question for anyone else reading: Does it make sense to use a password with -sk keys? I don't think it would make a difference either way.
Only if you want to protect your keys from being used by someone that has access to the private key + yubikey (i.e. someone physically present).
In other words, the -sk type private key is useless without the yubikey as well.
It's nice not to have to rely on an external yubikey
Any laptop that is listed as supported by Windows 11 will have an onboard TPM.
I don't use sudo often enough to warrant system changes, so I don't use those programs, but if they would be enabled by default, I would gladly use them.
I'm glad my windows PC only requires a PIN :)
There is probably low priority/ignored because most developers can easily do this on their own, so it's not really worth the hassle.
20 million / 1 billion = 2%
So yes, it seems like a small market relatively.
Developers are incredibly important for an ecosystem and having them a bit more optimistic about a platform can be quite beneficial (for a very low price, even).
- You cannot import your existing SSH keys
- You cannot transfer SSH keys if you get a new machine
BTW, if you have a key that you copy around to multiple machines, you’re doing it wrong!
With some security mechanism, I'd consider:
1. prevent other people from being able to use it. 2. recover from it in case it gets lost.
If your perspective is "if I lose this laptop, I have some other way to access the systems", then it's good to never access the SSH key secret.
If your perspective is that you want your secret key to be the only way to access some system, you'll want to have some way to recover the secret.
I think in any case, it's understood that having an unrecoverable secret being the only way to access some system is a bad idea.
If there is some sort of use case where I want to be able to backup a key, or share it with someone else I can always fall back to SSH keys on a hard disk. But those are usually anti-patterns.
I might also be ok if somebody like Apple had engineered a cloud solution for securely keeping backups, but only maybe.
For SSH it's probably easier since I can just have both public keys accessible for adding it to new servers and keep the token somewhere safe.
My preferred solution would be to generate the private key material outside of the secure enclave (but on a offline device or something), write it down on a piece of paper and then transfer it in to the enclave/hardware device.
That way I could just restore the same private key if the physical secure enclave is destroyed.
Yes.
> Then I need to remember to enroll the second one whenever I sign up for something (or keep both keys with me, which kinda negates the backup perspective).
Alternatively you print out the backup codes.
> My preferred solution would be to generate the private key material outside of the secure enclave (but on a offline device or something), write it down on a piece of paper and then transfer it in to the enclave/hardware device.
The primary reason why we want to do hardware at all, is that to the best extent we know the key is generated by it and will remain in it. That most of the threat becomes someone in the physical world stealing it from you.
Though some more open-source webauthn tokens would allow you to do what you described. Secure key management procedures are just not something we should encourage people to do themselves, it's difficult.
But those are per site right?
Re hardware and that above is not something for most people:
Yeah I agree. Something like https://uni.horse/notes/solo-key-backups.html, but it shouldn’t be a solution for most people.
But I still think the backup story is flawed, and could be improved to work in a easy and secure way:
Using some easy vendor GUI tool, with a simple clone button:
1: Generate on-hardware webauthn master key on device A. 2: Generate on-hardware key-par on device B 3: Export B’s public key to A 4: Encrypt A’s private key with B’s public key 5: Export encrypted master key to B 6: Decrypt on B
But I guess we ideally would want some standardized protocol for doing this so you can do cross vendor backup.
(Most likely this will be solved by the mobile os vendors who will sync and backup your private key for you. Using your phones HSM instead of an external device)
It's really quite flexible, and despite its age, still works pretty well with current programming paradigms, whether your UI is text or graphical or whatever. The one oddity is that when it asks you to prompt for some kind of user input, it will actually expect you to return the resulting input from the same callback function. So if you're using a modern-ish GUI toolkit, you'll need to run the PAM stuff off on a different thread that's allowed to block while your UI thread is free to do what it needs to do. But overall that's just... fine?
Thanks to open standards (really POSIX in this case), even a small program can immediately benefit from PAM authentication because it will work in any organizational environment, regardless of whatever over-engineered backend system (like LDAP or Kerberos) or SaaS (like Okta or O365) is providing the list of users and groups.
When exploring a technology I like to search GitHub for it, since that should surface a healthy sample of code that uses it. For instance the “pam” topic looks like a fun rabbit hole to click into, with a list of repositories demonstrating a wide array of use cases for PAM. [0]
Not sure which one macOS' implementation is based on but considering its history I would bet on one of the BSDs.
The code is fairly small so it can be an example for doing other PAM things too.
auth sufficient pam_fprintd.so sudo cp ~/Dropbox/etc-pam.d-sudo /etc/pam.d/sudo
Type the password once and you're done. I've been carrying this around for quite a while. No need to edit the file every MacOS, just copy it.But once it did utterly go south when Dropbox's "load files on demand" functionality replaced the file with a bunch of zero bytes. That wasn't fun to fix. So maybe Dropbox isn't the best storage place.
sudo perl -pi -e 's/(pam_smartcard.so)/$1\nauth sufficient pam_tid.so/' /etc/pam.d/sudoAnyway, here's the version of your one-liner I used to preserve the spacing used in the rest of the file:
sudo perl -pi -e 's/(pam_smartcard.so)/$1\nauth sufficient pam_tid.so/' /etc/pam.d/sudo printf '%s\n' '/pam_smartcard\.so/a' 'auth sufficient pam_tid.so' . wq | sudo ex -s /etc/pam.d/sudoWhy? Because asking for a password for su / sudo broke the flow -- not only did I have to move my right hand from the home row (or both, for my watch), but it popped up a modal-like window away from where my eyes were. Basically it impinged on my focus.
Nice idea, not so nice in practice.
I wrote a patcher that changed this behavior, it patched pam_tid directly on your system and just updates the API Apple calls to allow unlocking with watch-only when touch ID is unavailable:
https://github.com/inickt/pam_wtid
Was a fun reverse engineering experience and wrote up some more info in the README.
https://github.com/insidegui/pam-watchid
... and my /etc/pam.d/sudo needs to be changed like this:
# sudo: auth account password session
auth sufficient pam_watchid.so
(...)
This needs to be applied after every system update. Apart of that, it works really well (I have very dry skin so touch ID works for me 50% on a good day)⸻
1. I was able to fix it using Repair Permissions in DiskUtil. If I were running Linux I don’t know that I could have fixed it at all, although maybe Linux is more forgiving of this sort of sin?
Ps just mentioning it in case you didn't know about it. I know there's still ways to lock yourself out that visudo doesn't catch.
TIL, I wondered why every time I did this it would reset after a while. Thanks!
Is it idempotent? No, every reboot it adds the line again. Doesn't appear to matter though.
See my other reply on this thread.
https://github.com/shinzui/dotfiles.nix/blob/master/modules/...
if ! grep -q "pam_tid.so" /etc/pam.d/sudo ; then
echo "touch ID no longer enabled for sudo. Insert the following line as line 2 in /etc/pam.d/sudo:"
echo " auth sufficient pam_tid.so # enables touch id auth for sudo"
fi2021.03.01: https://news.ycombinator.com/item?id=26302139
72 days ago: https://news.ycombinator.com/item?id=31750560
I use external monitors now and leave my MacBook closed in a dock, so it would be nice if I could use an external fingerprint reader that I plug in via USB. I guess the Yubikey is sort of like this, but it's probably not as secure as using a fingerprint.
Is it possible for a process to authenticate a user without root privileges, including setuid/setgid?
And like others said, it doesn't persist anymore. I also edited the sshd_config to enforce public key Auth but this was getting annoying.
I use FreeBSD now which lets me use my computer the way I want to.
My work profile is one finger, personal profile a different, both work great.
I have noticed if I remove my fingerprint then add it back, it's more accurate for a short time. Then over time it goes back to not working as well.
I set my nose as a finger and I t worked.
Like literally 100 %, I don't think I've ever had to touch the sensor twice or wait more than half a second.
PS: My hands don't sweat much and I keep the keyboard clean and without dust.
I also only enroll one fingerprint, because I use a Magic Keyboard with Touch ID when I have the MacBook docked, the Touch ID sensor is always in the same position relative to my hands.
Regardless, I still hope we'll have Face ID on Macs one day.
I wish Mac OS would allow the use of a "stress" fingerprint, e.g. right index fingerprint is to use when you're under duress, while instead another fingerprint is for normal use.
I typically lock my system when away from it so having fingerprint sufficient for sudo doesn't seem so bad.
Never heard of similar stuff for Macs, this is Linux software. Worked fine on my ThinkPad laptop running Fedora.
it was fun to set up, but not really worth maintaining.
https://arstechnica.com/information-technology/2020/10/apple...
That said the checkm8 exploit requires (as far as I’m aware) physical access to the target device, which is a fairly constrained attack vector for any real world attack. Obviously if you are at risk of such attacks though then your risk profile is _vastly_ different and the steps you need to take are also different.
"But the T2 also contains a vulnerability, known as Checkm8, that jailbreakers have already been exploiting in Apple's A5 through A11 (2011 to 2017) mobile chipsets. Now Checkra1n, the same group that developed the tool for iOS, has released support for T2 bypass."
"Computers that have the Apple T2 Security Chip": https://support.apple.com/en-us/HT208862