Skip to content

Support --remote-token-file for direct desktop remote connections - #349361

Open
francoisnt wants to merge 21 commits into
microsoft:mainfrom
francoisnt:feature/remote-token-file
Open

francoisnt wants to merge 21 commits into
microsoft:mainfrom
francoisnt:feature/remote-token-file

Conversation

@francoisnt

@francoisnt francoisnt commented Nov 20, 2026 •

Copy link
Copy Markdown

Summary

Fixes #344076.

Add --remote-token-file to the desktop CLI so external launchers can authenticate direct --remote host:port connections. For example, a launcher can start a token-protected VS Code Server in a container, forward its port over SSH, and open the remote project without a resolver extension.

code --remote 127.0.0.1:PORT --remote-token-file /absolute/path/to/token /remote/project

The option accepts an absolute local file path and uses the existing server token-file format and authentication handshake. Missing, unreadable, or invalid files fail the connection. Existing remote-host confirmation still applies.

Credential lifetime

  • The token-file binding is scoped to the target window and remote authority, including when the launch is forwarded to an already-running desktop instance.
  • Ordinary network reconnects reuse the token resolved for the session, as discussed in Support a connection token file when launching with --remote host:port #344076. Reloading the window reads the file again.
  • Session state stores only whether the window requires a token. Restoring that window after an application restart requires a fresh launch with the flag.

Testing

Automated coverage includes token-file parsing and validation, window credential isolation, restart arguments, window state, and direct authority resolution. The reconnect regression test replaces the file after initial resolution, clears and re-resolves the authority, and verifies that the reconnect loop still receives the original token. Thanks to Putluru Sandeep (@sunny-kavixo) for contributing the original regression test.

How to verify the desktop flow

  1. Start a matching VS Code Server configured with --connection-token-file. With the desktop app already running, use the command above with a local file containing the same token. The remote folder should open and authenticate.
  2. Replace the contents of the local token file with another valid token and briefly interrupt the connection. Leave the server token unchanged. The window should reconnect using the original token.
  3. Reload the window. The new connection should fail authentication. Restore the original local token and reload again to verify recovery.
  4. With the authenticated remote window open and window restoration enabled, quit and restart the desktop app without the flag. The restored window should ask for a fresh launch with the token file.

francoisnt and others added 8 commits October 24, 2026 20:58
…n-file

# Conflicts:
#	src/vs/platform/windows/electron-main/windowsStateHandler.ts
Add an integration regression test verifying that ordinary remote
reconnections retain the initial resolved connection token as a session
snapshot when the underlying connection-token file changes on disk.

This confirms maintainer-approved snapshot semantics and ensures that
mutations or replacements to the token file during an active session
are not adopted during ordinary network reconnection loops.

References microsoft#344076
…ect-snapshot

test: preserve resolved connection token during ordinary reconnection
Copilot AI balanced review requested due to automatic review settings November 20, 2026 00:06
@francoisnt

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Reconnection rereads the token file instead of retaining the session’s original token, so replacing or deleting the file can change credentials or block reconnection.

1 open issue
What changed in this PR

Adds desktop --remote-token-file support for direct --remote host:port connections, allowing external launchers to authenticate without a resolver extension.

Changes:

  • Adds CLI validation and window-scoped credential access through the native host service.
  • Reuses the server token format while preserving remote-host confirmation and adding reload, restart, and restore handling.
  • Adds documentation and tests for validation, credential isolation, authority resolution, and lifecycle behavior.
File Description
src/​vs/​workbench/​test/​electron-browser/​workbenchTestServices.ts Adds the native token-service test stub.
src/​vs/​workbench/​services/​extensions/​test/​common/​directRemoteAuthority.test.ts Tests token lookup, confirmation, and failures.
src/​vs/​workbench/​services/​extensions/​electron-browser/​nativeExtensionService.ts Integrates authenticated direct resolution.
src/​vs/​workbench/​services/​extensions/​common/​directRemoteAuthority.ts Resolves direct connections after host confirmation.
src/​vs/​server/​test/​node/​serverConnectionToken.test.ts Tests desktop/server token compatibility.
src/​vs/​server/​node/​serverConnectionToken.ts Uses shared token validation and parsing.
src/​vs/​platform/​windows/​test/​electron-main/​windowsStateHandler.test.ts Tests persistence of the authentication requirement.
src/​vs/​platform/​windows/​electron-main/​windowsStateHandler.ts Stores and retrieves the non-secret restore marker.
src/​vs/​platform/​windows/​electron-main/​windowsMainService.ts Manages credential bindings across window operations.
src/​vs/​platform/​windows/​electron-main/​windows.ts Extends window-service and launch contracts.
src/​vs/​platform/​window/​common/​window.ts Adds the authentication requirement to window configuration.
src/​vs/​platform/​remote/​test/​node/​remoteConnectionToken.test.ts Tests token files, isolation, recovery, and reconnect behavior.
src/​vs/​platform/​remote/​test/​node/​fixtures/​remoteConnectionTokenProcess.ts Exercises token handling in a child process.
src/​vs/​platform/​remote/​test/​common/​connectionToken.test.ts Tests shared token-format rules.
src/​vs/​platform/​remote/​README.md Documents usage, security, lifecycle, and validation.
src/​vs/​platform/​remote/​node/​remoteConnectionToken.ts Implements token-file validation and window-scoped bindings.
src/​vs/​platform/​remote/​common/​connectionToken.ts Defines shared token validation and parsing.
src/​vs/​platform/​native/​electron-main/​nativeHostMainService.ts Delegates window-specific token requests.
src/​vs/​platform/​native/​common/​native.ts Adds the native token lookup contract.
src/​vs/​platform/​lifecycle/​electron-main/​lifecycleMainService.ts Sanitizes token-bearing relaunch arguments.
src/​vs/​platform/​launch/​electron-main/​launchMainService.ts Routes token-bearing launches through window loading.
src/​vs/​platform/​environment/​test/​node/​argv.test.ts Tests relaunch argument sanitization.
src/​vs/​platform/​environment/​node/​argvHelper.ts Validates arguments and strips transient relaunch options.
src/​vs/​platform/​environment/​node/​argv.ts Registers the CLI option and help text.
src/​vs/​platform/​environment/​common/​argv.ts Adds the parsed argument type.
src/​vs/​code/​node/​cli.ts Validates token files before desktop launch.
src/​vs/​code/​electron-main/​main.ts Reports token-related startup failures.

Review effort: Balanced

@francoisnt

Copy link
Copy Markdown
Author

Hi Connor Peet (@connor4312) , thanks for clarifying the token snapshot behavior in #344076. This PR implements it for direct desktop connections. The reconnect regression test verifies that changing the token file during a session leaves ordinary reconnects using the original token. When you have a chance, could you take a look and let me know whether this is the direction you’d want?

@francoisnt

Copy link
Copy Markdown
Author

Hi Alexandru Dima (@alexdima), would you be the right person to review this change to direct remote connections?

The PR implements the session snapshot behavior discussed with Connor Peet (@connor4312) in #344076, and I've resolved the conflicts with upstream.

In the meantime, would it be possible to approve the CI workflows so I can address any build or test failures ahead of the review?

Thanks!

@francoisnt

Copy link
Copy Markdown
Author

While waiting for upstream CI approval, I ran independent validation on my fork against the current PR revision (79b8ed1). Client compilation, TypeScript type checking, and all targeted Node.js and Electron tests passed, including the reconnection regression test.

Successful CI run

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support a connection token file when launching with --remote host:port

3 participants