Skip to content

[Bug]: Cannot retrieve values stored using extension context SecretStorage #6395

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
4 tasks done
pablocabrera85 opened this issue Aug 24, 2023 · 10 comments · Fixed by #6450
Closed
4 tasks done

[Bug]: Cannot retrieve values stored using extension context SecretStorage #6395

pablocabrera85 opened this issue Aug 24, 2023 · 10 comments · Fixed by #6450
Labels
bug Something isn't working triage This issue needs to be triaged by a maintainer

Comments

@pablocabrera85
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

OS/Web Information

  • Web Browser: Chrome
  • Local OS: macOS
  • Remote OS: Ubuntu
  • Remote Architecture: amd64
  • code-server --version: 4.16.1

Steps to Reproduce

  1. Install the attached extension (rename .zip to .vsix)
  2. Execute the hello world command. This will prompt for a value that will be stored using the context.secrets instance for this extension. Input any value and proceed.
  3. Reload the browser tab
  4. Execute the hello world command again so that this time, we read the value and display it.
  5. Instead of showing the value, you will be prompted again for a value to store.
    secrets-0.0.1.zip

NOTE: If you prefer, you can just create an extension with the following code:

// The module 'vscode' contains the VS Code extensibility API
// Import the module and reference it with the alias vscode in your code below
import * as vscode from 'vscode';

// this method is called when your extension is activated
// your extension is activated the very first time the command is executed
export function activate(context: vscode.ExtensionContext) {
	
	// Use the console to output diagnostic information (console.log) and errors (console.error)
	// This line of code will only be executed once when your extension is activated
	console.log('Congratulations, your extension "secrets" is now active!');

	// The command has been defined in the package.json file
	// Now provide the implementation of the command with registerCommand
	// The commandId parameter must match the command field in package.json
	let disposable = vscode.commands.registerCommand('secrets.helloWorld', async () => {
		// The code you place here will be executed every time your command is executed
		// Display a message box to the user
			const value= await context.secrets.get('secrets.pass');
		if(value){
			vscode.window.showInformationMessage(`Retrieved ${value}`);
		}else{
			const value=await vscode.window.showInputBox({ title: 'Input secret value'});
			if(value){
				context.secrets.store('secrets.pass',value);
			}
		}
	});
	context.subscriptions.push(disposable);
}

// this method is called when your extension is deactivated
export function deactivate() {}

Expected

After the reload and executing the command a second time, the persisted value should be displayed.

According to the API, the secrets should be automatically persisted. But every time the browser tab reloads, the value is not there

		/**
		 * A storage utility for secrets. Secrets are persisted across reloads and are independent of the
		 * current opened {@link workspace.workspaceFolders workspace}.
		 */
		readonly secrets: SecretStorage;

Actual

Values are not stored between sessions/reloads

I tried the same extension in codespaces and it worked as expected

Logs

No response

Screenshot/Video

No response

Does this issue happen in VS Code or GitHub Codespaces?

  • I cannot reproduce this in VS Code.
  • I cannot reproduce this in GitHub Codespaces.

Are you accessing code-server over HTTPS?

  • I am using HTTPS.

Notes

No response

@pablocabrera85 pablocabrera85 added bug Something isn't working triage This issue needs to be triaged by a maintainer labels Aug 24, 2023
@pablocabrera85
Copy link
Author

Code server 4.11 does not have this issue

@code-asher
Copy link
Member

code-asher commented Aug 28, 2023 via email

@benz0li
Copy link
Contributor

benz0li commented Sep 2, 2023

For containers: Use environment variables to provide credentials. See #5072 (comment) ff for more information.

@pablocabrera85
Copy link
Author

@code-asher @benz0li Thanks for your replies, but the problems we are facing are not related to the github extension. We have other extensions that use the secret storage API.

We have tried also running code-server in a plain ubuntu image (not in a container), and we have the same problem with the code snippet provided.

From the dbus session logs, we can see that code-server is trying to retrieve the values from it, but we never see any event when trying to store the value.

We are using the default configuration when running code-server. Do we need to do anything in particular for the secret storage API to work?

Thanks in advance.

@code-asher
Copy link
Member

code-asher commented Sep 13, 2023 via email

@speriasamy0
Copy link

speriasamy0 commented Sep 15, 2023

Facing the same issue. After upgrading to 4.16.1, page refresh is resetting the session. I spent some time comparing codespace and my container. I didn't notice keyring or dbus configured/running in my codespace instance. Also codespace version is different from what comes with 4.16.1 which I am using.

Codespace version

/home/codespace/.vscode-remote/bin/abd2f3db4bdb28f9e95536dfa84d8479f1eb312d/bin/code-server --version
1.82.2
abd2f3db4bdb28f9e95536dfa84d8479f1eb312d
x64

My code-server instance 4.16.1 94ef3776ad7bebfb5780dfc9632e04d20d5c9a6c with Code 1.80.2

Also the doc mentions that since version 1.80 VS Code moved away from using keytar. But in my logs I see keytar is being used. Also there are references in code

[18:16:35] Going to get password from keytar: code-oss-serverundefined_publisher.secrets secrets.pass
[18:16:35] Doing get password from keytar: code-oss-serverundefined_publisher.secrets secrets.pass
[18:16:35] Did not get a password from keytar for account: secrets.pass

@speriasamy0
Copy link

speriasamy0 commented Sep 15, 2023

Attaching an archive that has a Dockerfile that bundles the example extension provided by @pablocabrera85. This has dbus and keyring configured.

docker build . -t secrets_test:latest
docker run --rm -d --name secrets-test-container --privileged -p8080:8080 secrets_test:latest

To rule out any setup issues I've added a python program. You can invoke it by launching a terminal within the browser and type python /main.py. To invoke from outside the browser, you have to ensure you're in a dbus session and the keyring unlocked.

export $(dbus-launch) 
echo | gnome-keyring-daemon --unlock # unlock the system's keyring
python /main.py

code-server-secrets.zip

fina.mov

@code-asher
Copy link
Member

code-asher commented Sep 15, 2023 via email

@matias-mule
Copy link

Same issue here.
Is there any ETA for a fixed / workaround?

@code-asher
Copy link
Member

code-asher commented Sep 22, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triage This issue needs to be triaged by a maintainer
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants