BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
2f875c40
Commit
2f875c40
authored
Jul 04, 2017
by
Pawel Chojnacki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Finish refactring processed configuraiton, and add test validating ip range matching
parent
e5a6f268
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
10 deletions
+24
-10
requires_whitelisted_monitoring_client.rb
...ollers/concerns/requires_whitelisted_monitoring_client.rb
+3
-3
metrics_controller_spec.rb
spec/controllers/metrics_controller_spec.rb
+21
-7
No files found.
app/controllers/concerns/requires_whitelisted_monitoring_client.rb
View file @
2f875c40
module
RequiresWhitelistedMonitoringClient
module
RequiresWhitelistedMonitoringClient
extend
ActiveSupport
::
Concern
extend
ActiveSupport
::
Concern
included
do
included
do
before_action
:validate_ip_whitelisted!
before_action
:validate_ip_whitelisted
_or_token_is_valid
!
end
end
private
private
def
validate_ip_whitelisted!
def
validate_ip_whitelisted
_or_token_is_valid
!
render_404
unless
client_ip_whitelisted?
||
token_valid?
render_404
unless
client_ip_whitelisted?
||
token_valid?
end
end
def
client_ip_whitelisted?
def
client_ip_whitelisted?
Settings
.
monitoring
.
ip_whitelist
.
any?
{
|
e
|
e
.
include?
(
Gitlab
::
RequestContext
.
client_ip
)
}
ip_whitelist
.
any?
{
|
e
|
e
.
include?
(
Gitlab
::
RequestContext
.
client_ip
)
}
end
end
def
ip_whitelist
def
ip_whitelist
...
...
spec/controllers/metrics_controller_spec.rb
View file @
2f875c40
...
@@ -6,21 +6,19 @@ describe MetricsController do
...
@@ -6,21 +6,19 @@ describe MetricsController do
let
(
:json_response
)
{
JSON
.
parse
(
response
.
body
)
}
let
(
:json_response
)
{
JSON
.
parse
(
response
.
body
)
}
let
(
:metrics_multiproc_dir
)
{
Dir
.
mktmpdir
}
let
(
:metrics_multiproc_dir
)
{
Dir
.
mktmpdir
}
let
(
:whitelisted_ip
)
{
'127.0.0.1'
}
let
(
:whitelisted_ip
)
{
'127.0.0.1'
}
let
(
:not_whitelisted_ip
)
{
'127.0.0.2'
}
let
(
:whitelisted_ip_range
)
{
'10.0.0.0/24'
}
let
(
:ip_in_whitelisted_range
)
{
'10.0.0.1'
}
let
(
:not_whitelisted_ip
)
{
'10.0.1.1'
}
before
do
before
do
stub_env
(
'IN_MEMORY_APPLICATION_SETTINGS'
,
'false'
)
stub_env
(
'IN_MEMORY_APPLICATION_SETTINGS'
,
'false'
)
stub_env
(
'prometheus_multiproc_dir'
,
metrics_multiproc_dir
)
stub_env
(
'prometheus_multiproc_dir'
,
metrics_multiproc_dir
)
allow
(
Gitlab
::
Metrics
).
to
receive
(
:prometheus_metrics_enabled?
).
and_return
(
true
)
allow
(
Gitlab
::
Metrics
).
to
receive
(
:prometheus_metrics_enabled?
).
and_return
(
true
)
allow
(
Settings
.
monitoring
).
to
receive
(
:ip_whitelist
).
and_return
([
IPAddr
.
new
(
whitelisted_ip
)
])
allow
(
Settings
.
monitoring
).
to
receive
(
:ip_whitelist
).
and_return
([
whitelisted_ip
,
whitelisted_ip_range
])
end
end
describe
'#index'
do
describe
'#index'
do
context
'accessed from whitelisted ip'
do
shared_examples_for
'endpoint providing metrics'
do
before
do
allow
(
Gitlab
::
RequestContext
).
to
receive
(
:client_ip
).
and_return
(
whitelisted_ip
)
end
it
'returns DB ping metrics'
do
it
'returns DB ping metrics'
do
get
:index
get
:index
...
@@ -61,6 +59,22 @@ describe MetricsController do
...
@@ -61,6 +59,22 @@ describe MetricsController do
end
end
end
end
context
'accessed from whitelisted ip'
do
before
do
allow
(
Gitlab
::
RequestContext
).
to
receive
(
:client_ip
).
and_return
(
whitelisted_ip
)
end
it_behaves_like
'endpoint providing metrics'
end
context
'accessed from ip in whitelisted range'
do
before
do
allow
(
Gitlab
::
RequestContext
).
to
receive
(
:client_ip
).
and_return
(
ip_in_whitelisted_range
)
end
it_behaves_like
'endpoint providing metrics'
end
context
'accessed from not whitelisted ip'
do
context
'accessed from not whitelisted ip'
do
before
do
before
do
allow
(
Gitlab
::
RequestContext
).
to
receive
(
:client_ip
).
and_return
(
not_whitelisted_ip
)
allow
(
Gitlab
::
RequestContext
).
to
receive
(
:client_ip
).
and_return
(
not_whitelisted_ip
)
...
...
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