Skip to content

Authenticate over SSH with the default key files - #20

Merged
frantufro merged 3 commits into
mainfrom
ssh-default-key-files
Nov 12, 2026
Merged

frantufro merged 3 commits into
mainfrom
ssh-default-key-files

Conversation

@frantufro

@frantufro frantufro commented Nov 12, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • The credentials callback tries the ssh-agent, then ~/.ssh/id_ed25519, id_ecdsa and id_rsa that exist. Each credential is handed out once so libgit2 cannot retry forever.
  • Passphrase-protected keys (OpenSSH or PEM) are skipped, because libgit2 aborts the whole connection when given one without its passphrase.
  • When nothing is accepted the error names the key files tried and skipped, and says what to set up.
  • docs/ARCHITECTURE.md documents the credential order and that libgit2 ignores ~/.ssh/config (non-standard ports need an ssh:// URL).
  • The cubil task stays in doing/ until the release ships.

Testing

  • Unit tests cover key ordering, one-shot hand-out, passphrase detection and the error text.
  • Checked by hand against a local user-level sshd (127.0.0.1:2299), with no SSH_AUTH_SOCK: a key file clones and sync_write pushes; a rejected key and a passphrase-protected key each fail with an error naming the key; a stale SSH_AUTH_SOCK falls through to the key file; no key at all gives the setup hint. CI cannot run an sshd, so these are not automated.
  • cargo test, cargo clippy --all-targets -W clippy::pedantic and cargo fmt --check pass for this change.

When no ssh-agent is available, try ~/.ssh/id_ed25519, id_ecdsa and id_rsa
in order, and name the keys tried when none is accepted. Document the
credential order and the ~/.ssh/config limits in ARCHITECTURE.md.
libgit2 aborts the connection when handed an encrypted key without its
passphrase, so detect OpenSSH and PEM encryption and skip those keys,
naming them in the error. A failed agent attempt is an ordinary auth
failure that libgit2 retries, so the SSH_AUTH_SOCK gate is dropped.
Fix the ARCHITECTURE.md section order and move the task back to doing
until the release ships.
@frantufro
frantufro merged commit 90492b9 into main Nov 12, 2026
6 checks passed
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