33 * Licensed under the MIT License. See License.txt in the project root for license information.
44 *--------------------------------------------------------------------------------------------*/
55
6- import { ExtensionServiceDefinition , ExtensionServiceImplementation , GetWorkspaceAuthInfoRequest , GetWorkspaceAuthInfoResponse , PingRequest , SendErrorReportRequest , SendLocalSSHUserFlowStatusRequest } from '../../proto/typescript/ipc/v1/ipc' ;
6+ import { ExtensionServiceDefinition , ExtensionServiceImplementation , GetWorkspaceAuthInfoRequest , GetWorkspaceAuthInfoResponse , PingRequest } from '../../proto/typescript/ipc/v1/ipc' ;
77import { Disposable } from '../../common/dispose' ;
88import { ILogService } from '../../services/logService' ;
99import { ISessionService } from '../../services/sessionService' ;
1010import { CallContext , ServerError , Status } from 'nice-grpc-common' ;
1111import { IHostService } from '../../services/hostService' ;
1212import { Server , createChannel , createClient , createServer } from 'nice-grpc' ;
13- import { ITelemetryService , UserFlowTelemetryProperties } from '../../common/telemetry' ;
13+ import { ITelemetryService } from '../../common/telemetry' ;
1414import { Configuration } from '../../configuration' ;
1515import { timeout } from '../../common/async' ;
1616import { BrowserHeaders } from 'browser-headers' ;
1717import { ControlServiceClient , ServiceError } from '@gitpod/supervisor-api-grpcweb/lib/control_pb_service' ;
1818import { NodeHttpTransport } from '@improbable-eng/grpc-web-node-http-transport' ;
19- import { CreateSSHKeyPairRequest } from '@gitpod/supervisor-api-grpcweb/lib/control_pb' ;
19+ import { CreateSSHKeyPairRequest , CreateSSHKeyPairResponse } from '@gitpod/supervisor-api-grpcweb/lib/control_pb' ;
2020import * as ssh2 from 'ssh2' ;
2121import { ParsedKey } from 'ssh2-streams' ;
2222import { WrapError } from '../../common/utils' ;
@@ -66,15 +66,15 @@ class ExtensionServiceImpl implements ExtensionServiceImplementation {
6666 private async getWorkspaceSSHKey ( ownerToken : string , workspaceUrl : string , signal : AbortSignal ) {
6767 const url = new URL ( workspaceUrl ) ;
6868 url . pathname = '/_supervisor/v1' ;
69- const privateKey = await wrapSupervisorAPIError ( ( ) => new Promise < string > ( ( resolve , reject ) => {
69+ const { privateKey, userName } = await wrapSupervisorAPIError ( ( ) => new Promise < CreateSSHKeyPairResponse . AsObject > ( ( resolve , reject ) => {
7070 const metadata = new BrowserHeaders ( ) ;
7171 metadata . append ( 'x-gitpod-owner-token' , ownerToken ) ;
7272 const client = new ControlServiceClient ( url . toString ( ) , { transport : NodeHttpTransport ( ) } ) ;
7373 client . createSSHKeyPair ( new CreateSSHKeyPairRequest ( ) , metadata , ( err , resp ) => {
7474 if ( err ) {
7575 return reject ( err ) ;
7676 }
77- resolve ( resp ! . toObject ( ) . privateKey ) ;
77+ resolve ( resp ! . toObject ( ) ) ;
7878 } ) ;
7979 } ) , { signal } ) ;
8080
@@ -83,7 +83,7 @@ class ExtensionServiceImpl implements ExtensionServiceImplementation {
8383 throw new Error ( 'Error while parsing workspace SSH private key' ) ;
8484 }
8585
86- return ( parsedResult as ParsedKey ) . getPrivatePEM ( ) ;
86+ return { sshkey : ( parsedResult as ParsedKey ) . getPrivatePEM ( ) , username : userName } ;
8787 }
8888
8989 async getWorkspaceAuthInfo ( request : GetWorkspaceAuthInfoRequest , _context : CallContext ) : Promise < GetWorkspaceAuthInfoResponse > {
@@ -126,6 +126,7 @@ class ExtensionServiceImpl implements ExtensionServiceImplementation {
126126 let ownerToken = '' ;
127127 let workspaceHost = '' ;
128128 let sshkey = '' ;
129+ let username = '' ;
129130 if ( wsData . phase === 'running' ) {
130131 ownerToken = await this . sessionService . getAPI ( ) . getOwnerToken ( actualWorkspaceId , _context . signal ) ;
131132
@@ -137,7 +138,7 @@ class ExtensionServiceImpl implements ExtensionServiceImplementation {
137138 actualWorkspaceUrl = actualWorkspaceUrl . replace ( actualWorkspaceId , workspaceId ) ;
138139 }
139140
140- sshkey = await this . getWorkspaceSSHKey ( ownerToken , actualWorkspaceUrl , _context . signal ) ;
141+ ( { sshkey, username } = await this . getWorkspaceSSHKey ( ownerToken , actualWorkspaceUrl , _context . signal ) ) ;
141142 }
142143
143144 return {
@@ -149,6 +150,7 @@ class ExtensionServiceImpl implements ExtensionServiceImplementation {
149150 ownerToken,
150151 sshkey,
151152 phase : wsData . phase ,
153+ username,
152154 } ;
153155 } catch ( e ) {
154156 let code = Status . INTERNAL ;
@@ -169,41 +171,6 @@ class ExtensionServiceImpl implements ExtensionServiceImplementation {
169171 }
170172 }
171173
172- // TODO remove from protocol, don't pass sensitive info back and forth, only once for auth, daemon should do telemetry directly
173- async sendLocalSSHUserFlowStatus ( request : SendLocalSSHUserFlowStatusRequest , _context : CallContext ) : Promise < { } > {
174- if ( ! request . flowStatus || request . flowStatus === '' ) {
175- return { } ;
176- }
177- const flow : UserFlowTelemetryProperties = {
178- flow : 'local_ssh' ,
179- workspaceId : request . workspaceId ,
180- instanceId : request . instanceId ,
181- daemonVersion : request . daemonVersion ,
182- userId : request . userId ,
183- gitpodHost : request . gitpodHost ,
184- failureCode : request . flowFailureCode ,
185- } ;
186- this . telemetryService . sendUserFlowStatus ( request . flowStatus , flow ) ;
187- return { } ;
188- }
189-
190- // TODO remove from protocol, don't pass sensitive info back and forth, only once for auth, daemon should do telemetry directly
191- // local ssh daemon should be own component in reporting?
192- async sendErrorReport ( request : SendErrorReportRequest , _context : CallContext ) : Promise < { } > {
193- const err = new Error ( request . errorMessage ) ;
194- err . name = `${ request . errorName } [local-ssh]` ;
195- err . stack = request . errorStack ;
196- this . telemetryService . sendTelemetryException ( err , {
197- gitpodHost : request . gitpodHost ,
198- workspaceId : request . workspaceId ,
199- instanceId : request . instanceId ,
200- daemonVersion : request . daemonVersion ,
201- extensionVersion : request . extensionVersion ,
202- userId : request . userId ,
203- } ) ;
204- return { } ;
205- }
206-
207174 async ping ( _request : PingRequest , _context : CallContext ) : Promise < { } > {
208175 return { } ;
209176 }
0 commit comments