@@ -68,12 +68,14 @@ import { migrateAuthToSecretsStorage } from "./migration";
6868import {
6969 getGitForWindowsSshConfigPath ,
7070 getSshHomeDir ,
71- SshConfig ,
71+ includeCoderSshConfig ,
7272 type SshValues ,
7373 mergeSshConfigValues ,
7474 parseCoderSshOptions ,
7575 parseSshConfig ,
76+ readSshConfig ,
7677 validateDeploymentSshOptions ,
78+ writeCoderSshConfig ,
7779} from "./sshConfig" ;
7880import { getRemoteSshConfigFile , getRemoteSshPath } from "./sshExtension" ;
7981import { applySettingOverrides , buildSshOverrides } from "./sshOverrides" ;
@@ -913,18 +915,12 @@ export class Remote {
913915 const { hostPrefix, safeHostname, sshHost } = parts ;
914916 // -F skips /etc/ssh/ssh_config, so use it only when Remote-SSH does.
915917 const configFile = getRemoteSshConfigFile ( ) ;
916- // One file per (host prefix, deployment); the user's config gains one shared include.
917- const sshConfig = new SshConfig (
918- configFile ?? path . join ( getSshHomeDir ( ) , ".ssh" , "config" ) ,
919- this . logger ,
920- ) ;
921- await sshConfig . load ( ) ;
922- // Never loaded: update() regenerates it without reading the old content.
923- const coderConfig = new SshConfig (
924- this . pathResolver . getSshConfigPath ( safeHostname , hostEditorId ( sshHost ) ) ,
925- this . logger ,
926- undefined ,
927- createManagedPermissions ( ) ,
918+ // The user's config gains one shared include.
919+ const userConfigPath =
920+ configFile ?? path . join ( getSshHomeDir ( ) , ".ssh" , "config" ) ;
921+ // The CLI writes its block to the user's config, so read it from there.
922+ const configSshOptions = parseCoderSshOptions (
923+ await readSshConfig ( userConfigPath ) ,
928924 ) ;
929925
930926 // Options the user set themselves win the merge below, so they are exempt
@@ -934,8 +930,6 @@ export class Remote {
934930 . getConfiguration ( "coder" )
935931 . get < string [ ] > ( "sshConfig" , [ ] ) ;
936932 const userConfig = parseSshConfig ( userConfigSsh ) ;
937- // The CLI writes its block to the user's config, so read it from there.
938- const configSshOptions = parseCoderSshOptions ( sshConfig . getRaw ( ) ) ;
939933
940934 let deploymentSshConfig = { } ;
941935 try {
@@ -996,20 +990,32 @@ export class Remote {
996990 SendEnv : SESSION_TYPE_ENV ,
997991 } ;
998992
999- // Write our file before including it, so the include never dangles.
1000- await coderConfig . update ( sshValues , sshConfigOverrides ) ;
1001- const includeDir = this . pathResolver . getSshConfigDir ( ) ;
1002- await sshConfig . updateInclude ( includeDir , safeHostname ) ;
993+ // One file per (host prefix, deployment). Write it before including it,
994+ // so the include never dangles.
995+ const coderConfigText = await writeCoderSshConfig (
996+ {
997+ path : this . pathResolver . getSshConfigPath (
998+ safeHostname ,
999+ hostEditorId ( sshHost ) ,
1000+ ) ,
1001+ permissions : createManagedPermissions ( ) ,
1002+ } ,
1003+ { values : sshValues , overrides : sshConfigOverrides } ,
1004+ this . logger ,
1005+ ) ;
1006+ const include = { dir : this . pathResolver . getSshConfigDir ( ) , safeHostname } ;
1007+ const userConfigText = await includeCoderSshConfig (
1008+ userConfigPath ,
1009+ include ,
1010+ this . logger ,
1011+ ) ;
10031012 // Without -F, Git for Windows ssh reads its own home's config. When that
10041013 // is the profile's config, the include is already there: no write.
10051014 const gitConfigPath = getGitForWindowsSshConfigPath ( ) ;
10061015 if ( ! configFile && gitConfigPath ) {
10071016 try {
10081017 await raceWithAbort (
1009- new SshConfig ( gitConfigPath , this . logger ) . updateInclude (
1010- includeDir ,
1011- safeHostname ,
1012- ) ,
1018+ includeCoderSshConfig ( gitConfigPath , include , this . logger ) ,
10131019 AbortSignal . timeout ( GIT_SSH_CONFIG_TIMEOUT_MS ) ,
10141020 ) ;
10151021 } catch ( error ) {
@@ -1028,12 +1034,12 @@ export class Remote {
10281034 ) ;
10291035 } catch ( error ) {
10301036 if ( error instanceof SshProxyCommandMissingError ) {
1031- this . warnCoderSshConfigNotRead ( includeDir , error . configFiles ) ;
1037+ this . warnCoderSshConfigNotRead ( include . dir , error . configFiles ) ;
10321038 }
10331039 this . logger . warn ( "ssh -G failed, parsing the SSH config instead" , error ) ;
10341040 return computeSshProperties (
10351041 parts . sshHost ,
1036- `${ coderConfig . getRaw ( ) } \n${ sshConfig . getRaw ( ) } ` ,
1042+ `${ coderConfigText } \n${ userConfigText } ` ,
10371043 ) ;
10381044 }
10391045 }
0 commit comments