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
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
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
10 deletions
+24
-10
app/controllers/concerns/requires_whitelisted_monitoring_client.rb
...ollers/concerns/requires_whitelisted_monitoring_client.rb
+3
-3
spec/controllers/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
extend
ActiveSupport
::
Concern
included
do
before_action
:validate_ip_whitelisted!
before_action
:validate_ip_whitelisted
_or_token_is_valid
!
end
private
def
validate_ip_whitelisted!
def
validate_ip_whitelisted
_or_token_is_valid
!
render_404
unless
client_ip_whitelisted?
||
token_valid?
end
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
def
ip_whitelist
...
...
spec/controllers/metrics_controller_spec.rb
View file @
2f875c40
...
...
@@ -6,21 +6,19 @@ describe MetricsController do
let
(
:json_response
)
{
JSON
.
parse
(
response
.
body
)
}
let
(
:metrics_multiproc_dir
)
{
Dir
.
mktmpdir
}
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
stub_env
(
'IN_MEMORY_APPLICATION_SETTINGS'
,
'false'
)
stub_env
(
'prometheus_multiproc_dir'
,
metrics_multiproc_dir
)
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
describe
'#index'
do
context
'accessed from whitelisted ip'
do
before
do
allow
(
Gitlab
::
RequestContext
).
to
receive
(
:client_ip
).
and_return
(
whitelisted_ip
)
end
shared_examples_for
'endpoint providing metrics'
do
it
'returns DB ping metrics'
do
get
:index
...
...
@@ -61,6 +59,22 @@ describe MetricsController do
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
before
do
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