Remote Tunnels
Relevant source files
The following files were used as context for generating this wiki page:Remote Tunnels allow developers to securely connect to a remote machine from a local VS Code client, without needing to configure SSH. This functionality is primarily managed through a command-line interface (CLI) tool and a corresponding VS Code extension (tunnel-forwarding). The system leverages a service, referred to as "dev tunnels," to create and manage these secure connections.
The feature is composed of two main parts: the CLI for tunnel management (creation, listing, deletion) and a VS Code extension that integrates this functionality into the editor. The extension activates onTunnel events and provides commands for interacting with the active tunnel, such as showing logs or restarting the service. Other extensions can also leverage tunnel capabilities through proposed APIs like tunnelFactory and tunnels.
CLI Integration
The VS Code CLI provides a dedicated tunnel command to manage remote tunnels. This is the primary entry point for users to interact with the tunnel service from the command line.
Sources: cli/src/main.rs, cli/src/commands/tunnels.rs
Command Structure
The main application logic dispatches the tunnel command and its arguments to the tunnels module for execution.
This diagram illustrates the flow of a CLI command from the user to the responsible module.
Subcommands
The tunnel command exposes several subcommands for managing the lifecycle of tunnels and user authentication.
| Command | Description |
|---|---|
user | Manages the tunnel user, including login and showing user information. |
service | Installs and manages the tunnel service. |
rename | Renames a tunnel. |
prune | Deletes all existing tunnels. |
list | Lists available tunnels. |
delete | Deletes a tunnel. |
Sources: cli/src/commands/tunnels.rs:41-59
Dev Tunnels Service
The dev_tunnels module contains the core logic for interacting with the underlying tunnel service. It abstracts the API calls for creating, listing, renaming, and deleting tunnels.
Sources: cli/src/tunnels/dev_tunnels.rs
Core Operations
The DevTunnels struct is the central component for making requests to the tunnel service. It is instantiated with authentication and service details and provides methods that map directly to the tunnel management subcommands.
This sequence diagram shows how the code tunnel list command is processed.
Key functions within the dev_tunnels module include:
list(): Fetches a list of all tunnels for the authenticated user.rename(): Renames a tunnel given its current name and a new name.delete(): Deletes a specified tunnel.
Sources: cli/src/tunnels/dev_tunnels.rs:104-150
Tunnel Forwarding Extension
The tunnel-forwarding extension integrates the remote tunnel functionality directly into the VS Code UI. It is responsible for handling tunnel-related events and providing user-facing commands.
Sources: extensions/tunnel-forwarding/package.json, extensions/tunnel-forwarding/src/extension.ts
Extension Manifest
The package.json for the extension defines its core properties, activation events, and contributions.
- Activation: The extension is activated by the
onTunnelevent. - API Proposals: It uses the
resolversandtunnelFactoryAPI proposals, indicating its role in creating and managing connection tunnels. - Commands: It contributes commands for managing the tunnel from within VS Code.
Sources: extensions/tunnel-forwarding/package.json:19-38
Commands
The extension provides the following commands accessible from the command palette:
| Command ID | Title | Enablement |
|---|---|---|
tunnel-forwarding.showLog | Show Log | tunnelForwardingHasLog |
tunnel-forwarding.restart | Restart | tunnelForwardingIsRunning |
Sources: extensions/tunnel-forwarding/package.json:24-37
Activation Logic
The extension.ts file contains the activation logic. When activated, it registers a TunnelFactory which is responsible for creating new tunnels.
// extensions/tunnel-forwarding/src/extension.ts:24-29
export function activate(context: vscode.ExtensionContext) {
const logger = new Logger(vscode.l10n.t('Tunnel-Forwarding'));
context.subscriptions.push(
vscode.workspace.registerTunnelProvider(
new TunnelProvider(logger, context.extensionUri),
{
Sources: extensions/tunnel-forwarding/src/extension.ts:24-29
API and Integration
The remote tunnel functionality is designed to be extensible, allowing other VS Code extensions to programmatically create and manage tunnels.
API Proposals
The following API proposals are key to the tunnel functionality:
| Proposal | Description | Used In |
|---|---|---|
tunnels | Provides APIs for working with tunnels. | vscode-test-resolver |
tunnelFactory | Allows extensions to provide a factory for creating tunnels. | tunnel-forwarding |
resolvers | Enables extensions to act as remote authority resolvers. | tunnel-forwarding, vscode-test-resolver |
Sources: extensions/tunnel-forwarding/package.json:19-22, extensions/vscode-test-resolver/package.json:8-11
Third-Party Dependencies
Other components within the ecosystem, such as the GitHub extension, may include dependencies related to tunneling, although they might not directly use the tunnelFactory API. For instance, the github extension has a dependency on the tunnel npm package.