Skip to content

Commit 8143c99

Browse files
committed
feat: use environment variables for CLI auth instead of file flags
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
1 parent 91d481e commit 8143c99

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

src/core/cliManager.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -710,10 +710,10 @@ export class CliManager {
710710
}
711711

712712
/**
713-
* Update the URL for the deployment with the provided label on disk which can
714-
* be used by the CLI via --url-file. If the URL is falsey, do nothing.
713+
* Update the URL for the deployment with the provided label on disk for
714+
* persistence. If the URL is falsey, do nothing.
715715
*
716-
* If the label is empty, read the old deployment-unaware config instead.
716+
* If the label is empty, use the old deployment-unaware path instead.
717717
*/
718718
private async updateUrlForCli(
719719
label: string,
@@ -728,10 +728,9 @@ export class CliManager {
728728

729729
/**
730730
* Update the session token for a deployment with the provided label on disk
731-
* which can be used by the CLI via --session-token-file. If the token is
732-
* null, do nothing.
731+
* for persistence. If the token is null, do nothing.
733732
*
734-
* If the label is empty, read the old deployment-unaware config instead.
733+
* If the label is empty, use the old deployment-unaware path instead.
735734
*/
736735
private async updateTokenForCli(
737736
label: string,

src/remote/remote.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,8 @@ export class Remote {
479479
binaryPath,
480480
logDir,
481481
featureSet,
482+
baseUrlRaw,
483+
token,
482484
);
483485
} catch (error) {
484486
this.logger.warn("Failed to configure SSH", error);
@@ -597,6 +599,8 @@ export class Remote {
597599
binaryPath: string,
598600
logDir: string,
599601
featureSet: FeatureSet,
602+
url: string,
603+
token: string,
600604
) {
601605
let deploymentSSHConfig = {};
602606
try {
@@ -677,9 +681,7 @@ export class Remote {
677681
? `${escapeCommandArg(binaryPath)}${globalConfigs} ssh --stdio --usage-app=vscode --disable-autostart --network-info-dir ${escapeCommandArg(this.pathResolver.getNetworkInfoPath())}${await this.formatLogArg(logDir)} --ssh-host-prefix ${hostPrefix} %h`
678682
: `${escapeCommandArg(binaryPath)}${globalConfigs} vscodessh --network-info-dir ${escapeCommandArg(
679683
this.pathResolver.getNetworkInfoPath(),
680-
)}${await this.formatLogArg(logDir)} --session-token-file ${escapeCommandArg(this.pathResolver.getSessionTokenPath(label))} --url-file ${escapeCommandArg(
681-
this.pathResolver.getUrlPath(label),
682-
)} %h`;
684+
)}${await this.formatLogArg(logDir)} %h`;
683685

684686
const sshValues: SSHValues = {
685687
Host: hostPrefix + `*`,
@@ -690,9 +692,9 @@ export class Remote {
690692
LogLevel: "ERROR",
691693
};
692694
if (sshSupportsSetEnv()) {
693-
// This allows for tracking the number of extension
694-
// users connected to workspaces!
695-
sshValues.SetEnv = " CODER_SSH_SESSION_TYPE=vscode";
695+
// Pass Coder URL, session token, and session type via environment.
696+
// The CLI reads CODER_URL and CODER_SESSION_TOKEN from the environment.
697+
sshValues.SetEnv = ` CODER_URL=${url} CODER_SESSION_TOKEN=${token} CODER_SSH_SESSION_TYPE=vscode`;
696698
}
697699

698700
await sshConfig.update(label, sshValues, sshConfigOverrides);

0 commit comments

Comments
 (0)