]> source.dussan.org Git - gitea.git/commitdiff
Allow custom SSH user in UI for built-in SSH server (#2617) (#2678)
authorPatrick G <geek1011@outlook.com>
Sat, 14 Oct 2017 15:51:00 +0000 (11:51 -0400)
committerLauris BH <lauris@nix.lv>
Sat, 14 Oct 2017 15:51:00 +0000 (18:51 +0300)
* Allow custom SSH user in UI for built-in SSH server (#2617)

* Some fixes

* Did make fmt

* Updated according to review

- Renamed config to BUILTIN_SSH_SERVER_USER
- Removed unnecessary default string value for config item

* Updated according to review

* Fixed some minor issues

conf/app.ini
models/repo.go
modules/setting/setting.go

index 9674b815c98178fe8b082ffe97e74a6e6ed4b2e8..d4cb53d849992637197c3e7a19a48ed7db0786fb 100644 (file)
@@ -113,6 +113,8 @@ LOCAL_ROOT_URL = %(PROTOCOL)s://%(HTTP_ADDR)s:%(HTTP_PORT)s/
 DISABLE_SSH = false
 ; Whether use builtin SSH server or not.
 START_SSH_SERVER = false
+; Username to use for builtin SSH server. If blank, then it is the value of RUN_USER.
+BUILTIN_SSH_SERVER_USER =
 ; Domain name to be exposed in clone URL
 SSH_DOMAIN = %(DOMAIN)s
 ; Network interface builtin SSH server listens on
index 740bbe8da9d44512aa1a87b2ac10466df6bf475d..7ad9ad4dc9139b2f6a20c6f429c620cc90be8961 100644 (file)
@@ -806,14 +806,19 @@ func (repo *Repository) cloneLink(isWiki bool) *CloneLink {
                repoName += ".wiki"
        }
 
+       sshUser := setting.RunUser
+       if setting.SSH.StartBuiltinServer {
+               sshUser = setting.SSH.BuiltinServerUser
+       }
+
        repo.Owner = repo.MustOwner()
        cl := new(CloneLink)
        if setting.SSH.Port != 22 {
-               cl.SSH = fmt.Sprintf("ssh://%s@%s:%d/%s/%s.git", setting.RunUser, setting.SSH.Domain, setting.SSH.Port, repo.Owner.Name, repoName)
+               cl.SSH = fmt.Sprintf("ssh://%s@%s:%d/%s/%s.git", sshUser, setting.SSH.Domain, setting.SSH.Port, repo.Owner.Name, repoName)
        } else if setting.Repository.UseCompatSSHURI {
-               cl.SSH = fmt.Sprintf("ssh://%s@%s/%s/%s.git", setting.RunUser, setting.SSH.Domain, repo.Owner.Name, repoName)
+               cl.SSH = fmt.Sprintf("ssh://%s@%s/%s/%s.git", sshUser, setting.SSH.Domain, repo.Owner.Name, repoName)
        } else {
-               cl.SSH = fmt.Sprintf("%s@%s:%s/%s.git", setting.RunUser, setting.SSH.Domain, repo.Owner.Name, repoName)
+               cl.SSH = fmt.Sprintf("%s@%s:%s/%s.git", sshUser, setting.SSH.Domain, repo.Owner.Name, repoName)
        }
        cl.HTTPS = ComposeHTTPSCloneURL(repo.Owner.Name, repoName)
        return cl
index 6b1b269b73481c81e32cff458aad31f20ab83519..85ffa643a9cc1c7f2dd8f808c846b8f6e5afd3b7 100644 (file)
@@ -90,6 +90,7 @@ var (
        SSH = struct {
                Disabled             bool           `ini:"DISABLE_SSH"`
                StartBuiltinServer   bool           `ini:"START_SSH_SERVER"`
+               BuiltinServerUser    string         `ini:"BUILTIN_SSH_SERVER_USER"`
                Domain               string         `ini:"SSH_DOMAIN"`
                Port                 int            `ini:"SSH_PORT"`
                ListenHost           string         `ini:"SSH_LISTEN_HOST"`
@@ -915,6 +916,8 @@ func NewContext() {
                }
        }
 
+       SSH.BuiltinServerUser = Cfg.Section("server").Key("BUILTIN_SSH_SERVER_USER").MustString(RunUser)
+
        // Determine and create root git repository path.
        sec = Cfg.Section("repository")
        Repository.DisableHTTPGit = sec.Key("DISABLE_HTTP_GIT").MustBool()