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
b296c289
Commit
b296c289
authored
Jan 11, 2022
by
nmilojevic1
Committed by
Nikola Milojevic
Jan 12, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove GITLAB_USE_REDIS_SESSIONS_STORE env variable
- Clean specs
parent
1ff48797
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
17 additions
and
86 deletions
+17
-86
app/models/active_session.rb
app/models/active_session.rb
+7
-8
config/initializers/session_store.rb
config/initializers/session_store.rb
+1
-7
ee/lib/gitlab/auth/otp/session_enforcer.rb
ee/lib/gitlab/auth/otp/session_enforcer.rb
+2
-4
lib/gitlab/anonymous_session.rb
lib/gitlab/anonymous_session.rb
+3
-4
lib/gitlab/redis/sessions_store_helper.rb
lib/gitlab/redis/sessions_store_helper.rb
+0
-27
lib/tasks/gitlab/cleanup.rake
lib/tasks/gitlab/cleanup.rake
+1
-3
spec/initializers/session_store_spec.rb
spec/initializers/session_store_spec.rb
+3
-33
No files found.
app/models/active_session.rb
View file @
b296c289
...
...
@@ -21,7 +21,6 @@
#
class
ActiveSession
include
ActiveModel
::
Model
include
::
Gitlab
::
Redis
::
SessionsStoreHelper
SESSION_BATCH_SIZE
=
200
ALLOWED_NUMBER_OF_ACTIVE_SESSIONS
=
100
...
...
@@ -66,7 +65,7 @@ class ActiveSession
end
def
self
.
set
(
user
,
request
)
redis_store_clas
s
.
with
do
|
redis
|
Gitlab
::
Redis
::
Session
s
.
with
do
|
redis
|
session_private_id
=
request
.
session
.
id
.
private_id
client
=
DeviceDetector
.
new
(
request
.
user_agent
)
timestamp
=
Time
.
current
...
...
@@ -107,7 +106,7 @@ class ActiveSession
end
def
self
.
list
(
user
)
redis_store_clas
s
.
with
do
|
redis
|
Gitlab
::
Redis
::
Session
s
.
with
do
|
redis
|
cleaned_up_lookup_entries
(
redis
,
user
).
map
do
|
raw_session
|
load_raw_session
(
raw_session
)
end
...
...
@@ -115,7 +114,7 @@ class ActiveSession
end
def
self
.
cleanup
(
user
)
redis_store_clas
s
.
with
do
|
redis
|
Gitlab
::
Redis
::
Session
s
.
with
do
|
redis
|
clean_up_old_sessions
(
redis
,
user
)
cleaned_up_lookup_entries
(
redis
,
user
)
end
...
...
@@ -138,7 +137,7 @@ class ActiveSession
def
self
.
destroy_session
(
user
,
session_id
)
return
unless
session_id
redis_store_clas
s
.
with
do
|
redis
|
Gitlab
::
Redis
::
Session
s
.
with
do
|
redis
|
destroy_sessions
(
redis
,
user
,
[
session_id
].
compact
)
end
end
...
...
@@ -147,7 +146,7 @@ class ActiveSession
sessions
=
not_impersonated
(
user
)
sessions
.
reject!
{
|
session
|
session
.
current?
(
current_rack_session
)
}
if
current_rack_session
redis_store_clas
s
.
with
do
|
redis
|
Gitlab
::
Redis
::
Session
s
.
with
do
|
redis
|
session_ids
=
sessions
.
flat_map
(
&
:ids
)
destroy_sessions
(
redis
,
user
,
session_ids
)
if
session_ids
.
any?
end
...
...
@@ -182,7 +181,7 @@ class ActiveSession
#
# Returns an array of strings
def
self
.
session_ids_for_user
(
user_id
)
redis_store_clas
s
.
with
do
|
redis
|
Gitlab
::
Redis
::
Session
s
.
with
do
|
redis
|
redis
.
smembers
(
lookup_key_name
(
user_id
))
end
end
...
...
@@ -195,7 +194,7 @@ class ActiveSession
def
self
.
sessions_from_ids
(
session_ids
)
return
[]
if
session_ids
.
empty?
redis_store_clas
s
.
with
do
|
redis
|
Gitlab
::
Redis
::
Session
s
.
with
do
|
redis
|
session_keys
=
rack_session_keys
(
session_ids
)
session_keys
.
each_slice
(
SESSION_BATCH_SIZE
).
flat_map
do
|
session_keys_batch
|
...
...
config/initializers/session_store.rb
View file @
b296c289
...
...
@@ -19,15 +19,9 @@ cookie_key = if Rails.env.development?
"_gitlab_session"
end
store
=
if
Gitlab
::
Utils
.
to_boolean
(
ENV
[
'GITLAB_USE_REDIS_SESSIONS_STORE'
],
default:
true
)
Gitlab
::
Redis
::
Sessions
.
store
(
store
=
Gitlab
::
Redis
::
Sessions
.
store
(
namespace:
Gitlab
::
Redis
::
Sessions
::
SESSION_NAMESPACE
)
else
Gitlab
::
Redis
::
SharedState
.
store
(
namespace:
Gitlab
::
Redis
::
Sessions
::
SESSION_NAMESPACE
)
end
Gitlab
::
Application
.
config
.
session_store
(
:redis_store
,
# Using the cookie_store would enable session replay attacks.
...
...
ee/lib/gitlab/auth/otp/session_enforcer.rb
View file @
b296c289
...
...
@@ -4,20 +4,18 @@ module Gitlab
module
Auth
module
Otp
class
SessionEnforcer
include
::
Gitlab
::
Redis
::
SessionsStoreHelper
def
initialize
(
key
)
@key
=
key
end
def
update_session
redis_store_clas
s
.
with
do
|
redis
|
Gitlab
::
Redis
::
Session
s
.
with
do
|
redis
|
redis
.
setex
(
key_name
,
session_expiry_in_seconds
,
true
)
end
end
def
access_restricted?
redis_store_clas
s
.
with
do
|
redis
|
Gitlab
::
Redis
::
Session
s
.
with
do
|
redis
|
!
redis
.
get
(
key_name
)
end
end
...
...
lib/gitlab/anonymous_session.rb
View file @
b296c289
...
...
@@ -2,14 +2,13 @@
module
Gitlab
class
AnonymousSession
include
::
Gitlab
::
Redis
::
SessionsStoreHelper
def
initialize
(
remote_ip
)
@remote_ip
=
remote_ip
end
def
count_session_ip
redis_store_clas
s
.
with
do
|
redis
|
Gitlab
::
Redis
::
Session
s
.
with
do
|
redis
|
redis
.
pipelined
do
|
pipeline
|
pipeline
.
incr
(
session_lookup_name
)
pipeline
.
expire
(
session_lookup_name
,
24
.
hours
)
...
...
@@ -18,13 +17,13 @@ module Gitlab
end
def
session_count
redis_store_clas
s
.
with
do
|
redis
|
Gitlab
::
Redis
::
Session
s
.
with
do
|
redis
|
redis
.
get
(
session_lookup_name
).
to_i
end
end
def
cleanup_session_per_ip_count
redis_store_clas
s
.
with
do
|
redis
|
Gitlab
::
Redis
::
Session
s
.
with
do
|
redis
|
redis
.
del
(
session_lookup_name
)
end
end
...
...
lib/gitlab/redis/sessions_store_helper.rb
deleted
100644 → 0
View file @
1ff48797
# frozen_string_literal: true
module
Gitlab
module
Redis
module
SessionsStoreHelper
extend
ActiveSupport
::
Concern
module
StoreMethods
def
redis_store_class
use_redis_session_store?
?
Gitlab
::
Redis
::
Sessions
:
Gitlab
::
Redis
::
SharedState
end
private
def
use_redis_session_store?
Gitlab
::
Utils
.
to_boolean
(
ENV
[
'GITLAB_USE_REDIS_SESSIONS_STORE'
],
default:
true
)
end
end
include
StoreMethods
included
do
extend
StoreMethods
end
end
end
end
lib/tasks/gitlab/cleanup.rake
View file @
b296c289
...
...
@@ -100,15 +100,13 @@ namespace :gitlab do
namespace
:sessions
do
desc
"GitLab | Cleanup | Sessions | Clean ActiveSession lookup keys"
task
active_sessions_lookup_keys: :gitlab_environment
do
use_redis_session_store
=
Gitlab
::
Utils
.
to_boolean
(
ENV
[
'GITLAB_USE_REDIS_SESSIONS_STORE'
],
default:
true
)
redis_store_class
=
use_redis_session_store
?
Gitlab
::
Redis
::
Sessions
:
Gitlab
::
Redis
::
SharedState
session_key_pattern
=
"
#{
Gitlab
::
Redis
::
Sessions
::
USER_SESSIONS_LOOKUP_NAMESPACE
}
:*"
last_save_check
=
Time
.
at
(
0
)
wait_time
=
10
.
seconds
cursor
=
0
total_users_scanned
=
0
redis_store_clas
s
.
with
do
|
redis
|
Gitlab
::
Redis
::
Session
s
.
with
do
|
redis
|
begin
cursor
,
keys
=
redis
.
scan
(
cursor
,
match:
session_key_pattern
)
total_users_scanned
+=
keys
.
count
...
...
spec/initializers/session_store_spec.rb
View file @
b296c289
...
...
@@ -10,40 +10,10 @@ RSpec.describe 'Session initializer for GitLab' do
end
describe
'config#session_store'
do
context
'when the GITLAB_USE_REDIS_SESSIONS_STORE env is not set'
do
before
do
stub_env
(
'GITLAB_USE_REDIS_SESSIONS_STORE'
,
nil
)
end
it
'initialized as a redis_store with a proper servers configuration'
do
expect
(
subject
).
to
receive
(
:session_store
).
with
(
:redis_store
,
a_hash_including
(
redis_store:
kind_of
(
::
Redis
::
Store
)))
it
'initialized with Multistore as ENV var defaults to true'
do
expect
(
subject
).
to
receive
(
:session_store
).
with
(
:redis_store
,
a_hash_including
(
redis_store:
kind_of
(
::
Redis
::
Store
)))
load_session_store
end
end
context
'when the GITLAB_USE_REDIS_SESSIONS_STORE env is disabled'
do
before
do
stub_env
(
'GITLAB_USE_REDIS_SESSIONS_STORE'
,
false
)
end
it
'initialized as a redis_store with a proper servers configuration'
do
expect
(
subject
).
to
receive
(
:session_store
).
with
(
:redis_store
,
a_hash_including
(
redis_store:
kind_of
(
Redis
::
Store
)))
load_session_store
end
end
context
'when the GITLAB_USE_REDIS_SESSIONS_STORE env is enabled'
do
before
do
stub_env
(
'GITLAB_USE_REDIS_SESSIONS_STORE'
,
true
)
end
it
'initialized as a redis_store with a proper servers configuration'
do
expect
(
subject
).
to
receive
(
:session_store
).
with
(
:redis_store
,
a_hash_including
(
redis_store:
kind_of
(
::
Redis
::
Store
)))
load_session_store
end
load_session_store
end
end
end
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