@@ -63,7 +63,7 @@ export class SshAddResource extends Resource<SshAddConfig> {
6363
6464 let appleUseKeychain : boolean | undefined ;
6565 if ( parameters . appleUseKeychain ) {
66- appleUseKeychain = Utils . isMacOS ( ) ? ( await this . isKeyLoadedInKeychain ( sshPath ) ) : parameters . appleUseKeychain ;
66+ appleUseKeychain = ( Utils . isMacOS ( ) && ! ( await this . isInsideVM ( ) ) ) ? ( await this . isKeyLoadedInKeychain ( sshPath ) ) : parameters . appleUseKeychain ;
6767 }
6868
6969 return {
@@ -109,21 +109,41 @@ export class SshAddResource extends Resource<SshAddConfig> {
109109 return false ;
110110 }
111111
112-
113- const $ = getPty ( ) ;
112+ const $ = getPty ( ) ;
114113 const { data : keychainKeys , status } = await $ . spawnSafe ( '/usr/bin/ssh-add --apple-load-keychain' , { interactive : true } ) ;
115114 if ( status === SpawnStatus . ERROR ) {
116115 return false ;
117116 }
118117
118+ if ( keychainKeys . includes ( 'No identity found' ) ) {
119+ return false ;
120+ }
121+
119122 return keychainKeys . trim ( )
120123 . split ( / \n / )
121124 . filter ( Boolean )
122125 . map ( ( l ) => {
123- const [ line , path , comment ] = l . trim ( ) . match ( APPLE_KEYCHAIN_REGEX ) ?? [ ] ;
124- return { line, path, comment } ;
126+ const result = l . trim ( ) . match ( APPLE_KEYCHAIN_REGEX ) ?? [ ] ;
127+ if ( result . length < 3 ) {
128+ return undefined ;
129+ }
130+
131+ return { line : result [ 0 ] , path : result [ 1 ] , comment : result [ 2 ] } ;
125132 } )
126- . some ( ( result ) => path . resolve ( keyPath ) === path . resolve ( result . path ) )
133+ . filter ( Boolean )
134+ . some ( ( result ) => path . resolve ( keyPath ) === path . resolve ( result ! . path ) )
135+ }
136+
137+ /**
138+ * Check if the script is currently executing inside a VM. Tart VM's don't work properly with apple keychain currently.
139+ * We're introducing a HACK to skip out on the keychain check if inside a VM.
140+ * @private
141+ */
142+ private async isInsideVM ( ) : Promise < boolean > {
143+ const $ = getPty ( ) ;
144+ const { data : model } = await $ . spawnSafe ( 'sysctl -n hw.model' )
145+
146+ return model . includes ( 'VirtualMac' ) ;
127147 }
128148
129149}
0 commit comments