Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
nexus
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
flg_projects
nexus_vdi
nexus
Commits
ab5a566b
Commit
ab5a566b
authored
1 month ago
by
Florent Gluck
Browse files
Options
Downloads
Patches
Plain Diff
server: users are now locked according to the number of attempts for a given ip
bumped server version to 1.11.6
parent
df90f138
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/server/router/auth.go
+13
-6
13 additions, 6 deletions
src/server/router/auth.go
src/server/version/version.go
+1
-1
1 addition, 1 deletion
src/server/version/version.go
with
14 additions
and
7 deletions
src/server/router/auth.go
+
13
−
6
View file @
ab5a566b
...
...
@@ -27,7 +27,12 @@ type auth struct {
tokenAccess
middleware
.
JWTConfig
}
var
loginAttempts
map
[
string
]
int
// Number of consecutive wrong logins for the same user
type
userRequest
struct
{
email
string
ip
string
}
var
loginAttempts
map
[
userRequest
]
int
// Number of consecutive wrong logins for the same user
var
loginAttemptsMutex
*
sync
.
Mutex
var
lockedUsers
map
[
string
]
time
.
Time
// Locked users and timestamps when their accounts were locked
...
...
@@ -37,7 +42,7 @@ var jwtSecretKey string
// Creates an auth object.
func
NewAuth
(
u
*
users
.
Users
)
(
*
auth
,
error
)
{
loginAttempts
=
make
(
map
[
string
]
int
)
loginAttempts
=
make
(
map
[
userRequest
]
int
)
loginAttemptsMutex
=
new
(
sync
.
Mutex
)
lockedUsers
=
make
(
map
[
string
]
time
.
Time
)
lockedUsersMutex
=
new
(
sync
.
Mutex
)
...
...
@@ -115,20 +120,21 @@ func (auth *auth) Login(c echo.Context) error {
err
=
bcrypt
.
CompareHashAndPassword
([]
byte
(
user
.
Pwd
),
[]
byte
(
reqUser
.
Pwd
))
// If err == nil, passwords match!
userReq
:=
userRequest
{
email
:
user
.
Email
,
ip
:
c
.
RealIP
()}
if
err
==
nil
{
loginAttemptsMutex
.
Lock
()
loginAttempts
[
user
.
Email
]
=
0
loginAttempts
[
user
Req
]
=
0
loginAttemptsMutex
.
Unlock
()
}
else
{
// Stores the number of attempted logins.
loginAttemptsMutex
.
Lock
()
count
,
found
:=
loginAttempts
[
user
.
Email
]
count
,
found
:=
loginAttempts
[
user
Req
]
if
found
{
count
=
count
+
1
}
else
{
count
=
1
}
loginAttempts
[
user
.
Email
]
=
count
loginAttempts
[
user
Req
]
=
count
loginAttemptsMutex
.
Unlock
()
log
.
Info
(
"Login attempt "
,
count
,
" for user "
,
user
.
Email
,
", source ip="
,
c
.
RealIP
())
if
count
>
conf
.
Auth
.
MaxLoginAttempts
{
...
...
@@ -207,7 +213,8 @@ func UnlockUser(c echo.Context, emailToUnlock string) error {
// unlock user by removing it from the locked map
delete
(
lockedUsers
,
emailToUnlock
)
loginAttemptsMutex
.
Lock
()
loginAttempts
[
emailToUnlock
]
=
0
// reset the number of attempts
userReq
:=
userRequest
{
email
:
userEmail
,
ip
:
c
.
RealIP
()}
loginAttempts
[
userReq
]
=
0
// reset the number of attempts
loginAttemptsMutex
.
Unlock
()
log
.
Info
(
"User "
,
userEmail
,
" unlocked user "
,
emailToUnlock
,
", source ip="
,
c
.
RealIP
())
return
nil
...
...
This diff is collapsed.
Click to expand it.
src/server/version/version.go
+
1
−
1
View file @
ab5a566b
...
...
@@ -7,7 +7,7 @@ import (
const
(
major
=
1
minor
=
11
bugfix
=
5
bugfix
=
6
)
var
version
params
.
Version
=
params
.
NewVersion
(
major
,
minor
,
bugfix
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment