Repository navigation
[Security] Stop the FIDO2 setup staging its authfile at a predictable /tmp path - #7904
Conversation
There was a problem hiding this comment.
Pull request overview
Hardens FIDO2 enrollment and migration against insecure temporary files, symlinks, and user-owned authentication files.
Changes:
- Securely stages and installs FIDO2 credentials.
- Repairs legacy authfile ownership and permissions.
- Adds shell coverage for secure enrollment.
Tip
If you aren't ready for review, convert to a draft PR.
Click "Convert to draft" or run gh pr ready --undo.
Click "Ready for review" or run gh pr ready to reengage.
Reviewed changes
Copilot reviewed 2 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
bin/omarchy-setup-security-fido2 |
Uses secure temporary staging and root-owned installation. |
bin/omarchy-remove-security-fido2 |
Removes dangling FIDO2 directory symlinks. |
migrations/1787494718.sh |
Repairs legacy authfile ownership and permissions. |
test/shell.d/security-fido2-test.sh |
Tests secure enrollment staging and installation. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| sudo chown root:root "$authfile" | ||
| sudo chmod 600 "$authfile" |
| if [[ -L $authfile ]]; then | ||
| echo " $authfile is a symlink, not a regular file." | ||
| echo " Leaving it alone. If you did not create it, remove it and re-run Setup > Security > Fido2." | ||
| exit 0 |
|
Reviewed this closely — Opus 5 for the first pass, with Codex at xhigh reasoning as an independent second opinion. Two defects found and fixed on your branch; one thing deliberately left for a maintainer decision; and one collision you should know about. Thanks for the writeup — the pam_u2f ownership analysis in it is right, and it's what made this worth landing. PushedBoth commits landed under @dhh's account rather than this one, because that is where the push credential sat — read that as where the bytes came from, not as a maintainer signing off on the change. [55ad177] [d759911] The migration chowned in place. This is the one that matters. Permission is checked at Two test changes went with those. Your cleanup unlinked every staged path outside the scratch directory, taking the path from the script under test and already resolved through any symlink — against a script staging through one, that would have named a file of the user's and deleted it. It now unlinks only a file its own stub wrote into. And the The migration had no test at all, so it has one now. It drives a scratch copy with the one path literal retargeted rather than reading the path from the environment: this migration hands Not pushed — your call, and the maintainer'sMode 600 vs 644. pam_u2f drops to the authenticating uid before opening even an absolute authfile when On the threat modelThe Your Ctrl-C claim checks out, incidentally — I doubted it, reproduced it against a real terminal, and bash does run the EXIT trap before dying on SIGINT. No file is stranded. Collision#7703 fixes the same two defects — What was checked
Codex reviewed the original PR and then reviewed my changes, both at xhigh. On the first pass it contributed the missing Waiting on a maintainer for the choice between this and #7703, and on you for the 600/644 question. |
… /tmp path pamu2fcfg wrote to /tmp/fido2 and the registration was then moved into place with `sudo mv`. Any other local user can pre-create /tmp/fido2, and rename(2) does not dereference the final component, so the privileged move installed the attacker's symlink itself as pam_u2f's global authfile -- a file consulted by `sufficient` lines in /etc/pam.d/sudo and /etc/pam.d/polkit-1. The same move also carried the staged file's ownership into /etc, so on every install to date /etc/fido2/fido2 is owned by the invoking user at mode 0644. That needs no attacker: anything running as that uid can add its own credential and satisfy the machine's sudo prompt without root. Stage under mktemp and hand the bytes to `install` instead, so the authfile is always a fresh root-owned regular file rather than an inode a non-root user still controls. Guard the already-registered check with -L, which -f would otherwise follow, and reject a symlinked /etc/fido2 in the remove path for the same reason. A migration takes ownership of authfiles left behind by the old code; it reports a symlink rather than repairing one, since chown would follow it and removing it would strip sudo from anyone whose only credential is the token. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_012e6WagC5iUigCGoK1tQeFz
`install SRC DEST` without -T treats an existing directory at DEST as a destination directory: it drops the credential inside as /etc/fido2/fido2/tmp.XXXX, exits 0, and setup reports a successful registration while PAM goes on reading a path that is not a file. -T makes that an error. The already-registered check has the same blind spot from the other side. -f follows symlinks, so it reads a symlinked authfile as a registration and leaves it in place, and is false for a directory, so it tries to register over one. Only a regular file is a pam_u2f authfile; anything else is now refused with the same advice to remove it and set FIDO2 up again. The test deleted every staged path that fell outside its scratch directory, taking the path from the script under test and already resolved through any symlink -- so a script staging through one would have named a file of the user's and had it unlinked. It now unlinks only a file its own stub wrote into. On a machine that already has /etc/fido2/fido2 the staging assertions cannot run at all, and the file used to pass without exercising one of them. That branch now asserts what the host state promises instead: a regular authfile still has to be recognised as a registration and left alone, and anything else has to be refused. Co-Authored-By: Claude Opus 5 <[email protected]> Co-Authored-By: Codex XHigh <[email protected]>
Permission is checked at open(2), not at write(2), so a descriptor the registering user opened on the authfile while it was still theirs stays writable through chown and chmod alike. pam_u2f resolves /etc/fido2/fido2 to that same inode, so the repair left the account it authenticates able to append a credential it controls -- the exact state the migration exists to end, now recorded as migrated and never revisited. Installing a fresh root-owned copy and renaming it over the path leaves any such descriptor writing to a file nothing reads. Credit to omacom#7703, which reached the same conclusion independently. An interrupted run heals: the staged copy is root-owned 600 and inert, no marker is written, and the next run replaces it. A directory or device at the authfile path is no more ours to rewrite than a symlink is, and chmod 600 on a directory would only make it untraversable, so both are now reported rather than repaired. The repair had no test, because it names an absolute path no unprivileged suite can write. It is exercised through a scratch copy with that one literal retargeted, rather than by reading the path from the environment: the migration hands `install` and `mv` root, and an operand the caller can choose is a privileged write to anywhere. The copy is only as honest as the substitution, so the test fails if the migration stops naming the path exactly once. Covered: the no-op on a machine that never registered a key, which must not cost a password prompt; the repair itself; the new inode; the absence of a staged copy afterwards; a second account finding it done; and the symlink and non-regular cases. Each assertion was checked against a mutation that defeats it -- notably a repair with the right install call, mode, content and cleanup that writes through the old inode, which only the inode assertion catches. Co-Authored-By: Claude Opus 5 <[email protected]> Co-Authored-By: Codex XHigh <[email protected]>
d759911 to
11b87bd
Compare
install -d follows a symlink at /etc/fido2 and applies the mode and ownership to whatever it points at, so the credential would be staged and published inside the link target and that directory silently reopened to root:root 755. The leaf guard above it only covered fido2 itself, and this is the same threat omarchy-remove-security-fido2 already names on its side. mktemp's output is an operand for a privileged tee, chmod, mv and rm. The migration validates it before any of them run; the setup did not, so take only the name it asked for there too. The suite was guarded on the host's own /etc/fido2/fido2 and exited early when one existed, which meant the staging assertions asserted nothing on exactly the machines that use FIDO2. Drive a retargeted copy the way the migration suite already does, so every branch is a fixture and all of them run everywhere. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
omarchy-migrate writes the per-user completion marker on any zero exit, so the two states this migration cannot repair got one line in the update terminal and were then silenced for good: no login notice, no re-run, the migration recorded as done having repaired nothing. Those are precisely the machines where the authfile may already be under someone else's control, so raise them through omarchy-notification-send as well, where they outlive the scrollback. Delivery is best-effort: a machine with no user bus or no notification server must not abort the migration and take every later one with it. The early exit had the same shape of problem. It read the authfile unprivileged, and the old setup created /etc/fido2 with `sudo mkdir -p`, which took the union of the caller's umask and sudoers' 0022 — so registering under `umask 077` left the directory mode 0700 with the user-owned authfile still inside. Absence and "cannot look" are the same answer to those tests, and the migration exited 0 and marked itself complete. Ask root whether a registration is actually behind an untraversable directory before reopening it, so an aborted setup that left an empty directory, or one an administrator keeps private, does not have its mode widened and its group and special bits discarded for a repair it does not need. A machine that never set FIDO2 up has no directory here and still reaches exit 0 without a password prompt. The notification assertion checks argument shape rather than a substring of the command line. The glyph is a private-use codepoint, and losing it shifts every argument left: -g swallows the headline, the body becomes the title, and the message goes out with no description — which a substring match reads as a pass. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Co-Authored-By: Codex XHigh <[email protected]>
The -d to -e || -L change is load-bearing for the threat its own comment names — a dangling link at /etc/fido2 that -d reads as absent, left for the next setup to install an authfile through — and it was the one part of this work with no test behind it. Name the directory once so the suite can retarget a copy, the same seam the setup and migration suites use, and assert both halves: the link goes, and the directory it pointed at does not. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
Reviewed this and pushed three commits. Everything below was verified against the source before it was acted on, and every fix is proven by breaking it on purpose and watching its test fail. The second opinion came from Codex at xhigh, and it found a real bug in my own first attempt at these fixes. What I pushed Guard the FIDO2 directory and the stage path the setup writes through. The leaf guard covered That commit also had to fix the suite before either change could be tested at all: it was guarded on the host's real Stop the FIDO2 migration recording a repair it never made. Cover the FIDO2 removal's symlink guard. The What I did not change: the 600 to 644 relaxation is right I went in expecting to argue with this one and came out agreeing with you. Upstream Tests Run on a disposable worker VM, never on the machine holding credentials: 39 assertions across the three FIDO2 suites, all green, plus What the second opinion added Codex at xhigh caught a real defect in my own fix. The notification glyph is a private-use codepoint that my edit silently dropped, which shifts every argument one place left: I rejected nothing of substance from it. Its one remaining note — that the One thing left for the maintainer, not for you The settled-state check validates the authfile but not its parent directory, so if |
… /tmp path (backport of #7904) Backport of the FIDO2 authfile fix (PR #7904 by @mdisec, merged to quattro as 23dab9e) onto the v4-0-1 release branch. pamu2fcfg wrote to /tmp/fido2 and the registration was then moved into place with sudo mv. Any other local user can pre-create /tmp/fido2, and rename(2) does not dereference the final component, so the privileged move installed the attacker's symlink itself as pam_u2f's global authfile -- a file consulted by sufficient lines in /etc/pam.d/sudo and /etc/pam.d/polkit-1. The same move also carried the staged file's ownership into /etc, so on every install to date /etc/fido2/fido2 is owned by the invoking user at mode 0644. That needs no attacker, no race and no second account: anything running as that uid can append its own credential and satisfy the machine's sudo prompt without knowing the password. The setup now creates a unique staging file as root beside the final authfile and pipes pamu2fcfg into it, so root never reopens a caller-owned pathname, rejects failed or empty enrollment output, publishes with an atomic mv -Tf, cleans the exact staging file after every failure, refuses non-regular authfile states, and installs root:root 0644. A migration repairs machines set up by earlier versions by replacing the inode rather than chowning in place: a process that already holds a writable descriptor on the legacy user-owned mapping keeps it, so the repair has to leave that inode behind where PAM no longer reads it. Clean cherry-pick: all six files are byte-identical to quattro, so merging v4-0-1 into quattro resolves without a conflict. The migration's timestamp (1787494718) is older than others already on this branch, which is harmless: omarchy-migrate marks each migration by filename rather than tracking a watermark, so this one runs on every machine that has not run this exact file. test/shell passes: 195 files, including the three this adds -- the setup's staging and failure paths, the migration's repair and unrepairable states, and the removal's symlink handling. test/cli passes. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_018DEMYa9UWtroz93DhMTtcV
… /tmp path (omacom#7904) * [Security] Stop the FIDO2 setup staging its authfile at a predictable /tmp path pamu2fcfg wrote to /tmp/fido2 and the registration was then moved into place with `sudo mv`. Any other local user can pre-create /tmp/fido2, and rename(2) does not dereference the final component, so the privileged move installed the attacker's symlink itself as pam_u2f's global authfile -- a file consulted by `sufficient` lines in /etc/pam.d/sudo and /etc/pam.d/polkit-1. The same move also carried the staged file's ownership into /etc, so on every install to date /etc/fido2/fido2 is owned by the invoking user at mode 0644. That needs no attacker: anything running as that uid can add its own credential and satisfy the machine's sudo prompt without root. Stage under mktemp and hand the bytes to `install` instead, so the authfile is always a fresh root-owned regular file rather than an inode a non-root user still controls. Guard the already-registered check with -L, which -f would otherwise follow, and reject a symlinked /etc/fido2 in the remove path for the same reason. A migration takes ownership of authfiles left behind by the old code; it reports a symlink rather than repairing one, since chown would follow it and removing it would strip sudo from anyone whose only credential is the token. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_012e6WagC5iUigCGoK1tQeFz * Install the FIDO2 authfile with -T and refuse a non-regular path `install SRC DEST` without -T treats an existing directory at DEST as a destination directory: it drops the credential inside as /etc/fido2/fido2/tmp.XXXX, exits 0, and setup reports a successful registration while PAM goes on reading a path that is not a file. -T makes that an error. The already-registered check has the same blind spot from the other side. -f follows symlinks, so it reads a symlinked authfile as a registration and leaves it in place, and is false for a directory, so it tries to register over one. Only a regular file is a pam_u2f authfile; anything else is now refused with the same advice to remove it and set FIDO2 up again. The test deleted every staged path that fell outside its scratch directory, taking the path from the script under test and already resolved through any symlink -- so a script staging through one would have named a file of the user's and had it unlinked. It now unlinks only a file its own stub wrote into. On a machine that already has /etc/fido2/fido2 the staging assertions cannot run at all, and the file used to pass without exercising one of them. That branch now asserts what the host state promises instead: a regular authfile still has to be recognised as a registration and left alone, and anything else has to be refused. Co-Authored-By: Claude Opus 5 <[email protected]> Co-Authored-By: Codex XHigh <[email protected]> * Replace the FIDO2 authfile inode rather than chowning it in place Permission is checked at open(2), not at write(2), so a descriptor the registering user opened on the authfile while it was still theirs stays writable through chown and chmod alike. pam_u2f resolves /etc/fido2/fido2 to that same inode, so the repair left the account it authenticates able to append a credential it controls -- the exact state the migration exists to end, now recorded as migrated and never revisited. Installing a fresh root-owned copy and renaming it over the path leaves any such descriptor writing to a file nothing reads. Credit to omacom#7703, which reached the same conclusion independently. An interrupted run heals: the staged copy is root-owned 600 and inert, no marker is written, and the next run replaces it. A directory or device at the authfile path is no more ours to rewrite than a symlink is, and chmod 600 on a directory would only make it untraversable, so both are now reported rather than repaired. The repair had no test, because it names an absolute path no unprivileged suite can write. It is exercised through a scratch copy with that one literal retargeted, rather than by reading the path from the environment: the migration hands `install` and `mv` root, and an operand the caller can choose is a privileged write to anywhere. The copy is only as honest as the substitution, so the test fails if the migration stops naming the path exactly once. Covered: the no-op on a machine that never registered a key, which must not cost a password prompt; the repair itself; the new inode; the absence of a staged copy afterwards; a second account finding it done; and the symlink and non-regular cases. Each assertion was checked against a mutation that defeats it -- notably a repair with the right install call, mode, content and cleanup that writes through the old inode, which only the inode assertion catches. Co-Authored-By: Claude Opus 5 <[email protected]> Co-Authored-By: Codex XHigh <[email protected]> * Finish hardening FIDO2 authfile installation * Guard the FIDO2 directory and the stage path the setup writes through install -d follows a symlink at /etc/fido2 and applies the mode and ownership to whatever it points at, so the credential would be staged and published inside the link target and that directory silently reopened to root:root 755. The leaf guard above it only covered fido2 itself, and this is the same threat omarchy-remove-security-fido2 already names on its side. mktemp's output is an operand for a privileged tee, chmod, mv and rm. The migration validates it before any of them run; the setup did not, so take only the name it asked for there too. The suite was guarded on the host's own /etc/fido2/fido2 and exited early when one existed, which meant the staging assertions asserted nothing on exactly the machines that use FIDO2. Drive a retargeted copy the way the migration suite already does, so every branch is a fixture and all of them run everywhere. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> * Stop the FIDO2 migration recording a repair it never made omarchy-migrate writes the per-user completion marker on any zero exit, so the two states this migration cannot repair got one line in the update terminal and were then silenced for good: no login notice, no re-run, the migration recorded as done having repaired nothing. Those are precisely the machines where the authfile may already be under someone else's control, so raise them through omarchy-notification-send as well, where they outlive the scrollback. Delivery is best-effort: a machine with no user bus or no notification server must not abort the migration and take every later one with it. The early exit had the same shape of problem. It read the authfile unprivileged, and the old setup created /etc/fido2 with `sudo mkdir -p`, which took the union of the caller's umask and sudoers' 0022 — so registering under `umask 077` left the directory mode 0700 with the user-owned authfile still inside. Absence and "cannot look" are the same answer to those tests, and the migration exited 0 and marked itself complete. Ask root whether a registration is actually behind an untraversable directory before reopening it, so an aborted setup that left an empty directory, or one an administrator keeps private, does not have its mode widened and its group and special bits discarded for a repair it does not need. A machine that never set FIDO2 up has no directory here and still reaches exit 0 without a password prompt. The notification assertion checks argument shape rather than a substring of the command line. The glyph is a private-use codepoint, and losing it shifts every argument left: -g swallows the headline, the body becomes the title, and the message goes out with no description — which a substring match reads as a pass. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Co-Authored-By: Codex XHigh <[email protected]> * Cover the FIDO2 removal's symlink guard The -d to -e || -L change is load-bearing for the threat its own comment names — a dangling link at /etc/fido2 that -d reads as absent, left for the next setup to install an authfile through — and it was the one part of this work with no test behind it. Name the directory once so the suite can retarget a copy, the same seam the setup and migration suites use, and assert both halves: the link goes, and the directory it pointed at does not. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> --------- Co-authored-by: Claude Opus 5 (1M context) <[email protected]> Co-authored-by: David Heinemeier Hansson <[email protected]> Co-authored-by: Codex XHigh <[email protected]>
Summary
Fixes the FIDO2 authentication mapping so it is never writable by the user it authenticates, never staged through a caller-owned pathname that root later reopens, and safely repairs mappings created by
earlier Omarchy versions.
The previous setup did this:
pamu2fcfg >/tmp/fido2 sudo mv /tmp/fido2 /etc/fido2/fido2Because
pamu2fcfgruns unprivileged, the staged file belonged to the invoking user.mvpreserved that ownership, leaving/etc/fido2/fido2writable by the account whose sudo and polkit authentication itcontrols. Any process running as that user could append its own credential and then satisfy the
pam_u2fentry without knowing the password.This ownership defect requires no second account, race, symlink, or unusual sysctl configuration.
Why replacing the inode matters
Changing ownership or permissions in place is insufficient. Permission is checked when a file is opened, so a process that opened the legacy user-owned mapping for writing before
chownorchmodretains awritable descriptor afterward.
The migration therefore creates a fresh root-owned copy and atomically renames it over the path. Existing descriptors remain attached to the old inode, which PAM no longer reads.
Enrollment changes
omarchy-setup-security-fido2now:pamu2fcfgoutput directly into that root-owned file, so root never reopens a caller-owned pathname.pipefailand rejects failed or empty enrollment output.mv -Tf./etc/fido2asroot:rootmode0755.root:rootmode0644.Mode
0644is intentional.pam_u2fmay open even an absolute authfile as the authenticating user whenopenasuseris configured. The mapping contains credential identifiers and public keys, while theauthenticator retains the private key. Integrity requires root-only writes; compatibility requires authenticated users to be able to read it.
Migration
The migration:
/etc/fido2/fido2path rather than a caller-controlled environment override.A suspicious symlink is reported and left for manual removal and re-enrollment. Automatically following or deleting it could either expose its target or lock out someone whose password is disabled.
Threat-model clarification
On a stock Arch installation,
fs.protected_symlinks=1and the sticky/tmpdirectory block the cross-UID symlink redirect described in the original version of this PR.The primary vulnerability is the user-owned authfile, which affects every installation created by the old setup. Same-UID pathname replacement also remains relevant even with
mktemp: another processrunning as that user can observe and replace a named temporary file before root reopens it. This implementation avoids that class by sending enrollment output through a pipe into a root-created file.
Removal
omarchy-remove-security-fido2now also detects a dangling or non-directory/etc/fido2symlink. Removing it withrm -rfremoves the link itself without following its target.Credit and relationship to #7703
Credit to @calebdw for independently identifying the same ownership defect in #7703 and, importantly, recognizing that the migration must replace the inode rather than merely
chownit in place.The two PRs cannot both merge unchanged because they rewrite the same setup path and add overlapping migrations.
This PR carries that core insight forward while addressing additional issues in the current #7703 implementation:
mktempfile that root later reopens. A same-UID process can replace that file after enrollment.OMARCHY_FIDO2_AUTHFILE..newstaging name can collide between concurrent per-user migrations.For those reasons, #7703 should receive credit for the independent finding and fresh-inode repair, but should not be merged alongside or instead of this implementation unchanged.
Testing
./test/cli— 116 assertionsbash test/shell.d/security-fido2-test.sh— 5 focused setup assertionsbash test/shell.d/security-fido2-migration-test.sh— 17 focused migration assertionsbash -non all changed shell filesgit diff --checkThe focused tests cover successful enrollment, empty and failed
pamu2fcfgoutput, chmod and rename failures, cleanup, fresh-inode replacement, malformed staging output, migration metadata checks, and symlink/non-regular states.