kreuzwerker / awsu

Enhanced account switching for AWS, supports Yubikey as MFA source

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

scard Sharing violation

forsberg opened this issue · comments

From time to time (multiple times a day, usually), I get this problem:

awsu -p <profile> -- <command>
error: failed to aquire credentials for profile "default": failed to initialize Yubikey: failed to establish context: scard: Sharing violation.

Unplugging and plugging the Yubikey, or running ykman oauth code <profile name> resets things to a working state.

Perhaps this should rather be reported on some Yubikey go library?

I cannot really reproduce the issue. Will retries also solve it? Or do you need to physically unplug / re-plug the device?

For me this happens related to the OpenPGP/Smartcard features of the Yubikey. Parallel to awsu I also use Yubikey to keep my SSH keys private (as described here https://florin.myip.org/blog/easy-multifactor-authentication-ssh-using-yubikey-neo-tokens ) and whenever I used the related OpenPGP agent to pull the private key, awsu would run into this issue. Running ykman oath code ... in between would reset the OpenPGP agent and also allow awsu to access the Yubikey without errors.

Finally reproduced it and tracked it here: yawn/ykoath#14.

I believe the easiest fix is to have platform specific recovery options such as (e.g. on Mac) sending KILL to com.apple.ctkpcscd. Or use aliases e.g. alias awsu="killall com.apple.ctkpcscd; awsu"?