Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
82fcd2d2
Commit
82fcd2d2
authored
Nov 27, 2018
by
Stan Hu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Log X-Forwarded-For IPs when UNIX domain sockets are in use
Closes #183
parent
7a806e0c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
53 additions
and
1 deletion
+53
-1
internal/upstream/upstream.go
internal/upstream/upstream.go
+5
-1
internal/upstream/upstream_test.go
internal/upstream/upstream_test.go
+48
-0
No files found.
internal/upstream/upstream.go
View file @
82fcd2d2
...
...
@@ -56,7 +56,11 @@ func (u *upstream) configureURLPrefix() {
}
func
(
u
*
upstream
)
ServeHTTP
(
ow
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
// Automatic quasi-intelligent X-Forwarded-For parsing
// Unix domain sockets have a remote addr of @. This will make the
// xff package lookup the X-Forwarded-For address if available.
if
r
.
RemoteAddr
==
"@"
{
r
.
RemoteAddr
=
"127.0.0.1:0"
}
r
.
RemoteAddr
=
xff
.
GetRemoteAddr
(
r
)
w
:=
helper
.
NewStatsCollectingResponseWriter
(
ow
)
...
...
internal/upstream/upstream_test.go
0 → 100644
View file @
82fcd2d2
package
upstream
import
(
"net/http"
"net/http/httptest"
"testing"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/config"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
// This test doesn't actually listen for a connection so there may be
// some error spew that can be ignored.
func
TestXForwardedForHeaders
(
t
*
testing
.
T
)
{
testCases
:=
[]
struct
{
initial
string
forwarded
string
expected
string
}{
{
initial
:
"@"
,
forwarded
:
""
,
expected
:
"127.0.0.1:0"
},
{
initial
:
"@"
,
forwarded
:
"18.245.0.1"
,
expected
:
"18.245.0.1:0"
},
{
initial
:
"@"
,
forwarded
:
"127.0.0.1"
,
expected
:
"127.0.0.1:0"
},
{
initial
:
"@"
,
forwarded
:
"192.168.0.1"
,
expected
:
"127.0.0.1:0"
},
{
initial
:
"192.168.1.1:0"
,
forwarded
:
""
,
expected
:
"192.168.1.1:0"
},
{
initial
:
"192.168.1.1:0"
,
forwarded
:
"18.245.0.1"
,
expected
:
"18.245.0.1:0"
},
}
for
_
,
tc
:=
range
testCases
{
req
,
err
:=
http
.
NewRequest
(
"POST"
,
"unix:///tmp/test.socket/info/refs"
,
nil
)
require
.
NoError
(
t
,
err
)
req
.
RemoteAddr
=
tc
.
initial
if
tc
.
forwarded
!=
""
{
req
.
Header
.
Add
(
"X-Forwarded-For"
,
tc
.
forwarded
)
}
config
:=
config
.
Config
{}
u
:=
NewUpstream
(
config
)
resp
:=
httptest
.
NewRecorder
()
u
.
ServeHTTP
(
resp
,
req
)
assert
.
Equal
(
t
,
tc
.
expected
,
req
.
RemoteAddr
)
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment