VSCode Keychain Issues
发现问题
更新完VSCode,突然提示出错。询问请打开疑难解答指南以解决此问题,也可以使用不用 OS keyring 的较弱加密。
有关此提示的i18n信息
1 | "vs/workbench/services/secrets/electron-sandbox/secretStorageService": { |
解决问题
根据官方文档[1]的教程,试试看日志有什么报错:
1 | code --verbose --vmodule="*/components/os_crypt/*=1" | less |
第二行看到了问题所在:
1 | [23476:0714/131505.501724:VERBOSE1:key_storage_util_linux.cc(54)] Password storage detected desktop environment: (unknown) |
那问题很好解决了,直接照着官方文档改一下argv.json
就行了。
1 | { |
更新(2024-02-07):对于我而言,此前设置 --password-store=gnome
是有效的,但是 VSCode 更新后,我修改了新设置 --password-store=gnome-libsecret
才修复重新出现的问题。
(2023) Settings SYnc in Visual Studio Code§Troubleshooting keychain issues
Troubleshooting keychain issues
NOTE: This section applies to VS Code version 1.80 and higher. In 1.80, we moved away from keytar, due to its archival, in favor of Electron’s safeStorage API.
NOTE: keychain, keyring, wallet, credential store are synonymous in this document.
Settings Sync persists authentication information on desktop using the OS keychain for encryption. Using the keychain can fail in some cases if the keychain is misconfigured or the environment isn’t recognized.
To help diagnose the problem, you can restart VS Code with the following flags to generate a verbose log:
1
code --verbose --vmodule="*/components/os_crypt/*=1"
Windows & macOS
At this time, there are no known configuration issues on Windows or macOS but, if you suspect something is wrong, you can open an issue on VS Code with the verbose logs from above. This is important for us to support additional desktop configurations.
Linux
Towards the top of the logs from the previous command, you will see something to the effect of:
1
2[9699:0626/093542.027629:VERBOSE1:key_storage_util_linux.cc(54)] Password storage detected desktop environment: GNOME
[9699:0626/093542.027660:VERBOSE1:key_storage_linux.cc(122)] Selected backend for OSCrypt: GNOME_ANYWe rely on Chromium’s oscrypt module to discover and store encryption key information in the keyring. Chromium supports a number of different desktop environments. Outlined below are some popular desktop environments and troubleshooting steps that may help if the keyring is misconfigured.
GNOME or UNITY (or similar)
If the error you’re seeing is “Cannot create an item in a locked collection”, chances are your keyring’s
Login
keyring is locked. You should launch your OS’s keyring (Seahorse is the commonly used GUI for seeing keyrings) and ensure the default keyring (usually referred to asLogin
keyring) is unlocked. This keyring needs to be unlocked when you log into your system.KDE
KDE 6 is not yet fully supported by Visual Studio Code. As a workaround: The latest kwallet6 is also accessible as kwallet5, so you can force it to use kwallet5 by setting the password store to
kwallet5
as explained below in Configure the keyring to use with VS Code.It’s possible that your wallet (aka keyring) is closed. If you open KWalletManager, you can see if the default
kdewallet
is closed and if it is, make sure you open it.Other Linux desktop environments
First off, if your desktop environment wasn’t detected, you can open an issue on VS Code with the verbose logs from above. This is important for us to support additional desktop configurations.
(recommended) Configure the keyring to use with VS Code
You can manually tell VS Code which keyring to use by passing the
password-store
flag. Our recommended configuration is to first install gnome-keyring if you don’t have it already and then launch VS Code withcode --password-store="gnome"
.If this solution works for you, you can persist the value of
password-store
by opening the Command Palette (kb(workbench.action.showCommands)
) and running the Preferences: Configure Runtime Arguments command. This will open theargv.json
file where you can add the setting"password-store":"gnome"
.NOTE: If you would rather not use
gnome-keyring
, you can try using a package that implements the Secret Service API. If you do this, thepassword-store
flag can still be set tognome
and Electron will detect other implementations of the Secret Service API. Additionally, you could try installingkwallet5
on your system. If you do, you will want to set thepassword-store
flag tokwallet5
to detect the installedkwallet5
. All possible values forpassword-store
can be found in Chromium’s source.Don’t hesitate to open an issue on VS Code with the verbose logs if you run into any issues.
(not recommended) Configure basic text encryption
We rely on Chromium’s oscrypt module to discover and store encryption key information in the keyring. Chromium offers an opt-in fallback encryption strategy that uses an in-memory key based on a string that is hardcoded in the Chromium source. Because of this, this fallback strategy is, at best, obfuscation, and should only be used if you are accepting of the risk that any process on the system could, in theory, decrypt your stored secrets.
If you accept this risk, you can set
password-store
tobasic
by opening the Command Palette (kb(workbench.action.showCommands)
) and running the Preferences: Configure Runtime Arguments command. This will open theargv.json
file where you can add the setting"password-store":"basic"
. ↩︎