Keyboard layout switching back to qwerty

I am on the latest 4.1 with 6.2.10-1 kernel.
On dom0, my localectl output is the following:

System Locale: LANG=fr_FR.UTF-8
VC Keymap: fr-bepo_afnor
X11 Layout: fr
X11 Model: tm2030USB-102
X11 Variant: bepo_afnor
X11 Options: grp:shifts_toggle

Sometimes, an entire AppVM switches back to qwerty. If I restart the AppVM, I get my layout back.

I may have found a pattern: I think it happens after I accidently touch my yubikey. I am supposed to touch it to confirm a gpg private key request, but, if I do it when there is no specific request, it behaves like a keyboard and sends a lot of random characters.
I have read on Yubiko website that yubikeys are recognized as keyboards by the system.

Pressing both shifts keys are not enough to switch back to my layout.

Any idea what is happening exactly in this situation, and how to prevent it from happening?
Thank you for your help!

Open a terminal in AppVM with your yubikey attached and run sudo showkey in it to see which keyboard codes will be sent by yubikey.

I get dozens of keycodes and characters, with many repetitions. The beginning of the sequence is always the same.
I have many existing keycodess (46 for Delete, 20 for caps lock, 18 for Alt…) and many unaffected (47, 22, 32…).

I am not sure what combination could trigger my issue.
I imagine that it is not an accidently result of X11 Options: grp:shifts_toggle…

I don’t know why it happens, but I have experienced the same thing happening with my yubikey.

I use a foreign language keyboard layout, and connecting the yubikey something makes the layout switch to English.

I can return to the original settings by manually switching the dom0 keyboard layout.

Indeed. Trying to switch the layout with both shifts (in my case) inside the VM is uneffective. But switching it twice in dom0 works for all the system, even for the VM. Thanks!

(It switches to azerty, then back to bépo. But I don’t know why, since bépo is the only keymap I have defined with localectl…)

EDIT: after doing that (the double layout switch in dom0), I was able to switch between bépo and qwerty in my VM, even after pressing my yubikey. And I noticed that, in another VM, it was between bépo and… azerty. It is just so strange :smile:

The yubikey needs a specific keyboard layout, or special characters wouldn’t work if you use the system layout with a different language.

I’m guessing the layout gets changed because usb keyboards are passed to dom0, and the key is able to tell dom0 what layout to use.

That is an interesting guess and it would explain what happens.
But, because the Yubikey USB device is linked to a VM, I guess I should read: “are passed to the VM”?

Can you think of a configuration where it would ignore the Yubikey layout change? (Is it safe to assume that, when I use the Yubikey with gpg, the Yubikey does not need any specific layout? After all, the layout change occurs only when I use my Yubikey outside of a gpg request.)

The key is a USB keyboard, and keyboards are controlled by this policy /etc/qubes-rpc/policy/qubes.InputKeyboard. I think the default is you allow dom0 to be able to use keyboards, which I’m guessing is why the key changes the dom0 settings.

If the policy has a rule that says sys-usb dom0 allow I think you can remove that line, but it will break your system if you are using a USB keyboard.

The key does not change dom0, it only changes the VM I am using when I press the Yubikey.
I am using a USB keyboard, so I cannot disable all USB keyboards…