2021-02-03 21:09:17 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2011-10-08 21:36:38 +00:00
|
|
|
# Be sure to restart your server when you modify this file.
|
|
|
|
|
2015-06-13 04:22:55 +00:00
|
|
|
require 'gitlab/current_settings'
|
2015-09-09 14:19:58 +00:00
|
|
|
|
2015-11-24 14:57:28 +00:00
|
|
|
# allow it to fail: it may do so when create_from_defaults is executed before migrations are actually done
|
2015-09-09 14:19:58 +00:00
|
|
|
begin
|
2017-08-31 09:47:03 +00:00
|
|
|
Settings.gitlab['session_expire_delay'] = Gitlab::CurrentSettings.current_application_settings.session_expire_delay || 10080
|
2021-04-26 12:09:44 +00:00
|
|
|
rescue StandardError
|
2015-11-24 11:11:31 +00:00
|
|
|
Settings.gitlab['session_expire_delay'] ||= 10080
|
2015-09-09 14:19:58 +00:00
|
|
|
end
|
2015-06-05 17:16:32 +00:00
|
|
|
|
2017-06-01 06:15:58 +00:00
|
|
|
cookie_key = if Rails.env.development?
|
|
|
|
"_gitlab_session_#{Digest::SHA256.hexdigest(Rails.root.to_s)}"
|
2021-09-15 03:11:01 +00:00
|
|
|
elsif ::Gitlab.ee? && ::Gitlab::Geo.connected? && ::Gitlab::Geo.secondary?
|
|
|
|
"_gitlab_session_geo_#{Digest::SHA256.hexdigest(GeoNode.current_node_name)}"
|
2017-06-01 06:15:58 +00:00
|
|
|
else
|
|
|
|
"_gitlab_session"
|
|
|
|
end
|
|
|
|
|
2021-11-24 18:14:31 +00:00
|
|
|
store = if Gitlab::Utils.to_boolean(ENV['GITLAB_USE_REDIS_SESSIONS_STORE'], default: true)
|
|
|
|
Gitlab::Redis::Sessions.store(
|
|
|
|
namespace: Gitlab::Redis::Sessions::SESSION_NAMESPACE
|
|
|
|
)
|
|
|
|
else
|
|
|
|
Gitlab::Redis::SharedState.store(
|
|
|
|
namespace: Gitlab::Redis::Sessions::SESSION_NAMESPACE
|
|
|
|
)
|
|
|
|
end
|
2016-05-30 21:13:42 +00:00
|
|
|
|
2021-11-24 18:14:31 +00:00
|
|
|
Gitlab::Application.config.session_store(
|
|
|
|
:redis_store, # Using the cookie_store would enable session replay attacks.
|
|
|
|
redis_store: store,
|
|
|
|
key: cookie_key,
|
|
|
|
secure: Gitlab.config.gitlab.https,
|
|
|
|
httponly: true,
|
|
|
|
expires_in: Settings.gitlab['session_expire_delay'] * 60,
|
|
|
|
path: Rails.application.config.relative_url_root.presence || '/'
|
|
|
|
)
|