CreatePGPUnlocker leaves a partial unlocker directory on disk when fingerprint resolution fails #48
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
From the 1.0 security survey. Small, but it produces exactly the corrupt-unlocker state that #42 is about handling gracefully — better to not create it.
Problem
CreatePGPUnlocker(internal/secret/pgpunlocker.go:260) writes its on-disk state across several steps, and the last validation happens after most of the writing is done::249-304create the unlocker directory, writepub.txt, and writelongterm.age.:324then re-resolves the GPG fingerprint, feedingwritePGPUnlockerMetadataat:341.If that resolution fails — the key was removed from the keyring between the pre-check and here, the agent died, a smartcard was unplugged — the function errors out having already written an unlocker directory with no metadata file. That is precisely the shape that broke
secret unlocker listin issue #1, and the same shape that currently makesPGPUnlocker.GetID()panic (#42).The pre-flight validation is good and already exists:
internal/cli/unlockers.go:671-674callsResolveGPGKeyFingerprintbeforeCreatePGPUnlocker, andpreparePGPUnlockerDircallscheckGPGAvailable(). So the window is narrow. It is not zero, and the consequence is a vault the user cannot list.Definition of done
CreatePGPUnlockereither completes fully or leaves no trace. Any failure after the unlocker directory is created removes it before returning.:324.make checkgreen.TODO.mdupdated in the same commit.Implementation requirements
RemoveAllon a directory this function created is safe; make sure it cannot ever run against a directory that already existed before the call, which would delete a working unlocker. Track whether this invocation created it.