510 points · by syck · 5y ago · 214 comments
Why does the sudo file not persist between updates? This case is quite minor for personal computers, but what about companies that log in with yubikeys or smart cards? Do they have to reconfigure after every update too?
enable-sudo-touchid() {
sudo sed -i -e '1s;^;auth sufficient pam_tid.so\n;' /etc/pam.d/sudo
}
But probably automating the check (if the automated checker has the correct permission) would not be that hard. sudo() {
unset -f sudo
if [[ "$(uname)" == 'Darwin' ]] && ! grep 'pam_tid.so' /etc/pam.d/sudo --silent; then
sudo sed -i -e '1s;^;auth sufficient pam_tid.so\n;' /etc/pam.d/sudo
fi
sudo "$@"
} function sudo --description "Execute a command as another user."
if [ (uname) = "Darwin" ]
set --local needle "^auth\b.*\bpam_\(reattach\|tid\|watchid\)\.so\$"
if ! grep $needle --silent /etc/pam.d/sudo && \
[ -f /usr/local/lib/pam/pam_reattach.so* ] && \
[ -f /usr/local/lib/pam/pam_watchid.so* ]
command sudo sh -c "
cat << EOF >/etc/pam.d/sudo
auth optional pam_reattach.so
auth sufficient pam_tid.so
auth sufficient pam_watchid.so
\$(grep -v '$needle' /etc/pam.d/sudo)
EOF"; or return $status
end
end
command sudo $argv
endThought on the second thought, I’ll continue to use the more “manual” method for now. As it gives me more control and it would be easier to switch off when touch ID sudo will be supported more officially.
It’s already starting to add noticeable latency from all of the various eval statements in there.
Edit: I missed it’s a function def which should be fine speed wise.
A macOS update isn’t “whatever was previously on your OS volume, plus arbitrary patch X”; rather it’s “a new, fresh OS disk image, written to a separate APFS volume, with a fixed SHA, with update transfer-size optimized by composing said image partially from files in your current OS, but only in such a way that the volume will still hash the same in the end.”
(In many ways, macOS’s update system now reuses the logic from iOS’s IPSW firmware-update system. You can even now download macOS updates from Apple as IPSW files, and then use Apple Configurator to push them to macOS devices.)
Unlike ChromeOS/CoreOS, after the first-round SHA verification of the volume, macOS will then patch the new OS-base-image volume with certain files from your current OS-base-image volume, if 1. they’re distinct from the ones it expected to be there, and 2. they appear on a whitelist of known-safe files.
If any of this patching happens, the OS volume’s metadata tree will then be re-hashed, and the new hash will be blessed by the volume-signing utility.
(If you’ve seen a “Recovered Files” directory on your desktop after an update, and it’s contained a “foo.system_default” file, that’s a copy of the file that macOS would have composed into the OS volume if it hadn’t found your known-safe customized file to use instead. /etc/shells is a usual trigger.)
Some preference files in /System/Library are known-safe; but others aren’t. It’s a whitelist, and it’s a conservative one.
Preference files in /Library live in the user volume, not the OS volume, and so will never be wiped. This is why most of the “trivial” preferences stick around.
Note that by “known-safe” here, I don’t mean “can’t be customized to malicious ends.” This isn’t a security thing. It’s an ABI stability thing. These files are safe in that they’re known to have the same ABI format between OS versions, and so keeping a customized version of them around won’t confuse newer versions of system daemons.
It’s about the same as if Linux had a set of known-safe DKMS modules that use interfaces that the kernel intentionally doesn’t change between releases, such that the kernel module files composed from those DKMS modules could be reused by the new kernel without requiring decompilation, rather than being tossed out at every single kernel update.
Red Hat CoreOS (and other Linux systems managed with OSTree, such as Fedora Silverblue) now do something similar by merging the current /etc directory with the "upstream" version.
The richest company in the world can't think different?
The file in question is configuration and should not be part of the update image. (Better yet, Apple should surface this functionality somewhere reasonable, like the System Preferences.)
There was an issue with iOS a few years ago that caused higher than normal battery drain when I was managing a department that supported a lot of iOS devices. A lot of users thought they needed a new battery. The battery drain issue was resolved for 100% of our users by doing an "Erase all data" and NOT restoring the backup. This process will still fix an amazing number of weird iOS issues in 2021, especially issues with the device slowing down, getting hot, or draining battery. It works because you end up with default config files that were designed for that version of the OS. If you restore the backup, often it will "restore" the problem you were trying to fix because the iOS restore process puts some OS config files back.
It will be interesting to see if Macos becomes less susceptible to win-rot type issues because of this config file reset behavior, as annoying as it may seem.
After awhile they would all become unusable, and I would reinstall everything back to default and try again. Great for leaning, lousy for day to day work.
Resetting things back to a known state can make life lot easier.
In 10 years I can’t recall needing to reset a Mac.
People getting their pf rules thrown away each time - it is like unlocking your front door each time you run the vacuum cleaner.
This helps.
1. sudo -Si
2. chmod 644 /etc/pam.d/sudo
3. vi /etc/pam.d/sudo
4. Add the 'Auth sufficient pam_tid.so' line
5. chmod 444 /etc/pam.d/sudo
6. ...
7. Profit!
Very handy tip though, thanks!On 11.2.1
visudo will lint the resulting file and (should) reject the change if it would break your system.
You can also use this to secure SSHD on servers by delegating to PAM with keyboard-interactive.
I'm waiting for U2F OpenSSH support to trickle down to stable distros but in the meantime pam_yubico is pretty damn good... not to mention you don't have to worry about terminal support since it relies on the yubikey OTP emulating a keyboard.
I use this feature for other touch cases (e.g. unlocking 1Password) but would hate it when in the flow.
Admittedly my password is well wired into my fingers.
I haven't tried it myself ...
I haven't used a full size keyboard in so long, I had to think about the print reference. I have lost direct placement of Home/Print Screen/End type button locations in my memory. To be more accurate to the keyboard in question, it is a slight extension past the delete key. The only hazard is if you come up short, you might bring up Siri (depending on touchbar mode) which is an even bigger distraction. </pedanticmode>
Can you clarify what you mean by this? I love the idea of unlocking and running admin stuff with my watch but kinda gave up on the idea because I assumed there would be security implications. After thinking about it a little more, though, I haven't really been able to come up with anything that didn't already require physical access to my machine and some way to authenticate (password or fingerprint). Since you have to authenticate your device to authenticate the watch and it un-authenticates any time it's removed, it seems like you don't lose anything security-wise.
I think this isn’t a great UX for other reasons I posted on this discussion. But the security is acceptable to me.
Coupled with `expect` I use it to authenticate through SSH (that is the only feasible option I got to connect to hosts I’ve got limited access). I even wrote about it: https://antonio-ramadas.github.io/blog/2020/10/30/ssh-login-...
Here is the gist of it:
#!/usr/bin/expect
# Connects via SSH to the host passed as argument
set timeout 60
set server [lindex $argv 0]
set username <USERNAME>
set password [exec sudo cat <PATH_TO_YOUR_PASSWORD_FILE>]
spawn ssh $username@$server
expect {
"yes/no" { send "yes\r" ; exp_continue }
"\*?assword" { send "$password\r" }
}
interact
Edit: Please remove all permissions from the password file with: chmod a-rwx <PATH_TO_PASSWORD_FILE>
I’m also assuming you run this script on an environment you control and trust. Be wary of your password.pam_modules-159.50.4/modules/pam_tid/pam_tid.c appeared in macOS 10.12.4 https://opensource.apple.com/release/macos-10124.html
And macOS 10.12.4 was posted on Mar 27, 2017, according to https://support.apple.com/kb/DL1911
Rote but effective.
/usr/bin/security find-internet-password -wgs mydomain.com
It requires the keychain to be unlocked, which can be handled with touch ID, and you can have it confirm with a "are you sure" dialog box every time.If you really wanted to be prompted for a fingerprint basically every time, you could probably use a separate keychain that locks after 1 minute of inactivity.
https://docs.sweeting.me/s/power-button-password-manager-sho...
Why is this not very efficient? Isn't moving my finger to touch the key equivalent to a single key stroke? How is a single key stroke less efficient then many key strokes?
Also it's arguably not the fastest combination of characters I can type, because my password is not "test1234" and I don't get much opportunity to type it at all anymore since everything can be unlocked via TouchID except the terminal, or so I thought at least :)
I always just re-assign the caps-lock key to CTRL.
You mean the black void where there’s no feedback on how many characters you typed? I always have to write my password a couple of times to get it right.
(I'll probably shorten it soon, but it's a slightly mangled lyric from a popular song, so it's easy enough to remember.)
Does anyone know why this happens? I was very happy when I found out APFS is CoW but it kind of sucks that restoring an old snapshot apparently erases the secure enclave in my M1 chip.
https://docs.sweeting.me/s/power-button-password-manager-sho...
(I don't have a Touch ID Mac to find out.)
Unless I'm missing something, the security cost of this should be negligible, especially if you're in the habit of locking your computer screen when you're not using it (and this typically happens by default after a few minutes even if you forget). And if you're relying on the sudo password prompt to protect you against untrusted scripts, I'd argue you have bigger problems.
Personally I don't have passwordless sudo but I'm also curious as to what the attack vector might be here if you were to enable it.
auth sufficient pam_smartcard.so sudo chmod +w /etc/pam.d/sudoIn TouchID, the biometric is stored only in the secure enclave, and is used to generate a private key signature, which serves as the password.
Additionally, it's always possible to reset TouchID to an unauthenticated state, where it will refuse a fingerprint read until the password is typed in.
There's no sense cargo-culting this bit of conventional wisdom without understanding where it comes from, and what sort of attacks it is meant to prevent.
and yes, adding this in you do _not_ have to type out your sudo password and can grant permissions using only touch id.
And the fingerprints -- you leave them on your devices.
Biometric are non-revocable.
But yes, it is very frustrating that every time there's a system update you have to redo it.
I was excited to set this up when the first fingerprint sensor macs came out. Within a couple of days I’d switched it off. It is quite inconvenient and especially bad if you use an external keyboard.
BTW the face system is so automatic on the phone that I don't think I'd want it for much beyond login. The flow-breaking reminders when installing apps and the explicit requirement of typing sudo are good ways to require deliberate intent for dependent risks. Login, App Store purchases and the like would be OK by me if controlled by face.
All that being said: the Mac camera remains astonishingly terrible (see a recent HN front pager about how bad webcams are in general). Not just low resolution but poor white balance etc. I am not sure it's been upgraded in the last decade.
There is much speculation as to why (no room in the lid, which is plausible); I feel like for some reason this is an issue on which they simply don't care for some reason as they make a lot of fuss about the changes in speaker and microphone. Perhaps it simply is good enough, based on the innumerable Zoom calls I've been on.
Face ID needs more than a better camera, it also needs an IR channel. I do expect that when they finally do get around to upgrading the camera system they will jump ahead to something like the iphone front facing system.
However that aside, thickness concerns don't apply a single bit to the iMac or to a standalone (Mac only) module (or even integration in Apple's ultra fancy display), so that objection doesn't cover the spectrum of Macs.
Secrets can be changed easily when they get compromissed, your figerprints/iris/whatever cannot.
https://www.csoonline.com/article/3330695/6-reasons-biometri...
I think modern devices that use biometrics to unlock a secret key are different from the old-school case of biometric authentication. If someone is storing a picture of your fingerprint, then of course they can replay that to impersonate you. But that's not what TouchID is doing -- it's just a chip that will only give up the private key if it detects your fingerprint. You have to have physical access to that chip, and a finger analog that will fool the chip into giving up the secret key, and then you can use that key to compromise things. But if you detect that, you just revoke the key, get a new device, and are good to go.
I don't have a great analysis for sudo. You want root on MacOS to do something like install a long-term compromise. Your regular user account already has your GMail session cookie and bank information, so sudo isn't really good for anything else; if you leave your unlocked laptop around somewhere, your Internet life is over. But if someone physically steals your finger so they can gain access to sudo and install a keylogger or something, you already know you're compromised -- your laptop and finger are gone, so you know something's up, defeating the purpose of a long-term compromise.
This attack can't be done remotely; if someone sshs to your laptop and wants to sudo, they can't just take a picture of your fingerprint and upload it... they have to physically touch the sensor on your laptop.
Overall, I think biometrics like TouchID / FaceID / U2F / WebAuthn are strictly better than passwords. They are super convenient. They can be revoked. They can't be phished. That's a huge win over passwords.
Further, if I take a high resolution photo of you, and then go to your mom and ask for money by presenting her the picture, she won't accept that picture as proof that I am you (although she may suspect I'm blackmailing or otherwise threatening you). This, moreso than qualms about the resolution/quality of the sensor is the GP's point. If the sensors are accurate, that specific set of bits that is translated as your fingerprint will not change. If someone knows those bits, it's extremely likely they can convince the sensor they are you. From our example, once I have your picture, I can tell your mother I'm you--and she'll believe me!
Making sweeping generalizations about something as complex as information security is always a bad idea.