Skip to content

Commit

Permalink
keep track of login attempts, both successful and failures
Browse files Browse the repository at this point in the history
and show them in the account and admin interfaces. this should help with
debugging, to find misconfigured clients, and potentially find attackers trying
to login.

we include details like login name, account name, protocol, authentication
mechanism, ip addresses, tls connection properties, user-agent. and of course
the result.

we group entries by their details. repeat connections don't cause new records
in the database, they just increase the count on the existing record.

we keep data for at most 30 days. and we keep at most 10k entries per account.
to prevent unbounded growth. for successful login attempts, we store them all
for 30d. if a bad user causes so many entries this becomes a problem, it will
be time to talk to the user...

there is no pagination/searching yet in the admin/account interfaces. so the
list may be long. we only show the 10 most recent login attempts by default.
the rest is only shown on a separate page.

there is no way yet to disable this. may come later, either as global setting
or per account.
  • Loading branch information
mjl- committed Feb 6, 2025
1 parent d08e0d3 commit 1277d78
Show file tree
Hide file tree
Showing 34 changed files with 1,676 additions and 206 deletions.
5 changes: 5 additions & 0 deletions admin/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,11 @@ func AccountRemove(ctx context.Context, account string) (rerr error) {
return fmt.Errorf("account removed, but removing tls public keys failed: %v", err)
}

if err := store.LoginAttemptRemoveAccount(context.Background(), account); err != nil {
log.Errorx("removing historic login attempts for removed account", err)
return fmt.Errorf("account removed, but removing historic login attempts failed: %v", err)
}

log.Info("account removed", slog.String("account", account))
return nil
}
Expand Down
4 changes: 2 additions & 2 deletions ctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ func servectlcmd(ctx context.Context, ctl *ctl, cid int64, shutdown func()) {
*/

to := ctl.xread()
a, addr, err := store.OpenEmail(log, to, false)
a, _, addr, err := store.OpenEmail(log, to, false)
ctl.xcheck(err, "lookup destination address")

msgFile, err := store.CreateMessageTemp(log, "ctl-deliver")
Expand Down Expand Up @@ -1155,7 +1155,7 @@ func servectlcmd(ctx context.Context, ctl *ctl, cid int64, shutdown func()) {
if name != "" {
tlspubkey.Name = name
}
acc, _, err := store.OpenEmail(ctl.log, loginAddress, false)
acc, _, _, err := store.OpenEmail(ctl.log, loginAddress, false)
ctl.xcheck(err, "open account for address")
defer func() {
err := acc.Close()
Expand Down
Loading

0 comments on commit 1277d78

Please sign in to comment.