Skip to content

Conversation

@vitorpy
Copy link

@vitorpy vitorpy commented Nov 22, 2025

Summary

Implements SendEnv directive parsing and environment variable forwarding to remote hosts, matching OpenSSH behavior.

Features

  • Parse SendEnv directives from SSH config files
  • Support wildcard patterns (e.g., LC_*, LANG)
  • Filter and export local environment variables to remote
  • Cross-platform support (Linux, macOS, Windows)
  • Graceful degradation when remote doesn't accept env vars

Implementation Details

Files Modified

  1. src/ssh/sshConfig.ts

    • Added 'sendenv': 'SendEnv' to SSH_CONFIG_PROPERTIES
  2. src/authResolver.ts

    • Created globToRegex(): Converts glob patterns to regex
    • Created filterEnvBySendEnv(): Filters local env vars based on patterns
    • Extracts SendEnv config and filters process.env
    • Added comprehensive trace/info logging
  3. src/serverSetup.ts

    • Updated ServerInstallOptions interface with sendEnvVars
    • Modified bash script generator to export env vars
    • Modified PowerShell script generator to set env vars

How It Works

  1. Reads SendEnv directives from SSH config
  2. Matches patterns against local environment variables with wildcard support (*, ?)
  3. Exports matched env vars in the remote shell before starting VSCode server
  4. Works on all platforms (Bash and PowerShell)

Example Usage

Host myserver
  HostName server.example.com
  SendEnv LANG LC_*
  SendEnv MY_CUSTOM_VAR

Testing

  • TypeScript compilation successful
  • Webpack bundling successful
  • Manual testing with real SSH connection
  • Verify environment variables on remote

Notes

  • Assumes AcceptEnv is configured on the remote SSH server
  • Handles both string and array formats from ssh-config library
  • Includes debug logging for troubleshooting

Implements SendEnv directive parsing and environment variable forwarding
to remote hosts, matching OpenSSH behavior.

Features:
- Parse SendEnv directives from SSH config files
- Support wildcard patterns (e.g., LC_*, LANG)
- Filter and export local environment variables to remote
- Cross-platform support (Linux, macOS, Windows)
- Graceful degradation when remote doesn't accept env vars

Implementation:
- Added SendEnv to SSH_CONFIG_PROPERTIES in sshConfig.ts
- Created glob-to-regex pattern matching in authResolver.ts
- Modified server installation scripts to export env vars
- Added comprehensive logging for debugging

The feature assumes AcceptEnv is configured on the remote SSH server.
Environment variables are exported in the remote shell before starting
the VSCode server.
@vitorpy vitorpy marked this pull request as ready for review November 22, 2025 12:36
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.

1 participant