Skip to content

Commit

Permalink
tunnel-server: store envId in envStore (#152)
Browse files Browse the repository at this point in the history
  • Loading branch information
Roy Razon authored Aug 1, 2023
1 parent f59e26b commit b90effa
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 2 deletions.
3 changes: 2 additions & 1 deletion tunnel-server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const sshServer = createSshServer({
socketDir: '/tmp', // TODO
})
.on('client', client => {
const { clientId, publicKey } = client
const { clientId, publicKey, envId } = client
const tunnels = new Map<string, string>()
client
.on('forward', async (requestId, { path: remotePath, access }, accept, reject) => {
Expand All @@ -71,6 +71,7 @@ const sshServer = createSshServer({
const forward = await accept()
sshLogger.debug('creating tunnel %s for localSocket %s', key, forward.localSocketPath)
await envStore.set(key, {
envId,
target: forward.localSocketPath,
clientId,
publicKey: createPublicKey(publicKey.getPublicPEM()),
Expand Down
1 change: 1 addition & 0 deletions tunnel-server/src/preview-env.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { KeyObject } from 'crypto'

export type PreviewEnv = {
envId: string
clientId: string
target: string
publicKey: KeyObject
Expand Down
1 change: 1 addition & 0 deletions tunnel-server/src/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ export function proxyHandlers({
}
)
}, err => logger.error('error forwarding traffic %j', { error: err })),

wsHandler: asyncHandler(async (req: IncomingMessage, socket: internal.Duplex, head: Buffer) => {
const env = await resolveTargetEnv(req)
if (!env) {
Expand Down
4 changes: 3 additions & 1 deletion tunnel-server/src/ssh-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export interface ClientForward extends EventEmitter {
}

export interface SshClient extends EventEmitter {
envId: string
clientId: string
publicKey: ParsedKey
on: (
Expand Down Expand Up @@ -126,8 +127,9 @@ export const sshServer = (
preevySshClient = Object.assign(new EventEmitter(), {
publicKey: keyOrError,
clientId: idFromPublicSsh(keyOrError.getPublicSSH()),
envId: ctx.username,
})
log.debug('accepting clientId %j', preevySshClient.clientId)
log.debug('accepting clientId %j envId %j', preevySshClient.clientId, preevySshClient.envId)
ctx.accept()
serverEmitter.emit('client', preevySshClient)
})
Expand Down

0 comments on commit b90effa

Please sign in to comment.