aboutsummaryrefslogtreecommitdiffstats
path: root/routers/private/internal.go
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2022-10-11 16:57:37 +0800
committerGitHub <noreply@github.com>2022-10-11 16:57:37 +0800
commit1428877c379e21481c31114cf39df2c0c14d874f (patch)
tree9d1c6cd976d1b97f1b8ed59359a4248646fe7402 /routers/private/internal.go
parentc540ee08d322c5de41c014330434351fbd885d74 (diff)
downloadgitea-1428877c379e21481c31114cf39df2c0c14d874f.tar.gz
gitea-1428877c379e21481c31114cf39df2c0c14d874f.zip
log real ip of requests from ssh (#21216)
Partially fix #21213. This PR will get client IP address from SSH_CONNECTION env which should be the first field of that. And deliver it to the internal API so Gitea routers could record the real IP from SSH requests. Co-authored-by: wxiaoguang <wxiaoguang@gmail.com> Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: zeripath <art27@cantab.net>
Diffstat (limited to 'routers/private/internal.go')
-rw-r--r--routers/private/internal.go4
1 files changed, 4 insertions, 0 deletions
diff --git a/routers/private/internal.go b/routers/private/internal.go
index e9cc20a77d..f8e451e80f 100644
--- a/routers/private/internal.go
+++ b/routers/private/internal.go
@@ -17,6 +17,7 @@ import (
"code.gitea.io/gitea/modules/web"
"gitea.com/go-chi/binding"
+ chi_middleware "github.com/go-chi/chi/v5/middleware"
)
// CheckInternalToken check internal token is set
@@ -57,6 +58,9 @@ func Routes() *web.Route {
r := web.NewRoute()
r.Use(context.PrivateContexter())
r.Use(CheckInternalToken)
+ // Log the real ip address of the request from SSH is really helpful for diagnosing sometimes.
+ // Since internal API will be sent only from Gitea sub commands and it's under control (checked by InternalToken), we can trust the headers.
+ r.Use(chi_middleware.RealIP)
r.Post("/ssh/authorized_keys", AuthorizedPublicKeyByContent)
r.Post("/ssh/{id}/update/{repoid}", UpdatePublicKeyInRepo)