Skip to content

Conversation

@ibetitsmike
Copy link
Collaborator

Summary

Pass CODER_URL and CODER_SESSION_TOKEN via SSH SetEnv directive instead of using --session-token-file and --url-file CLI flags. This simplifies the auth flow by using environment variables that the CLI natively supports.

Changes

  • Remove --session-token-file and --url-file from vscodessh ProxyCommand
  • Add CODER_URL and CODER_SESSION_TOKEN to SSH SetEnv directive
  • Update doc comments to reflect persistence-only purpose of file storage
  • Keep file-based storage for extension's own credential persistence across sessions

How it works

Previously:

ProxyCommand coder vscodessh --session-token-file /path/to/session --url-file /path/to/url %h

Now:

ProxyCommand coder vscodessh %h
SetEnv CODER_URL=https://example.coder.com CODER_SESSION_TOKEN=xxx CODER_SSH_SESSION_TYPE=vscode

The CLI reads credentials from environment variables, which SSH passes via SetEnv.

Pass CODER_URL and CODER_SESSION_TOKEN via SSH SetEnv directive instead
of using --session-token-file and --url-file CLI flags. This simplifies
the auth flow by using environment variables that the CLI natively supports.

Changes:
- Remove --session-token-file and --url-file from vscodessh ProxyCommand
- Add CODER_URL and CODER_SESSION_TOKEN to SSH SetEnv directive
- Update doc comments to reflect persistence-only purpose of file storage
- Keep file-based storage for extension's own credential persistence
Comment on lines -680 to -682
)}${await this.formatLogArg(logDir)} --session-token-file ${escapeCommandArg(this.pathResolver.getSessionTokenPath(label))} --url-file ${escapeCommandArg(
this.pathResolver.getUrlPath(label),
)} %h`;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This removes the session token and URL file from being passed to vscodessh which is the old client that I think is only used by some older servers (< 2.19.0)

UserKnownHostsFile: "/dev/null",
LogLevel: "ERROR",
};
if (sshSupportsSetEnv()) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Wouldn't this just fail if the SSH does not support SetEnv? is it possible to have this as a fallback?

sshValues.SetEnv = " CODER_SSH_SESSION_TYPE=vscode";
// Pass Coder URL, session token, and session type via environment.
// The CLI reads CODER_URL and CODER_SESSION_TOKEN from the environment.
sshValues.SetEnv = ` CODER_URL=${url} CODER_SESSION_TOKEN=${token} CODER_SSH_SESSION_TYPE=vscode`;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Here we still have the token in plaintext but it's now in <globalDir>/<deployment url>/session and in the proxy command (somewhere in ~/.ssh/config?)

Comment on lines 737 to 744
private globalConfigs(label: string): string {
const vscodeConfig = vscode.workspace.getConfiguration();
const args = getGlobalFlags(
vscodeConfig,
this.pathResolver.getGlobalConfigDir(label),
);
return ` ${args.join(" ")}`;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

If we want to rely on environment variables fully then we need to update the getGlobalFlags function to not return "--global-config", escapeCommandArg(configDir)

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.

2 participants