Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support SSH for go get #12192

Closed
2 of 7 tasks
skaldesh opened this issue Jul 8, 2020 · 13 comments · Fixed by #24664
Closed
2 of 7 tasks

Support SSH for go get #12192

skaldesh opened this issue Jul 8, 2020 · 13 comments · Fixed by #24664
Labels
issue/confirmed Issue has been reviewed and confirmed to be present or accepted to be implemented type/enhancement An improvement of existing functionality

Comments

@skaldesh
Copy link

skaldesh commented Jul 8, 2020

  • Gitea version (or commit ref): 1.12.1 built with GNU Make 4.2.1, go1.14.4 : bindata, sqlite, sqlite_unlock_notify
  • Git version: 2.24.3
  • Operating system: Arch Linux
  • Database (use [x]):
    • PostgreSQL
    • MySQL
    • MSSQL
    • SQLite
  • Can you reproduce the bug at https://try.gitea.io:
    • Yes (provide example URL)
    • No
    • Not relevant
  • Log gist:

Description

We have a private gitea repository containing a go module. When we want to go get git.company.com/organization/private, gitea returns only the HTTPS link of the repository, not the SSH one.
To reproduce, one can simply open a link in the browser: https://git.company.com/organization/private?go-get=1
and examine the returned HTML:

<!DOCTYPE html>
<html>
<head>
<meta name="go-import" content="git.company.com/organization/private git https://git.company.com/organization/private.git">
<meta name="go-source" content="git.company.com/organization/private _ https://git.company.com/organization/private/src/branch/master{/dir} https://git.company.com/organization/private/src/branch/master{/dir}/{file}#L{line}">
</head>
<body cz-shortcut-listen="true">
go get git.company.com/organization/private
</body>
</html>

Here are the relevant source code locations:

templates/base/head.tmpl:	<meta name="go-import" content="{{.GoGetImport}} git {{.CloneLink.HTTPS}}">
modules/context/repo.go:	ctx.PlainText(200, []byte(com.Expand(`<meta name="go-import" content="{GoGetImport} git {CloneLink}">`,
modules/context/context.go:		<meta name="go-import" content="{GoGetImport} git {CloneLink}">

One can see in these files/lines that only the HTTPS path is ever returned. We expected that this can be at least configured to either return the SSH or HTTPS one. When disabling HTTPS for the repo, the returned links still stayed the same.

@lunny
Copy link
Member

lunny commented Jul 9, 2020

I don't think go get support SSH protocol.

@r0l1
Copy link

r0l1 commented Jul 9, 2020

It does. We use it in production. The meta tag should look as following:

<meta name="go-import" content="git.company.com/organization/private git ssh://[email protected]/organization/private">

When a version control system supports multiple protocols, each is tried in turn when downloading. For example, a Git download tries https://, then git+ssh://.

https://golang.org/cmd/go/#hdr-Remote_import_paths

@lunny lunny added the type/enhancement An improvement of existing functionality label Jul 9, 2020
@lunny
Copy link
Member

lunny commented Jul 9, 2020

It does. We use it in production. The meta tag should look as following:

<meta name="go-import" content="git.company.com/organization/private git ssh://[email protected]/organization/private">

When a version control system supports multiple protocols, each is tried in turn when downloading. For example, a Git download tries https://, then git+ssh://.

https://golang.org/cmd/go/#hdr-Remote_import_paths

Interesting! Thanks for the information.

@r0l1
Copy link

r0l1 commented Jul 9, 2020

It's quite useful for private internal git modules :)

@zeripath
Copy link
Contributor

OK looking at: https://github.com/golang/go/blob/95e1ea4598175a3461f40d00ce47a51e5fa6e5ea/src/cmd/go/internal/get/discovery.go#L36-L64

I think we could even have a second go-import tag which would save yet another setting...

@zeripath
Copy link
Contributor

OK I think this is going to need (yet) another setting. The ideal would be a global setting and a per repository setting.

Simply because every time we do this we're causing a change of schema - I think we need a generic settings system and I'm opening an issue for that.

@stale
Copy link

stale bot commented Sep 11, 2020

This issue has been automatically marked as stale because it has not had recent activity. I am here to help clear issues left open even if solved or waiting for more insight. This issue will be closed if no further activity occurs during the next 2 weeks. If the issue is still valid just add a comment to keep it alive. Thank you for your contributions.

@stale stale bot added the issue/stale label Sep 11, 2020
@zeripath zeripath added the issue/confirmed Issue has been reviewed and confirmed to be present or accepted to be implemented label Sep 11, 2020
@stale stale bot removed the issue/stale label Sep 11, 2020
@mei-rune
Copy link
Contributor

Why don't you solve this, this is very useful for private repositories

HTTPS access requires a username and password, while SSH is not required

In my Jenkins I can only use git, not https, because I can't type in usernames and passwords

为什么这个不解决呢, 这个对私有仓库很有用啊

https 访问方式,需要用户名和密码, 而 git 可以不用

在我的 jenkins 中我只能用 git, 不能用 https, 因为我不可能去输用户名和密码啊

@wxiaoguang
Copy link
Contributor

Here is : https://github.com/go-gitea/gitea/blob/main/CODE_OF_CONDUCT.md

Before asking "Why don't you solve this", please ask: could you write some code to help the open-source projects?

Complaining doesn't help anything. Being constructive and respectful

@mei-rune
Copy link
Contributor

@wxiaoguang 你说的很对, 我来解决这个问题

mei-rune added a commit to mei-rune/gitea that referenced this issue May 11, 2023
@mei-rune
Copy link
Contributor

I send a pull request for this;

补丁好不好不说, 反正我提供了

@wxiaoguang
Copy link
Contributor

Awesome, thank you very much. I did a quick review, I think the PR is high quality.

Before approving, there are only a few nits (I can vote my approval, it needs at least 2 approvals to be merged, other maintainers will also review)

mei-rune added a commit to mei-rune/gitea that referenced this issue May 11, 2023
mei-rune pushed a commit to mei-rune/gitea that referenced this issue May 12, 2023
mei-rune pushed a commit to mei-rune/gitea that referenced this issue May 12, 2023
silverwind added a commit that referenced this issue May 12, 2023
fix #12192 Support SSH for go get

---------

Co-authored-by: Lunny Xiao <[email protected]>
Co-authored-by: Giteabot <[email protected]>
Co-authored-by: mfk <[email protected]>
Co-authored-by: silverwind <[email protected]>
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 27, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
issue/confirmed Issue has been reviewed and confirmed to be present or accepted to be implemented type/enhancement An improvement of existing functionality
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants