Skip to content

Fall back to default SSH private keys during authentication - #3040

Open
cjc0013 wants to merge 2 commits into
gitui-org:masterfrom
cjc0013:fix/issue-495-ssh-key-fallback
Open

cjc0013 wants to merge 2 commits into
gitui-org:masterfrom
cjc0013:fix/issue-495-ssh-key-fallback

Conversation

@cjc0013

@cjc0013 cjc0013 commented Oct 15, 2026 •

Copy link
Copy Markdown

This Pull Request partially addresses #495.

It changes the following:

  • keeps SSH-agent authentication as the first SSH credential attempt
  • falls back to existing conventional OpenSSH private keys in preference order: ~/.ssh/id_ed25519, ~/.ssh/id_ecdsa, then ~/.ssh/id_rsa
  • passes a matching .pub file to libgit2 when one exists, while preserving private-key fallback when it does not
  • tries each SSH credential source at most once so libgit2 can continue its authentication sequence without retrying one source indefinitely

This mirrors OpenSSH’s default behavior, which tries the agent and then the standard identity files.

The branch base already enables the git2 dependency's ssh feature (the prerequisite addressed by #3009).

Scope

  • Passphrase-protected fallback keys are not unlocked or prompted for. They continue to work when already loaded into an SSH agent; direct fallback currently supports keys usable without a passphrase.
  • The fallback checks only the three conventional filenames above. It does not parse ~/.ssh/config, including IdentityFile, host aliases, or configured Port values. An explicit port in an SSH URL remains handled by the existing transport path.
  • HTTPS token authentication is unchanged and out of scope.

Validation:

  • cargo build --locked -p asyncgit — passed
  • cargo test --locked -p asyncgit — passed (0 failures)
  • the credential-callback tests cover agent → Ed25519 → ECDSA → RSA order, one attempt per source, bounded exhaustion, and matching or missing .pub files
  • rustfmt --edition 2021 --check asyncgit/src/sync/cred.rs asyncgit/src/sync/remotes/callbacks.rs — passed
  • make check — passed, including workspace clippy, nextest, TOML formatting, and dependency-policy checks
  • git diff --cached --check — passed
  • isolated no-agent SSH fetch through asyncgit’s fetch API (the code path gitui uses) against a loopback sshd — the exact unpatched head failed; the patched tree succeeded and fetched the expected ref using a throwaway ~/.ssh/id_ed25519
  • passphrase-protected-key negative control — failed as expected, confirming the limitation documented above

I followed the checklist:

  • I added unittests
  • I ran make check without errors
  • I tested the overall application
  • I added an appropriate item to the changelog

Prior work and attribution

  • HanabishiRecca identified the no-agent failure mode that motivated the fallback.
  • extrawurst provided issue triage and clarified the expected authentication behavior.
  • gcgbarbosa's work in fix: Update git2 dependency to include 'ssh' feature #3009 restored the SSH transport support this change relies on.

No code was copied from issue comments or prior pull requests.

Issue-discussion provenance (not authorship or implementation attribution)

For provenance only, the issue thread also contains reports, reproductions, environment details, questions, or confirmations from: 52617365, a-essawy, Abraxos, AllenDang, apraga, aragalie, austinbutler, ayuayue, brendon-at-rea, burgessa23, ccalvarez, cd-a, cz2415, Diablo-D3, dmytro-tolkodubov, DreckSallow, eggcaker, FBen3, fgimian, frixaco, grv07, heliostatic, jamesb93, JSilva6, kyruzic, leechdraw, Martan404, matthewp, MiragianCycle, nik-rev, non-descriptive, parrotdance, psuong, RilDev, rokrdev, rootex-, Sammmmm, ser-art, ser-drephs, staszewski, tmpgnh, Tony1324, tyoc213, vagra, VictorKoenders, vtvz, xanderificnl, Zeonova, Zhoujinpeng1999.

This list is not authorship or implementation credit, and no code from these participants was copied into this change.

@cjc0013
cjc0013 marked this pull request as ready for review October 15, 2026 13:29
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