Skip to content
Closed
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
4 changes: 4 additions & 0 deletions packages/ssh/src/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,10 @@ export const buildSshChildEnvironment = Effect.fn("ssh/auth.buildSshChildEnviron
export function isSshAuthFailure(error: unknown): boolean {
const message = error instanceof Error ? error.message : String(error);
const normalized = message.toLowerCase();
// Surface the agent signing error instead of hiding it behind a password prompt.
if (/(?:^|\n)sign_and_send_pubkey: signing failed [^\n]* from agent: /u.test(normalized)) {
return false;
}
return (
/permission denied \((?:publickey|password|keyboard-interactive|hostbased|gssapi-with-mic)[^)]*\)/u.test(
normalized,
Expand Down
96 changes: 96 additions & 0 deletions packages/ssh/src/tunnel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,102 @@ describe("ssh tunnel scripts", () => {
}),
);

it.effect.each([
{
name: "agent signing failure",
stderr:
'sign_and_send_pubkey: signing failed for ED25519 "/tmp/key" from agent: agent refused operation\nubuntu@127.0.0.1: Permission denied (publickey,password,keyboard-interactive).',
expectedPrompts: 0,
},
{
name: "agent communication failure while signing",
stderr:
'sign_and_send_pubkey: signing failed for ED25519 "/tmp/key" from agent: communication with agent failed\r\nubuntu@127.0.0.1: Permission denied (publickey,password).',
expectedPrompts: 0,
},
{
name: "agent unreachable before any key is offered",
stderr:
"error fetching identities: communication with agent failed\nubuntu@127.0.0.1: Permission denied (publickey,password).",
expectedPrompts: 1,
},
{
name: "agent signing failure on a key-only server",
stderr:
'sign_and_send_pubkey: signing failed for ED25519 "/tmp/key" from agent: agent refused operation\nubuntu@127.0.0.1: Permission denied (publickey).',
expectedPrompts: 0,
},
{
name: "publickey-only denial",
stderr: "ubuntu@127.0.0.1: Permission denied (publickey).",
expectedPrompts: 1,
},
{
name: "password denial",
stderr: "ubuntu@127.0.0.1: Permission denied (publickey,password).",
expectedPrompts: 1,
},
{
name: "keyboard-interactive denial",
stderr: "ubuntu@127.0.0.1: Permission denied (publickey,keyboard-interactive).",
expectedPrompts: 1,
},
])(
"prompts for a password unless the agent failed to sign: $name",
({ stderr, expectedPrompts }) =>
Effect.gen(function* () {
let prompts = 0;
const spawner = ChildProcessSpawner.make((command) =>
Effect.succeed(
commandArgs(command).includes("-G")
? makeSuccessfulProcess("")
: {
...makeSuccessfulProcess(""),
exitCode: Effect.succeed(ChildProcessSpawner.ExitCode(255)),
stderr: Stream.make(new TextEncoder().encode(stderr)),
},
),
);
const layer = Layer.mergeAll(
NodeServices.layer,
Layer.succeed(ChildProcessSpawner.ChildProcessSpawner, spawner),
Layer.succeed(HttpClient.HttpClient, hangingHttpClient),
Layer.succeed(NetService.NetService, testNetService),
Layer.succeed(
SshAuth.SshPasswordPrompt,
SshAuth.SshPasswordPrompt.of({
isAvailable: true,
request: () =>
Effect.sync(() => {
prompts++;
return null;
}),
}),
),
SshTunnel.SshEnvironmentManager.layer({ resolveCliRunner: Effect.succeed(ARCHIVE) }),
);
yield* Effect.gen(function* () {
const manager = yield* SshTunnel.SshEnvironmentManager;
const result = yield* Effect.result(
manager.ensureEnvironment({
alias: "devbox",
hostname: "127.0.0.1",
username: "ubuntu",
port: null,
}),
);
assert.isTrue(Result.isFailure(result));
assert.equal(prompts, expectedPrompts);
if (expectedPrompts === 0 && Result.isFailure(result)) {
assert.instanceOf(result.failure, SshCommandError);
if (result.failure instanceof SshCommandError) {
assert.equal(result.failure.stderr, stderr);
}
}
}).pipe(Effect.provide(layer), Effect.scoped);
}),
);

it.effect.each(["local tunnel", "remote server"] as const)(
"waits for %s shutdown before reconnecting the same target",
(stalledStep) =>
Expand Down
Loading