Skip to content

Commit

Permalink
audit logs for failed login attempts (#4564)
Browse files Browse the repository at this point in the history
* audit logs for failed login attempts

* updating ee ref
  • Loading branch information
alpetric authored Oct 22, 2024
1 parent ae3961e commit 18fc0e4
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 6 deletions.
2 changes: 1 addition & 1 deletion backend/ee-repo-ref.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ce38a7f85ca257c48471c46e3811a1281d9e2f27
d61c163e0a311ecd86d1398aff883eaea8d0b09a
1 change: 1 addition & 0 deletions backend/windmill-api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10735,6 +10735,7 @@ components:
- "users.delete"
- "users.update"
- "users.login"
- "users.login_failure"
- "users.logout"
- "users.accept_invite"
- "users.decline_invite"
Expand Down
28 changes: 23 additions & 5 deletions backend/windmill-api/src/users.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2290,6 +2290,8 @@ async fn login(
) -> Result<String> {
let mut tx = db.begin().await?;
let email = email.to_lowercase();
let audit_author =
AuditAuthor { email: email.clone(), username: email.clone(), username_override: None };
let email_w_h: Option<(String, String, bool, bool)> = sqlx::query_as(
"SELECT email, password_hash, super_admin, first_time_user FROM password WHERE email = $1 AND login_type = \
'password'",
Expand All @@ -2305,6 +2307,16 @@ async fn login(
.verify_password(password.as_bytes(), &parsed_hash)
.is_err()
{
audit_log(
&mut *tx,
&audit_author,
"users.login_failure",
ActionKind::Create,
"global",
None,
None,
)
.await?;
Err(Error::BadRequest("Invalid login".to_string()))
} else {
if first_time_user {
Expand All @@ -2330,11 +2342,7 @@ async fn login(

audit_log(
&mut *tx,
&AuditAuthor {
username: email.clone(),
email: email.clone(),
username_override: None,
},
&audit_author,
"users.login",
ActionKind::Create,
"global",
Expand All @@ -2347,6 +2355,16 @@ async fn login(
Ok(token)
}
} else {
audit_log(
&mut *tx,
&audit_author,
"users.login_failure",
ActionKind::Create,
"global",
None,
None,
)
.await?;
Err(Error::BadRequest("Invalid login".to_string()))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@
USERS_SETPASSWORD: 'users.setpassword',
USERS_UPDATE: 'users.update',
USERS_LOGIN: 'users.login',
USERS_LOGIN_FAILURE: 'users.login_failure',
USERS_LOGOUT: 'users.logout',
USERS_ACCEPT_INVITE: 'users.accept_invite',
USERS_DECLINE_INVITE: 'users.decline_invite',
Expand Down

0 comments on commit 18fc0e4

Please sign in to comment.