diff options
author | Igor Drozdov <idrozdov@gitlab.com> | 2022-07-01 11:02:59 +0000 |
---|---|---|
committer | Igor Drozdov <idrozdov@gitlab.com> | 2022-07-01 11:02:59 +0000 |
commit | 0d7ef238cb8c05eabaec85e62bec70a40147d1df (patch) | |
tree | 9179705f9e8b6ee309d456323fbaedaa70141c7e /client/gitlabnet.go | |
parent | 01f4e022c04b29b896eb383e6e6a33f96a6beeb1 (diff) | |
parent | 9b60ce49460876d0e599f2fec65f02856930dbcd (diff) | |
download | gitlab-shell-0d7ef238cb8c05eabaec85e62bec70a40147d1df.tar.gz |
Merge branch 'sshd-forwarded-for' into 'main'
Pass original IP from PROXY requests to internal API calls
See merge request gitlab-org/gitlab-shell!665
Diffstat (limited to 'client/gitlabnet.go')
-rw-r--r-- | client/gitlabnet.go | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/client/gitlabnet.go b/client/gitlabnet.go index 31131d2..c34f148 100644 --- a/client/gitlabnet.go +++ b/client/gitlabnet.go @@ -41,6 +41,9 @@ type ApiError struct { Msg string } +// To use as the key in a Context to set an X-Forwarded-For header in a request +type OriginalRemoteIPContextKey struct{} + func (e *ApiError) Error() string { return e.Msg } @@ -150,6 +153,11 @@ func (c *GitlabNetClient) DoRequest(ctx context.Context, method, path string, da } request.Header.Set(apiSecretHeaderName, tokenString) + originalRemoteIP, ok := ctx.Value(OriginalRemoteIPContextKey{}).(string) + if ok { + request.Header.Add("X-Forwarded-For", originalRemoteIP) + } + request.Header.Add("Content-Type", "application/json") request.Header.Add("User-Agent", c.userAgent) request.Close = true |