GitSshdSessionFactory - why do I need a credentialsProvider if I've configured the SshSessionFactory?
- Dominant language
- Java
- Stars
- 1.1k
- Forks
- 400
- Avg merge
- 5d 1h
- Merged PRs (30d)
- 1
Description
Hello,
I'm using the following JGit and Apache MINA dependencies in my project:
```
implementation "org.eclipse.jgit:org.eclipse.jgit:6.10.0.202406032230-r"
implementation "org.eclipse.jgit:org.eclipse.jgit.ssh.apache:6.10.0.202406032230-r"
implementation "org.apache.sshd:sshd-git:2.13.1"
```
I've created a default `org.apache.sshd.client.SshClient` with:
`SshClient sshClient = SshClient.setUpDefaultClient();`
and then set an instance of the GitSshdSessionFactory on JGits SshSessionFactory:
`SshSessionFactory.setInstance(new GitSshdSessionFactory(sshClient));`
By default the sshClient is reading the SSH keys I have stored in the `~/.ssh` folder where the `config` file has the following configuration:
```
Host github.com
IdentityFile ~/.ssh/my-ssh-key
```
I am using a **_passphrase-less_** private SSH key.
The question I have is around JGits Git push command call when talking back to the remote repository.
For example,
1. Given I have cloned a repository on my machine with SSH in a terminal:
`git clone git@github.com:devvthedev/my-project.git`
2. Made some changes to the repo
3. Opened the repo using JGit with `Git.open(...)` and get a `Git` object back
4. Staged the changes I made and committed them:
```
git.add()
.addFilepattern(".")
.call();
```
```
git.commit()
.setCommitter(new PersonIdent("me", "me@example.com"))
.setMessage("message")
.call();
```
6. When I try to push those changes with JGit:
```
git.push()
.call();
```
I get the following error:
```
Caused by: org.eclipse.jgit.errors.TransportException: Unable to connect
at org.apache.sshd.git.transport.GitSshdSessionFactory.getSession(GitSshdSessionFactory.java:134)
at org.eclipse.jgit.transport.SshTransport.getSession(SshTransport.java:107)
at org.eclipse.jgit.transport.TransportGitSsh$SshPushConnection.(TransportGitSsh.java:356)
at org.eclipse.jgit.transport.TransportGitSsh.openPush(TransportGitSsh.java:157)
at org.eclipse.jgit.transport.PushProcess.execute(PushProcess.java:140)
at org.eclipse.jgit.transport.Transport.push(Transport.java:1555)
at org.eclipse.jgit.api.PushCommand.call(PushCommand.java:158)
... 2 more
Caused by: java.lang.NullPointerException: Cannot invoke "org.eclipse.jgit.transport.CredentialsProvider.isInteractive()" because "credentialsProvider" is null
at org.apache.sshd.git.transport.GitSshdSession.(GitSshdSession.java:55)
at org.apache.sshd.git.transport.GitSshdSessionFactory$1.(GitSshdSessionFactory.java:90)
at org.apache.sshd.git.transport.GitSshdSessionFactory.getSession(GitSshdSessionFactory.java:90)
... 8 more
```
If I provide a CredentialsProvider with the `git` user and no password:
```
git.push()
.setCredentialsProvider(new UsernamePasswordCredentialsProvider("git", ""))
.call();
```
It works!
So my question is - why is a CredentialsProvider required given I have configured a `SshSessionFactory` instance?
I've also raised this to JGit maintainers [here](https://github.com/eclipse-jgit/jgit/issues/72)
Thank you
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the reported git.push() reproduction and inspect org.apache.sshd.git.transport.GitSshdSession.java:55, then follow GitSshdSessionFactory.java:90 and :134 where the NullPointerException is shown. Compare how the configured SshSessionFactory and credentialsProvider are passed through; done means the passphrase-less SSH push behaves correctly or the requirement is clearly documented.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- networking
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100