summaryrefslogtreecommitdiff
path: root/app/controllers/concerns
diff options
context:
space:
mode:
authorPawel Chojnacki <pawel@chojnacki.ws>2017-07-03 17:09:34 +0200
committerPawel Chojnacki <pawel@chojnacki.ws>2017-07-05 00:46:11 +0200
commit18521584bd6cfc8de9511722696e87aef59795c5 (patch)
treefa5b83fca15ff3d6f7a70fd9b87bc31ad575a08a /app/controllers/concerns
parent5af1fcd6f329858d757bab0d67cb50af6c820160 (diff)
downloadgitlab-ce-18521584bd6cfc8de9511722696e87aef59795c5.tar.gz
Remove the need to use health check token
in favor of whitelist that will be used to control the access to monitoring resources
Diffstat (limited to 'app/controllers/concerns')
-rw-r--r--app/controllers/concerns/requires_health_token.rb25
-rw-r--r--app/controllers/concerns/requires_whitelisted_monitoring_client.rb20
2 files changed, 20 insertions, 25 deletions
diff --git a/app/controllers/concerns/requires_health_token.rb b/app/controllers/concerns/requires_health_token.rb
deleted file mode 100644
index 34ab1a97649..00000000000
--- a/app/controllers/concerns/requires_health_token.rb
+++ /dev/null
@@ -1,25 +0,0 @@
-module RequiresHealthToken
- extend ActiveSupport::Concern
- included do
- before_action :validate_health_check_access!
- end
-
- private
-
- def validate_health_check_access!
- render_404 unless token_valid?
- end
-
- def token_valid?
- token = params[:token].presence || request.headers['TOKEN']
- token.present? &&
- ActiveSupport::SecurityUtils.variable_size_secure_compare(
- token,
- current_application_settings.health_check_access_token
- )
- end
-
- def render_404
- render file: Rails.root.join('public', '404'), layout: false, status: '404'
- end
-end
diff --git a/app/controllers/concerns/requires_whitelisted_monitoring_client.rb b/app/controllers/concerns/requires_whitelisted_monitoring_client.rb
new file mode 100644
index 00000000000..92ed559ba8a
--- /dev/null
+++ b/app/controllers/concerns/requires_whitelisted_monitoring_client.rb
@@ -0,0 +1,20 @@
+module RequiresWhitelistedMonitoringClient
+ extend ActiveSupport::Concern
+ included do
+ before_action :validate_ip_whitelisted!
+ end
+
+ private
+
+ def validate_ip_whitelisted!
+ render_404 unless client_ip_whitelisted?
+ end
+
+ def client_ip_whitelisted?
+ Settings.monitoring.ip_whitelist.any? {|e| e.include?(Gitlab::RequestContext.client_ip) }
+ end
+
+ def render_404
+ render file: Rails.root.join('public', '404'), layout: false, status: '404'
+ end
+end