go-git icon indicating copy to clipboard operation
go-git copied to clipboard

git clone gives error with SSH Agent

Open pgbytes opened this issue 5 years ago • 4 comments

I am trying to clone a repository in my CI pipeline (Bitbucket pipeline).

in the pipeline step:

a normal git clone [email protected]:company/repo-name.git works fine.

git.Clone() from go-git gives an error:

error creating SSH agent: "SSH agent requested but SSH_AUTH_SOCK not-specified"

Although the normal git clone worked, but to test I started a new ssh agent with eval $(ssh-agent) > /dev/null as a step in the pipeline. Now I get an ssh handshake error.

This go-git code works perfectly on my local machine.

I tried to provide an SSH Agent to the clone method:

agent, _ := ssh.NewSSHAgentAuth("bitbucket-pipelines")
repo, err := git.Clone(store, fs, &git.CloneOptions{
		URL:      repoPath,
		Progress: os.Stdout,
		Auth:     agent,
	})

but I still get the error:

ssh: handshake failed: ssh: unable to authenticate, attempted methods [none publickey], no supported methods remain

what am I missing here? do I need to configure the public key for every repository it will be cloning?

UPDATE

I added the following to my pipeline steps:

   - eval $(ssh-agent) > /dev/null
   - ssh-add /opt/atlassian/pipelines/agent/ssh/id_rsa

This made things work fine. Is there a way I can do this with the git-clone options?

pgbytes avatar Jul 28 '20 20:07 pgbytes

I get the same issues inside a docker container running on Kubernetes.

Edit: Any progress on this?

masus04 avatar Jun 01 '22 12:06 masus04

yes, what progress? Looks like go-git can't work without ssh-agent.

stalkerg avatar Jul 01 '22 09:07 stalkerg

The Go-Git clone repository is different from the Git client clone repository, so you can try using the Go-Git clone repository

liwenson avatar Sep 01 '22 07:09 liwenson

got same issues inside a docker container running on Kubernetes.

timestee avatar Sep 15 '22 08:09 timestee

Is someone willing to say something in this regard? Requiring the ssh agent is problematic for various reasons.

It happens also when using the ssh key directly as per example: https://github.com/go-git/go-git/blob/master/_examples/clone/auth/ssh/main.go.

bluebrown avatar Nov 13 '22 09:11 bluebrown

To help us keep things tidy and focus on the active tasks, we've introduced a stale bot to spot issues/PRs that haven't had any activity in a while.

This particular issue hasn't had any updates or activity in the past 90 days, so it's been labeled as 'stale'. If it remains inactive for the next 30 days, it'll be automatically closed.

We understand everyone's busy, but if this issue is still important to you, please feel free to add a comment or make an update to keep it active.

Thanks for your understanding and cooperation!

github-actions[bot] avatar Nov 14 '23 07:11 github-actions[bot]

Adding a comment so stalebot removes its label.

scallister avatar Nov 14 '23 07:11 scallister

@scallister can you please share a code sample and go-git version where you are experiencing the issue? A lot has changed since this issue was originally created, so I am not sure the same issue is occurring.

pjbgf avatar Nov 14 '23 19:11 pjbgf

@pjbgf I wish I still had a code sample to share but I no longer have access to the problematic code that caused me to follow this issue initially.

From what I remember, I think the issue I encountered had to do with the ssh agent being required even when using an ssh key directly. I believe this caused problems because having the ssh agent available was not something we could expect.

scallister avatar Nov 16 '23 06:11 scallister

@scallister thank you for the quick reply. I completely agree with the expectations there - users must be able to use SSH keys without having an ssh agent present. And also be able to rely on the ssh agent if they so wish. The former use case is working in projects I know that depend on go-git - so not sure if this issue still exists or there is a specific edge case that causes a failure.

pjbgf avatar Nov 16 '23 08:11 pjbgf

Perhaps we let stalebot mark this as stale the next time it triggers? Might give another individual reading this thread a chance to find a broken example or confirm a broken example is now working?

I’m also fine with you closing this out in the meantime too. Thanks for your follow up as well.

scallister avatar Nov 16 '23 17:11 scallister

Thank you for understanding and for the quick replies. :bow:

Overall, there are a lot of stale or duplicate issues, so let's close it for the time being. If anyone is still experiencing the issue and provide us a detailed report we can always reopen it.

pjbgf avatar Nov 16 '23 17:11 pjbgf