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
caf03f78
Commit
caf03f78
authored
Mar 12, 2019
by
GitLab Bot
Browse files
Options
Browse Files
Download
Plain Diff
Automatic merge of gitlab-org/gitlab-ce master
parents
fdc6eeb2
ef19ded4
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
74 additions
and
3 deletions
+74
-3
changelogs/unreleased/sh-revert-rack-request-health-checks.yml
...elogs/unreleased/sh-revert-rack-request-health-checks.yml
+5
-0
lib/gitlab/middleware/basic_health_check.rb
lib/gitlab/middleware/basic_health_check.rb
+7
-1
lib/gitlab/request_context.rb
lib/gitlab/request_context.rb
+7
-1
spec/lib/gitlab/middleware/basic_health_check_spec.rb
spec/lib/gitlab/middleware/basic_health_check_spec.rb
+29
-0
spec/lib/gitlab/request_context_spec.rb
spec/lib/gitlab/request_context_spec.rb
+26
-1
No files found.
changelogs/unreleased/sh-revert-rack-request-health-checks.yml
0 → 100644
View file @
caf03f78
---
title
:
Fix health checks not working behind load balancers
merge_request
:
26055
author
:
type
:
fixed
lib/gitlab/middleware/basic_health_check.rb
View file @
caf03f78
...
...
@@ -24,7 +24,13 @@ module Gitlab
def
call
(
env
)
return
@app
.
call
(
env
)
unless
env
[
'PATH_INFO'
]
==
HEALTH_PATH
request
=
ActionDispatch
::
Request
.
new
(
env
)
# We should be using ActionDispatch::Request instead of
# Rack::Request to be consistent with Rails, but due to a Rails
# bug described in
# https://gitlab.com/gitlab-org/gitlab-ce/issues/58573#note_149799010
# hosts behind a load balancer will only see 127.0.0.1 for the
# load balancer's IP.
request
=
Rack
::
Request
.
new
(
env
)
return
OK_RESPONSE
if
client_ip_whitelisted?
(
request
)
...
...
lib/gitlab/request_context.rb
View file @
caf03f78
...
...
@@ -13,7 +13,13 @@ module Gitlab
end
def
call
(
env
)
req
=
ActionDispatch
::
Request
.
new
(
env
)
# We should be using ActionDispatch::Request instead of
# Rack::Request to be consistent with Rails, but due to a Rails
# bug described in
# https://gitlab.com/gitlab-org/gitlab-ce/issues/58573#note_149799010
# hosts behind a load balancer will only see 127.0.0.1 for the
# load balancer's IP.
req
=
Rack
::
Request
.
new
(
env
)
Gitlab
::
SafeRequestStore
[
:client_ip
]
=
req
.
ip
...
...
spec/lib/gitlab/middleware/basic_health_check_spec.rb
View file @
caf03f78
...
...
@@ -28,6 +28,35 @@ describe Gitlab::Middleware::BasicHealthCheck do
end
end
context
'with X-Forwarded-For headers'
do
let
(
:load_balancer_ip
)
{
'1.2.3.4'
}
before
do
env
[
'HTTP_X_FORWARDED_FOR'
]
=
"
#{
load_balancer_ip
}
, 127.0.0.1"
env
[
'REMOTE_ADDR'
]
=
'127.0.0.1'
env
[
'PATH_INFO'
]
=
described_class
::
HEALTH_PATH
end
it
'returns 200 response when endpoint is allowed'
do
allow
(
Settings
.
monitoring
).
to
receive
(
:ip_whitelist
).
and_return
([
load_balancer_ip
])
expect
(
app
).
not_to
receive
(
:call
)
response
=
middleware
.
call
(
env
)
expect
(
response
[
0
]).
to
eq
(
200
)
expect
(
response
[
1
]).
to
eq
({
'Content-Type'
=>
'text/plain'
})
expect
(
response
[
2
]).
to
eq
([
'GitLab OK'
])
end
it
'returns 404 when whitelist is not configured'
do
allow
(
Settings
.
monitoring
).
to
receive
(
:ip_whitelist
).
and_return
([])
response
=
middleware
.
call
(
env
)
expect
(
response
[
0
]).
to
eq
(
404
)
end
end
context
'whitelisted IP'
do
before
do
env
[
'REMOTE_ADDR'
]
=
'127.0.0.1'
...
...
spec/lib/gitlab/request_context_spec.rb
View file @
caf03f78
...
...
@@ -6,6 +6,31 @@ describe Gitlab::RequestContext do
let
(
:app
)
{
->
(
env
)
{}
}
let
(
:env
)
{
Hash
.
new
}
context
'with X-Forwarded-For headers'
,
:request_store
do
let
(
:load_balancer_ip
)
{
'1.2.3.4'
}
let
(
:headers
)
do
{
'HTTP_X_FORWARDED_FOR'
=>
"
#{
load_balancer_ip
}
, 127.0.0.1"
,
'REMOTE_ADDR'
=>
'127.0.0.1'
}
end
let
(
:env
)
{
Rack
::
MockRequest
.
env_for
(
"/"
).
merge
(
headers
)
}
it
'returns the load balancer IP'
do
client_ip
=
nil
endpoint
=
proc
do
client_ip
=
Gitlab
::
SafeRequestStore
[
:client_ip
]
[
200
,
{},
[
"Hello"
]]
end
Rails
.
application
.
middleware
.
build
(
endpoint
).
call
(
env
)
expect
(
client_ip
).
to
eq
(
load_balancer_ip
)
end
end
context
'when RequestStore::Middleware is used'
do
around
do
|
example
|
RequestStore
::
Middleware
.
new
(
->
(
env
)
{
example
.
run
}).
call
({})
...
...
@@ -15,7 +40,7 @@ describe Gitlab::RequestContext do
let
(
:ip
)
{
'192.168.1.11'
}
before
do
allow_any_instance_of
(
ActionDispatch
::
Request
).
to
receive
(
:ip
).
and_return
(
ip
)
allow_any_instance_of
(
Rack
::
Request
).
to
receive
(
:ip
).
and_return
(
ip
)
described_class
.
new
(
app
).
call
(
env
)
end
...
...
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