Skip to content

fix(sshclient): 修复 SSH agent 阻断文件私钥回退 - #1

Merged
shayuc137 merged 1 commit into
mainfrom
codex/ssh-agent-key-fallback
Sep 9, 2026
Merged

shayuc137 merged 1 commit into
mainfrom
codex/ssh-agent-key-fallback

Conversation

@shayuc137

Copy link
Copy Markdown
Owner

Summary

可连接但为空或密钥不匹配的 SSH agent 会阻断有效的 IdentityFile / 默认私钥认证。将所有 signer 合并为单个 publickey 方法后,文件密钥能够按顺序继续尝试,密码仍作为独立后备方式。

Changes

  • 保留既有修复:合并 agent、显式 IdentityFile 与默认私钥的 signer,避免 x/crypto/ssh 按方法名去重而跳过后续密钥。
  • agent 无法连接、为空或读取失败时继续使用文件私钥;限制 agent I/O 等待时间。
  • Dial 在成功和配置、拨号、握手失败路径释放 agent socket,保留握手期间的签名能力。
  • 扩展回归测试为直接调用生产 Dial 的 12 个场景;密码后备断言确实先拒绝公钥,连接清理在 Client.Close 前验证。

Testing

  • go test ./...
  • go test -race ./...
  • go vet ./...
  • staticcheck ./...
  • go build ./...
  • Linux / Darwin / Windows × amd64 / arm64:六组 GOOS=... GOARCH=... go build ./...
  • 独立临时副本使用基线 cc3130c 和新增测试:empty-agent、wrong-agent-key、default-key 均按预期失败;修复后全部 12 场景通过。
  • 当前源码构建的 sshq 在继承的 SSH 环境中执行 doctor rn、exec rn --no-daemon pwd、exec rn pwd 均成功,远端命令退出 0。

验证环境:Go 1.26.0 linux/amd64,staticcheck 2026.1。部分未变更包使用 Go 测试缓存。

验证边界:daemon 未运行,普通 exec 日志显示 direct;没有真实 daemon、ProxyJump 或 macOS/Windows 原生运行证据。交叉构建仅证明编译通过。CLI、flags 和 metadata 未变更,无需重新生成 skill 文档。未打版本标签或发布 Release。

Combine agent, explicit identity and default key signers into one publickey authentication method so x/crypto/ssh does not skip later key sources. Keep password authentication as a separate fallback and release the agent socket after Dial succeeds or fails.

Exercise production Dial with 12 authentication and cleanup scenarios, including an unresponsive agent and public-key rejection before password fallback.
@coderabbitai

coderabbitai Bot commented Sep 9, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: f5a60a50-2bb9-4713-a2a9-346d5aaa45fe


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@shayuc137
shayuc137 merged commit 11bcec9 into main Sep 9, 2026
5 checks passed
shayuc137 added a commit that referenced this pull request Oct 23, 2026
Bumps the version markers that must move together (internal/version,
SKILL.md frontmatter and the generated references) and closes the
changelog section.

The changelog gains the one entry it was missing: 5b04b0f, merged via
PR #1, fixed key files being skipped whenever an SSH agent was running.
x/crypto/ssh uses only the first public-key auth method, so the agent
shadowed IdentityFile and the default keys.

v0.5.0 rather than v0.4.2 because `cp -r` now lands at <dst>/<name>
for existing or slash-terminated destinations, which changes the result
of commands that used to work.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AFntpiMHjBwGsW94eNmAbP
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant