-
Notifications
You must be signed in to change notification settings - Fork 35
feat: use environment variables for CLI auth instead of file flags #663
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
Conversation
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
| )}${await this.formatLogArg(logDir)} --session-token-file ${escapeCommandArg(this.pathResolver.getSessionTokenPath(label))} --url-file ${escapeCommandArg( | ||
| this.pathResolver.getUrlPath(label), | ||
| )} %h`; |
There was a problem hiding this comment.
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()) { |
There was a problem hiding this comment.
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`; |
There was a problem hiding this comment.
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?)
| private globalConfigs(label: string): string { | ||
| const vscodeConfig = vscode.workspace.getConfiguration(); | ||
| const args = getGlobalFlags( | ||
| vscodeConfig, | ||
| this.pathResolver.getGlobalConfigDir(label), | ||
| ); | ||
| return ` ${args.join(" ")}`; | ||
| } |
There was a problem hiding this comment.
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)
Summary
Pass
CODER_URLandCODER_SESSION_TOKENvia SSHSetEnvdirective instead of using--session-token-fileand--url-fileCLI flags. This simplifies the auth flow by using environment variables that the CLI natively supports.Changes
--session-token-fileand--url-filefromvscodesshProxyCommandCODER_URLandCODER_SESSION_TOKENto SSHSetEnvdirectiveHow it works
Previously:
Now:
The CLI reads credentials from environment variables, which SSH passes via
SetEnv.