Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v15] Add ssh.forwardAgent setting to Connect #46897

Merged
merged 1 commit into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/pages/connect-your-client/teleport-connect.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,7 @@ Below is the list of the supported config properties.
| `keymap.openSearchBar` | `Command+K` on macOS<br/>`Ctrl+K` on Windows/Linux | Shortcut to open the search bar. |
| `headless.skipConfirm` | false | Skips the confirmation prompt for Headless WebAuthn approval and instead prompts for WebAuthn immediately. |
| `ssh.noResume` | false | Disables SSH connection resumption. |
| `ssh.forwardAgent` | true | Enables agent forwarding. |

<Admonition
type="note"
Expand Down
2 changes: 2 additions & 0 deletions web/packages/teleterm/src/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ async function getElectronGlobals(): Promise<ElectronGlobals> {
{
ssh: {
noResume: mainProcessClient.configService.get('ssh.noResume').value,
forwardAgent:
mainProcessClient.configService.get('ssh.forwardAgent').value,
},
terminal: {
windowsBackend: mainProcessClient.configService.get(
Expand Down
6 changes: 6 additions & 0 deletions web/packages/teleterm/src/services/config/appConfigSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,12 @@ export const createAppConfigSchema = (platform: Platform) => {
.boolean()
.default(false)
.describe('Disables SSH connection resumption.'),
'ssh.forwardAgent': z
.boolean()
.default(true)
.describe(
"Enables agent forwarding when connecting to SSH nodes. It's the equivalent of the forward-agent flag in tsh ssh."
),
});
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,17 @@ import {
ShellCommand,
TshLoginCommand,
GatewayCliClientCommand,
SshOptions,
} from '../types';

import { getPtyProcessOptions } from './buildPtyOptions';

const makeSshOptions = (options: Partial<SshOptions> = {}): SshOptions => ({
noResume: false,
forwardAgent: false,
...options,
});

describe('getPtyProcessOptions', () => {
describe('pty.gateway-cli-client', () => {
it('merges process env with the env from cmd', () => {
Expand All @@ -47,7 +54,7 @@ describe('getPtyProcessOptions', () => {

const { env } = getPtyProcessOptions(
makeRuntimeSettings(),
{ ssh: { noResume: false }, windowsPty: { useConpty: true } },
{ ssh: makeSshOptions(), windowsPty: { useConpty: true } },
cmd,
processEnv
);
Expand Down Expand Up @@ -76,7 +83,7 @@ describe('getPtyProcessOptions', () => {

const { env } = getPtyProcessOptions(
makeRuntimeSettings(),
{ ssh: { noResume: false }, windowsPty: { useConpty: true } },
{ ssh: makeSshOptions(), windowsPty: { useConpty: true } },
cmd,
processEnv
);
Expand All @@ -103,12 +110,71 @@ describe('getPtyProcessOptions', () => {

const { args } = getPtyProcessOptions(
makeRuntimeSettings(),
{ ssh: { noResume: true }, windowsPty: { useConpty: true } },
{
ssh: makeSshOptions({ noResume: true }),
windowsPty: { useConpty: true },
},
cmd,
processEnv
);

expect(args).toContain('--no-resume');
});

it('enables agent forwarding on tsh ssh invocations if the option is set', () => {
const processEnv = {
processExclusive: 'process',
shared: 'fromProcess',
};
const cmd: TshLoginCommand = {
kind: 'pty.tsh-login',
clusterName: 'bar',
proxyHost: 'baz',
login: 'bob',
serverId: '01234567-89ab-cdef-0123-456789abcdef',
rootClusterId: 'baz',
leafClusterId: undefined,
};

const { args } = getPtyProcessOptions(
makeRuntimeSettings(),
{
ssh: makeSshOptions({ forwardAgent: true }),
windowsPty: { useConpty: true },
},
cmd,
processEnv
);

expect(args).toContain('--forward-agent');
});

it('does not enable agent forwarding on tsh ssh invocations if the option is not set', () => {
const processEnv = {
processExclusive: 'process',
shared: 'fromProcess',
};
const cmd: TshLoginCommand = {
kind: 'pty.tsh-login',
clusterName: 'bar',
proxyHost: 'baz',
login: 'bob',
serverId: '01234567-89ab-cdef-0123-456789abcdef',
rootClusterId: 'baz',
leafClusterId: undefined,
};

const { args } = getPtyProcessOptions(
makeRuntimeSettings(),
{
ssh: makeSshOptions({ forwardAgent: false }),
windowsPty: { useConpty: true },
},
cmd,
processEnv
);

expect(args).not.toContain('--forward-agent');
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export function getPtyProcessOptions(
`--proxy=${cmd.rootClusterId}`,
'ssh',
...(options.ssh.noResume ? ['--no-resume'] : []),
'--forward-agent',
...(options.ssh.forwardAgent ? ['--forward-agent'] : []),
loginHost,
];

Expand Down
4 changes: 4 additions & 0 deletions web/packages/teleterm/src/services/pty/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ export type SshOptions = {
* (by adding the `--no-resume` option).
*/
noResume: boolean;
/**
* Enables agent forwarding when running `tsh ssh` by adding the --forward-agent option.
*/
forwardAgent: boolean;
};

export type TerminalOptions = {
Expand Down
Loading