Skip to content

Commit

Permalink
Merge branch 'main' into add-session-support-to-tunnel-server
Browse files Browse the repository at this point in the history
  • Loading branch information
AssafKr committed Aug 1, 2023
2 parents 3128fb0 + b90effa commit b218523
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/compose-tunnel-agent/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const sshConnectionConfigFromEnv = async (): Promise<{ connectionConfig: SshConn
connectionConfig: {
...parsed,
clientPrivateKey,
username: process.env.USER ?? 'foo',
username: process.env.PREEVY_ENV_ID ?? 'foo',
knownServerPublicKeys,
insecureSkipVerify: Boolean(process.env.INSECURE_SKIP_VERIFY),
tlsServerName: process.env.TLS_SERVERNAME || undefined,
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/commands/up/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ const up = async ({
).stdout.trim()

const remoteModel = addComposeTunnelAgentService({
envId,
debug,
tunnelOpts,
urlSuffix: envId,
Expand Down
4 changes: 3 additions & 1 deletion packages/core/src/compose-tunnel-agent-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,14 @@ export const addBaseComposeTunnelAgentService = (
})

export const addComposeTunnelAgentService = (
{ tunnelOpts, sshPrivateKeyPath, knownServerPublicKeyPath, urlSuffix, debug, user }: {
{ tunnelOpts, sshPrivateKeyPath, knownServerPublicKeyPath, urlSuffix, debug, user, envId }: {
tunnelOpts: TunnelOpts
urlSuffix: string
sshPrivateKeyPath: string
knownServerPublicKeyPath: string
debug: boolean
user: string
envId: string
},
model: ComposeModel,
): ComposeModel => ({
Expand Down Expand Up @@ -89,6 +90,7 @@ export const addComposeTunnelAgentService = (
SSH_URL: tunnelOpts.url,
TLS_SERVERNAME: tunnelOpts.tlsServerName,
TUNNEL_URL_SUFFIX: urlSuffix,
PREEVY_ENV_ID: envId,
PORT: COMPOSE_TUNNEL_AGENT_SERVICE_PORT.toString(),
...debug ? { DEBUG: '1' } : {},
HOME: '/preevy',
Expand Down
3 changes: 2 additions & 1 deletion tunnel-server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,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 @@ -80,6 +80,7 @@ const sshServer = createSshServer({
const pk = createPublicKey(publicKey.getPublicPEM())

await envStore.set(key, {
envId,
target: forward.localSocketPath,
clientId,
publicKey: pk,
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
hostname: string
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 b218523

Please sign in to comment.