summaryrefslogtreecommitdiff
path: root/app/controllers
diff options
context:
space:
mode:
authorDJ Mountney <david@twkie.net>2016-05-09 16:21:22 -0700
committerDJ Mountney <david@twkie.net>2016-05-10 08:46:02 -0700
commit160ef66d1bbbbc593516c7575d6b02ddb019c000 (patch)
tree95d2b3e09d56a2237da09c48281201d5ab8d73bf /app/controllers
parent9898f9b4e6b80edaa914675edfa9b229498b31fe (diff)
downloadgitlab-ce-160ef66d1bbbbc593516c7575d6b02ddb019c000.tar.gz
Add health_check access token, and enforce on the health_check endpoint
Also added a health check page to the admin section for resetting the token.
Diffstat (limited to 'app/controllers')
-rw-r--r--app/controllers/admin/application_settings_controller.rb6
-rw-r--r--app/controllers/admin/health_check_controller.rb9
-rw-r--r--app/controllers/health_check_controller.rb13
3 files changed, 28 insertions, 0 deletions
diff --git a/app/controllers/admin/application_settings_controller.rb b/app/controllers/admin/application_settings_controller.rb
index ec22548ddeb..7b9a88cd319 100644
--- a/app/controllers/admin/application_settings_controller.rb
+++ b/app/controllers/admin/application_settings_controller.rb
@@ -19,6 +19,12 @@ class Admin::ApplicationSettingsController < Admin::ApplicationController
redirect_to admin_runners_path
end
+ def reset_health_check_token
+ @application_setting.reset_health_check_access_token!
+ flash[:notice] = 'New health check access token has been generated!'
+ redirect_to :back
+ end
+
def clear_repository_check_states
RepositoryCheck::ClearWorker.perform_async
diff --git a/app/controllers/admin/health_check_controller.rb b/app/controllers/admin/health_check_controller.rb
new file mode 100644
index 00000000000..3153a765e35
--- /dev/null
+++ b/app/controllers/admin/health_check_controller.rb
@@ -0,0 +1,9 @@
+class Admin::HealthCheckController < Admin::ApplicationController
+ def show
+ begin
+ @errors = HealthCheck::Utils.process_checks('standard')
+ rescue => e
+ @errors = e.message.blank? ? e.class.to_s : e.message.to_s
+ end
+ end
+end
diff --git a/app/controllers/health_check_controller.rb b/app/controllers/health_check_controller.rb
new file mode 100644
index 00000000000..b974489836f
--- /dev/null
+++ b/app/controllers/health_check_controller.rb
@@ -0,0 +1,13 @@
+class HealthCheckController < HealthCheck::HealthCheckController
+ before_action :validate_health_check_access!
+
+ protected
+
+ def validate_health_check_access!
+ return render_404 unless params[:token].presence && params[: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