@@ -69,25 +69,35 @@ function generatePrompt(session: SessionState): string {
6969}
7070
7171export function createSSHServer ( config : SSHConfig ) : Server {
72- const sshKeysDir = join ( process . cwd ( ) , "ssh-keys" ) ;
73- const hostKeyPath = join ( sshKeysDir , "ssh_host_rsa_key" ) ;
74-
75- if ( ! existsSync ( hostKeyPath ) ) {
72+ // Try mounted secret first, fallback to writable directory
73+ const mountedKeyPath = join ( process . cwd ( ) , "ssh-keys" , "ssh_host_ed25519_key" ) ;
74+ const generatedKeysDir = join ( process . cwd ( ) , "data" , "ssh-keys" ) ;
75+ const generatedKeyPath = join ( generatedKeysDir , "ssh_host_rsa_key" ) ;
76+
77+ let hostKeyPath = mountedKeyPath ;
78+ let hostKey : Buffer ;
79+
80+ if ( existsSync ( mountedKeyPath ) ) {
81+ console . log ( "[SSH] Using mounted host key" ) ;
82+ hostKey = readFileSync ( mountedKeyPath ) ;
83+ } else if ( existsSync ( generatedKeyPath ) ) {
84+ console . log ( "[SSH] Using generated host key" ) ;
85+ hostKey = readFileSync ( generatedKeyPath ) ;
86+ } else {
7687 console . log ( "[SSH] Generating host key..." ) ;
77- if ( ! existsSync ( sshKeysDir ) ) {
78- mkdirSync ( sshKeysDir , { recursive : true } ) ;
88+ if ( ! existsSync ( generatedKeysDir ) ) {
89+ mkdirSync ( generatedKeysDir , { recursive : true } ) ;
7990 }
8091 const { privateKey } = generateKeyPairSync ( "rsa" , {
8192 modulusLength : 2048 ,
8293 publicKeyEncoding : { type : "pkcs1" , format : "pem" } ,
8394 privateKeyEncoding : { type : "pkcs1" , format : "pem" } ,
8495 } ) ;
85- writeFileSync ( hostKeyPath , privateKey , { mode : 0o600 } ) ;
96+ writeFileSync ( generatedKeyPath , privateKey , { mode : 0o600 } ) ;
97+ hostKey = Buffer . from ( privateKey ) ;
8698 console . log ( "[SSH] Host key generated" ) ;
8799 }
88100
89- const hostKey = readFileSync ( hostKeyPath ) ;
90-
91101 const server = new Server (
92102 {
93103 hostKeys : [ hostKey ] ,
0 commit comments